forked from Automattic/vip-go-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools-init.sh
210 lines (168 loc) · 7.95 KB
/
tools-init.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
#!/bin/bash
export PHP_CODESNIFFER_VER="3.3.2"
export PHP_CODESNIFFER_SHA1SUM="1091af07e902c2fcc13730dc51d44cbf99b7dcb9"
export WP_CODING_STANDARDS_VER="2.1.1"
export WP_CODING_STANDARDS_SHA1SUM="d35ec268531453cbf2078c57356e38c5f8936e87";
export VIP_CODING_STANDARDS_VER="2.0.0"
export VIP_CODING_STANDARDS_SHA1SUM="3dc5a0e27625b0a1b0782bc790186ab7c13283ae";
export PHP_COMPATIBILITY_VER="9.3.1"
export PHP_COMPATIBILITY_SHA1SUM="81ab7d465b90658863b6dbc0c9ef3dc293b7cbbe";
export PHP_COMPATIBILITY_WP_VER="2.0.0"
export PHP_COMPATIBILITY_WP_SHA1SUM="e898c99749bf2a61ef21995329a222b279fab471"
export PHP_COMPATIBILITY_PARAGONIE_VER="1.0.1"
export PHP_COMPATIBILITY_PARAGONIE_SHA1SUM="28db0909de7bd505755964537b36a1515c739251"
export VIP_GO_SVG_SANITIZER_VER="0.9.4"
export VIP_GO_SVG_SANITIZER_SHA1SUM="34fdca27c90828c8866a45c7b548ebc24018ffe2"
export TMP_LOCK_FILE="$HOME/.vip-go-ci-tools-init.lck"
function sha1sum_check() {
FILENAME=$1
CORRECT_HASH=$2
TMP_HASH=`sha1sum $FILENAME|awk '{print $1}'`
if [ "$TMP_HASH" != "$CORRECT_HASH" ] ; then
echo "FAILED sha1sum check for $FILENAME; $TMP_HASH (downloaded) vs. $CORRECT_HASH (correct)";
exit;
fi
}
function lock_place() {
# Get lock, if that fails, just exit
if [ -f "$TMP_LOCK_FILE" ] ; then
echo "$0: Lock in place already, not doing anything."
exit 0
fi
# Acquire lock
touch "$TMP_LOCK_FILE"
}
function lock_remove() {
rm -f "$TMP_LOCK_FILE"
}
lock_place
#
# Exit if running as root
#
if [ "$USERNAME" == "root" ] ; then
echo "$0: Will not run as root, exiting"
lock_remove
exit 1
fi
if [ -d ~/vip-go-ci-tools ] ; then
#
# We have got the tools installed already,
# only check in 33% of cases if we should
# upgrade.
#
export TMP_RAND=`seq 1 3 | sort -R | head -n 1`
if [ "$TMP_RAND" -ne "1" ] ; then
echo "$0: Not due to update anything, exiting"
lock_remove
exit 1
fi
fi
# Fetch the latest release tag of vip-go-ci
export VIP_GO_CI_VER=""
if [ -f ~/vip-go-ci-tools/vip-go-ci/latest-release.php ] ||
[ -x ~/vip-go-ci-tools/vip-go-ci/latest-release.php ] ; then
export VIP_GO_CI_VER=`php ~/vip-go-ci-tools/vip-go-ci/latest-release.php`
fi
if [ "$VIP_GO_CI_VER" == "" ] ; then
# latest-release.php is not available, fetch it
# and then fetch the latest release number of vip-go-ci
TMP_FILE=`mktemp /tmp/vip-go-ci-latest-release-XXXXX.php`
echo "$0: Trying to determine latest release of vip-go-ci, need to fetch latest-release.php first..."
wget -O "$TMP_FILE" https://raw.githubusercontent.com/Automattic/vip-go-ci/master/latest-release.php && \
chmod u+x "$TMP_FILE" && \
export VIP_GO_CI_VER=`php $TMP_FILE` && \
rm "$TMP_FILE" && \
echo "$0: Latest release of vip-go-ci is: $VIP_GO_CI_VER"
fi
# The release number is not available at all, abort
if [ "$VIP_GO_CI_VER" == "" ] ; then
echo "$0: Could not determine latest release of vip-go-ci -- aborting";
lock_remove
exit 1
fi
if [ -d ~/vip-go-ci-tools ] ; then
# Tools installed, check if versions installed match with
# the versions specified in the current version of this file.
# If not, remove what is already installed and re-install
# Assume that no re-install is needed
export TMP_DO_DELETE="0"
for TMP_FILE in "vip-coding-standards-$VIP_CODING_STANDARDS_VER.txt" "wp-coding-standards-$WP_CODING_STANDARDS_VER.txt" "php-codesniffer-$PHP_CODESNIFFER_VER.txt" "vip-go-ci-$VIP_GO_CI_VER.txt" "php-compatibility-$PHP_COMPATIBILITY_VER.txt" "php-compatibility-wp-$PHP_COMPATIBILITY_WP_VER.txt" "php-compatibility-paragonie-$PHP_COMPATIBILITY_PARAGONIE_VER.txt" "vip-go-svg-sanitizer-$VIP_GO_SVG_SANITIZER_VER.txt" ; do
if [ ! -f ~/vip-go-ci-tools/$TMP_FILE ] ; then
export TMP_DO_DELETE="1"
fi
done
if [ "$TMP_DO_DELETE" -eq "1" ] ; then
echo "$0: Detected obsolete vip-go-ci tools, removing them"
# One or more of the versions do not match,
# remove and reinstall
rm -rf ~/vip-go-ci-tools
echo "$0: Removed tools"
fi
fi
if [ -d ~/vip-go-ci-tools ] ; then
echo "$0: Nothing to update, exiting"
lock_remove
exit 0
else
#
# No tools installed, do install them,
#
echo "$0: No vip-go-ci tools present, will install"
TMP_FOLDER=`mktemp -d /tmp/vip-go-ci-tools-XXXXXX`
cd $TMP_FOLDER && \
wget "https://github.com/squizlabs/PHP_CodeSniffer/archive/$PHP_CODESNIFFER_VER.tar.gz" && \
sha1sum_check "$PHP_CODESNIFFER_VER.tar.gz" "$PHP_CODESNIFFER_SHA1SUM" && \
tar -zxvf "$PHP_CODESNIFFER_VER.tar.gz" && \
rm -fv "$PHP_CODESNIFFER_VER.tar.gz" && \
mv "PHP_CodeSniffer-$PHP_CODESNIFFER_VER/" phpcs && \
touch $TMP_FOLDER/php-codesniffer-$PHP_CODESNIFFER_VER.txt && \
wget "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/$WP_CODING_STANDARDS_VER.tar.gz" && \
sha1sum_check "$WP_CODING_STANDARDS_VER.tar.gz" "$WP_CODING_STANDARDS_SHA1SUM" && \
tar -zxvf "$WP_CODING_STANDARDS_VER.tar.gz" && \
rm -fv "$WP_CODING_STANDARDS_VER.tar.gz" && \
mv WordPress-Coding-Standards-$WP_CODING_STANDARDS_VER/WordPress* phpcs/src/Standards/ && \
touch $TMP_FOLDER/wp-coding-standards-$WP_CODING_STANDARDS_VER.txt && \
wget "https://github.com/Automattic/VIP-Coding-Standards/archive/$VIP_CODING_STANDARDS_VER.tar.gz" && \
sha1sum_check "$VIP_CODING_STANDARDS_VER.tar.gz" "$VIP_CODING_STANDARDS_SHA1SUM" && \
tar -zxvf "$VIP_CODING_STANDARDS_VER.tar.gz" && \
mv "VIP-Coding-Standards-$VIP_CODING_STANDARDS_VER/WordPressVIPMinimum/" phpcs/src/Standards/ && \
mv "VIP-Coding-Standards-$VIP_CODING_STANDARDS_VER/WordPress-VIP-Go/" phpcs/src/Standards/ && \
rm -f "$VIP_CODING_STANDARDS_VER".tar.gz && \
touch $TMP_FOLDER/vip-coding-standards-$VIP_CODING_STANDARDS_VER.txt && \
wget "https://github.com/PHPCompatibility/PHPCompatibility/archive/$PHP_COMPATIBILITY_VER.tar.gz" && \
sha1sum_check "$PHP_COMPATIBILITY_VER.tar.gz" "$PHP_COMPATIBILITY_SHA1SUM" && \
tar -zxvf "$PHP_COMPATIBILITY_VER.tar.gz" && \
mv "PHPCompatibility-$PHP_COMPATIBILITY_VER/PHPCompatibility" phpcs/src/Standards/ && \
mv "PHPCompatibility-$PHP_COMPATIBILITY_VER/PHPCSAliases.php" phpcs/src/Standards/ && \
touch "$TMP_FOLDER/php-compatibility-$PHP_COMPATIBILITY_VER.txt" && \
rm -f "$PHP_COMPATIBILITY_VER.tar.gz" && \
wget "https://github.com/PHPCompatibility/PHPCompatibilityWP/archive/$PHP_COMPATIBILITY_WP_VER.tar.gz" && \
sha1sum_check "$PHP_COMPATIBILITY_WP_VER.tar.gz" "$PHP_COMPATIBILITY_WP_SHA1SUM" && \
tar -zxvf "$PHP_COMPATIBILITY_WP_VER.tar.gz" && \
mv "PHPCompatibilityWP-$PHP_COMPATIBILITY_WP_VER/PHPCompatibilityWP" phpcs/src/Standards/ && \
touch $TMP_FOLDER/php-compatibility-wp-$PHP_COMPATIBILITY_WP_VER.txt && \
rm -f "$PHP_COMPATIBILITY_WP_VER.tar.gz" && \
wget "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/archive/$PHP_COMPATIBILITY_PARAGONIE_VER.tar.gz" && \
sha1sum_check "$PHP_COMPATIBILITY_PARAGONIE_VER.tar.gz" "$PHP_COMPATIBILITY_PARAGONIE_SHA1SUM" && \
tar -zxvf "$PHP_COMPATIBILITY_PARAGONIE_VER.tar.gz" && \
mv PHPCompatibilityParagonie-$PHP_COMPATIBILITY_PARAGONIE_VER/PHPCompatibilityParagonie* phpcs/src/Standards/ && \
touch $TMP_FOLDER/php-compatibility-paragonie-$PHP_COMPATIBILITY_PARAGONIE_VER.txt && \
rm -f "$PHP_COMPATIBILITY_PARAGONIE_VER.tar.gz" && \
wget "https://github.com/Automattic/vip-go-svg-sanitizer/archive/$VIP_GO_SVG_SANITIZER_VER.tar.gz" && \
sha1sum_check "$VIP_GO_SVG_SANITIZER_VER.tar.gz" "$VIP_GO_SVG_SANITIZER_SHA1SUM" && \
tar -zxvf "$VIP_GO_SVG_SANITIZER_VER.tar.gz" && \
mv "vip-go-svg-sanitizer-$VIP_GO_SVG_SANITIZER_VER" vip-go-svg-sanitizer && \
touch "$TMP_FOLDER/vip-go-svg-sanitizer-$VIP_GO_SVG_SANITIZER_VER.txt" && \
rm -f "$VIP_GO_SVG_SANITIZER_VER.tar.gz" && \
wget "https://github.com/Automattic/vip-go-ci/archive/$VIP_GO_CI_VER.tar.gz" && \
tar -zxvf "$VIP_GO_CI_VER.tar.gz" && \
mv "vip-go-ci-$VIP_GO_CI_VER" vip-go-ci && \
rm -f "$VIP_GO_CI_VER.tar.gz" && \
touch "$TMP_FOLDER/vip-go-ci-$VIP_GO_CI_VER.txt" && \
mv $TMP_FOLDER ~/vip-go-ci-tools && \
# Note that the last action above is atomic:
# Either moving the folder succeeds, and the tools
# are all installed, or it fails and no tools are installed.
echo "$0: Installation of tools finished"
fi
lock_remove