-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
executable file
·96 lines (79 loc) · 2.77 KB
/
install.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
#!/bin/sh
set -e
main() {
cndi_install="${CNDI_INSTALL:-$HOME/.cndi}"
bin_dir="$cndi_install/bin"
bin_suffix=""
if [ "$OS" = "Windows_NT" ]; then # WSL or Git Bash or Cygwin
bin_suffix=".exe"
target="win.exe"
else
case $(uname -sm) in
"Darwin x86_64") target="mac" ;;
"Darwin arm64") target="mac" ;;
"Linux aarch64")
echo "Error: Official CNDI builds for Linux aarch64 are not available" 1>&2
exit 1
;;
"Linux x86_64")
target="linux"
;;
*)
target="linux"
esac
fi
if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to install and upgrade CNDI!" 1>&2
exit 1
fi
cndi_uri="https://github.com/polyseam/cndi/releases/latest/download/cndi-${target}.tar.gz"
exe="$bin_dir/cndi"
if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
fi
curl --fail --location --progress-bar --output "$exe.tar.gz" "$cndi_uri"
tar -xzf "$exe.tar.gz" -C "$bin_dir"
chmod +x "$exe"
chmod +x "$bin_dir/kubeseal-cndi"
chmod +x "$bin_dir/terraform-cndi"
rm "$exe.tar.gz"
echo "cndi was downloaded successfully to $exe"
# set shell profile for user shell
case "$SHELL" in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".profile" ;;
esac
# if $cndi_install is not in $PATH
if ! command -v cndi >/dev/null; then
# if $cndi_install is not in $shell_profile
if ! grep -q "$bin_dir" "$HOME/$shell_profile"; then
echo "adding $bin_dir to \$PATH"
command printf '\nexport PATH="%s:$PATH"' "$bin_dir" >>"$HOME/$shell_profile"
fi
fi
# if $shell_profile is .zshrc exit because sourcing it will cause an error
if [ "$shell_profile" = ".zshrc" ]; then
echo "finalizing installation..."
# running 'cndi --help' will save the user wait time on first run
$exe --help --welcome
echo
echo "cndi was installed successfully! Please restart your terminal."
echo "Need some help? Join our Discord https://cndi.run/di?utm_id=5096"
echo
exit 0
fi
# source $shell_profile
if [ -f "$HOME/$shell_profile" ]; then
echo "sourcing $HOME/$shell_profile"
. "$HOME/$shell_profile"
echo "finalizing installation..."
# running 'cndi --help' will save the user wait time on first run
$exe --help --welcome
echo
echo "cndi was installed successfully! Please restart your terminal."
echo "Need some help? Join our Discord https://cndi.run/di?utm_id=5096"
echo
exit 0
fi
}
main "$@"