-
Notifications
You must be signed in to change notification settings - Fork 10
/
di-chronosync.sh
executable file
·129 lines (85 loc) · 2.86 KB
/
di-chronosync.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
#!/usr/bin/env zsh -f
# Purpose: Download and install/update the latest version of ChronoSync
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2019-12-20
NAME="$0:t:r"
if [[ -e "$HOME/.path" ]]
then
source "$HOME/.path"
fi
INSTALL_TO='/Applications/ChronoSync.app'
URL='https://downloads.econtechnologies.com/updates/CS4_Download.dmg'
FEED='https://www.econtechnologies.com/UC/updatecheck.php?prod=ChronoSync&vers=4.0&lang=en&plat=mac&os=10.14.1&hw=i64&req=1'
INFO=$(curl -sfLS "$FEED" |\
sed 's#<br>#\
#g')
LATEST_VERSION=$(echo "$INFO" | awk -F'=' '/^VERSION/{print $NF}')
RELEASE_NOTES_URL=$(echo "$INFO" | awk -F'=' '/^NOTICE/{print $NF}')
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}// /}.dmg"
if (( $+commands[lynx] ))
then
lynx -dump -nomargins -width='10000' -assume_charset=UTF-8 -pseudo_inlines "$RELEASE_NOTES_URL" | tee "$FILENAME:r.txt"
echo "\nVersion: ${LATEST_VERSION}\nSource: ${RELEASE_NOTES_URL}\nURL: $URL" | tee -a "$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"
echo "$NAME: Mounting $FILENAME:"
MNTPNT=$(hdiutil attach -nobrowse -plist "$FILENAME" 2>/dev/null \
| fgrep -A 1 '<key>mount-point</key>' \
| tail -1 \
| sed 's#</string>.*##g ; s#.*<string>##g')
if [[ "$MNTPNT" == "" ]]
then
echo "$NAME: MNTPNT is empty"
exit 1
else
echo "$NAME: MNTPNT is $MNTPNT"
fi
PKG=$(find "$MNTPNT" -maxdepth 1 -iname 'Install.pkg' -print)
if [[ "$PKG" == "" ]]
then
echo "$NAME: No 'Install.pkg' found in '$MNTPNT'." >>/dev/stderr
exit 1
fi
if (( $+commands[pkginstall.sh] ))
then
pkginstall.sh "$PKG"
else
sudo /usr/sbin/installer -verbose -pkg "$PKG" -dumplog -target / -lang en 2>&1
fi
EXIT="$?"
if [[ "$EXIT" != "0" ]]
then
echo "$NAME: installation of '$PKG' failed (\$EXIT = $EXIT)."
# Show the .pkg file at least, to draw their attention to it.
open -R "$PKG"
exit 1
fi
echo "$NAME: Unmounting $MNTPNT:"
diskutil eject "$MNTPNT"
exit 0
#EOF