-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·45 lines (35 loc) · 1.26 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
#!/usr/bin/env bash
#
# Copyright (c) Aaron Delasy
# Licensed under the MIT License
#
panic () {
echo "Error: $@" 1>&2
exit 1
}
main () {
install_dir="$HOME/.the/bin"
install_path="$install_dir/the"
[[ ! -d "$install_dir" ]] && mkdir -p "$install_dir"
if [[ "$OSTYPE" == "darwin"* ]]; then
cdn_url="https://cdn.thelang.io/cli-core-macos-$(uname -m)"
elif [[ "$OSTYPE" == "linux"* ]]; then
cdn_url="https://cdn.thelang.io/cli-core-linux"
else
panic "unknown platform"
fi
echo "Installing The CLI..."
curl -fsSL "$cdn_url" -o "$install_path" || panic "failed to download and install"
chmod +x "$install_path" || panic "failed to set permissions"
profile_file="$HOME/.zprofile"
[[ ! -e "$profile_file" ]] && profile_file="$HOME/.bash_profile"
[[ ! -e "$profile_file" ]] && profile_file="$HOME/.profile"
profile_content="export PATH=\"\$PATH:$HOME/.the/bin\" # Added by the-install (https://docs.thelang.io/install)"
if [ -s "$profile_file" ] && [ -n "$(tail -c 1 < "$profile_file")" ]; then
profile_content="$(printf "\n%s" "$profile_content")"
fi
echo "$profile_content" >> "$profile_file" || panic "failed to add to PATH"
echo "Successfully installed The CLI!"
echo " Type \`the -h\` to explore available options"
}
main $@