#!/bin/bash
#* -------------------------------------------------------------------------- */
#*                              Windows Server                                */
#*                                                                            */
#*                appliance.sh - Appliance controlling script                 */
#* -------------------------------------------------------------------------- */
#* Copyright (C) 2008 3Tera, Inc. All rights reserved.                        */
#*                                                                            */
#* Use of this notice does not imply publication or disclosure.               */
#* This software contains CONFIDENTIAL and PROPRIETARY information            */
#* constituting valuable TRADE SECRETS of 3Tera, Inc., which may be disclosed */
#* by 3Tera, Inc., only under strict limitations on its use and               */
#* confidentiality, and may not be (a) disclosed to third parties,            */
#* (b) copied in any form, or (c) used for any purpose except as specifically */
#* permitted in writing by 3Tera, Inc.                                        */
#* In addition, any hard-copy, printout or other tangible expression of this  */
#* software must include on every page thereof the copyright notice contained */
#* herein and the phrase "3TERA CONFIDENTIAL - HIGHLY PROPRIETARY".           */
#* -------------------------------------------------------------------------- */

source /var/run/applogic/appliance.sh

PWDFILE=/appliance/passwd.stamp

case "$1" in
   start)
      # determine if Administrator's password needs to be changed
      gen_pwd=1
      current_name="$__APP_NAME:$__COMP_NAME"
      if [ -f $PWDFILE ]; then
         old_name=`cat $PWDFILE`
         [ "$current_name" == "$old_name" ] && gen_pwd=0
      fi

      # generate new password
      if [ $gen_pwd -ne 0 ]; then
         newpwd=`dd if=/dev/random bs=1024 count=1 2>/dev/null | md5sum | cut -f1 -d' '`
         net user Administrator $newpwd
         echo "$current_name" > $PWDFILE
      fi
      # IIS (Props) init
      if [ -x /appliance/iis_init.sh ]; then
         /appliance/iis_init.sh
      fi
      # IIS counters
      if [ -x /usr/bin/iismon.pl ]; then
         cd /usr/bin && ./iismon.pl &
      fi
      ;;

   stop)
      ;;

   *)
      echo "usage: $0 {start|stop}"
      exit 1

esac

exit 0

