-
Notifications
You must be signed in to change notification settings - Fork 220
/
updater
executable file
·204 lines (159 loc) · 4.13 KB
/
updater
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
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
#AirConnect Updater - Pull latest Update from https://github.com/philippe44/AirConnect
#AirConnect by philippe44 - updater script by FaserF https://github.com/FaserF
#Variables
newversion=0000
currentversion=0000
state=NoLocalInstallationFound
currentdirectory=$PWD
tmpfolder=/tmp/AirConnect
backupfolder=$tmpfolder/backup
downloadfolder=$tmpfolder/download
function checkLocalInstallation() {
if [ -f "CHANGELOG" ] && [ -f "airupnp.service" ]
then
echo "Current installation detected"
#Remeber current install directory
currentdirectory=$PWD
#Set state
state=LocalInstallationFound
fi
if [ -f "$currentdirectory/AirConnect/CHANGELOG" ] && [ -f "$currentdirectory/AirConnect/airupnp.service" ]
then
echo "Current installation detected in subfolder AirConnect"
#Remeber current install directory
currentdirectory=$PWD/AirConnect
#Set state
state=LocalInstallationFound
fi
}
function cleanInstall() {
echo "First installation..."
#Ask for target installation directory
read -p "Enter full path where to install: " targetdirectory
if test -z "targetdirectory"
then
# install to current path if nothing is entered
targetdirectory=$PWD
fi
if [ "targetdirectory" = "/" ]
then
echo "Error: Can't install at root"
exit 1
fi
#Create target directory
if [ ! -d "$targetdirectory" ]
then
mkdir "$targetdirectory"
fi
#Install newest version
echo "----"
echo "Installing newest version..."
echo "----"
git clone --depth=1 https://github.com/philippe44/AirConnect.git $targetdirectory 2>&1 >/dev/null
}
function prepareTmpFolder() {
#Delete previous folder if still exist
if [ -d "$tmpfolder" ]
then
rm -rf $tmpfolder
fi
#Create new empty tmp folders
mkdir $tmpfolder
mkdir $tmpfolder/backup
mkdir $tmpfolder/download
}
function searchNewVersion() {
#Checking for new Updates
echo "----"
echo "Checking for new updates"
echo "----"
#Download online changelog
download https://raw.githubusercontent.com/philippe44/AirConnect/master/CHANGELOG $tmpfolder/CHANGELOG
#Calculate online version
newversion=$(head -n 1 $tmpfolder/CHANGELOG)
newversion=${newversion//[-._]}
#Delete online changelog
rm $tmpfolder/CHANGELOG
#Grep current version number
currentversion=$(head -n 1 $currentdirectory/CHANGELOG)
currentversion=${currentversion//[-._]}
if [ "$newversion" -gt "$currentversion" ]
then
echo "Found new version: $newversion"
state=NewVersionFoundOnGithub
else
echo "No new update found"
fi
}
function backupCurrentVersion() {
echo "----"
echo "Backing up old version..."
mv $currentdirectory/* $tmpfolder/backup
}
function updateCurrentVersion() {
#Remove previous version files
rm -rf $currentdirectory/*
#Download newest Version
echo "----"
echo "Update version..."
echo "----"
git clone --depth=1 https://github.com/philippe44/AirConnect.git $downloadfolder 2>&1 >/dev/null
#Install
mv $downloadfolder/* $currentdirectory
}
function validateUpdatedVersion() {
versioncheck=$(head -n 1 $currentdirectory/CHANGELOG)
versioncheck=${versioncheck//[-._]}
if [ "$versioncheck" -eq "$newversion" ]
then
echo "----"
echo "Update done"
echo "----"
echo "New Version: $versioncheck"
else
echo "----"
echo "Update failed"
echo "----"
echo "Current Version: $currentversion"
fi
echo "-----"
echo "Old version backup in: $backupfolder"
}
function download() {
url=$1
filename=$2
if [ -x "$(which wget)" ] ; then
wget -q $url -O $2
elif [ -x "$(which curl)" ]; then
curl -o $2 -sfL $url
else
echo "Could not find curl or wget, please install one." >&2
fi
}
#
# Main
#########################################
#
#
#Check if AirConnect is already installed
checkLocalInstallation
if [ $state = "NoLocalInstallationFound" ]
then
#Install new version
cleanInstall
else
#Create needed folder
prepareTmpFolder
#Check if a new version is available
searchNewVersion
if [ $state = "NewVersionFoundOnGithub" ]
then
#Backup Current Installation
backupCurrentVersion
#Update Current Installation
updateCurrentVersion
#Validate Version
validateUpdatedVersion
fi
fi