This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
astget.sh
155 lines (128 loc) · 2.92 KB
/
astget.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
#!/bin/bash
REPO=$(cat /etc/rc.d/acidrepo)
RCD=/etc/rc.d
DESTDIR=/usr/src
TMPDIR=/tmp
FORCEDL=0
IGNOREHASH=0
IGNOREVERSCK=0
function die {
echo "Fatal error: $1"
exit 1
}
#
# Stop people from using astupd unwisely
#
if [ $IGNOREVERSCK -eq 0 ]
then
echo "Checking to see if this system can be updated using astupd..."
if ! [ -f $RCD/acidvers ]
then
die "This version of acid is too old to be updated, an install from scratch will be necessary";
fi
wget -q -O /tmp/siteacidvers $REPO/installcd/acidvers
if [ $? -ne 0 ]
then
die "Cannot contact the download site: $SITE, please check your Internet connectivity and/or try again later"
fi
CURACIDVERS=$(cat $RCD/acidvers)
SITEACIDVERS=$(cat /tmp/siteacidvers)
rm -f /tmp/siteacidvers
if [ $CURACIDVERS != $SITEACIDVERS ]
then
echo "You have ACID version: $CURACIDVERS and the version on $REPO is: $SITEACIDVERS"
die "astupd.sh cannot be used, you must re-install ACID to update this system"
fi
fi
echo "Checking for updates to Asterisk...."
#
# Calculate local copy of sha256sum
#
if [ -e $DESTDIR/files.tar.gz ]
then
sha256sum $DESTDIR/files.tar.gz | cut -d ' ' -f 1 >$DESTDIR/files.tar.gz.sha256sum
else
FORCEDL=1
fi
wget -q $REPO/installcd/files.tar.gz.sha256sum -O $TMPDIR/files.tar.gz.sha256sum
if [ $? -gt 0 ]
then
IGNOREHASH=1
FORCEDL=1;
fi
#
# Compare the local and repo SHA256 hashes
#
if [ $FORCEDL -eq 0 ]
then
diff -q $DESTDIR/files.tar.gz.sha256sum $TMPDIR/files.tar.gz.sha256sum 2>/dev/null >/dev/null
if [ $? -ne 0 ]
then
FORCEDL=1
fi
fi
#
# If hashes identical, then no update is required.
#
if [ $FORCEDL -eq 0 ]
then
echo "Asterisk at latest version. No update required."
rm -f $TMPDIR/files.tar.gz.sha256sum
exit 0;
else
FORCEDL=1
fi
#
# Get a new copy of the sources
#
wget -q $REPO/installcd/files.tar.gz -O $TMPDIR/files.tar.gz
if [ $? -gt 0 ]
then
die "Cannot download a copy of files.tar.gz!"
fi
#
# Calculate SHA256 hash on downloaded image and verify it matches
#
if [ $IGNOREHASH -eq 0 ]
then
sha256sum $TMPDIR/files.tar.gz | cut -d ' ' -f 1 >$TMPDIR/files.tar.gz.repo.sha256sum
diff -q $TMPDIR/files.tar.gz.sha256sum $TMPDIR/files.tar.gz.repo.sha256sum 2>/dev/null >/dev/null
if [ $? -ne 0 ]
then
die "SHA256 check failed!"
fi
fi
#
# Get a newer astinstall.sh
#
rm $RCD/astinstall.sh
wget -q $REPO/installcd/astinstall.sh -O $RCD/astinstall.sh
if [ $? -gt 0 ]
then
die "Cannot download a copy of astinstall.sh!"
fi
if [ -e $RCD/astinstall.sh ]
then
chmod 770 $RCD/astinstall.sh
else
die "Cannot find astinstall.sh!"
fi
#
# Copy the source files to the destination
#
rm -f $DESTDIR/files.tar.*
mv -f $TMPDIR/files.tar.gz $DESTDIR
(cd $DESTDIR; rm -rf asterisk libpri zaptel allstar configs Makefile)
(cd /usr/lib/asterisk/modules; rm -f *.so)
#
# Exec install script
#
$RCD/astinstall.sh
#
# Restart asterisk if it is running
#
if [ -e /var/run/asterisk.ctl ]
then
echo "Restarting Asterisk...."
asterisk -rx "restart now"
fi