Here it is, in case bits of it help you too:
#!/bin/bash args=("$@") if [ -z ${args[0]} -o -z ${args[1]} ] then echo "Usage: update <version_from> <version_to>" exit fi releaseFolder="../releases/The_GAE_SWF_Project_$2" zipFile="../releases/The_GAE_SWF_Project_$2.zip" ftpFolder="/public_html/downloads/" echo "THE GAE SWF Project. Updating and deploying from version $1 to $2." if [ $1 != $2 ] then echo "Updating the base template with new version number..." sed s/$1/$2/ < templates/base.html > templates/temp_base.html mv templates/temp_base.html templates/base.html read -p "Commit version $2 in SVN? [y/(n)] " tag if [ $tag == "y" ] then echo "Commiting the new base template to Subversion..." svn commit -m "Updated version numbers in base.html template to $2" else echo "Skipped commit." fi fi echo "Exporting a clean version of the trunk..." rm -rf $releaseFolder > /dev/null svn export -q http://svn1.cvsdude.com/osflash/gaeswf/trunk $releaseFolder # Start the server and bring it up in the browser for testing. echo "[[[ Please test this version in the browser. Hit Ctrl-C to stop server when ready. ]]]" $releaseFolder/start read -p "Tag version $2 in SVN? [y/(n)] " tag if [ $tag == "y" ] then echo "Tagging version $2..." svn cp http://svn1.cvsdude.com/osflash/gaeswf/trunk http://svn1.cvsdude.com/osflash/gaeswf/tags/$2 -m "Version $2" else echo "Skipped tagging." fi read -p "Ready to deploy? [y, (n)] " deploy if [ $deploy == "y" ] then echo "Zipping the source code..." rm $zipFile > /dev/null zip -rq $zipFile $releaseFolder # SFTP the source file to my blog. # Uses an expect script to achieve this. ./ftpsource $2 # Deploy the app to Google App Engine appcfg.py update . else echo "Skipped deployment." fi # Open the remote site in Firefox. open -a firefox http://gaeswf.appspot.com echo "Version $2 successfully deployed."
I use a separate expect script to FTP the source zip file to aralbalkan.com:
#!/usr/bin/expect set version [lrange $argv 0 0] spawn sftp me@mydomain expect "password:" send "******\n"; expect "sftp>" send "put ../releases/The_GAE_SWF_Project_$version.zip path/to/downloads/ \r" expect "sftp>" send "quit \r"
Expect is a very cool way to script interactive instances (and yeah, I didn't want to mess with SSH!)
Down and dirty scripting can be a liberating and useful experience sometimes ![]()
The Shell scripting for fun and profit article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.
Oooh, I love a good shell script. Just one minor point though. You may wish to switch from
if [ … ]toif [[ … ]]. It’s a bash-ism, but it prevents certain irritating quoting issues which can occur in the above code.Also, I’m really glad to see someone still using expect. That saved my life when trying to configure Cisco routers a few years ago. I still have the O’Reilly book, but alas little chance to use it.
Sed has an inline function so there is no need for that superfluous mv.
sed -e s/$1/$2/g -i .bak templates/base.html
If you remove the .bak part it won’t even make a backup file.
I don’t recommend that though.
Hi Dominic, Kristof, thanks for your useful suggestions. I’ll update the script
And one more from me: I noticed that the expect script was timing out on the SFTP transfer so I added:
And that fixed it. It makes expect wait indefinitely for actions to end without timing out.