-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh.in
More file actions
executable file
·248 lines (212 loc) · 6.99 KB
/
setup.sh.in
File metadata and controls
executable file
·248 lines (212 loc) · 6.99 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
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
#!/bin/sh
set -e
set -u
display() {
lines=$(wc -l "$TEMPFILE" | cut -d ' ' -f 1)
case $lines in
0) echo ;;
1) head -1 $TEMPFILE ;;
*) echo ; cat $TEMPFILE | sed -e 's/^/ /g'
esac
}
run() {
message=$1
command=$2
fix=${3-No}
type=${4-Error}
printf "> $message...\r"
eval $command > $TEMPFILE 2>&1 && { echo "✓ $(display)$SPACE"; return 0; } || {
printf "\033[31;1m✕ $type #$?: $(display)$SPACE\n"
printf " Cannot verify $message executing \`$command'\033[0m\n"
if [ Warning = $type ] ; then
echo ' Ignoring for the moment'
return 0
fi
if [ No = "$fix" ] || [ Unattended = $MODE ] ; then
echo 'Installation cannot continue.'
return 1
fi
echo " This can be fixed by running \`$fix'"
echo
if [ No = ${4-No} ] ; then
printf ' Should we do this now ([y]es/[n]o)? '
else
printf ' Should we do this now ([y]es/[n]o/[f]orce)? '
fi
read answer </dev/fd/3
case $answer in
y|Y|yes)
eval $fix
run "$message" "$command"
return $?
;;
f|F|force)
echo ' Ignoring for the moment'
return 0
;;
*)
echo 'OK, you need to fix this yourself, then.'
return 2
;;
esac
}
}
download() {
url=$1
target=$2
printf '> Download'
if which curl >/dev/null 2>&1; then
curl '-#' -L "$url" -o $target
elif which wget >/dev/null 2>&1; then
wget -nv "$url" -O $target
fi
return $?
}
commands() {
for command in "$@"; do
which $command 2>/dev/null && return 0
done
echo "Cannot find $* in path"
return 127
}
bundle_php() {
releases=http://windows.php.net/downloads/releases/
download $releases - | grep -Eo 'php-[0-9.]+-nts-Win32-[VCvcsx0-9-]+.zip' | sort -rn | uniq > $TEMPFILE
echo "> Select which PHP version you want to use"
nl -b a $TEMPFILE
lines=$(wc -l "$TEMPFILE" | cut -d ' ' -f 1)
while : ; do
printf ' Select: '
read choice </dev/fd/3
test $choice -ge 1 2>/dev/null && test $choice -le $lines 2>/dev/null && break
printf "\033[31;1m✕ Obviously not a valid choice.\033[0m Use Ctrl+C to exit.\n"
done
release=$(head -$choice $TEMPFILE | tail -1)
test -f $release || download $releases/$release $release
pwd=$(cygpath -w $(pwd) | sed -e 's#\\#\\\\#g')
target=$(basename $release .zip)
mkdir -p $target
echo "var shell = WSH.createObject('Shell.Application');" > $TEMPFILE
echo "var origin = shell.nameSpace('$pwd\\\\$release').items();" >> $TEMPFILE
echo "var target = shell.nameSpace('$pwd\\\\$target');" >> $TEMPFILE
echo "for (var i = 0; i < origin.count; i++) {" >> $TEMPFILE
echo " WScript.Echo(' ' + origin.item(i));" >> $TEMPFILE
echo " target.copyHere(origin.item(i), 20);" >> $TEMPFILE
echo "}" >> $TEMPFILE
echo "> Extracting into $target"
cscript //NoLogo //e:JScript $(cygpath -w $TEMPFILE)
rm $release
PATH=$PATH:$target
return 0
}
configure() {
printf "> Configuration\r"
if [ -f xp.ini ] ; then
echo "! Not overwriting existing $(ls -al xp.ini)"
else
for option in "$@"; do
echo $option >> xp.ini
done
echo "✓ Created $(ls -al xp.ini)"
fi
cat xp.ini | sed -e 's/^/ /g'
}
main() {
printf "\033[32;1mXP Runners setup (@VERSION@)\033[0m\n"
echo '(c) 2017-2025 https://github.com/xp-runners/reference/'
echo
temp=${TMPDIR-${TEMP-${TMP-/tmp}}}
TEMPFILE=$(mktemp -u "$temp/tmp.XXXXXXXXXX")
SPACE=' '
MODE=Default
CHECKS=Error
FORCE=
while getopts :uf flag ; do
case $flag in
u) MODE=Unattended ; echo '> Unattended mode' ;;
f) CHECKS=Warning ; echo '> Ignoring errors from prerequisites checks' ;;
esac
done
if [ ! -t 1 ] ; then
echo '> Not running inside terminal, disabling user-interactive mode'
else
# Create FD3 to read user-interactive input from. As we're already being
# piped to, so reading from STDIN is going to result in the wrong outcome.
exec 3<&1
fi
EXTRACT='xp.exe class-main.php web-main.php'
OS=$(uname)
if [ 'Linux' = "$OS" ] && [ $(which lsb_release) ] ; then OS=$(lsb_release -si) ; fi
case $OS in
CYGWIN*)
run 'Cygwin' "uname -a"
run 'Tar' "commands tar" "/cygwinsetup.exe -P tar -q -n -W"
run 'Curl' "commands curl wget" "/cygwinsetup.exe -P curl -q -n -W"
run '.NET Framework installed' "ls -d $(cygpath -m $WINDIR)/Microsoft.NET/Framework*/v*" No $CHECKS
run 'PHP runtime available' "php.exe -v" "bundle_php" $CHECKS
php=$(which php.exe 2>/dev/null || echo No)
if [ No = $php ] ; then
echo "! No PHP runtime, cannot create xp.ini"
else
ver=$($php -r 'echo substr(PHP_VERSION, 0, 3);')
configure \
"rt=$ver" "" \
"[runtime@$ver]" \
"default=$(cygpath -w $php)" \
"extension_dir=$(cygpath -w $(dirname $php))\\ext" \
"extension=php_com_dotnet.dll"
fi
EXTRACT="$EXTRACT xar.exe tput.exe"
# Use current directory in case curl is its Windows version
temp=.
;;
Ubuntu*|Debian*)
run 'Linux' "uname -a"
run 'Tar' "commands tar" "sudo apt-get -y install tar"
run 'Curl' "commands curl wget" "sudo apt-get -y install curl"
run '.NET Framework installed' "mono --version" "sudo apt-get -y install libmono-corlib4.5-cil libmono-system-core4.0-cil libmono-system-runtime-serialization4.0-cil" $CHECKS
run 'PHP runtime available' "php -v" "sudo apt-get -y install php5-cli" $CHECKS
php=$(which php 2>/dev/null || echo No)
if [ No = "$php" ] ; then
echo "! No PHP runtime, cannot create xp.ini"
else
ver=$($php -r 'echo substr(PHP_VERSION, 0, 3);')
configure "rt=$ver" "" "[runtime@$ver]" "default=$php"
fi
echo '#!/bin/sh' > xp
echo 'exec '$(which mono)' $(dirname "$0")/xp.exe "$@"' >> xp
chmod 755 xp
echo '#!/bin/sh' > xar
echo 'exec '$(which mono)' $(dirname "$0")/xp.exe ar "$@"' >> xar
chmod 755 xar
;;
*)
run 'Un*x' "uname -a"
run 'Tar' "commands tar"
run 'Curl' "commands curl wget"
run '.NET Framework installed' "mono --version" No $CHECKS
run 'PHP runtime available' "php -v" No $CHECKS
php=$(which php 2>/dev/null || echo No)
if [ No = "$php" ] ; then
echo "! No PHP runtime, cannot create xp.ini"
else
ver=$($php -r 'echo substr(PHP_VERSION, 0, 3);')
configure "rt=$ver" "" "[runtime@$ver]" "default=$php"
fi
echo '#!/bin/sh' > xp
echo 'exec '$(which mono)' $(dirname "$0")/xp.exe "$@"' >> xp
chmod 755 xp
echo '#!/bin/sh' > xar
echo 'exec '$(which mono)' $(dirname "$0")/xp.exe ar "$@"' >> xar
chmod 755 xar
;;
esac
TARFILE=$(mktemp -u "$temp/tmp.XXXXXXXXXX")
download https://github.com/xp-runners/reference/releases/download/v@VERSION@/xp-runners_@VERSION@.tar.gz $TARFILE
run 'Extract' "tar xvfz $TARFILE $EXTRACT"
run 'Test' "ls -al $(pwd)/xp.exe"
echo
echo "Done, runners installed to $(pwd)"
rm "$TEMPFILE" "$TARFILE"
}
main "$@"