-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallD.sh
executable file
·806 lines (687 loc) · 20.3 KB
/
installD.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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
#!/usr/bin/env bash
#
# Copyright: Copyright Martin Nowak 2015 -.
# License: Boost License 1.0 (www.boost.org/LICENSE_1_0.txt)
# Authors: Martin Nowak
# Documentation: https://dlang.org/install.html
_() {
set -ueo pipefail
# ------------------------------------------------------------------------------
log_() {
local tilde='~'
echo "${@//$HOME/$tilde}"
}
log() {
if [ "$VERBOSITY" -gt 0 ]; then
log_ "$@"
fi
}
logV() {
if [ "$VERBOSITY" -gt 1 ]; then
log_ "$@"
fi
}
logE() {
log_ "$@" >&2
}
fatal() {
logE "$@"
exit 1
}
# ------------------------------------------------------------------------------
curl2() {
: "${CURL_USER_AGENT:="installer/install.sh $(command curl --version | head -n 1)"}"
TIMEOUT_ARGS=(--connect-timeout 5 --speed-time 30 --speed-limit 1024)
command curl --fail "${TIMEOUT_ARGS[@]}" -L "$@"
}
curl() {
if [ "$VERBOSITY" -gt 0 ]; then
curl2 -# "$@"
else
curl2 -sS "$@"
fi
}
retry() {
for i in {0..4}; do
if "$@"; then
break
elif [ $i -lt 4 ]; then
sleep $((1 << i))
else
fatal "Failed to download '$url'"
fi
done
}
# path, verify (0/1), urls...
# the gpg signature is assumed to be url+.sig
download() {
local path do_verify mirrors
path="$1"
do_verify="$2"
mirrors=("${@:3}")
try_all_mirrors() {
for i in "${!mirrors[@]}" ; do
if [ "$i" -gt 0 ] ; then
log "Falling back to mirror: ${mirrors[$i]}"
fi
if curl "${mirrors[$i]}" -o "$path" ; then
return
fi
done
return 1
}
retry try_all_mirrors
if [ "$do_verify" -eq 1 ]; then
verify "$path" "${mirrors[@]/%/.sig}"
fi
}
# path, urls...
download_with_verify() {
download "$1" 1 "${@:2}"
}
# path, urls...
download_without_verify() {
download "$1" 0 "${@:2}"
}
# urls...
fetch() {
local mirrors path
path=$(mktemp "$TMP_ROOT/XXXXXX")
mirrors=("$@")
try_all_mirrors() {
for mirror in "${mirrors[@]}" ; do
if curl2 -sS "$mirror" -o "$path" ; then
return
fi
done
return 1
}
retry try_all_mirrors
cat "$path"
rm "$path"
}
# ------------------------------------------------------------------------------
COMMAND=
COMPILER=dmd
VERBOSITY=1
ROOT=~/dlang
DUB_BIN_PATH=
case $(uname -s) in
Darwin) OS=osx;;
Linux) OS=linux;;
FreeBSD) OS=freebsd;;
*)
fatal "Unsupported OS $(uname -s)"
;;
esac
case $(uname -m) in
x86_64|amd64) ARCH=x86_64; MODEL=64;;
i*86) ARCH=x86; MODEL=32;;
*)
fatal "Unsupported Arch $(uname -m)"
;;
esac
check_tools() {
while [[ $# -gt 0 ]]; do
if ! command -v "$1" &>/dev/null &&
# detect OSX' liblzma support in libarchive
! { [ "$OS-$1" == osx-xz ] && otool -L /usr/lib/libarchive.*.dylib | grep -qF liblzma; }; then
local msg="Required tool $1 not found, please install it."
case $OS-$1 in
osx-xz) msg="$msg http://macpkg.sourceforge.net";;
esac
fatal "$msg"
fi
shift
done
}
# ------------------------------------------------------------------------------
mkdir -p "$ROOT"
TMP_ROOT=$(mktemp -d "$ROOT/.installer_tmp_XXXXXX")
mkdtemp() {
mktemp -d "$TMP_ROOT/XXXXXX"
}
cleanup() {
rm -rf "$TMP_ROOT";
}
trap cleanup EXIT
# ------------------------------------------------------------------------------
usage() {
log 'Usage
install.sh [<command>] [<args>]
Commands
install Install a D compiler (default command)
uninstall Remove an installed D compiler
list List all installed D compilers
update Update this dlang script
Options
-h --help Show this help
-p --path Install location (default ~/dlang)
-v --verbose Verbose output
Run "install.sh <command> --help to get help for a specific command.
If no argument are provided, the latest DMD compiler will be installed.
'
}
command_help() {
if [ -z "${1-}" ]; then
usage
return
fi
local _compiler='Compiler
dmd|gdc|ldc latest version of a compiler
dmd|gdc|ldc-<version> specific version of a compiler (e.g. dmd-2.071.1, ldc-1.1.0-beta2)
dmd|ldc-beta latest beta version of a compiler
dmd-nightly latest dmd nightly
dmd-2016-08-08 specific dmd nightly
'
case $1 in
install)
log 'Usage
install.sh install <compiler>
Description
Download and install a D compiler.
By default the latest release of the DMD compiler is selected.
Options
-a --activate Only print the path to the activate script
Examples
install.sh
install.sh dmd
install.sh install dmd
install.sh install dmd-2.071.1
install.sh install ldc-1.1.0-beta2
'
log "$_compiler"
;;
uninstall)
log 'Usage
install.sh uninstall <compiler>
Description
Uninstall a D compiler.
Examples
install.sh uninstall dmd
install.sh uninstall dmd-2.071.1
install.sh uninstall ldc-1.1.0-beta2
'
log "$_compiler"
;;
list)
log 'Usage
install.sh list
Description
List all installed D compilers.
'
;;
update)
log 'Usage
install.sh update
Description
Update the dlang installer itself.
'
esac
}
# ------------------------------------------------------------------------------
parse_args() {
local _help=
local _activate=
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
_help=1
;;
-p | --path)
if [ -z "${2:-}" ]; then
fatal '-p|--path must be followed by a path.';
fi
shift
ROOT="$1"
;;
-v | --verbose)
VERBOSITY=2
;;
-a | --activate)
_activate=1
;;
use | install | uninstall | list | update)
COMMAND=$1
;;
remove)
COMMAND=uninstall
;;
dmd | dmd-* | gdc | gdc-* | ldc | ldc-*)
COMPILER=$1
;;
*)
usage
fatal "Unrecognized command-line parameter: $1"
;;
esac
shift
done
if [ -n "$_help" ]; then
command_help $COMMAND
exit 0
fi
if [ -n "$_activate" ]; then
if [ "${COMMAND:-install}" == "install" ]; then
VERBOSITY=0
else
command_help $COMMAND
exit 1
fi
fi
}
# ------------------------------------------------------------------------------
# run_command command [compiler]
run_command() {
case $1 in
install)
check_tools curl
if [ ! -f "$ROOT/install.sh" ] || [ ! -f "$ROOT/d-keyring.gpg" ] ; then
install_dlang_installer
fi
if [ -z "${2:-}" ]; then
fatal "Missing compiler argument for $1 command.";
fi
if [ -d "$ROOT/$2" ]; then
log "$2 already installed";
else
install_compiler "$2"
fi
local -r binpath=$(binpath_for_compiler "$2")
if [ -f "$ROOT/$2/$binpath/dub" ]; then
if [[ $("$ROOT/$2/$binpath/dub" --version) =~ ([0-9]+\.[0-9]+\.[0-9]+(-[^, ]+)?) ]]; then
log "Using dub ${BASH_REMATCH[1]} shipped with $2"
else
log "Using dub shipped with $2"
fi
else
DUB_BIN_PATH="${ROOT}/dub"
install_dub
fi
write_env_vars "$2"
if [ "$(basename "$SHELL")" = fish ]; then
local suffix=.fish
fi
if [ "$VERBOSITY" -eq 0 ]; then
echo "$ROOT/$2/activate${suffix:-}"
else
log "
Run \`source $ROOT/$2/activate${suffix:-}\` in your shell to use $2.
This will setup PATH, LIBRARY_PATH, LD_LIBRARY_PATH, DMD, DC, and PS1.
Run \`deactivate\` later on to restore your environment."
fi
;;
uninstall)
if [ -z "${2:-}" ]; then
fatal "Missing compiler argument for $1 command.";
fi
uninstall_compiler "$2"
;;
list)
list_compilers
;;
update)
install_dlang_installer
;;
esac
}
install_dlang_installer() {
local tmp mirrors
tmp=$(mkdtemp)
local mirrors=(
"https://dlang.org/install.sh"
"https://nightlies.dlang.org/install.sh"
)
local keyring_mirrors=(
"https://dlang.org/d-keyring.gpg"
"https://nightlies.dlang.org/d-keyring.gpg"
)
mkdir -p "$ROOT"
log "Downloading https://dlang.org/d-keyring.gpg"
if [ ! -f "$ROOT/d-keyring.gpg" ]; then
download_without_verify "$tmp/d-keyring.gpg" "${keyring_mirrors[@]}"
else
download_with_verify "$tmp/d-keyring.gpg" "${keyring_mirrors[@]}"
fi
mv "$tmp/d-keyring.gpg" "$ROOT/d-keyring.gpg"
log "Downloading ${mirrors[0]}"
download_with_verify "$tmp/install.sh" "${mirrors[@]}"
mv "$tmp/install.sh" "$ROOT/install.sh"
rmdir "$tmp"
chmod +x "$ROOT/install.sh"
log "The latest version of this script was installed as $ROOT/install.sh.
It can be used it to install further D compilers.
Run \`$ROOT/install.sh --help\` for usage information.
"
}
resolve_latest() {
case $COMPILER in
dmd)
local mirrors=(
"http://downloads.dlang.org/releases/LATEST"
"http://ftp.digitalmars.com/LATEST"
)
logV "Determing latest dmd version (${mirrors[0]})."
COMPILER="dmd-$(fetch "${mirrors[@]}")"
;;
dmd-beta)
local mirrors=(
"http://downloads.dlang.org/pre-releases/LATEST"
"http://ftp.digitalmars.com/LATEST_BETA"
)
logV "Determing latest dmd-beta version (${mirrors[0]})."
COMPILER="dmd-$(fetch "${mirrors[@]}")"
;;
dmd-*) # nightly master or feature branch
# dmd-nightly, dmd-master, dmd-branch
# but not: dmd-2016-10-19 or dmd-branch-2016-10-20
# dmd-2.068.0 or dmd-2.068.2-5
if [[ ! $COMPILER =~ -[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] &&
[[ ! $COMPILER =~ -[0-9][.][0-9]{3}[.][0-9]{1,3}(-[0-9]{1,3})? ]]
then
local url=http://nightlies.dlang.org/$COMPILER/LATEST
logV "Determing latest $COMPILER version ($url)."
COMPILER="dmd-$(fetch "$url")"
fi
;;
ldc)
local url=https://ldc-developers.github.io/LATEST
logV "Determing latest ldc version ($url)."
COMPILER="ldc-$(fetch $url)"
;;
ldc-beta)
local url=https://ldc-developers.github.io/LATEST_BETA
logV "Determining latest ldc-beta version ($url)."
COMPILER="ldc-$(fetch $url)"
;;
gdc)
local url=http://gdcproject.org/downloads/LATEST
logV "Determing latest gdc version ($url)."
COMPILER="gdc-$(fetch $url)"
;;
esac
}
install_compiler() {
local compiler="$1"
# dmd-2.065, dmd-2.068.0, dmd-2.068.1-b1
if [[ $1 =~ ^dmd-2\.([0-9]{3})(\.[0-9])?(-.*)?$ ]]; then
local basename="dmd.2.${BASH_REMATCH[1]}${BASH_REMATCH[2]}${BASH_REMATCH[3]}"
local ver="2.${BASH_REMATCH[1]}"
if [[ $ver > "2.064z" ]]; then
basename="$basename.$OS"
ver="$ver${BASH_REMATCH[2]}"
if [ $OS = freebsd ]; then
basename="$basename-$MODEL"
fi
fi
if [[ $ver > "2.068.0z" ]]; then
local arch="tar.xz"
else
local arch="zip"
fi
local mirrors
if [ -n "${BASH_REMATCH[3]}" ]; then # pre-release
mirrors=(
"http://downloads.dlang.org/pre-releases/2.x/$ver/$basename.$arch"
"http://ftp.digitalmars.com/$basename.$arch"
)
else
mirrors=(
"http://downloads.dlang.org/releases/2.x/$ver/$basename.$arch"
"http://ftp.digitalmars.com/$basename.$arch"
)
fi
download_and_unpack_with_verify "$ROOT/$compiler" "${mirrors[@]}"
# dmd-2015-11-20, dmd-feature_branch-2016-10-20
elif [[ $1 =~ ^dmd(-(.*))?-[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
local branch=${BASH_REMATCH[2]:-master}
local basename="dmd.$branch.$OS"
if [ $OS = freebsd ]; then
basename="$basename-$MODEL"
fi
local url="http://nightlies.dlang.org/$1/$basename.tar.xz"
download_and_unpack_with_verify "$ROOT/$compiler" "$url"
# ldc-0.12.1 or ldc-0.15.0-alpha1
elif [[ $1 =~ ^ldc-([0-9]+\.[0-9]+\.[0-9]+(-.*)?)$ ]]; then
local ver=${BASH_REMATCH[1]}
local url="https://github.com/ldc-developers/ldc/releases/download/v$ver/ldc2-$ver-$OS-$ARCH.tar.xz"
if [ $OS != linux ] && [ $OS != osx ]; then
fatal "no ldc binaries available for $OS"
fi
download_and_unpack_without_verify "$ROOT/$compiler" "$url"
# gdc-4.8.2, gdc-4.9.0-alpha1, gdc-5.2, or gdc-5.2-alpha1
elif [[ $1 =~ ^gdc-([0-9]+\.[0-9]+(\.[0-9]+)?(-.*)?)$ ]]; then
local name=${BASH_REMATCH[0]}
if [ $OS != linux ]; then
fatal "no gdc binaries available for $OS"
fi
case $ARCH in
x86_64) local triplet=x86_64-linux-gnu;;
x86) local triplet=i686-linux-gnu;;
esac
local url="http://gdcproject.org/downloads/binaries/$triplet/$name.tar.xz"
download_and_unpack_without_verify "$ROOT/$compiler" "$url"
url=https://raw.githubusercontent.com/D-Programming-GDC/GDMD/a67179d54611ae8cfb1d791cf7ab8e36c3224b76/dmd-script
log "Downloading gdmd $url"
download_without_verify "$ROOT/$1/bin/gdmd" "$url"
chmod +x "$ROOT/$1/bin/gdmd"
else
fatal "Unknown compiler '$compiler'"
fi
}
find_gpg() {
if command -v gpg2 &>/dev/null; then
echo gpg2
elif command -v gpg &>/dev/null; then
echo gpg
else
echo "Warning: No gpg tool found to verify downloads." >&2
echo x
fi
}
# path, verify (0/1), urls...
# the gpg signature is assumed to be url+.sig
download_and_unpack() {
local path do_verify urls
path="$1"
do_verify="$2"
urls=("${@:3}")
local tmp name
tmp=$(mkdtemp)
name="$(basename "${urls[0]}")"
check_tools curl
if [[ $name =~ \.tar\.xz$ ]]; then
check_tools tar xz
else
check_tools unzip
fi
log "Downloading and unpacking ${urls[0]}"
download "$tmp/$name" "$do_verify" "${urls[@]}"
if [[ $name =~ \.tar\.xz$ ]]; then
tar --strip-components=1 -C "$tmp" -Jxf "$tmp/$name"
else
unzip -q -d "$tmp" "$tmp/$name"
mv "$tmp/dmd2"/* "$tmp/"
rmdir "$tmp/dmd2"
fi
rm "$tmp/$name"
mv "$tmp" "$path"
}
# path, urls...
download_and_unpack_with_verify() {
download_and_unpack "$1" 1 "${@:2}"
}
# path, urls...
download_and_unpack_without_verify() {
download_and_unpack "$1" 0 "${@:2}"
}
# path, urls...
verify() {
local path urls
path="$1"
urls=("${@:2}")
: "${GPG:=$(find_gpg)}"
if [ "$GPG" = x ]; then
return
fi
if ! $GPG -q --verify --keyring "$ROOT/d-keyring.gpg" --no-default-keyring <(fetch "${urls[@]}") "$path" 2>/dev/null; then
fatal "Invalid signature ${urls[0]}"
fi
}
binpath_for_compiler() {
case $1 in
dmd*)
local suffix=
[ $OS = osx ] || suffix=$MODEL
local -r binpath=$OS/bin$suffix
;;
ldc*)
local -r binpath=bin
;;
gdc*)
local -r binpath=bin
;;
esac
echo "$binpath"
}
write_env_vars() {
local -r binpath=$(binpath_for_compiler "$1")
case $1 in
dmd*)
local suffix=
[ $OS = osx ] || suffix=$MODEL
local libpath=$OS/lib$suffix
local dc=dmd
local dmd=dmd
;;
ldc*)
local libpath=lib
local dc=ldc2
local dmd=ldmd2
;;
gdc*)
if [ -d "$ROOT/$1/lib$MODEL" ]; then
local libpath=lib$MODEL
else
# older gdc releases only ship 64-bit libs
local libpath=lib
fi
local dc=gdc
local dmd=gdmd
;;
esac
logV "Writing environment variables to $ROOT/$1/activate"
cat > "$ROOT/$1/activate" <<EOF
deactivate() {
export PATH="\$_OLD_D_PATH"
export LIBRARY_PATH="\$_OLD_D_LIBRARY_PATH"
export LD_LIBRARY_PATH="\$_OLD_D_LD_LIBRARY_PATH"
export PS1="\$_OLD_D_PS1"
unset _OLD_D_PATH
unset _OLD_D_LIBRARY_PATH
unset _OLD_D_LD_LIBRARY_PATH
unset _OLD_D_PS1
unset DMD
unset DC
unset -f deactivate
}
_OLD_D_PATH="\${PATH:-}"
_OLD_D_LIBRARY_PATH="\${LIBRARY_PATH:-}"
_OLD_D_LD_LIBRARY_PATH="\${LD_LIBRARY_PATH:-}"
_OLD_D_PS1="\${PS1:-}"
export PATH="${DUB_BIN_PATH}${DUB_BIN_PATH:+:}$ROOT/$1/$binpath\${PATH:+:}\${PATH:-}"
export LIBRARY_PATH="$ROOT/$1/$libpath\${LIBRARY_PATH:+:}\${LIBRARY_PATH:-}"
export LD_LIBRARY_PATH="$ROOT/$1/$libpath\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH:-}"
export DMD=$dmd
export DC=$dc
export PS1="($1)\${PS1:-}"
EOF
logV "Writing environment variables to $ROOT/$1/activate.fish"
cat > "$ROOT/$1/activate.fish" <<EOF
function deactivate
set -gx PATH \$_OLD_D_PATH
set -gx LIBRARY_PATH \$_OLD_D_LIBRARY_PATH
set -gx LD_LIBRARY_PATH \$_OLD_D_LD_LIBRARY_PATH
functions -e fish_prompt
functions -c _old_d_fish_prompt fish_prompt
functions -e _old_d_fish_prompt
set -e _OLD_D_PATH
set -e _OLD_D_LIBRARY_PATH
set -e _OLD_D_LD_LIBRARY_PATH
set -e DMD
set -e DC
functions -e deactivate
end
set -g _OLD_D_PATH \$PATH
set -g _OLD_D_LIBRARY_PATH \$LIBRARY_PATH
set -g _OLD_D_LD_LIBRARY_PATH \$LD_LIBRARY_PATH
set -g _OLD_D_PS1 \$PS1
set -gx PATH ${DUB_BIN_PATH:+\'}${DUB_BIN_PATH}${DUB_BIN_PATH:+\' }'$ROOT/$1/$binpath' \$PATH
set -gx LIBRARY_PATH '$ROOT/$1/$libpath' \$LIBRARY_PATH
set -gx LD_LIBRARY_PATH '$ROOT/$1/$libpath' \$LD_LIBRARY_PATH
set -gx DMD $dmd
set -gx DC $dc
functions -c fish_prompt _old_d_fish_prompt
function fish_prompt
printf '($1)%s' (_old_d_fish_prompt)
end
EOF
}
uninstall_compiler() {
if [ ! -d "$ROOT/$1" ]; then
fatal "$1 is not installed in $ROOT"
fi
log "Removing $ROOT/$1"
rm -rf "${ROOT:?}/$1"
}
list_compilers() {
check_tools find
if [ -d "$ROOT" ]; then
find "$ROOT" \
-mindepth 1 \
-maxdepth 1 \
-not -name 'dub*' \
-not -name install.sh \
-not -name d-keyring.gpg \
-not -name '.*' \
-exec basename {} \; | \
grep . # fail if none found
fi
}
install_dub() {
if [ $OS != linux ] && [ $OS != osx ]; then
log "no dub binaries available for $OS"
return
fi
local latestMirrors=(
"http://dlang.github.io/dub/LATEST"
"http://code.dlang.org/download/LATEST"
)
logV "Determining latest dub version (${latestMirrors[0]})."
dubVersion="$(fetch "${latestMirrors[@]}")"
dub="dub-${dubVersion}"
if [ -d "$ROOT/$dub" ]; then
log "$dub already installed"
return
fi
local tmp url
tmp=$(mkdtemp)
local mirrors=(
"https://github.com/dlang/dub/releases/download/${dubVersion}/$dub-$OS-$ARCH.tar.gz"
"http://code.dlang.org/files/$dub-$OS-$ARCH.tar.gz"
)
log "Downloading and unpacking ${mirrors[0]}"
download_without_verify "$tmp/dub.tar.gz" "${mirrors[@]}"
tar -C "$tmp" -zxf "$tmp/dub.tar.gz"
logV "Removing old dub versions"
rm -rf "$ROOT/dub" "$ROOT/dub-*"
mv "$tmp" "$ROOT/$dub"
logV "Linking $ROOT/dub -> $ROOT/$dub"
ln -s "$dub" "$ROOT/dub"
}
# ------------------------------------------------------------------------------
parse_args "$@"
resolve_latest "$COMPILER"
run_command ${COMMAND:-install} "$COMPILER"
}
_ "$@"