# Copyright 2012 Arran Cudbard-Bell <a.cudbard-bell@freeradius.org>
# Tag to update when we successfully manage to start the server with a new configuration
-STABLE_TAG='stable'
+: ${STABLE_TAG='stable'}
+
+# Descriptive name of daemon
+: ${DAEMON_DESC='FreeRADIUS'}
# Command used to restart the RADIUS daemon
-RAD_REST='radmin -e hup'
+: ${DAEMON_REST='radmin -e hup'}
# Command used to verify the new configuration
-RAD_CONF='radiusd -Cxl stdout'
+: ${DAEMON_CONF='radiusd -Cxl stdout'}
# Command used to execute git functions
-GIT_EXEC='env -i git'
+: ${GIT_EXEC='env -i git'}
# Abort if there are local untracked files
-ABORT_UNTRACKED=true
+: ${ABORT_UNTRACKED=true}
# Push changes to any remotes we have configured
-PUSH_TO_REMOTES=false
+: ${PUSH_TO_REMOTES=false}
while read oldrev newrev refname
do
conf_rollback () {
# Use stable tag if it exists...
- if [ `$GIT_EXEC tag -l $STABLE_TAG | wc -l` -gt 0 ]; then
+ if $GIT_EXEC tag -v $STABLE_TAG > /dev/null 2>&1; then
echo -n "Attempting to roll config back to tag: \"$STABLE_TAG\"... "
$GIT_EXEC reset --hard $STABLE_TAG; ret=$?
else
conf_check () {
echo -n "Checking new configuration... "
- $RAD_CONF; ret=$?
+ $DAEMON_CONF; ret=$?
status $ret
return $ret
}
-rad_restart () {
+daemon_restart () {
echo -n "Restarting server... "
- $RAD_REST > /dev/null 2>&1; ret=$?
+ $DAEMON_REST > /dev/null 2>&1; ret=$?
status $ret
return $ret
# Friendly update of working copy to head state
$GIT_EXEC checkout -f
-if [ $ABORT_UNTRACKED -a `$GIT_EXEC status --porcelain | wc -l` -gt 0 ]; then
+if $ABORT_UNTRACKED && [ `$GIT_EXEC status --porcelain | wc -l` -gt 0 ]; then
echo "WARNING: Untracked changes have been made to this git repository,"
echo "changes have been committed but untracked files should be removed,"
- echo "committed or added to .gitignore and FreeRADIUS restarted manually."
+ echo "committed or added to .gitignore and $DAEMON_DESC restarted manually."
$GIT_EXEC status --short
- conf_check
- if [ $? -eq 0 ]; then
- exit 64
+ if ! conf_check
+ then exit 64
fi
- echo "WARNING: FreeRADIUS found errors in the configuration,"
+ echo "WARNING: $DAEMON_DESC found errors in the configuration,"
echo "these errors should be corrected before updating working copy."
exit 65
fi
# Clean out all untracked files and directories (if there are local files you
# wish to keep, they should be add to .gitignore)
-$GIT_EXEC clean -d -f
-if [ $? -ne 0 ]; then
- exit $?
+if ! $GIT_EXEC clean -d -f
+ then exit $?
fi
# Reset all tracked files to the HEAD state
-$GIT_EXEC reset --hard
-if [ $? -ne 0 ]; then
- exit $?
+if ! $GIT_EXEC reset --hard
+ then exit $?
fi
# Check if the server finds any errors in the new config
-conf_check
-if [ $? -ne 0 ]; then
- echo "WARNING: FreeRADIUS found errors in the configuration,"
+if ! conf_check then
+ echo "WARNING: $DAEMON_DESC found errors in the configuration,"
echo "please fix the errors and push the corrected configuration."
conf_rollback
exit 64
else
- rad_restart
- if [ $? -ne 0 ]; then
- conf_rollback
- if [ $? -ne 0 ]; then
- echo "WARNING: Manually verify server status immediately!"
+ if ! daemon_restart; then
+ if ! conf_rollback; then
+ echo "WARNING: Manually verify $DAEMON_DESC status immediately!"
exit 64
fi
- rad_restart
- if [ $? -ne 0 ]; then
- echo "WARNING: Manually verify server status immediately!"
+ if ! daemon_restart; then
+ echo "WARNING: Manually verify $DAEMON_DESC status immediately!"
exit 64
fi
$GIT_EXEC tag -f $STABLE_TAG $newrev
fi
-if [ $PUSH_TO_REMOTES ]; then
+if $PUSH_TO_REMOTES; then
echo "Pushing to remote repositories"
for remote in `$GIT_EXEC remote`; do
$GIT_EXEC push "$remote"