-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpackageManagerEnd.sh
executable file
·102 lines (93 loc) · 2.35 KB
/
packageManagerEnd.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# this script handles the actions AFTER PackageManager.py exits
# that can not be easily performed while it is running:
#
# uninstalling SetupHelper and therefore the PackageManager service
#
# system reboots are also handled here since that needs to happen
# AFTER SetupHelper is uninstalled
#
# GUI restart if needed
#
# this script is called from PackageManager.py just prior to it exiting
#
# PackageManager will pass the following options as appropriate:
#
# 'shUninstall' to uninstall SetupHelper
# 'reboot' to trigger a system reboot
# 'guiRestart' to trigger a GUI restart
#
# all are optional but at least one should be passed or
# this script will exit without doing anything
#
# reboot overrides a guiRestart since the reboot will restart the GUI
source "/data/SetupHelper/HelperResources/EssentialResources"
logToConsole=false
logMessage "starting packageManagerEnd.sh"
shUninstall=false
guiRestart=false
reboot=false
while [ $# -gt 0 ]; do
case $1 in
"shUninstall")
shUninstall=true
;;
"guiRestart")
guiRestart=true
;;
"reboot")
reboot=true
;;
*)
esac
shift
done
if $shUninstall || $reboot ; then
waitCount=0
# wait for up to 20 seconds for PM to exit
while true; do
if [ -z "$( pgrep -f PackageManager.py )" ]; then
break
elif (( waitCount == 0 )); then
logMessage "waiting for PackageManager.py to exit"
elif (( waitCount > 20 )); then
logMessage "PackageManager.py DID NOT EXIT - continuing anyway"
break
fi
(( waitCount += 1 ))
sleep 1
done
fi
if $shUninstall ; then
logMessage ">>>> uninstalling SetupHelper"
setupFile="/data/SetupHelper/setup"
if [ -f "$setupFile" ]; then
$setupFile uninstall runFromPm
returnCode=$( echo $? )
else
returnCode=$EXIT_SUCCESS
fi
if (( returnCode == $EXIT_REBOOT )); then
reboot=true
elif (( returnCode == $EXIT_RESTART_GUI )); then
guiRestart=true
fi
fi
if $reboot ; then
logMessage ">>>> REBOOTING ..."
# TODO: add -k for debugging - outputs message but doesn't reboot
shutdown -r now "PackageManager is REBOOTING SYSTEM ..."
elif $guiRestart ; then
if $shUninstall ; then
logMessage ">>>> restarting GUI"
else
logMessage ">>>> restarting GUI and Package Manager"
fi
if [ -e "/service/start-gui" ]; then
svc -t "/service/start-gui"
elif [ -e "/service/gui" ]; then
svc -t "/service/gui"
fi
fi
logMessage "end packageManagerEnd.sh"