#!/bin/bash # # EDM update script: Downloads only the changed files from the server # I'm not a Bash expert, but it should work... If it doesn't, # send bug reports to: j-kroll at gmx dot de # log () { echo "$1" "$2" | tee -a log/updates } findterm () { if [ `which xfce4-terminal` ]; then TERMINAL="`which xfce4-terminal` -e"; return; elif [ `which gnome-terminal` ]; then TERMINAL="`which gnome-terminal` -e"; return; elif [ `which xterm` ]; then TERMINAL="`which xterm` -e"; return; elif [ `which konsole` ]; then TERMINAL="`which konsole` -e"; return; else TERMINAL=""; return; # No terminal found, just get the update w/o interaction fi } allocterminal () { tty -s; if [ $? -eq 0 ]; then return; fi findterm; $TERMINAL "/bin/bash -c 'TERMWAIT=1 $0'"; exit 0 } endterm () { if [ "$TERMWAIT" ]; then echo -n "Hit Return to Exit. "; read junk; fi } extract_timestamp () { local RAWSTAMP=`strings bin_unix/edm_server_32 | grep 200..`; local TSTAMP=$(date +%s -d "`echo $RAWSTAMP | awk 'BEGIN { FIELDWIDTHS="4 2 2 2 2 2" } { print $1"/"$2"/"$3, $4":"$5 }'`") # subtract 30 days if [ "x$TSTAMP" != "x" ]; then echo $[ $TSTAMP - 2592000 ]; fi } get_timestamp () { TIMESTAMP=$[ `stat -c %Y data/.update-timestamp 2>/dev/null` ]; if [ $TIMESTAMP -eq 0 ]; then log log "Warning: You have no timestamp file!" TIMESTAMP=`extract_timestamp 2>/dev/null`; if [ "x$TIMESTAMP" != "x" ]; then log "Timestamp extracted from Binary ($TIMESTAMP)". else log "Couldn't extract timestamp from binary either." log "Setting timestamp to something near the Epoch." log "No Worries Mate." TIMESTAMP=1; fi fi; } # # Mainline Code Starts Here # if [ ! -d data ]; then echo echo "EDM Data directory not found." echo "Get the full download from http://edm-fps.net/" echo exit 1; fi mkdir log 2>/dev/null; touch log/updates; allocterminal; echo "Running Update at `LC_ALL=C date`" >> log/updates echo "-----------------------------------------------" >> log/updates get_timestamp; log log -n " * Checking Server for Updates... " CHECK=$(wget http://edm-fps.net/edm/download/update.php\?timestamp=$TIMESTAMP -t 10 --spider 2>&1 | tail -n 2 | head -n 1) if [ "`echo $CHECK | grep 500`" ]; then log "$CHECK" log endterm exit 1 elif [ "`echo $CHECK | grep 406`" ]; then log "Your binaries are up-to-date." log endterm exit 0 fi log "$CHECK" log " * Downloading Update..." log ARCH=$(tempfile -s .tar.gz 2>/dev/null) if [ x$ARCH = x ]; then ARCH=/tmp/edm-update.tar.gz; fi wget -O $ARCH http://edm-fps.net/edm/download/update.php\?timestamp=$TIMESTAMP\&download=1 -t 10 if [ $? -ne 0 ]; then endterm; exit 1; fi echo TAROUT=$(tar -tf $ARCH | grep -v update-timestamp) if [ $? -ne 0 ]; then log " *** Could not read $ARCH!"; log "$TAROUT" log endterm exit 1 fi log -n "updated files: " for i in $TAROUT; do log -n "$i "; done log log echo -n "Press Enter to Update, Ctrl-C to Quit. " read junk echo log " * Extracting files..." TAROUT=`tar -zxf $ARCH 2>&1` if [ $? -ne 0 ]; then log " *** Could not unpack $ARCH!"; log "$TAROUT" log exit 1 fi log " * Binaries successfully updated!" log rm $ARCH endterm