This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
test.sh
executable file
·99 lines (78 loc) · 2.29 KB
/
test.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
#!/bin/bash
# Basic mediawiki-containers install tests.
set -e
_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)}
__detect_color_support() {
if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then
RC="\033[1;31m"
GC="\033[1;32m"
BC="\033[1;34m"
YC="\033[1;33m"
EC="\033[0m"
else
RC=""
GC=""
BC=""
YC=""
EC=""
fi
}
__detect_color_support
# Echo info to stdout
echoinfo() {
printf "${GC}[TEST INFO]${EC}: %s\n" "$@";
}
# Echo error to stderr
echoerror() {
printf "${RC}[TEST ERROR]${EC}: %s\n" "$@" 1>&2;
}
# Echo warnings to stdout
echowarn() {
printf "${YC}[TEST WARN]${EC}: %s\n" "$@";
}
check_service() {
echoinfo "curl http://localhost/api/rest_v1/page/html/Main_Page"
# Make sure that the wiki is reachable & RESTBase works
curl http://localhost/api/rest_v1/page/html/Main_Page \
| grep -q "MediaWiki has been successfully installed"
}
# Make sure the installer does not ask questions
export MEDIAWIKI_DOMAIN=localhost
export AUTO_UPDATE=true
CHECKOUT=$(pwd)
test_install() {
cd /tmp
if [ -d /srv/mediawiki-containers ];then
echowarn "Found existing /srv/mediawiki-containers checkout."
read -p "Delete it? (y/[n]): " DELETE_IT
if [ "$DELETE_IT" == 'y' ];then
rm -rf /srv/mediawiki-containers
else
echoerror "Aborted test as /srv/mediawiki-containers exists."
exit 1
fi
fi
# Trick the installer into testing the new code, rather than master.
git clone "$CHECKOUT" /srv/mediawiki-containers
cat "$CHECKOUT/mediawiki-containers" | bash -s install
check_service
echoinfo "Restart the service"
service mediawiki-containers restart
sleep 10
check_service
echoinfo "Exercise the automatic updater"
/etc/cron.daily/mediawiki-containers
check_service
}
if [ "$1" == 'noinstall' ];then
echoinfo "noinstall option set, only testing 'mediawiki-containers start'".
# Sadly, `docker logs` ignores sigpipe, so we can't wait for startup to be
# done via | sed '/Done in /q'. Instead, employ a static sleep for now.
./mediawiki-containers restart &
sleep 180
check_service
else
test_install
fi
echoinfo "Congratulations, all is looking good!"
exit 0