-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-cli.sh
More file actions
136 lines (104 loc) · 3.04 KB
/
install-cli.sh
File metadata and controls
136 lines (104 loc) · 3.04 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
#!/usr/bin/env bash
if [[ ${OS:-} = Windows_NT ]]; then
echo 'Please install Rustbase using Windows Subsystem for Linux'
exit 1
fi
invalid_option() {
echo "Invalid option: $1" >&2
exit 1
}
no_path=0
while (($#)); do
[[ $1 = -- ]] && {
shift
break
}
[[ $1 = -?* ]] || break
case $1 in
--no-path) no_path=1 ;;
# -d) arg_d=1 ;;
-*) invalid_option "$1" ;;
esac
shift
done
case $(uname -ms) in
'Linux x86_64')
target=linux-x64
;;
'Linux i686')
target=linux-x86
;;
*)
error 'Unsupported platform'
;;
esac
rustbase_bin="$HOME/rustbase/bin"
rustbase_cli_repo="https://github.com/rustbase/rustbase-cli"
rustbase_cli_download="$rustbase_cli_repo/releases/latest/download/rustbase-cli-$target.zip"
rustbase_cli_exe="$rustbase_bin/rustbase"
# Check if has RUSTBASE_INSTALL_PATH env var and set rustbase_bin to it
if [[ -n $RUSTBASE_INSTALL_PATH ]]; then
rustbase_bin="$RUSTBASE_INSTALL_PATH"
rustbase_cli_exe="$rustbase_bin/rustbase"
fi
tmpdir=$(mktemp -d)
if [[ ! -d $rustbase_bin ]]; then
mkdir -p "$rustbase_bin" ||
error "Failed to create install directory \"$rustbase_bin\""
fi
if ! command -v unzip &>/dev/null; then
echo "unzip could not be found"
exit
fi
echo "Installing Rustbase CLI for $target..."
curl --fail --location -s --output "$tmpdir/rustbase-cli.zip" "$rustbase_cli_download" ||
echo "Failed to download Rustbase from \"$rustbase_cli_download\""
unzip -oqjd "$rustbase_bin" "$tmpdir/rustbase-cli.zip" ||
echo 'Failed to extract Rustbase'
mv "$rustbase_bin/rustbase-cli" "$rustbase_cli_exe" ||
echo 'Failed to move extracted Rustbase to destination'
chmod +x "$rustbase_cli_exe" ||
echo 'Failed to set permissions on Rustbase executable'
rm -r "$tmpdir/rustbase-cli.zip" ||
echo 'Failed to remove downloaded Rustbase archive'
if [[ $no_path -eq 0 ]]; then
echo "Adding $rustbase_bin to PATH..."
case $(basename "$SHELL") in
'fish')
commands=(
"set --export PATH $rustbase_bin\$PATH"
)
fish_config=$HOME/.config/fish/config.fish
{
echo -e '\n# Rustbase Database Server'
for command in "${commands[@]}"; do
echo "$command"
done
} >>"$fish_config"
echo "CLI added to PATH!"
;;
'zsh')
zsh_config=$HOME/.zshrc
{
echo -e '\n# Rustbase Database Server'
echo "export PATH=\"$rustbase_bin:\$PATH\""
} >>"$zsh_config"
echo "CLI added to PATH!"
;;
'bash')
bash_config=$HOME/.bashrc
{
echo -e '\n# Rustbase Database Server'
echo "export PATH=\"$rustbase_bin:\$PATH\""
} >>"$bash_config"
echo "CLI added to PATH!"
;;
*)
echo 'Manually add the directory to ~/.bashrc (or similar):'
echo "export PATH=\"$rustbase_bin:\$PATH\""
;;
esac
fi
rm -r "$tmpdir" ||
echo 'Failed to remove temporary directory'
echo "Rustbase CLI Installation complete!"