-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckReboot.sh
74 lines (65 loc) · 1.98 KB
/
checkReboot.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
#!/bin/bash
#
# Check for the reboot flag, meaning the a subprocess requires a system reboot.
#
# This is designed to go into the third party update workflow, where
# a master policy calls sub-policies. This script is ran at the end of the master policy
# and check for a reboot flag set by 098_Policy_SetReboot.sh during a sub-policy
#
# If the reboot flag is not set, this script will do a recon instead.
# $4 is the amount of time in minutes to delay a reboot.
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
RESTART="0"
USERS="0"
TIME=0
getRestart() {
REBOOT=$(defaults read /Library/Preferences/com.org.systeminfo REBOOT)
if [ "$REBOOT" == "TRUE" ]; then
RESTART="1"
defaults delete /Library/Preferences/com.org.systeminfo REBOOT
elif [ "$REBOOT" == "FALSE" ]; then
# Honestly this shouldn't be set, but let's delete it anyway.
defaults delete /Library/Preferences/com.org.systeminfo REBOOT
fi
}
# If no time parameter is set, default to 20 minutes.
# the -z checks for zero length strings
getTime() {
if [ -z "$1" ]; then
TIME=1200
else
TIME=`expr $1 \* 60`
fi
}
getUserCount() {
COUNT=$(ls -l /dev/console | awk '/ / { print $3 }' | wc -l | tr -d ' ')
if [ "$COUNT" -ne '0' ]; then
USERS="1"
fi
}
rebootPrompt() {
if [ "$RESTART" == "1" ]; then
getUserCount
if [ "$USERS" == "1" ]; then
/usr/local/bin/jamf displayMessage -message "This computer will restart automatically in $1 minutes. Please save anything you are working on and log out by choosing Log Out from the bottom of the Apple menu. You may also select restart from the Apple Menu to restart your computer sooner."
# Ping for the desired delay minutes
/sbin/ping -c $TIME 127.0.0.1 > /dev/null
/usr/local/bin/jamf reboot -immediately -background
else
/usr/local/bin/jamf reboot -immediately -background
fi
fi
}
runRecon() {
if [ "$RESTART" == "0" ]; then
/usr/local/bin/jamf recon
fi
}
Main() {
getTime "$4"
getRestart
runRecon
rebootPrompt "$4"
}
Main "$@"
exit 0