forked from ZupIT/ritchie-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·96 lines (71 loc) · 2.54 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
usage () {
echo "./install.sh"
}
idempotent_config() {
if [ -n "$SHELL_TYPE" ]; then
if [ -f ${HOME}"/."${SHELL_TYPE}"rc" ]; then
sed -i'' -e '/source <(rit completion/d' ${HOME}"/."${SHELL_TYPE}"rc"
if grep "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" ~/."${SHELL_TYPE}"rc > /dev/null
then
echo ".${SHELL_TYPE}rc IS ALREADY CONFIGURED TO SUPPORT RITCHIE AUTO COMPLETION"
else
echo "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" >> ~/."${SHELL_TYPE}"rc
echo "source ~/.rit_completion" >> ~/."${SHELL_TYPE}"rc
fi
elif [ -f ${HOME}"/."${SHELL_TYPE}"_profile" ]; then
sed -i'' -e '/source <(rit completion/d' ${HOME}"/."${SHELL_TYPE}"_profile"
if grep "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" ~/."${SHELL_TYPE}"_profile > /dev/null
then
echo ".${SHELL_TYPE}_profile IS ALREADY CONFIGURED TO SUPPORT RITCHIE AUTO COMPLETION"
else
echo "[[ -r "/usr/local/bin/rit" ]] && rit completion $SHELL_TYPE > ~/.rit_completion" >> ~/."${SHELL_TYPE}"_profile
echo "source ~/.rit_completion" >> ~/."${SHELL_TYPE}"_profile
fi
else
echo "Installed Ritchie without autocomplete"
return
fi
echo "Installed Ritchie with autocomplete"
fi
}
rit_install () {
echo "Downloading rit..."
STABLE_VERSION=$(curl -s https://commons-repo.ritchiecli.io/stable.txt)
curl -SLO "https://commons-repo.ritchiecli.io/${STABLE_VERSION}/${OPERATIONAL_SYSTEM}/rit"
chmod +x ./rit
INSTALL_PATH="/usr/local/bin"
if [ ! -d "$INSTALL_PATH" ]; then
sudo mkdir -p $INSTALL_PATH
fi
sudo mv ./rit $INSTALL_PATH/rit
$INSTALL_PATH/rit --version
idempotent_config
}
rit_identify_shell () {
if [ -n "$($SHELL -c 'echo $ZSH_VERSION')" ]; then
echo "Going to install autocomplete for zsh"
SHELL_TYPE="zsh"
elif [ -n "$($SHELL -c 'echo $BASH_VERSION')" ]; then
echo "Going to install autocomplete for bash"
SHELL_TYPE="bash"
else
echo "Please consider using bash or zsh to improve your ritchie experience"
SHELL_TYPE=""
fi
}
rit_identify_os () {
if [ $(uname) = "Linux" ]; then
echo "Installing Ritchie for Linux"
OPERATIONAL_SYSTEM="linux"
elif [ $(uname) = "Darwin" ]; then
echo "Installing Ritchie for Mac"
OPERATIONAL_SYSTEM="darwin"
else
echo "Unable to identify which OS you're using"
exit 1
fi
}
rit_identify_os
rit_identify_shell
rit_install