Difference between revisions of "Bash the wiki"

From Whitespace (Hackerspace Gent)
Jump to: navigation, search
Line 46: Line 46:
 
cd ~/root/extensions
 
cd ~/root/extensions
  
extensions=( Validator Maps SemanticMediaWiki SemanticDrilldown SemanticMaps SemanticForms SemanticResultFormats '''Awesomeness''' SemanticCompoundQueries ParserFunctions Widgets RSS googleAnalytics Cite ConfirmEdit LiquidThreads )
+
extensions=( Validator Maps SemanticMediaWiki SemanticDrilldown SemanticMaps SemanticForms SemanticResultFormats '''Awesomeness''' SemanticCompoundQueries ParserFunctions Widgets RSS googleAnalytics Cite ConfirmEdit LiquidThreads SemanticFormsInputs )
  
 
for i in ${extensions[@]}; do
 
for i in ${extensions[@]}; do
Line 101: Line 101:
 
# Confirmation by authentication
 
# Confirmation by authentication
 
echo "You are about to change $change for $space wiki"
 
echo "You are about to change $change for $space wiki"
ssh-add ~/.ssh/hackerspacebe.openssh
+
ssh-add ~/.ssh/hackerspacebe
  
  
Line 108: Line 108:
 
tempfolder="~/temp"
 
tempfolder="~/temp"
 
echo "Preparing temporary directory..."
 
echo "Preparing temporary directory..."
ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "rm -r -f $tempfolder/*"
+
ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "rm -r -f $tempfolder/*"
  
  
Line 125: Line 125:
  
  
# Upload all stuff the should be changed to temp dir
+
#Upload all stuff the should be changed to temp dir
 
for i in ${changes[@]}; do
 
for i in ${changes[@]}; do
 
     if [ $i == "core" ]; then
 
     if [ $i == "core" ]; then
 
echo "Uploading MediaWiki core to temp dir..."
 
echo "Uploading MediaWiki core to temp dir..."
ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "mkdir -p $tempfolder/phase3"
+
ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "mkdir -p $tempfolder/phase3"
scp -r -i ~/.ssh/hackerspacebe.openssh ~/export/phase3 hackerspace@hackerspace.be:$tempfolder
+
scp -r -i ~/.ssh/hackerspacebe ~/export/phase3 hackerspace@hackerspace.be:$tempfolder
 
     else
 
     else
 
echo "Uploading extension $i to temp dir..."
 
echo "Uploading extension $i to temp dir..."
ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "mkdir -p $tempfolder/extensions/$i"
+
ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "mkdir -p $tempfolder/extensions/$i"
scp -r -i ~/.ssh/hackerspacebe.openssh ~/export/extensions/$i hackerspace@hackerspace.be:$tempfolder/extensions
+
scp -r -i ~/.ssh/hackerspacebe ~/export/extensions/$i hackerspace@hackerspace.be:$tempfolder/extensions
 
     fi
 
     fi
 
done
 
done
Line 159: Line 159:
 
     # Make a backup
 
     # Make a backup
 
     echo "  Creating backup of $wikifolder at $oldfolder..."
 
     echo "  Creating backup of $wikifolder at $oldfolder..."
     ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "rm -r -f $oldfolder; mkdir -p $oldfolder; cp -r $wikifolder/* $oldfolder"
+
     ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "rm -r -f $oldfolder; mkdir -p $oldfolder; cp -r $wikifolder/* $oldfolder"
  
 
     for change in ${changes[@]}; do
 
     for change in ${changes[@]}; do
 
if [ $change == "core" ]; then
 
if [ $change == "core" ]; then
 
    echo "  Updating MediaWiki core..."
 
    echo "  Updating MediaWiki core..."
    ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "cp -r -f $tempfolder/phase3/* $wikifolder"
+
    ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "cp -r -f $tempfolder/phase3/* $wikifolder"
 
else
 
else
 
    echo "  Updating extension $change..."
 
    echo "  Updating extension $change..."
    ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "rm -r -f $wikifolder/extensions/$change; cp -r $tempfolder/extensions/$change* $wikifolder/extensions/$change"
+
    ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "rm -r -f $wikifolder/extensions/$change; cp -r $tempfolder/extensions/$change $wikifolder/extensions/$change"
 
fi
 
fi
 
     done
 
     done
  
     ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "php $wikifolder/maintenance/update.php"
+
     ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "php $wikifolder/maintenance/update.php"
  
 
     if [ "$1" == "jobs" ]; then
 
     if [ "$1" == "jobs" ]; then
ssh -i ~/.ssh/hackerspacebe.openssh hackerspace@hackerspace.be "php $wikifolder/maintenance/runJobs.php"
+
ssh -i ~/.ssh/hackerspacebe hackerspace@hackerspace.be "php $wikifolder/maintenance/runJobs.php"
 
     fi
 
     fi
  

Revision as of 01:40, 7 November 2010


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."