#! /usr/bin/perl -w ### # # logout.hook for a radmind client, perl-style. # Requires the radmind client tools. # (See http://rsug.itd.umich.edu/software/radmind) # ### ### # Copyright (c) 2002 Regents of The University of Michigan. # All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appears in all copies and # that both that copyright notice and this permission notice appear # in supporting documentation, and that the name of The University # of Michigan not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. This software is supplied as is without expressed or # implied warranties of any kind. # # Research Systems Unix Group # The University of Michigan # c/o Wesley Craig # 4251 Plymouth Road B1F2, #2600 # Ann Arbor, MI 48105-2785 ### # be strict use strict; # TLS Auth level. 0: None; 1: Verify Server; 2: Verify Server & Client my ( $authlevel ) = "-w 2"; my ( $rserver ) = "-h server.radmind..edu"; my ( $cksum ) = ""; my ( $fsdiffpath ) = "/"; my ( $fsdiffoutput ) = "/tmp/diff.T.$$"; my ( $fsdsize ); my ( $rc ); my ( $oldhandle ); # Turn on autoflush feature, to prevent buffering. $|++; $oldhandle = select( STDERR ); $|++; select( $oldhandle ); chdir( "/" ); # messages to stdout will be displayed in iHook's window print "Checking for updates on the server...\n"; # iHook Directives begin with a % sign, and are read on stdout. %<0-100> sets a # progress bar to a corresponding level of completion, e.g., %50 sets the # progress bar to half full. %0 begins a progress bar, and sets it to 0% done: print "%0\n"; # We want ktcheck's output to be displayed in the drawer, so we # redirect it to stderr: $rc = system( "/usr/local/bin/ktcheck -c sha1 $authlevel $rserver 1>&2" ); $rc = ( $rc / 256 ); if ( $rc == 0 ) { print( "No updates.\n" ); sleep( 2 ); exit( 0 ); } elsif ( $rc == 1 ) { print( "Updates found.\n" ); } else { print( "ktcheck failed!\n" ); exit( $rc ); } # update the progress bar to indicate that ktcheck has finished. # This number is arbitrary: you may feel that ktcheck # constitutes more or less than 20% of the script. print "%20\n"; # run fsdiff, redirecting output to a file. Error messages will automatically # appear in the drawer. # # This loops, re-running fsdiff and lapply if necessary. while ( 1 ) { # update the message in the iHook window print "Examining the filesystem for differences...\n"; $rc = system( "/usr/local/bin/fsdiff -A $cksum $fsdiffpath > $fsdiffoutput" ); $rc = ( $rc / 256 ); if ( $rc != 0 ) { print( "fsdiff failed!\n" ); exit( $rc ); } # update the progress bar. Again, this number is arbitrary. print "%70\n"; # check the output file size. If 0, skip the lapply step. $fsdsize = ( stat( $fsdiffoutput ))[ 7 ]; if ( $fsdsize > 0 ) { # update the message in the iHook window print( "Applying changes....\n" ); # run lapply. We want its output in the drawer, so we redirect it to stderr: $rc=system( "/usr/local/bin/lapply $cksum $authlevel $rserver $fsdiffoutput 1>&2" ); $rc = ( $rc / 256 ); if ( $rc == 0 ) { last; } elsif ( $rc == 1 ) { print( "Apply failed, no changes made.\n" ); exit( 1 ); } elsif ( $rc == 2 ) { print( "Apply failed, trying again...\n" ); print( "%OPENDRAWER\n" ); sleep( 2 ); print( "%50\n" ); redo; } } else { last; } } # script finished, end progress bar. %100 fills the progress bar and removes it # from the screen print "%100\n"; print "Update complete - rebooting.\n"; sleep( 2 ); system( "/sbin/reboot" );