#! /bin/sh # # initscript # # # Scott Baker # Justin Cappos # Jeffry Johnston # Jeremy Plichta # # # Downloads and installs stork on a standalone (non-PL) machine echo "Starting Stork initscript: Stage 2" # logging: mark when the stage1 initscript started running date > /tmp/stork_initscript_stage2.log # save original PWD OLDPWD=$PWD # URL and location of install files on the repository # These are used in case the nest is offline REPO_NAME=stork-repository.cs.arizona.edu REPO_INSTALL_URL=http://$REPO_NAME/stork-install/client_rpm_list # mutual exclusion # from: http://www.unixreview.com/documents/s=9040/ur0402g/ # note: there is a race condition because test & creation of the lock file is # not atomic LOCKFILE="/tmp/stork_initscript_lock" LOCKED="" # file to hold the pid of the initscript. Created while the initscript # mutex is held. Used to prevent running of pacman. PIDFILE=/var/run/stork_initscript.pid mutex_lock() { if test -r $LOCKFILE then # If a lock file exists, check if the process that created it # is still running. PROCESS=$(cat $LOCKFILE) else PROCESS=" " fi if (ps -p $PROCESS) > /dev/null 2>&1 then echo "The Stork initscript is already running" exit 1 else # The process is not running, create new lock file containing PID. rm -f $LOCKFILE echo $$ > $LOCKFILE LOCKED="true" fi echo $$ > $PIDFILE } mutex_unlock() { rm $PIDFILE # remove the lock file if the mutex was locked if [ -n "$LOCKED" ] then rm -f $LOCKFILE LOCKED="" fi } # error reporting function error() { echo echo "Please E-mail stork-support@cs.arizona.edu if you believe you have" echo "received this message in error." # restore original PWD cd $OLDPWD mutex_unlock exit 1 } # //////////////// end common code //////////////// check_deps() { rpm -q PyXML if [ $? -ne 0 ] then echo "Stork requires PyXML. Please install PyXML and re-run this script" mutex_unlock exit 1 fi } cleanup() { # logging: move the log files out of /tmp mkdir -p /usr/local/stork/var/log/initscript mv --force /tmp/stork_initscript*.log /usr/local/stork/var/log/initscript # remove this script, its signature, and publickey from /tmp # XXX This should have been done in the the stage1 initscript, but we'll # defer until we have a valid reason to trouble PLC with new initscripts rm -f /tmp/stork-stage2-initscript.* rm -f /tmp/stork-publickey.* } # check for root user if [ $UID -ne "0" ] then echo "You must run this program with root permissions..." error fi # grab a mutex so only one initscript can run at a time mutex_lock # check dependencies check_deps # clean up in case this script was run before and failed rm -rf /tmp/stork &> /dev/null # create /tmp/stork directory mkdir /tmp/stork if [ $? -ne "0" ] then echo echo "Could not create the /tmp/stork directory..." error fi # helper function to download stork packages from the repository. First # downloads a list called 'client_rpm_list', and then downloads the RPM files # contained inside that list. repo_download() { echo "Downloading stork packages from repository..." # download the list of stork packages from the repository wget -O /tmp/stork/client_rpm_list "$REPO_INSTALL_URL" if [ ! -f /tmp/stork/client_rpm_list -o $? -ne 0 ] then echo "Failed to download $REPO_INSTALL_URL" error fi # get a list of just the stork packages (not PyXML, etc) grep -i "stork-client-" /tmp/stork/client_rpm_list > /tmp/stork/stork_rpm_list grep -i "arizona-lib-" /tmp/stork/client_rpm_list >> /tmp/stork/stork_rpm_list # now download the packages in the list wget -P /tmp/stork -i /tmp/stork/stork_rpm_list } echo "Contacting the stork nest on this node..." # logging: mark when the stage1 initscript initiated download date > /tmp/stork_initscript_stage2_predownload.log # download from repository repo_download # logging: mark when the stage1 initscript finished download date > /tmp/stork_initscript_stage2_postdownload.log # change PWD to the /tmp/stork directory cd /tmp/stork if [ $? -ne "0" ] then echo echo "Could not access the /tmp/stork directory..." error fi # confirm that packages to be installed actually exist if echo *.rpm | grep '*' > /dev/null then echo echo "Error: Stork package download failed..." error fi # build a list of packages to remove packages="" for filename in *.rpm do # convert filename to a package name pack=`rpm -qp --qf "%{NAME}\n" $filename` if [ $? -eq "0" ] then # check to make sure the package is installed before adding to remove list rpm -q $pack &> /dev/null if [ $? -eq "0" ] then packages="$packages $pack" fi fi done if [ -n "$packages" ] then # remove Stork packages and files echo echo "Removing Stork packages:$packages ..." # TODO: If PyXML is depended on, then we cannot remove it, which means we # fail to remove any of the stork packages, which in turn causes us to # fail to install any packages. # remove old Stork packages rpm -e $packages fi # remove anything left in /usr/local/stork/bin rm -rf /usr/local/stork/bin/* &> /dev/null # install Stork packages echo echo "Installing packages..." # build a list of packages to install packages="" for filename in *.rpm do packages="$packages $filename" done # install the new stork packages rpm -i $packages # report package installation errors if [ $? -ne "0" ] then echo "Warning: Possible error installing Stork packages..." fi # restore original PWD cd $OLDPWD # clean up temporary files rm -rf /tmp/stork &> /dev/null # logging: mark when the stage1 initscript started to run stork date > /tmp/stork_initscript_stage2_prerunstork.log # run stork to update keyfiles and download package lists echo echo "Attempting to communicate with stork..." if stork then echo echo "Congratulations, you have successfully bound to stork!" echo echo "For help, you may type stork --help" echo #echo "There is also a storkquery command that will provide information" #echo "about packages in the repository." echo echo "For more help, visit the stork project online at" echo "http://www.cs.arizona.edu/stork/. Please contact" echo "stork-support@cs.arizona.edu for additional assistance." else echo echo "An error occurred during install finalization... Please contact" echo "stork-support@cs.arizona.edu for assistance." mutex_unlock exit 1 fi # logging: mark when the stage1 initscript completed date > /tmp/stork_initscript_stage2_complete.log echo "user = $USER" > /tmp/stork_initscript_stage2_username.log if [ -f /etc/slicename ] then echo "/etc/slicename follows:" >> /tmp/stork_initscript_stage2_username.log cat /etc/slicename >> /tmp/stork_initscript_stage2_username.log fi # cleanup files in /tmp cleanup # done mutex_unlock exit 0