Webapp update shell script
The best way is simply as you suggest. Some things you should do for your script would be:
- put
set -e
at the top of the script (after the shebang). This will cause your script to stop if any of the commands fail. So if it cannot cd to the directory, it will not runsvn update
or restart apache. You can do this programmatically by putting|| exit 0
after each command, but if that's all you're doing, you may as well useset -e
- Use full paths in your script. Do not assume the directory that the script is run from. In this specific case, the
cd
command has a relative path. Use a full (absolute) path, or use an environment variable like $HOME. - You may want to set up sudo so that it can run the command without asking for a password. This makes your script non-interactive which means it can be run in the background and from cron jobs and such.
As time goes by, you may add features and take command line arguments to parameterise the script. But don't bother doing this up front. Just evolve your scripts as you need.