• 0

    posted a message on Small BASH script for Subversion junkies
    I'm not recommending this script for general consumption. It seems stable and useful to me and I thought there might be a few people like myself who would find it helpful.

    Those who would find this script interesting, need to possess all of the following characteristics:

    • You maintain your own personal set of addons in your own Subversion repository
    • You prefer to work in a Linux shell environment (OSX is likely fine, possibly Cygwin for Windows)
    • You have basic GNU tools available, like "unzip, wget, diff, find"
    • You are comfortable working with BASH scripts
    [br]This script does basically the following in this order:

    • It downloads the contents of http://www.wowace.com/files/ to get a list of all addons and their current version numbers.
    • It figures out whether to download one or all addons
    • It updates our local copies of zip files to their latest version for addons in use
    • It looks at the zips and finds what files or directories have been added that our repository doesn't yet contain, and adds them
    • It looks at the repository for files it contains that are no longer present in the zip files, and deletes those
    [br]This assumes three things about your computer's file system:

    • You have your subversion-based addons checked out in a distinct location: e.g., /home/user/wow/addons
    • You have your zip files in a distinct location: e.g., /home/user/wow/zips
    • You have a temporary storage directory: e.g., /tmp

    I manage my addons on one of my Ubuntu servers at home and when I get some time to play WoW, I reboot my workstation into Windows and use TortoiseSVN to update my addons from my own repository on a home server over WebDAV: https://servername/svn/addons/

    Additionally, I have a number of addons from multiple places, but 80% of them are Ace. I only want this script to update the Ace addons. I also prefer to only update the differences, for the sake of storage on my Subversion server, and to keep my commits at a per-addon level, so that I can roll back any one addon independently of the others. Finally, I want this to be cron-able at a respectful interval for the http://www.wowace.com web site (e.g., weekly or so). This does not touch svn.wowace.com at all: it gets all content via zip file downloads and only downloads those that have been updated since the last time the script was run.

    Anyway, it's nothing fancy, but maybe someone out there in the minority might find it either useful, interesting, or helpful in some manner. I'm both attaching it and attempting to post it inline here ...not sure if the inline posting will leave it intact.


    #!/usr/bin/env bash
    declare -x ZIPS=/home/user/Ace2/zips/
    declare -x ADDONS=/home/user/Addons/
    declare -x CHECK=/tmp/acecheck.txt
    w3m -dump [url]http://www.wowace.com/files/[/url] -cols 10000 | \
      sed -e '
          s/^Last up.*//g
          ' > ${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"
        echo $1 > $CHECK
      printf "Updating all addons...\n"
      cat $ZIPS/wowace | awk '{ print $1 }' > $CHECK
    # 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 }')
        # Get the version number from the local zip copy
        if [[ -e $ZIPS/$i/VERSION ]]; then
          LVER=$(cat $ZIPS$i/VERSION)
        # 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"
          # 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...
          # 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"
    # 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
              # 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"
        # 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)"
          # For files in this addon...
          find "$ADDONS$ACE" | egrep -v "(\.svn|\.$)" |
            while read FILE; do
              # If this file is no longer in the zips...
              if [ ! -e "$ZIPS_FILE" ]; then
                svn delete "$ADDONS_FILE"
          # Commit any changes...
          VER=$(cat $ZIPS$ACE/VERSION)
          svn commit "$ADDONS$ACE" -m "Updating $ACE to version $VER"
    Posted in: General Chat
  • To post a comment, please or register a new account.