-
Notifications
You must be signed in to change notification settings - Fork 10
/
di-donotdisturb.sh
executable file
·180 lines (116 loc) · 4 KB
/
di-donotdisturb.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env zsh -f
# Purpose: Download and install/update the latest version of "Do Not Disturb"
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2018-09-13
NAME="$0:t:r"
if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
fi
HOMEPAGE="https://objective-see.com/products/dnd.html"
DOWNLOAD_PAGE="https://objective-see.com/products/dnd.html"
RELEASE_NOTES_URL='https://objective-see.com/products/changelogs/DoNotDisturb.txt'
SUMMARY="Physical access (or “evil maid”) attacks are some of the most insidious threats faced by those of us who travel with our Macs. Do Not Disturb (DND) is a free, open-source utility that aims to detect and alert you of such attacks."
INSTALL_TO='/Applications/Do Not Disturb.app'
INFO=($(curl -H "Accept-Encoding: gzip,deflate" -sfLS 'https://objective-see.com/products/dnd.html' \
| gunzip --force \
| tr -s '"|\047' '\012' \
| egrep '^http.*\.zip|sha-1:' \
| awk '{print $NF}' \
| head -2))
URL="$INFO[1]"
EXPECTED_SHA1="$INFO[2]"
LATEST_VERSION=$(echo "$URL:t:r" | tr -dc '[0-9]\.')
# If any of these are blank, we cannot continue
if [ "$URL" = "" -o "$LATEST_VERSION" = "" -o "$EXPECTED_SHA1" = "" ]
then
echo "$NAME: Error: bad data received:
LATEST_VERSION: $LATEST_VERSION
URL: $URL
EXPECTED_SHA1: $EXPECTED_SHA1
"
exit 1
fi
if [[ -e "$INSTALL_TO" ]]
then
INSTALLED_VERSION=$(defaults read "${INSTALL_TO}/Contents/Info" CFBundleShortVersionString)
autoload is-at-least
is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
VERSION_COMPARE="$?"
if [ "$VERSION_COMPARE" = "0" ]
then
echo "$NAME: Up-To-Date ($INSTALLED_VERSION)"
exit 0
fi
echo "$NAME: Outdated: $INSTALLED_VERSION vs $LATEST_VERSION"
FIRST_INSTALL='no'
else
FIRST_INSTALL='yes'
fi
FILENAME="$HOME/Downloads/${${INSTALL_TO:t:r}// /}-${LATEST_VERSION}.zip"
SHA_FILE="$HOME/Downloads/${${INSTALL_TO:t:r}// /}-${LATEST_VERSION}.sha1.txt"
echo "$EXPECTED_SHA1 ?$FILENAME:t" >| "$SHA_FILE"
( curl -H "Accept-Encoding: gzip,deflate" -sfLS "$RELEASE_NOTES_URL" \
| gunzip -f -c) | tee "$FILENAME:r.txt"
OS_VER=$(SYSTEM_VERSION_COMPAT=1 sw_vers -productVersion | cut -d. -f2)
if [ "$OS_VER" -lt "12" ]
then
echo "$NAME: [WARNING] '$INSTALL_TO:t' is only compatible with macOS versions 10.12 and higher (you are using 10.$OS_VER)."
echo "$NAME: [WARNING] Will download, but the app might not install or function properly."
fi
echo "$NAME: Downloading '$URL' to '$FILENAME':"
curl --continue-at - --progress-bar --fail --location --output "$FILENAME" "$URL"
EXIT="$?"
## exit 22 means 'the file was already fully downloaded'
[ "$EXIT" != "0" -a "$EXIT" != "22" ] && echo "$NAME: Download of $URL failed (EXIT = $EXIT)" && exit 0
[[ ! -e "$FILENAME" ]] && echo "$NAME: $FILENAME does not exist." && exit 0
[[ ! -s "$FILENAME" ]] && echo "$NAME: $FILENAME is zero bytes." && rm -f "$FILENAME" && exit 0
##
echo "$NAME: Checking '$FILENAME' against '$SHA_FILE':"
cd "$FILENAME:h"
shasum -c "$SHA_FILE"
EXIT="$?"
if [ "$EXIT" = "0" ]
then
echo "$NAME: SHA-1 verification passed"
else
echo "$NAME: SHA-1 verification failed (\$EXIT = $EXIT)"
exit 1
fi
##
MAC_TYPE=$(sysctl hw.model | awk -F' ' '/^hw.model/{print $NF}' | tr -d '[0-9],')
case "$MAC_TYPE" in
MacBook|MacBook*)
:
;;
iMac|iMac*)
echo "$NAME: '$INSTALL_TO:t' can only be installed on MacBook, but this is an ${MAC_TYPE}. Installation cancelled."
exit 0
;;
*)
echo "$NAME: '$INSTALL_TO:t' can only be installed on MacBook, but this is a ${MAC_TYPE}. Installation cancelled."
exit 0
;;
esac
##
UNZIP_TO=$(mktemp -d "${TMPDIR-/tmp/}${NAME}-XXXXXXXX")
echo "$NAME: Unzipping '$FILENAME' to '$UNZIP_TO':"
ditto -xk --noqtn "$FILENAME" "$UNZIP_TO"
EXIT="$?"
if [[ "$EXIT" == "0" ]]
then
echo "$NAME: Unzip successful"
else
# failed
echo "$NAME failed (ditto -xkv '$FILENAME' '$UNZIP_TO')"
exit 1
fi
INSTALLER="$UNZIP_TO/Do Not Disturb Installer.app"
echo "$NAME: launching custom installer/updater: '$INSTALLER'"
# launch the custom installer app and wait for it to finish.
open -a "$INSTALLER"
exit 0
#
#EOF