-
Notifications
You must be signed in to change notification settings - Fork 3
/
abitti_dlimg.sh
executable file
·77 lines (61 loc) · 2.04 KB
/
abitti_dlimg.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
#!/usr/bin/env bash
# Downloads and unpacks Abitti (www.abitti.fi) disk images.
#
# This script is public domain.
#
# This script is not supported by Matriculation Examination Board of
# Finland. The download URLs may change without any notice. For
# supported tools see www.abitti.fi.
IMAGEPATH=~/abitti_images
if [ "$(uname)" == "Darwin" ]; then
# MacOS download command
DLCMD_TOFILE="curl -o"
DLCMD_STDOUT="curl"
else
# Download command for other unices
DLCMD_TOFILE="wget -c -O"
DLCMD_STDOUT="wget --quiet -O -"
fi
sanitise_versioncode() {
INPUT=$1
echo -n $INPUT | perl -pe 's/[^\w\d]//g;'
}
download_and_extract() {
ZIP_URL=$1
ZIP_PATH=$2
FILE_INSIDE_ZIP=$3
FILE_OUTSIDE_ZIP=$4
ZIP_FILE=`basename $ZIP_URL`
if [ ! -d $ZIP_PATH ]; then
mkdir -p $ZIP_PATH
fi
if [ -f $ZIP_PATH/$ZIP_FILE ]; then
echo "File $ZIP_PATH/$ZIP_FILE already exists"
else
$DLCMD_TOFILE $ZIP_PATH/$ZIP_FILE $ZIP_URL
fi
if [ -f $ZIP_PATH/$FILE_OUTSIZE_ZIP ]; then
echo "File $ZIP_PATH/$FILENAME_OUTSIDE_ZIP already exists"
else
BASENAME_INSIDE_ZIP=`basename $FILE_INSIDE_ZIP`
unzip $ZIP_PATH/$ZIP_FILE $FILE_INSIDE_ZIP -d $ZIP_PATH
mv $ZIP_PATH/$FILE_INSIDE_ZIP $ZIP_PATH/$FILE_OUTSIDE_ZIP
fi
if [ -d $ZIP_PATH/ytl ]; then
rmdir $ZIP_PATH/ytl
fi
}
NEW_VERSION_ABITTI=`$DLCMD_STDOUT https://static.abitti.fi/etcher-usb/koe-etcher.ver`
NEW_VERSION_ABITTI=`sanitise_versioncode $NEW_VERSION_ABITTI`
if [ ! -f $IMAGEPATH/$NEW_VERSION_ABITTI/koe.dd ]; then
echo "Must download new Abitti ($NEW_VERSION_ABITTI)"
download_and_extract https://static.abitti.fi/etcher-usb/koe-etcher.zip $IMAGEPATH/$NEW_VERSION_ABITTI ytl/koe.img koe.dd
fi
NEW_VERSION_SERVER=`$DLCMD_STDOUT https://static.abitti.fi/etcher-usb/ktp-etcher.ver`
NEW_VERSION_SERVER=`sanitise_versioncode $NEW_VERSION_SERVER`
if [ ! -f $IMAGEPATH/$NEW_VERSION_SERVER/ktp.dd ]; then
echo "Must download new server ($NEW_VERSION_SERVER)"
download_and_extract https://static.abitti.fi/etcher-usb/ktp-etcher.zip $IMAGEPATH/$NEW_VERSION_SERVER ytl/ktp.img ktp.dd
fi
# Normal termination
exit 0