Bash the wiki

From Whitespace (Hackerspace Gent)
Revision as of 00:40, 7 November 2010 by Jeroen De Dauw (Talk | contribs)

Jump to: navigation, search


Bash the wiki
WhitespaceLogo.gif
What:
Bash script for updating the wiki codebase
Participants:
Jeroen De Dauw


Cornify
Newfag bash script for updating the hackerspace wiki's from a local install.

TODO's

Sorted DESC on added awesomeness:

  • Run maintenance/update.php after copying of code
  • Archive the stuff before uploading and unarchive to upload folder on the server
  • Add option to update a wiki from what's in the upload folder
  • Have an option to run maintenance/runJobs.php after copying of code

Teh script

#! /bin/bash

# set -x

echo "Initiating update of hackerspace wiki(s)..."



# Update local code first
#svnup.sh



# Svn export
echo "Preparing export directories..."
rm -r -f ~/export
mkdir ~/export
mkdir ~/export/extensions



echo "Initiating svn export..."

cd ~/root
svn export phase3 ~/export/phase3

cd ~/root/extensions

extensions=( Validator Maps SemanticMediaWiki SemanticDrilldown SemanticMaps SemanticForms SemanticResultFormats '''Awesomeness''' SemanticCompoundQueries ParserFunctions Widgets RSS googleAnalytics Cite ConfirmEdit LiquidThreads SemanticFormsInputs )

for i in ${extensions[@]}; do
    if [ -d $i ]; then
	svn export $i ~/export/extensions/$i;
    fi
done

echo "... svn export finished."



in_array(){
    local i
    needle=$1
    shift 1
    # array() undefined
    [ -z "$1" ] && return 1
    for i in $*
    do
	    [ "$i" == "$needle" ] && return 0
    done
    return 1
}

get_changes(){
    echo "Choose the stuff to update:"
    select change in ${changes[@]} ${extensions[@]}; do
	if in_array $change ${changes[@]} ${extensions[@]}; then
	    break
	fi
    done
}

get_space(){
    echo "Choose the space:"
    select space in "all" ${spaces[@]}; do
	if in_array $space "all" ${spaces[@]}; then
	    break
	fi
    done
}

spaces=( ghent brussels )

get_space

changes=( all core extensions )

get_changes



# Confirmation by authentication
echo "You are about to change $change for $space wiki"
ssh-add ~/.ssh/hackerspacebe



# Clear temp folder
tempfolder="~/temp"
echo "Preparing temporary directory..."
ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "rm -r -f $tempfolder/*"



# Normalize changes list
if [ $change == "all" ]; then
    changes=( "core" ${extensions[@]} )
elif [ $change == "extensions" ]; then
    changes=( ${extensions[@]} )
elif [ $change == "core" ]; then
    changes=( "core" )
else
    changes=( $change )
fi



#Upload all stuff the should be changed to temp dir
for i in ${changes[@]}; do
    if [ $i == "core" ]; then
	echo "Uploading MediaWiki core to temp dir..."
	ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "mkdir -p $tempfolder/phase3"
	scp -r -i ~/.ssh/hackerspacebe ~/export/phase3 hackerspace@hackerspace.be:$tempfolder
    else
	echo "Uploading extension $i to temp dir..."
	ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "mkdir -p $tempfolder/extensions/$i"
	scp -r -i ~/.ssh/hackerspacebe ~/export/extensions/$i hackerspace@hackerspace.be:$tempfolder/extensions
    fi
done



# Normalize spaces list
if [ $space != "all" ]; then
    spaces=( $space )
fi

# Space path info
declare -A options
options[ghent]="smw"
options[brussels]="smw"

# Apply the changes for all spaces
for space in ${spaces[@]}; do
    echo "Starting update of $space wiki..."

    wikifolder="~/$space/www/${options[$space]}"
    oldfolder="~/$space/www/smw-old"

    # Make a backup
    echo "  Creating backup of $wikifolder at $oldfolder..."
    ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "rm -r -f $oldfolder; mkdir -p $oldfolder; cp -r $wikifolder/* $oldfolder"

    for change in ${changes[@]}; do
	if [ $change == "core" ]; then
	    echo "  Updating MediaWiki core..."
	    ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "cp -r -f $tempfolder/phase3/* $wikifolder"
	else
	    echo "  Updating extension $change..."
	    ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "rm -r -f $wikifolder/extensions/$change; cp -r $tempfolder/extensions/$change $wikifolder/extensions/$change"
	fi
    done

    ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "php $wikifolder/maintenance/update.php"

    if [ "$1" == "jobs" ]; then
	ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "php $wikifolder/maintenance/runJobs.php"
    fi

    echo "... $space wiki updated."
done



echo "... all wiki's have been updated."