summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--update-me.in61
1 files changed, 31 insertions, 30 deletions
diff --git a/update-me.in b/update-me.in
index 4c59d66..c872600 100644
--- a/update-me.in
+++ b/update-me.in
@@ -1,43 +1,41 @@
#!/bin/bash
usage() {
- >&2 echo 'usage: update-me [-s|-c]'
+ >&2 echo 'usage: update-me [-s|-c] [-u[ ]$user]'
>&2 echo ' -s: play it save'
>&2 echo ' -c: clear for exit'
+ >&2 echo ' -u$user: safety-file should be owned by $user'
exit 1
}
play_it_safe=false
safety_file='/tmp/update-me.do-not-exit'
+flags="$*"
-case $# in
- 0)
- ;;
- 1)
- case "x$1" in
- 'x-s')
- play_it_safe=true
- ;;
- 'x-c')
- if [ -f "${safety_file}" ] && kill -0 $(cat "${safety_file}"); then
- rm "${safety_file}"
- exit 0
- fi
- if pgrep -x update-me | grep -vxF $$; then
- exit 1
- else
- exit 2
- fi
- ;;
- *)
- usage
- ;;
- esac
- ;;
- *)
- usage
- ;;
-esac
+while [ $# -gt 0 ]; do
+ case "x$1" in
+ 'x-s')
+ play_it_safe=true
+ ;;
+ 'x-c')
+ if [ -f "${safety_file}" ] && kill -0 $(cat "${safety_file}"); then
+ rm "${safety_file}"
+ exit 0
+ fi
+ if pgrep -x update-me | grep -vxF $$; then
+ exit 1
+ else
+ exit 2
+ fi
+ ;;
+ 'x-u'*)
+ user="${1#-u}"
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
preCmds=('hostname')
cmds=()
@@ -62,6 +60,9 @@ fi
exit_or_rescue_shell() {
if "${play_it_safe}"; then
printf '%s' "$$" >"${safety_file}"
+ if [ -n "${user}" ] && [ "$(whoami)" != "${user}" ]; then
+ chown "${user}" "${safety_file}"
+ fi
>&2 printf '%s: waiting for clearance ...' "$(hostname)"
while [ -f "${safety_file}" ] && [ "$(cat "${safety_file}")" = "$$" ]; do
if read -t 1; then
@@ -97,7 +98,7 @@ if [ ! "$(whoami)" == "root" ]; then
maxCount=3
while [ ${err} -eq 1 ] && [ ${maxCount} -gt 0 ]
do
- su -c "$(readlink -f "$0") || exit 2"
+ su -c "$(readlink -f "$0") ${flags} || exit 2"
err=$?
maxCount=$[${maxCount} - 1]
done