Debian Codegraph @

scripts/git/post-receive

raw
1 #!/bin/sh
2 # git Post-receive configuration update script
3 #
4 # To install:
5 # * Enable r/w control socket for the user you're pushing with
6 # * cd <config-dir>/raddb git config receive.denyCurrentBranch ignore
7 # * cp ./post-receive <config-dir>/raddb/.git/hooks/
8 # * # Edit the capitalized variables below to match your environment.
9 #
10 # Copyright 2012 Arran Cudbard-Bell <[email protected]>
11
12 PATH=/bin:/usr/bin:/usr/sbin:/sbin
13 # Tag to update when we successfully manage to start the server with a new configuration
14 : ${STABLE_TAG='stable'}
15
16 # Descriptive name of daemon
17 : ${DAEMON_DESC='FreeRADIUS'}
18
19 # Init script for radiusd
20 : ${DAEMON_STATUS='/etc/init.d/radiusd status'}
21
22 # Command used to restart the RADIUS daemon
23 : ${DAEMON_REST='radmin -e hup'}
24
25 # Command used to verify the new configuration
26 : ${DAEMON_CONF='radiusd -Cxl stdout'}
27
28 # Command used to execute git functions
29 : ${GIT_EXEC='env -i git'}
30
31 # Abort if there are local untracked files
32 : ${ABORT_UNTRACKED=true}
33
34 # Push changes to any remotes we have configured
35 : ${PUSH_TO_REMOTES=false}
36
37 while read oldrev newrev refname
38 do
39 :
40 done
41
42 status () {
43 if [ $1 -ne 0 ]; then
44 echo "failed"
45 else
46 echo "ok"
47 fi
48 }
49
50 conf_rollback () {
51 # Use stable tag if it exists...
52 if $GIT_EXEC show-ref $STABLE_TAG > /dev/null 2>&1; then
53 echo -n "Attempting to roll config back to tag: \"$STABLE_TAG\"... "
54 $GIT_EXEC reset --hard $STABLE_TAG; ret=$?
55 else
56 echo -n "Attempting to roll config back to commit: \"$oldrev\"... "
57 $GIT_EXEC reset --hard $oldrev; ret=$?
58 fi
59
60 status $ret
61 return $ret
62 }
63
64 conf_check () {
65 echo -n "Checking new configuration... "
66 $DAEMON_CONF; ret=$?
67
68 status $ret
69 return $ret
70 }
71
72 daemon_status () {
73 echo -n "Checking if radiusd is running ... "
74 $DAEMON_STATUS; ret=$?
75
76 return $ret
77 }
78
79 daemon_restart () {
80 echo -n "Restarting server... "
81
82 $DAEMON_REST > /dev/null 2>&1; ret=$?
83
84 status $ret
85 return $ret
86 }
87
88 # Reset the current working directory state
89 cd ..
90
91 # Friendly update of working copy to head state
92 $GIT_EXEC checkout -f
93 if $ABORT_UNTRACKED && [ `$GIT_EXEC status --porcelain | wc -l` -gt 0 ]; then
94 echo "WARNING: Untracked changes have been made to this git repository,"
95 echo "changes have been committed but untracked files should be removed,"
96 echo "committed or added to .gitignore and $DAEMON_DESC restarted manually."
97 $GIT_EXEC status --short
98
99 if ! conf_check; then
100 exit 64
101 fi
102
103 echo "WARNING: $DAEMON_DESC found errors in the configuration,"
104 echo "these errors should be corrected before updating working copy."
105 exit 65
106 fi
107
108 # Clean out all untracked files and directories (if there are local files you
109 # wish to keep, they should be add to .gitignore)
110 if ! $GIT_EXEC clean -d -f
111 then exit $?
112 fi
113
114 # Reset all tracked files to the HEAD state
115 if ! $GIT_EXEC reset --hard
116 then exit $?
117 fi
118
119 # Check if the server finds any errors in the new config
120 if ! conf_check; then
121 echo "WARNING: $DAEMON_DESC found errors in the configuration,"
122 echo "please fix the errors and push the corrected configuration."
123
124 conf_rollback
125 exit 64
126 else
127 if daemon_status && ! daemon_restart ; then
128 if ! conf_rollback; then
129 echo "WARNING: Manually verify $DAEMON_DESC status immediately!"
130 exit 64
131 fi
132
133 if ! daemon_restart; then
134 echo "WARNING: Manually verify $DAEMON_DESC status immediately!"
135 exit 64
136 fi
137
138 exit 64
139 fi
140
141 $GIT_EXEC tag -f $STABLE_TAG $newrev
142 fi
143
144 if $PUSH_TO_REMOTES; then
145 echo "Pushing to remote repositories"
146 for remote in `$GIT_EXEC remote`; do
147 $GIT_EXEC push "$remote"
148 done
149 fi
150
151 exit 0