-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-server.sh
executable file
·329 lines (308 loc) · 8.32 KB
/
update-server.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
#import settings.
if [ -f ~/.sm5-server.rc ]; then
. ~/.sm5-server.rc
else
echo "configuration missing!"
exit 1
fi
_CPUS=($(nproc) - 1)
#verify settings import
#log to console if verbose and to syslog if not.
log()
{
_MESSAGE=$@
if [ $VERBOSE = 1 ]; then
echo "$_MESSAGE"
fi
logger piu-updater: $_MESSAGE
}
#usage display.
usage()
{
cat << EOF
usage: $0 options
This script will check for updates in stepmania, piuio, and the piu-dex-gw skins and build packages if they exist..
OPTIONS:
-h Show this message
-s Force a build of stepmania
-p Force a build for piuio
-t Force a build on the themese directory
-v Verbose
-c Check only (implies -v)
EOF
}
#parse options.
BUILD_SM=0
BUILD_PIUIO=0
BUILD_THEME=0
VERBOSE=0
CHECK_ONLY=0
declare -a BUILD_THEME_NAMES
while getopts .hsptvc. OPTION
do
case $OPTION in
h)
usage
exit 1
;;
v)
VERBOSE=1
;;
s)
BUILD_SM=1
;;
p)
BUILD_PIUIO=1
;;
t)
BUILD_THEME=1
;;
c)
VERBOSE=1
CHECK_ONLY=1
;;
?)
usage
exit
;;
esac
done
#declare SM_VER
declare SM_VER="xx"
#spinner class for long tasks
spinner()
{
local pid=$1
local delay=0.75
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
if [ $VERBOSE = 1 ]; then
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
fi
done
if [ $VERBOSE = 1 ]; then
printf " \b\b\b\b"
fi
}
#cleanup directories Takes 1 arg for directory. Will keep the latest 5 .md5sum and tar.gz in the directory.
cleanup ()
{
CLEAN_PATH=$1
cd "$CLEAN_PATH"
log "Cleaning up $CLEAN_PATH"
ls -d -C1 -t $CLEAN_PATH/*.gz| awk 'NR>6'|xargs rm -f
ls -d -C1 -t $CLEAN_PATH/*.md5sum| awk 'NR>6'|xargs rm -f
}
#custom script specifically for cleaning the themes directory.
clean_themes ()
{
CLEAN_PATH=$1
cd "$THEME_PATH"
for THEME in **
do
log "Cleaning up $THEME in $CLEAN_PATH"
ls -d -C1 -t $CLEAN_PATH/*$THEME*.gz| awk 'NR>6'|xargs rm -f
ls -d -C1 -t $CLEAN_PATH/*$THEME*.md5sum| awk 'NR>6'|xargs rm -f
done
}
#basic function to update to the latest git, run make clean and make and if successful build the release package.
build_sm ()
{
cd "$SM_PATH"
log "Updating Stepmania sources"
git pull > /dev/null
log "Cleaning Stepmania source directory"
make clean > /dev/null 2>&1 &
spinner $!
log "Configuring Stepmania"
./autogen.sh
./configure --with-static-png --with-static-jpeg --with-static-zlib --with-static-bzip --with-static-vorbis --prefix=$SM_INSTALL_PATH > configure.out 2>&1 &
spinner $!
rm -rf $SM_INSTALL_PATH/stepmania\ 5
log "Making Stepmania!"
make -j$_CPUS > make.out 2>&1 &
spinner $!
if [ $? -eq 0 ]; then
make install > make.install 2>&1 &
spinner $!
SM_VER=$(grep PACKAGE_VERSION= configure | awk -F\' '{print $(NF-1)}')
cd "$SM_INSTALL_PATH/stepmania-$SM_VER"
mkdir -p $SM_INSTALL_PATH/stepmania-$SM_VER/Packages > /dev/null
touch portable.ini
bundle_sm
else
log "error in make!"
fi
}
#build the release package and md5sum and update -current symlinks
bundle_sm ()
{
if [ -f "$SM_INSTALL_PATH/stepmania-$SM_VER/stepmania" ]; then
_NOW=$(date +%Y%m%d%H%M)
cd "$SM_INSTALL_PATH/stepmania-$SM_VER"
touch build-$_NOW
log "Creating stepmania tar bundle."
tar -czf $SM_REPO_PATH/stepmania-build-$_NOW.tar.gz *
ln -sf $SM_REPO_PATH/stepmania-build-$_NOW.tar.gz $SM_REPO_PATH/stepmania-build-current.tar.gz
log "Creating stepmania md5sum"
md5sum $SM_REPO_PATH/stepmania-build-$_NOW.tar.gz | awk '{ print $1 }' > $SM_REPO_PATH/stepmania-build-$_NOW.md5sum
ln -sf $SM_REPO_PATH/stepmania-build-$_NOW.md5sum $SM_REPO_PATH/stepmania-build-current.md5sum
cleanup $SM_REPO_PATH
else
log "stepmania failed to build."
fi
#clean up installation path.
cd ~
rm -rf "$SM_INSTALL_PATH/stepmania-$SM_VER"
}
bundle_piu_theme ()
{
_NOW=$(date +%Y%m%d%H%M)
cd "$THEME_PATH"
for THEME in ${BUILD_THEME_NAMES[@]}
do
if [ -d $THEME_PATH/$THEME/.git ]; then
cd "$THEME_PATH/$THEME"
git pull > /dev/null
fi
cd "$THEME_PATH"/..
log "Creating theme $THEME bundle"
# tar -cazf $THEME_REPO_PATH/piu-$THEME-theme-$_NOW.tar.gz $THEME
# ln -sf $THEME_REPO_PATH/piu-$THEME-theme-$_NOW.tar.gz $THEME_REPO_PATH/piu-$THEME-theme-current.tar.gz
# log "Creating theme $THEME md5sum"
# md5sum $THEME_REPO_PATH/piu-$THEME-theme-$_NOW.tar.gz | awk '{ print $1 }' > $THEME_REPO_PATH/piu-$THEME-theme-$_NOW.md5sum
# ln -sf $THEME_REPO_PATH/piu-$THEME-theme-$_NOW.md5sum $THEME_REPO_PATH/piu-$THEME-theme-current.md5sum
zip -9 -r -q $THEME_REPO_PATH/$THEME.smzip Themes/$THEME
done
# clean_themes $THEME_REPO_PATH
}
bundle_piuio ()
{
_NOW=$(date +%Y%m%d%H%M)
cd "$PIUIO_PATH"
git pull > /dev/null
log "Creating PIUIO bundle"
cd ..
tar -cazf $PIUIO_REPO_PATH/piuio-$_NOW.tar.gz piuio
ln -sf $PIUIO_REPO_PATH/piuio-$_NOW.tar.gz $PIUIO_REPO_PATH/piuio-current.tar.gz
log "Creating PIUIO md5sum"
md5sum $PIUIO_REPO_PATH/piuio-$_NOW.tar.gz | awk '{ print $1 }' > $PIUIO_REPO_PATH/piuio-$_NOW.md5sum
ln -sf $PIUIO_REPO_PATH/piuio-$_NOW.md5sum $PIUIO_REPO_PATH/piuio-current.md5sum
cleanup $PIUIO_REPO_PATH
}
#check a git repository to see if it needs to be updated.
#expects $1 to be the path to the git repository and $2 to be the name of the repository.
check_git ()
{
local GIT_CHECK=0
cd "$1"
git fetch
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
if [ $LOCAL = $REMOTE ]; then
log "$2 is current."
elif [ $LOCAL = $BASE ]; then
log "building $2 bundle"
GIT_CHECK=1
elif [ $REMOTE = $BASE ]; then
log "Local $2 repo manually updated."
else
log "Local $2 repo diverged"
fi
exit $GIT_CHECK
}
#takes md5sum of files and then md5sums those files.
# $1 is the path to the directory to be checked.
# $2 is the path to the md5sum directory
# $3 name of the repository
check_md5sum ()
{
local CHECK_PATH=$1
local MD5_PATH=$2
local REPO_NAME=$3
local MD5_CHECK=0
local NEW_MD5=$(find $CHECK_PATH -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum| awk '{ print $1 }')
if [ -f $MD5_PATH/$REPO_NAME ]; then
#load md5sum file and compare
CURRENT_MD5=$(<$MD5_PATH/$REPO_NAME)
if [ "$CURRENT_MD5" = "$NEW_MD5" ]; then
log "$REPO_NAME is current."
else
log "building $REPO_NAME bundle"
MD5_CHECK=1
if [ $CHECK_ONLY = 0 ]; then
echo $NEW_MD5 > $MD5_PATH/$REPO_NAME
fi
fi
else
MD5_CHECK=1
echo $NEW_MD5 > $MD5_PATH/$REPO_NAME
log "Creating new repo for $REPO_NAME"
fi
exit $MD5_CHECK
}
#main functions.
#checks piuio git
if [ $BUILD_PIUIO = 0 ]; then
STATUS=$(check_git $PIUIO_PATH 'piuio')
BUILD_PIUIO=$?
log $STATUS
else
log 'Forcing update of piuio package'
fi
#check stepmania's git
if [ $BUILD_SM = 0 ]; then
STATUS=$(check_git $SM_PATH 'stepmania')
BUILD_SM=$?
log $STATUS
else
log 'Forcing update of stepmania package'
fi
#checks each directory in the themes directory, determines if it's a git repo or needs an md5sum check and then makes the check
#if it needs to be updated it will add the theme name to $BUILD_THEME_NAMES and set BUILD_THEME to 1.
if [ $BUILD_THEME = 0 ]; then
cd "$THEME_PATH"
for THEME in **
do
log "Checking Theme: $THEME"
if [ -d $THEME_PATH/$THEME/.git ]; then
STATUS=$(check_git $THEME_PATH/$THEME $THEME)
else
STATUS=$(check_md5sum $THEME_PATH/$THEME $THEME_PATH/.md5sum $THEME)
fi
BUILD_CHECK=$?
if [ $BUILD_CHECK = 1 ]; then
BUILD_THEME=1
BUILD_THEME_NAMES+=($THEME)
fi
log $STATUS
done
else
cd "$THEME_PATH"
for THEME in **
do
BUILD_THEME_NAMES+=($THEME)
done
log 'Forcing update of theme packages'
fi
#if we're running a check only we skip this.
#Otherwise we run the specific build routines that were either forced by a flag or
#Were determined to be out of date.
if [ $CHECK_ONLY = 0 ]; then
if [ $BUILD_SM = 1 ]; then
build_sm
fi
if [ $BUILD_THEME = 1 ]; then
bundle_piu_theme
fi
if [ $BUILD_PIUIO = 1 ]; then
bundle_piuio
fi
fi
exit 0