#!/bin/bash # # update1 - NJ6N - 2008-03-31 # # Description: Installs updated crontab entries and ipchk.sh script # KERNEL=`/bin/uname -r`; UPDATE_URL="http://dsyncg2.dstarusers.org/index.php" CURL="/usr/bin/curl --connect-timeout 30 --max-time 240" DSICONF=/opt/products/dstar/dstar_gw/dsipsvd/dsipsvd.conf DSYNC=http://dsyncg2.dstarusers.org GW_CALL=`egrep -e '^ZR_CALLSIGN' $DSICONF | sed -e 's/ //g' | awk -F"=" '{print $2}' |sed -e 's/\r//'` TRUST_SERVER=`egrep -e '^TRUST_SERVER' $DSICONF | sed -e 's/ //g' | awk -F"=" '{print $2}' |sed -e 's/\r//'` IPCHK=/opt/products/dstar/dstar_gw/dsipsvd/ipchk.sh PGCONF='/opt/products/dstar/pgsql/data/postgresql.conf' # # MD5 sums of installed files # # gw_schedule script SUM1=b72ab907515cbc158c81c4d90ae28283 # crontab SUM2=d847dcfaa133e8b8cb19ce545c2ae827 # IPCheck Script SUM3=f9ec633476ba529f9f50ee25962b8d57 # postgres config SUM4=e08928a6a1c08d88186ae68349eff059 # Script updater SUM5=fc6410330c0b4135f18909aafb45cb12 if [ $EUID != 0 ] ; then echo "Update script must be run as root, aborting." exit fi # # functions # update_file () { URL=$1 FILE=$2 INSTLOC=$3 SUM=$4 cd /tmp echo `date` "Downloading $FILE ..." $CURL -O $URL/$FILE 2>/dev/null if [ $? != 0 ]; then echo `date` "Error downloading $FILE from $URL, aborting." exit fi echo -n `date` "Verifying $FILE ... " VERIFY_SUM=`/usr/bin/md5sum ./$FILE | awk '{print $1}'` if [ $VERIFY_SUM != $SUM ]; then echo echo `date` "## Invalid MD5 checksum for: $FILE, Aborting." exit; else echo "[ok]" cp $FILE $INSTLOC fi } # # Install gateway scheduler script # mkdir -p /dstar/scripts update_file $DSYNC gw_schedule /dstar/scripts/gw_schedule $SUM1 # # Install script updater script # update_file $DSYNC update_scripts_g2 /dstar/scripts/update_scripts_g2 $SUM5 # # Install new crontab # echo "Backing up current root crontab to /tmp/old_crontab." /usr/bin/crontab -u root -l > old_crontab update_file $DSYNC g2-crontab /tmp/crontab $SUM2 echo "Installing new crontab." crontab -u root /tmp/crontab # # Install updated ipchk.sh script # echo "Backing up old IPCHK script to /tmp" /bin/cp -p $IPCHK /tmp/ipchk.sh.old # update_file $DSYNC ipchk.sh $IPCHK $SUM3 # # Postgres configuration file update # echo "Updating postgres configuration file." cp $PGCONF /tmp/postgresql.conf.backup update_file $DSYNC postgresql.conf $PGCONF $SUM4 # # All done, send report to dsync site and reboot. # DATE=`date -u "+%F %T"` $CURL $UPDATE_URL \ -d gateway_call="$GW_CALL" \ -d datetime="$DATE" \ -d status="Update #1 Installed." \ -d trust="$TRUST_SERVER" \ -d notify_em="" \ -d version="$0 $VERSION
$KERNEL" > /dev/null 2>&1 echo "All done." echo "Rebooting server in 10 seconds..." sleep 10 /usr/bin/reboot exit