forked from clk-project/clk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·172 lines (153 loc) · 4.65 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
set -e
_check_pip () {
local good_version="$(python3 -c '
import re
import pip
version_number=int(re.match("^([0-9]+)\.", pip.__version__).group(1))
print(version_number >= 19)
')"
[ "${good_version}" == "True" ]
}
_check_python3 () {
local good_version="$(python3 -c '
import re
import sys
version_number=int(re.match("^3\.([0-9]+)\.", sys.version).group(1))
print(version_number >= 8)
')"
[ "${good_version}" == "True" ]
}
_find_suitable_python_version ( ) {
if which python3 > /dev/null && _check_python3
then
PYTHON=python3
elif which python3.9 > /dev/null
then
PYTHON=python3.9
elif which python3.8 > /dev/null
then
PYTHON=python3.8
else
printf "${yellow}warning:${reset} Could not find a suitable python version (at least 3.8).\n"
printf "${yellow}warning:${reset} Make sure one is installed and available.\n"
printf "${yellow}warning:${reset} Hint: on debian-like systems -> sudo apt install python3.9.\n"
exit 1
fi
echo "Using this command to run python: ${PYTHON}"
}
if [ -t 1 ]; then
green="\e[32m"
yellow="\e[33m"
reset="\e[0m"
function spin {
msg=$1
pid=$!
spinchars='-\|/'
i=0
while kill -0 $pid 2> /dev/null; do
i=$(( (i+1) %4 ))
echo -e -n "\r${msg}... ${spinchars:$i:1}"
sleep .3
done
echo -e "\r${msg}... done"
}
else
green=""
yellow=""
reset=""
function spin {
msg=$1
pid=$!
echo -n "${msg}... "
while kill -0 $pid 2> /dev/null; do
sleep .1
done
echo "done"
}
fi
if [ "$(uname)" == "Darwin" ]; then
if ! which pip3 > /dev/null; then
if ! which brew > /dev/null; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install python3
fi
PIP=pip3
USER_OPT=
INSTALL_PATH=/usr/local/bin
else
if ! which wget > /dev/null && ! which curl > /dev/null; then
if which sudo apt-get > /dev/null; then
sudo apt-get install -y curl python3-distutils
elif which sudo yum > /dev/null; then
sudo yum -y install curl
fi
fi
INSTALL_PATH=$HOME/.local/bin
mkdir -p "${INSTALL_PATH}"
touch "${INSTALL_PATH}/somedummyscripttotest"
chmod +x "${INSTALL_PATH}/somedummyscripttotest"
ASK_NEW_BASH=""
if ! which somedummyscripttotest > /dev/null
then
export PATH="${INSTALL_PATH}:${PATH}"
echo "export PATH='${INSTALL_PATH}:${PATH}'" >> "${HOME}/.bashrc"
ASK_NEW_BASH="1"
fi
rm "${INSTALL_PATH}/somedummyscripttotest"
_find_suitable_python_version
if ! _check_pip
then
if ! "${PYTHON}" -c "import distutils.cmd"
then
echo "You need to install distutils as well (see https://github.com/pypa/get-pip/issues/124)"
printf "${yellow}warning:${reset} Hint: on debian-like systems -> sudo apt install python3-distutils.\n"
exit 1
fi
# we need to force the reinstall in order to make sure the latest version of
# pip is there
GET_PIP_TMP_DIR="${TMPDIR:-/tmp}/get-pip.py"
if which curl > /dev/null; then
curl -sSL https://bootstrap.pypa.io/get-pip.py -o "${GET_PIP_TMP_DIR}"
"${PYTHON}" ${TMPDIR:-/tmp}/get-pip.py --force-reinstall --user --quiet & spin "installing pip"
elif which wget > /dev/null; then
wget -nv https://bootstrap.pypa.io/get-pip.py -O "${GET_PIP_TMP_DIR}"
"${PYTHON}" ${TMPDIR:-/tmp}/get-pip.py --force-reinstall --user --quiet & spin "installing pip"
else
echo "Error: can't find or install pip"
exit 1
fi
trap "rm '${GET_PIP_TMP_DIR}'" 0
fi
if ! _check_pip
then
echo "Error: we could not install a suitable pip version..."
exit 1
fi
PIP="${PYTHON} -m pip"
USER_OPT=--user
fi
if which clk > /dev/null 2>&1
then
verb="updating"
else
verb="installing"
fi
CLK="${CLK:-clk}"
${PIP} install ${USER_OPT} --quiet --upgrade "${CLK}" & spin "${verb} ${CLK}"
echo -n "installing clk completion... "
for s in bash zsh fish; do
$INSTALL_PATH/clk -L warning completion install $s
done
echo "done"
if [ "${ASK_NEW_BASH}" == "1" ]
then
$INSTALL_PATH/clk log --level warning "You have to restart bash to see clk working"
fi
echo -e "${green}clk successfully installed! Enjoy!${reset}"
for extension in ${CLK_EXTENSIONS}
do
echo "installing clk extension ${extension}... "
"${INSTALL_PATH}/clk" extension install "${extension}"
done