#!/usr/bin/env bash declare -x ZIPS=/home/gene/wow/zips/ declare -x ADDONS=/home/gene/wow/addons/ declare -x CHECK=/tmp/acecheck.txt w3m -dump http://www.wowace.com/files/ -cols 10000 | \ sed -e ' 1,3d s/━*//g s/^Last up.*//g /^$/d ' > ${ZIPS}wowace # We allow ourselves to update all addons or a single addon... if [[ $1 ]]; then printf "Updating %s...\n" $1 # Make sure the requested addon actually exists locally if [[ ! $(grep "^$1 " $ZIPS/wowace) ]]; then echo "ERROR: $1 not found in zip list" exit else echo $1 > $CHECK fi else printf "Updating all addons...\n" cat $ZIPS/wowace | awk '{ print $1 }' > $CHECK fi # Update our zips to the latest version for i in $(ls $ZIPS); do ITEM=$(grep "^$i " $ZIPS/wowace) if [[ $ITEM ]]; then # Get the current version number from the web site VER=$(echo $ITEM | awk '{ print $2 }') URL="http://www.wowace.com/files/$i/$i-$VER.zip" # Get the version number from the local zip copy if [[ -e $ZIPS/$i/VERSION ]]; then LVER=$(cat $ZIPS$i/VERSION) else LVER=0 fi # Check the local copy against the Web site version if [[ $VER != $LVER ]]; then printf "UPDATING $i... " rm -rf $ZIPS$i wget $URL -O /tmp/ace.zip --quiet # Exit the script if we didn't get a zip file downloaded if [[ ! -e /tmp/ace.zip ]]; then printf "ERROR fetching $URL\n" exit fi # Unzip that file locally and store the version number we downloaded unzip -q /tmp/ace.zip -d $ZIPS echo $VER > $ZIPS$i/VERSION rm /tmp/ace.zip printf "DONE\n" # We already have the current version... else # Be more verbose if we're only after a single addon if [[ $1 ]]; then printf "$1's local zip copy is already at the current version: $VER\n" fi fi fi done # Only review Addons that are also Ace... cat $CHECK | awk '{ print $1 }' | ( while read ACE; do # FIRST: Look at the Zips archive ... # We want to find new or altered files/directories if [ -d "$ZIPS$ACE" ]; then # For all the files in this zip... find "$ZIPS$ACE" | ( while read FILE; do ZIPS_FILE="$FILE" ADDONS_FILE="$ADDONS${FILE#$ZIPS}" # If we are missing this file/directory, add it... if [ ! -e "$ADDONS_FILE" ]; then cp -rf "$ZIPS_FILE" "$ADDONS_FILE" svn add "$ADDONS_FILE" # They both exist, but may be different... # And if this is a file... elif [ -f "$ZIPS_FILE" ]; then #echo "ZIPS_FILE: $ZIPS_FILE .... ADDONS_FILE: $ADDONS_FILE" if [[ $(diff "$ZIPS_FILE" "$ADDONS_FILE") ]]; then cp -rf "$ZIPS_FILE" "$ADDONS_FILE" fi fi done ) fi # SECOND: Look at the local Addon store ... # We want to find files/directories that are no longer needed if [ -d "$ADDONS$ACE" ]; then # A small sanity check... if [ ! -d "$ZIPS$ACE" ]; then echo "FATAL ERROR: I don't have this in ZIPS! ($ZIPS)" exit fi # For files in this addon... find "$ADDONS$ACE" | egrep -v "(\.svn|\.$)" | ( while read FILE; do ZIPS_FILE="$ZIPS${FILE#$ADDONS}" ADDONS_FILE="$FILE" # If this file is no longer in the zips... if [ ! -e "$ZIPS_FILE" ]; then svn delete "$ADDONS_FILE" fi done ) # Commit any changes... VER=$(cat $ZIPS$ACE/VERSION) svn commit "$ADDONS$ACE" -m "Updating $ACE to version $VER" fi done ) exit