@@ -23,7 +23,7 @@ usage() {
23
23
$this : download go binaries for tetratelabs/getmesh
24
24
25
25
Usage: $this [-b] bindir [-d] [tag]
26
- -b sets bindir or installation directory, Defaults to . /bin
26
+ -b sets bindir or installation directory, Defaults to {HOME}/.getmesh /bin
27
27
-d turns on debug logging
28
28
[tag] is a tag from
29
29
https://github.com/tetratelabs/getmesh/releases
37
37
}
38
38
39
39
parse_args () {
40
- # BINDIR is . /bin unless set be ENV
40
+ # BINDIR is ${HOME}/.getmesh /bin unless set be ENV
41
41
# over-ridden by flag below
42
42
43
- BINDIR=${BINDIR:- ./ bin}
43
+ BINDIR=${BINDIR:- .getmesh / bin}
44
44
while getopts " b:dh?x" arg; do
45
45
case " $arg " in
46
46
b) BINDIR=" $OPTARG " ;;
@@ -64,13 +64,13 @@ execute() {
64
64
hash_sha256_verify " ${tmpdir} /${TARBALL} " " ${tmpdir} /${CHECKSUM} "
65
65
srcdir=" ${tmpdir} "
66
66
(cd " ${tmpdir} " && untar " ${TARBALL} " )
67
- test ! -d " ${BINDIR} " && install -d " ${BINDIR} "
67
+ test ! -d " ${HOME} / ${ BINDIR}" && install -d " ${HOME} / ${BINDIR} "
68
68
for binexe in $BINARIES ; do
69
69
if [ " $OS " = " windows" ]; then
70
70
binexe=" ${binexe} .exe"
71
71
fi
72
- install " ${srcdir} /${binexe} " " ${BINDIR} /"
73
- log_info " installed $( pwd ) /${BINDIR} /${binexe} "
72
+ install " ${srcdir} /${binexe} " " ${HOME} / ${ BINDIR} /"
73
+ log_info " installed ${HOME} /${BINDIR} /${binexe} "
74
74
done
75
75
rm -rf " ${tmpdir} "
76
76
}
125
125
is_command () {
126
126
command -v " $1 " > /dev/null
127
127
}
128
+ echo_fexists () {
129
+ [ -f " $1 " ] && echo " $1 "
130
+ }
128
131
echoerr () {
129
132
echo " $@ " 1>&2
130
133
}
@@ -383,8 +386,96 @@ TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
383
386
CHECKSUM=getmesh_${VERSION} _checksums.txt
384
387
CHECKSUM_URL=${GITHUB_DOWNLOAD} /${TAG} /${CHECKSUM}
385
388
386
-
389
+ # Install
387
390
execute
388
391
389
392
# Aa a sanity check, install the latest default Istio.
390
- $( pwd) /bin/getmesh fetch
393
+ ${HOME} /.getmesh/bin/getmesh fetch > /dev/null
394
+
395
+ # Updating profile - originally copied from https://wasmtime.dev/install.sh with some modifications
396
+ detect_profile () {
397
+ local shellname=" $1 "
398
+ local uname=" $2 "
399
+
400
+ if [ -f " $PROFILE " ]; then
401
+ echo " $PROFILE "
402
+ return
403
+ fi
404
+
405
+ # try to detect the current shell
406
+ case " $shellname " in
407
+ bash)
408
+ # based on Ubuntu 20.04 tests - the sequence of the profiles processing
409
+ # is the same for both Linux and Mac - .bash_profile first and then
410
+ # bashrc, also confirmed here:
411
+ # https://askubuntu.com/questions/161249/bashrc-not-executed-when-opening-new-terminal
412
+ echo_fexists " $HOME /.bash_profile" || echo_fexists " $HOME /.bashrc"
413
+ ;;
414
+ zsh)
415
+ echo " $HOME /.zshrc"
416
+ ;;
417
+ fish)
418
+ echo " $HOME /.config/fish/config.fish"
419
+ ;;
420
+ * )
421
+ # Fall back to checking for profile file existence. Once again, the order
422
+ # differs between macOS and everything else.
423
+ local profiles
424
+
425
+ profiles=( .profile .bash_profile .bashrc .zshrc .config/fish/config.fish )
426
+ ;;
427
+ * )
428
+
429
+ for profile in " ${profiles[@]} " ; do
430
+ echo_fexists " $HOME /$profile " && break
431
+ done
432
+ ;;
433
+ esac
434
+ }
435
+
436
+ # generate shell code to source the loading script and modify the path for the input profile
437
+ build_path_str () {
438
+ local profile=" $1 "
439
+ local profile_install_dir=" $2 "
440
+
441
+ if [[ $profile =~ \. fish$ ]]; then
442
+ # fish uses a little different syntax to modify the PATH
443
+ cat << END_FISH_SCRIPT
444
+ set -gx GETMESH_HOME "$profile_install_dir "
445
+ string match -r ".getistio" "\$ PATH" > /dev/null; or set -gx PATH "\$ GETMESH_HOME/bin" \$ PATH
446
+ END_FISH_SCRIPT
447
+ else
448
+ # bash and zsh
449
+ cat << END_BASH_SCRIPT
450
+ export GETMESH_HOME="$profile_install_dir "
451
+ export PATH="\$ GETMESH_HOME/bin:\$ PATH"
452
+ END_BASH_SCRIPT
453
+ fi
454
+ }
455
+
456
+ update_profile () {
457
+ local install_dir=" $1 "
458
+
459
+ local profile_install_dir=$( echo " $install_dir " | sed " s:^$HOME :\$ HOME:" )
460
+ local detected_profile=" $( detect_profile $( basename " /$SHELL " ) $( uname -s) ) "
461
+ local path_str=" $( build_path_str " $detected_profile " " $profile_install_dir " ) "
462
+
463
+ if [ -z " ${detected_profile-} " ] ; then
464
+ log_err " no user profile found."
465
+ log_err " tried \$ PROFILE ($PROFILE ), ~/.bashrc, ~/.bash_profile, ~/.zshrc, ~/.profile, and ~/.config/fish/config.fish."
466
+ log_err ' '
467
+ log_err " you can either create one of these and try again or add these lines to the appropriate file:"
468
+ printf " \n$path_str \n"
469
+ return 1
470
+ else
471
+ if ! command grep -qc ' GETMESH_HOME' " $detected_profile " ; then
472
+ log_info " updating user profile ($detected_profile )..."
473
+ log_info " the following two lines are added into your profile ($detected_profile ):"
474
+ printf " \n$path_str \n"
475
+ command printf " $path_str " >> " $detected_profile "
476
+ printf " \nFinished installation. Open a new terminal to start using getmesh!\n"
477
+ fi
478
+ fi
479
+ }
480
+
481
+ update_profile ${HOME} /.getmesh
0 commit comments