-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·103 lines (87 loc) · 3.48 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
97
98
99
100
101
102
103
#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status.
set -e
reset="\033[0m"
red="\033[31m"
green="\033[32m"
cyan="\033[36m"
DOWNLOAD_URL="https://subilo.gateway.scarf.sh/v0.2.1/x86-64-linux"
# the following function was brought from https://yarnpkg.com/install.sh
# https://github.com/yarnpkg/yarn/blob/master/LICENSE
detect_profile() {
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
echo "${PROFILE}"
return
fi
local DETECTED_PROFILE
DETECTED_PROFILE=''
local SHELLTYPE
SHELLTYPE="$(basename "/$SHELL")"
if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "$SHELLTYPE" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ "$SHELLTYPE" = "fish" ]; then
DETECTED_PROFILE="$HOME/.config/fish/config.fish"
fi
if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.config/fish/config.fish" ]; then
DETECTED_PROFILE="$HOME/.config/fish/config.fish"
fi
fi
if [ ! -z "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE"
fi
}
install_subilo() {
local INSTALL_DIR="${HOME}/.subilo/bin"
local INSTALL_FILE="${INSTALL_DIR}/subilo"
# Do not re create the folder if it already exists, the user might have sensitive
# configuration on it.
test -d "$INSTALL_DIR" || mkdir -p "$INSTALL_DIR"
curl --location --show-error --progress-bar $DOWNLOAD_URL --output "$INSTALL_FILE"
chmod +x "$INSTALL_FILE"
# Add Subilo bin to PATH
# the following code block was brought from https://yarnpkg.com/install.sh
# https://github.com/yarnpkg/yarn/blob/master/LICENSE
SUBILO_PROFILE="$(detect_profile)"
SOURCE_STR="\nexport PATH=\"\$HOME/.subilo/bin:\$PATH\"\n"
if [ -z "${SUBILO_PROFILE-}" ] ; then
printf "$red> Profile not found. Tried ${SUBILO_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.\n"
echo "> Create one of them and run this script again"
echo "> Create it (touch ${SUBILO_PROFILE}) and run this script again"
echo " OR"
printf "> Append the following lines to the correct file yourself:$reset\n"
command printf "${SOURCE_STR}"
else
if ! grep -q 'subilo/bin' "$SUBILO_PROFILE"; then
if [[ $SUBILO_PROFILE == *"fish"* ]]; then
command fish -c 'set -U fish_user_paths $fish_user_paths ~/.subilo/bin'
printf "$cyan> We've added ~/.subilo/bin to your fish_user_paths universal variable\n"
else
command printf "$SOURCE_STR" >> "$SUBILO_PROFILE"
printf "$cyan> We've added the following to your $SUBILO_PROFILE\n"
fi
echo "> If this isn't the profile of your current shell then please add the following to your correct profile:"
printf " $SOURCE_STR$reset\n"
fi
version=`$HOME/.subilo/bin/subilo --version` || (
printf "$red> Subilo was installed, but doesn't seem to be working :(.$reset\n"
exit 1;
)
printf "$green> Successfully installed Subilo $version! Please source the profile or open another terminal where the \`subilo\` command will now be available.$reset\n"
fi
}
install_subilo