summaryrefslogtreecommitdiff
path: root/bin/do-reboot
blob: 0f4772d19af8c54ce6f5467e2e6687338355107c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
me=${0}
PATH=${me%/*}:$PATH

error() { echo "$@" 1>&2; }
fail() { error "$@"; exit 1; }

[ "$(id -u)" = "0" ] || fail "not root"
clean=false
keep_logs=false
save=""
reboot=true
for i in "$@"; do
   case "$i" in
      clean) clean=true;;
      keep?logs) keep_logs=true;;
      save=*) save=${i#save=};;
      no-reboot) reboot=false;;
   esac
done

if [ -n "$save" ]; then
   save-old-data "$save" || fail "failed save data"
   error "saved to $save"
fi

if $clean; then
   # clean but leave the seed directory (lxc)
   ( set -e;
     cd /var/lib/cloud
     for i in *; do
         [ "$i" = "seed" ] && continue
         rm -Rf "$i"
     done ) || fail "failed clean of /var/lib/cloud"
   error "cleared /var/lib/cloud"
fi

if ! $keep_logs; then
   rm -Rf /var/log/cloud* || fail "failed remove logs"
   error "cleared logs"
else
   error "kept logs"
fi

if $reboot; then
    error "rebooting"
    reboot
fi