-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-update.sh
More file actions
executable file
·90 lines (77 loc) · 2.98 KB
/
docker-update.sh
File metadata and controls
executable file
·90 lines (77 loc) · 2.98 KB
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
#!/bin/bash
TDate=$(date +%m-%d-%Y)
RelPath=$(dirname "$0")
HostIP=$(ip -4 addr show eth0 | grep -oP "(?<=inet ).*(?=/)")
if [[ -f "${RelPath}/ost/index.html" ]]; then
OSTver=$(grep -o -P '(?<=OpenSpeedTest.com V).*(?=Loaded)' ${RelPath}/ost/index.html | tr -d " ")
echo "Current version #-"$OSTver"-#"
else
### Clone OpenSpeedTest
git clone https://github.com/openspeedtest/Speed-Test.git ${RelPath}/temp
### Move the files we only need
mkdir ${RelPath}/ost/
mv -f ${RelPath}/temp/index.html ${RelPath}/ost/index.html
mv -f ${RelPath}/temp/hosted.html ${RelPath}/ost/hosted.html
mv -f ${RelPath}/temp/downloading ${RelPath}/ost/downloading
mv -f ${RelPath}/temp/upload ${RelPath}/ost/upload
mv -f ${RelPath}/temp/License.md ${RelPath}/ost/License.md
mv -f ${RelPath}/temp/assets ${RelPath}/ost/assets
rm -r ${RelPath}/temp/
fi
if [[ ! -f "${RelPath}/ost/10G-S.gif" ]]; then
wget https://github.com/openspeedtest/v2-Test/raw/main/images/10G-S.gif -P ${RelPath}/ost/ #2>/dev/null
fi
read -p "Clone fresh Repo? (default n)[y/n]: " Response
if [[ $Response =~ ^[Yy]$ ]]; then
### Clone OpenSpeedTest
git clone https://github.com/openspeedtest/Speed-Test.git ${RelPath}/temp
### Move the files we only need
mv -f ${RelPath}/temp/index.html ${RelPath}/ost/index.html
mv -f ${RelPath}/temp/hosted.html ${RelPath}/ost/hosted.html
mv -f ${RelPath}/temp/downloading ${RelPath}/ost/downloading
mv -f ${RelPath}/temp/upload ${RelPath}/ost/upload
mv -f ${RelPath}/temp/License.md ${RelPath}/ost/License.md
mv -f ${RelPath}/temp/assets ${RelPath}/ost/assets
rm -r ${RelPath}/temp/
fi
### Extracting Version number
## Example: "OpenSpeedTest.com V2.5.4 Loaded" via index.html
OSTver=$(grep -o -P '(?<=OpenSpeedTest.com V).*(?=Loaded)' ${RelPath}/ost/index.html | tr -d " ")
echo "### Verify version varible correctly grabbed in between #-Number-#"
echo ""
echo "#-"$OSTver"-#"
echo ""
read -p "Version displayed correctly? (default n)[y/n]: " Response
if [[ ! $Response =~ ^[Yy]$ ]]; then
echo "Aborted"
exit 1
fi
### Build docker image
docker build -t fitzdockerhub/openspeedtest:${OSTver} \
--build-arg BUILD_DATE="${TDate}" \
--build-arg OpenSpeedTest_VERSION="${OSTver}" \
${RelPath}
### Check Run
docker run --rm -d \
--name test-openspeedtest \
-p 83:80 \
fitzdockerhub/openspeedtest:${OSTver}
### Pause before server check
sleep 1
ServCheck=$(curl ${HostIP}:83 -s | grep "<title>")
### Verify check
if [[ ! "$ServCheck" == *"Speed Test by OpenSpeedTest.com"* ]]; then
echo "String not found or Server not running"
echo "#-"ServCheck"-#"
exit 1
else
echo "Success - WebServer successfully responded"
docker stop test-openspeedtest 2>/dev/null
fi
### Add Proper Tags
docker tag fitzdockerhub/openspeedtest:${OSTver} fitzdockerhub/openspeedtest:latest
### Deploy
docker push fitzdockerhub/openspeedtest:${OSTver}
docker push fitzdockerhub/openspeedtest:latest
## Ignore my notes
echo "*.txt" > .gitignore