Hi all, Following my earlier post about a script which installs applications after unattended has finished, here is the script I use.
I run the script remotely using cygwin. At the moment, it's run manually as and when required. I propose to automate this using the cyg-apt.py script from <http://www.lilypond.org/cygwin/cyg-apt> and cron. The intention is to allow machines to periodically check for newly 'approved' software in our group and install it. This script is designed to be run under cygwin via ssh. Feel free to comment, adapt or otherwise use this. Yours, Frank #!/bin/sh # Addapp.sh - a shell script to re-start the 'unattended' procedure # on a workstation and run aribitrary numbers of batch files # (C) Frank Lee 2004 for Unattended.sourceforge.net # begin DEBUG # set -xv set -e # end DEBUG # Some definitions appropriate to the distribution # The usual unattended meanings here Z_PATH='\\ntserver\install' Z_USER=guest Z_PASS=guest # Machine will automatically log in as $UDOMAIN/$UUSER using $UPASS as a password UUSER=Administrator UPASS=SecretWord UDOMAIN=`hostname` # DEFDOM is the default domain for users to log into # (They never check...) DEFDOM=OURDOMAIN ## No user serviceable parts inside ## # fake echo command ECHO="/usr/bin/echo -e -n" CRLF="\\r\\n" # Test for valid number of applications APPS="$@" if [ -z $APPS ] ; then cat <<EOF Usage: $0 application [ application [ application ... ]] where application is the name of the .bat file in z:\scripts example: $0 acrobat.bat textpad.bat EOF exit fi # Check for Perl: first native win32 $ECHO Searching for Perl: WINPERL=1 PERL=`ls -1 /cygdrive/*/Perl/bin/perl.exe | tail -1` if [ -z $PERL ] ; then # Or in the default location \Perl\bin\perl.exe elsewhere PERL=`which perl` WINPERL=0 $ECHO Using CYGWIN\'s perl interpreter. This might not work properly. \\n else $ECHO ' 'Perl for WIN32 found. \\n fi if [ -z $PERL ] ; then $ECHO Not found \\n $ECHO Please install perl and then try again. \\n exit fi # Might not have OS installed on c: # Will unattended's scripts handle this? C=`echo $SYSTEMROOT | sed s/:.*//` # Create netinst/logs directories mkdir -p /cygdrive/$C/netinst/logs # Find a free drive letter $ECHO Searching for a free drive letter ... Z=empty for TESTDRIVE in z y x w v u t s r q p o n m l k j i h g f e d c ; do if ( [ $Z = empty ] && [ ! -d /cygdrive/$TESTDRIVE ] ) ; then Z=$TESTDRIVE: CYGZ=$TESTDRIVE fi done if [ $Z = empty ] ; then $ECHO None available.\\n $ECHO You have 24 mounted filesystems, apparently.\\n exit fi $ECHO $Z \(/cygdrive/$CYGZ\) works for me. \\n # Map the network drive $ECHO Mounting $Z_PATH: \\n net use $Z $Z_PATH $Z_PASS /user:$Z_USER # Check that this is the right-looking place if [ ! -f /cygdrive/$CYGZ/bin/autolog.pl ] ; then echo Unable to map drive. Baling out. exit fi # Create tempcred.bat $ECHO Creating tempcred.bat, $ECHO @SET Z_USER=$Z_USER$CRLF >/cygdrive/$C/netinst/tempcred.bat $ECHO @SET Z_PASS=$Z_PASS$CRLF >>/cygdrive/$C/netinst/tempcred.bat # Create permcred.bat $ECHO ' 'permcred.bat, $ECHO @SET Z=$Z$CRLF >/cygdrive/$C/netinst/permcred.bat $ECHO @SET Z_PATH='\\'$Z_PATH$CRLF >>/cygdrive/$C/netinst/permcred.bat # Create UserWarn.vbs $ECHO ' 'userwarn.vbs, ( $ECHO 'msgbox "Maintenance is required on this machine. "&chr(10)&chr(13) & _ ' $CRLF $ECHO ' "Please reboot this machine as soon as convenient. ",0,"'$DEFDOM' Admin Message"' $CRLF ) >/cygdrive/$C/netinst/userwarn.vbs # Create addapp.bat $ECHO ' 'addapp.bat ( $ECHO @ECHO OFF$CRLF $ECHO if %USERNAME%==$UUSER goto good$CRLF $ECHO wscript $C':\\netinst\\userwarn.vbs'$CRLF $ECHO goto end$CRLF $ECHO :good$CRLF $ECHO rundll32.exe user32.dll,LockWorkStation$CRLF $ECHO del $C:'\\netinst\\userwarn.vbs'$CRLF $ECHO call $C:'\\netinst\\mapznrun.bat '$Z:'\\bin\\todo.pl --go'$CRLF $ECHO :end ) >/cygdrive/$C/netinst/addapp.bat $ECHO done \\n # copy mapznrun.bat $ECHO Copying mapznrun.bat, cp /cygdrive/$CYGZ/bin/mapznrun.bat /cygdrive/$C/netinst/ $ECHO ' 'completed. \\n # Set autologon to Administrator account as unattended. $ECHO Configuring auto-logon for $UUSER ... if [ $WINPERL -eq 1 ] ; then AULOGON=$Z\\bin\\autolog.pl TODO=$Z\\bin\\todo.pl else AULOGON=/cygdrive/$CYGZ/bin/autolog.pl TODO=/cygdrive/$CYGZ/bin/todo.pl fi $PERL $AULOGON --logon=1 --user=$UUSER --password=$UPASS --domain=$UDOMAIN $ECHO ' 'done.\\n # Set registry to lock workstation at next logon # and to run the logoff script. $ECHO Finding a spare file ... FILE=lk`date | md5sum | sed s/........................// | sed s/\ .*//`.reg while [ -f /tmp/$FILE ] ; do FILE=lk`date | md5sum | sed s/........................// | sed s/\ .*//`.reg done $ECHO ' '\($FILE\)\, adding registry settings ... ( $ECHO REGEDIT4 $CRLF $ECHO $CRLF $ECHO [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run] $CRLF $ECHO \"AddApp\"=\"cmd /c $C:'\\\\netinst\\\\addapp.bat'\" $CRLF ) >/tmp/$FILE $ECHO ' 'done. \\n $ECHO Locating cygwin in DOS space: CYGDRIVE=`ls -d1 /cygdrive/*/cygwin/tmp/$FILE | sed sZ/cygdrive/ZZ | sed sZ/.*ZZ | tail -1` $ECHO ' '$CYGDRIVE:'\\cygwin' \\n $ECHO Processing registry file $FILE ... regedit /s $CYGDRIVE:\\cygwin\\tmp\\$FILE $ECHO completed.\\n $ECHO Filling $FILE with settings to undo autologon ... # Prepare a registry file to undo that change ( $ECHO REGEDIT4 $CRLF $ECHO $CRLF $ECHO [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run] $CRLF $ECHO \"Addpp\"=- $CRLF $ECHO $CRLF ) >/tmp/$FILE $ECHO ' 'done.\\n # Start to push commands onto the unattended stack $ECHO Adding commands to todo.txt: $PERL $TODO ".reboot" $PERL $TODO "del $CYGDRIVE:\\cygwin\\tmp\\$FILE" $PERL $TODO "regedit /s $CYGDRIVE:\\cygwin\\tmp\\$FILE" $PERL $TODO "autolog.pl --logon=0 --domain=$DEFDOM" for APP in $APPS ; do $PERL $TODO $APP done $PERL $TODO "del $WINDIR\system32\GroupPolicy\User\Scripts\Logoff\reboot.bat" $ECHO ' 'done.\\n # Finished with network connections $ECHO Removing network connections: \\n net use '*' /y /del $ECHO This machine - `hostname` - will begin installation at the next reboot.\\n # Do nothing else: Wait until user reboots ... ------------------------------------------------------- This SF.Net email is sponsored by: SourceForge.net Broadband Sign-up now for SourceForge Broadband and get the fastest 6.0/768 connection for only $19.95/mo for the first 3 months! http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click _______________________________________________ unattended-info mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/unattended-info
