-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreboot-via-dsme.sh
71 lines (68 loc) · 1.98 KB
/
reboot-via-dsme.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Normally shutdown and reboot should always go through DSME.
#
# Running reboot/poweroff/etc binaries directly bypasses DSME
# and the shutdown does not work the same way as powering off
# via UI. The differences include for example:
# - Emergency calls/alarms/charger/etc are not considered
# - Applications do not get save-data and pre-shutdown signals
# - Shutdown vibration, led and logo do not get triggered
#
# Use shell functions to allow users to continue using familiar
# commands from interactive shell, but do the shutdown/reboot
# via dsme.
#
# If needed, the real systemd binaries (e.g. reboot) can still
# be invoked by using the full path:
# # /usr/sbin/reboot
#
# Or by ignoring the shell functions via command:
# # command reboot
# Define shell functions for interactive shells only
case "$-" in *i*) ;; *) return ;; esac
# Replace simple poweroff/halt/reboot/shutdown invocations
# with equivalent dsmetool operations
poweroff()
{
[ "$#" -eq 0 ] && /usr/sbin/dsmetool --shutdown || /usr/sbin/poweroff "$@"
}
halt()
{
[ "$#" -eq 0 ] && /usr/sbin/dsmetool --shutdown || /usr/sbin/halt "$@"
}
reboot()
{
[ "$#" -eq 0 ] && /usr/sbin/dsmetool --reboot || /usr/sbin/reboot "$@"
}
shutdown()
{
DSME_SHUTDOWN_MODE="--shutdown"
DSME_SHUTDOWN_TIME=""
DSME_SHUTDOWN_MESG=""
DSME_SHUTDOWN_UNKN=""
for f in "$@"; do
case "$f" in
-H|--halt|-P|--poweroff|-h)
DSME_SHUTDOWN_MODE="--shutdown"
;;
-r|--reboot)
DSME_SHUTDOWN_MODE="--reboot"
;;
-*)
DSME_SHUTDOWN_UNKN="y"
;;
*)
if [ -z "$DSME_SHUTDOWN_TIME" ]; then
DSME_SHUTDOWN_TIME="$f"
else
DSME_SHUTDOWN_MESG="$f"
fi
;;
esac
done
[ "${DSME_SHUTDOWN_TIME:-now}" = "now" ] && \
[ "$DSME_SHUTDOWN_MESG" = "" ] && \
[ "$DSME_SHUTDOWN_UNKN" = "" ] && \
/usr/sbin/dsmetool "$DSME_SHUTDOWN_MODE" || /usr/sbin/shutdown "$@"
unset DSME_SHUTDOWN_MODE DSME_SHUTDOWN_TIME
unset DSME_SHUTDOWN_MESG DSME_SHUTDOWN_UNKN
}