From: Arran Cudbard-Bell Date: Wed, 5 Sep 2012 17:23:13 +0000 (+0100) Subject: Allow defaults to come from env X-Git-Tag: release_2_2_0~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e492b126e2e508cd7e6caf06e62a77039796793;p=thirdparty%2Ffreeradius-server.git Allow defaults to come from env --- diff --git a/scripts/git/post-receive b/scripts/git/post-receive index e9d45931e74..94e57da8a7f 100755 --- a/scripts/git/post-receive +++ b/scripts/git/post-receive @@ -10,19 +10,25 @@ # Copyright 2012 Arran Cudbard-Bell # 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 -C' +: ${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} while read oldrev newrev refname do @@ -39,7 +45,7 @@ status () { 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 -q --hard $STABLE_TAG; ret=$? else @@ -53,16 +59,16 @@ conf_rollback () { 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 @@ -73,55 +79,48 @@ cd .. # 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 @@ -131,4 +130,11 @@ else $GIT_EXEC tag -f $STABLE_TAG $newrev fi +if $PUSH_TO_REMOTES; then + echo "Pushing to remote repositories" + for remote in `$GIT_EXEC remote`; do + $GIT_EXEC push "$remote" + done +fi + exit 0