-
Notifications
You must be signed in to change notification settings - Fork 10
/
di-audiohijack.sh
executable file
·194 lines (126 loc) · 4.82 KB
/
di-audiohijack.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env zsh -f
# Purpose: Download and install Audio Hijack 3
#
# From: Tj Luo.ma
# Mail: luomat at gmail dot com
# Web: http://RhymesWithDiploma.com
# Date: 2015-01-20
[[ -e "$HOME/.path" ]] && source "$HOME/.path"
[[ -e "$HOME/.config/di/defaults.sh" ]] && source "$HOME/.config/di/defaults.sh"
INSTALL_TO="${INSTALL_DIR_ALTERNATE-/Applications}/Audio Hijack.app"
NAME="$0:t:r"
HOMEPAGE="https://www.rogueamoeba.com/audiohijack/"
DOWNLOAD_PAGE="https://rogueamoeba.com/audiohijack/download.php"
SUMMARY="Record any application’s audio, including VoIP calls from Skype, web streams from Safari, and much more. Save audio from hardware devices like microphones and mixers as well. You can even record all the audio heard on your Mac at once! If you can hear it, Audio Hijack can record it."
zmodload zsh/datetime
function timestamp { strftime "%Y-%m-%d at %H:%M:%S" "$EPOCHSECONDS" }
# OS_VER=$(SYSTEM_VERSION_COMPAT=1 sw_vers -productVersion | tr -d '.')
# OS_VER='10157'
XML_FEED="https://rogueamoeba.net/ping/versionCheck.cgi?format=sparkle&bundleid=com.rogueamoeba.audiohijack3&system=10160&platform=osx&arch=x86_64&version=3762003"
# sparkle:version= is the only version information in feed
LATEST_VERSION=`curl -sfL "$XML_FEED" | awk -F'"' '/sparkle:version=/{print $2}'`
## could hard-code 'https://rogueamoeba.com/audiohijack/download/AudioHijack.zip' but I'm not
URL=$(curl -sfL "${DOWNLOAD_PAGE}" | tr '"' '\012' | egrep '^https:.*\.zip$' | head -1)
if [[ "$URL" == "" ]]
then
echo "$NAME: URL is empty"
exit 1
fi
# If any of these are blank, we should not continue
if [ "$LATEST_VERSION" = "" -o "$XML_FEED" = "" ]
then
echo "$NAME: Error: bad data received:
LATEST_VERSION: $LATEST_VERSION
XML_FEED: $XML_FEED
"
exit 1
fi
if [ -d "$INSTALL_TO" ]
then
INSTALLED_VERSION=`defaults read "$INSTALL_TO/Contents/Info" CFBundleVersion 2>/dev/null || echo 0`
if [[ "$LATEST_VERSION" == "$INSTALLED_VERSION" ]]
then
echo "$NAME: Up-To-Date ($INSTALLED_VERSION)"
exit 0
fi
autoload is-at-least
is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
if [ "$?" = "0" ]
then
echo "$NAME: Installed version ($INSTALLED_VERSION) is ahead of official version $LATEST_VERSION"
exit 0
fi
echo "$NAME: Outdated (Installed = $INSTALLED_VERSION vs Latest = $LATEST_VERSION)"
fi
FILENAME="${DOWNLOAD_DIR_ALTERNATE-$HOME/Downloads}/${${INSTALL_TO:t:r}// /}-${${LATEST_VERSION}// /}.zip"
if (( $+commands[lynx] ))
then
RELEASE_NOTES_URL="$XML_FEED"
RELEASE_NOTES=$(curl -sfL "$RELEASE_NOTES_URL" \
| sed '1,/<body>/d; /<\/body>/,$d' \
| egrep -i '[a-z]|[0-9]' \
| lynx -dump -nomargins -width=10000 -assume_charset=UTF-8 -pseudo_inlines -stdin)
echo "${RELEASE_NOTES}\nSource: ${RELEASE_NOTES_URL}\nURL: ${URL}" | tee "$FILENAME:r.txt"
fi
echo "$NAME: Downloading '$URL' to '$FILENAME':"
curl --continue-at - --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
(cd "$FILENAME:h" ; echo "\nLocal sha256:" ; shasum -a 256 "$FILENAME:t" ) >>| "$FILENAME:r.txt"
## make sure that the .zip is valid before we proceed
(command unzip -l "$FILENAME" 2>&1 )>/dev/null
EXIT="$?"
if [ "$EXIT" = "0" ]
then
echo "$NAME: '$FILENAME' is a valid zip file."
else
echo "$NAME: '$FILENAME' is an invalid zip file (\$EXIT = $EXIT)"
mv -fv "$FILENAME" "$HOME/.Trash/"
mv -fv "$FILENAME:r".* "$HOME/.Trash/"
exit 0
fi
## unzip to a temporary directory
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
if [[ -e "$INSTALL_TO" ]]
then
pgrep -xq "$INSTALL_TO:t:r" \
&& echo "$NAME: '$INSTALL_TO:t' is running. Not replacing it." \
&& exit 1
echo "$NAME: Moving existing (old) '$INSTALL_TO' to '$HOME/.Trash/'."
mv -vf "$INSTALL_TO" "$HOME/.Trash/$INSTALL_TO:t:r.$INSTALLED_VERSION.app"
EXIT="$?"
if [[ "$EXIT" != "0" ]]
then
echo "$NAME: failed to move existing $INSTALL_TO to $HOME/.Trash/"
exit 1
fi
fi
echo "$NAME: Moving new version of '$INSTALL_TO:t' (from '$UNZIP_TO') to '$INSTALL_TO'."
# Move the file out of the folder
mv -vn "$UNZIP_TO/$INSTALL_TO:t" "$INSTALL_TO"
EXIT="$?"
if [[ "$EXIT" = "0" ]]
then
echo "$NAME: Successfully installed '$UNZIP_TO/$INSTALL_TO:t' to '$INSTALL_TO'."
else
echo "$NAME: Failed to move '$UNZIP_TO/$INSTALL_TO:t' to '$INSTALL_TO'."
exit 1
fi
[[ "$LAUNCH" = "yes" ]] && open -a "$INSTALL_TO"
exit 0
#
#EOF