-
Notifications
You must be signed in to change notification settings - Fork 1
/
language_package.sh
163 lines (150 loc) · 4.23 KB
/
language_package.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
#!/usr/bin/env bash
#> +---------------------------+
#> | language_package.sh |
#> +---------------------------+
#-
#- SYNOPSIS
#-
#- ./language_package.sh [-h]
#-
#- It will intatll Language Packages below:
#- Python : pyenv, pipenv
#- NodeJS : nvm
#-
#- OPTIONS
#-
#- -y, all accept.
#- -h, --help print help information.
#-
#- EXAMPLES
#-
#- $ ./language_package.sh -y
#====================================================
# Part 1. Option Tool
#====================================================
# Print script help
function show_script_help(){
echo
head -22 $0 | # find this file top 16 lines.
grep "^#[-|>]" | # show the line that include "#-" or "#>".
sed -e "s/^#[-|>]*//1" # use nothing to replace "#-" or "#>" that the first keyword in every line.
echo
}
# Receive arguments in slient mode.
all_accept=0
if [ "$#" -gt 0 ]; then
while [ "$#" -gt 0 ]; do
case "$1" in
# Help
"-h"|"--help")
show_script_help
exit 1
;;
# All Accept
"-y")
all_accept=1
shift 1
;;
esac
done
fi
function Echo_Color(){
case $1 in
r* | R* )
COLOR='\033[0;31m'
;;
g* | G* )
COLOR='\033[0;32m'
;;
y* | Y* )
COLOR='\033[0;33m'
;;
b* | B* )
COLOR='\033[0;34m'
;;
*)
echo "$COLOR Wrong COLOR keyword!\033[0m"
;;
esac
echo -e "$COLOR$2\033[0m"
}
function Ask_yn(){
printf "\033[0;33m$1\033[0m\033[0;33m [y/n] \033[0m"
if [ $all_accept = 1 ]; then
echo '-y'
return 1
fi
read respond
if [ "$respond" = "y" -o "$respond" = "Y" -o "$respond" = "" ]; then
return 1
elif [ "$respond" = "n" -o "$respond" = "N" ]; then
return 0
else
Echo_Color r 'wrong command!!'
Ask_yn $1
return $?
fi
unset respond
}
#====================================================
# Part 2. Main
#====================================================
pyenv_Keyword='eval "$(pyenv init -)"'
pyenv_Keyword_login='export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"'
pipenv_Keyword='export PATH=~/.local/bin:$PATH'
case $SHELL in
*zsh )
shell=zsh
profile=~/.zshrc
login_profile=~/.zprofile
;;
*bash )
shell=bash
profile=~/.bashrc
login_profile=~/.bash_profile
;;
*ksh )
shell=ksh
profile=~/.profile
;;
* )
Echo_Color r "Unknow shell, need to manually add pyenv config on your shell profile!!"
;;
esac
Ask_yn "Do you want to install pyenv"; result=$?
if [ $result = 1 ]; then
sudo apt-get update
sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
if [ "$(grep -xn "$pyenv_Keyword" $profile)" != "" ]; then
Echo_Color g "You have already added pyenv config in $profile !!"
else
# config profile
printf "\n# pyenv setting\n$pyenv_Keyword\n" >> $profile
fi
if [ "$(grep -xn "$pyenv_Keyword_login" $login_profile)" != "" ]; then
Echo_Color g "You have already added pyenv config in $login_profile !!"
else
# config login_profile
printf "\n# pyenv setting\n$pyenv_Keyword_login\n" >> $login_profile
fi
fi
Ask_yn "Do you want to install pipenv?"; result=$?
if [ $result = 1 ]; then
pip3 install --user pipenv
if [ "$(grep -xn "$pipenv_Keyword" $profile)" != "" ]; then
Echo_Color g "You have already added pipenv PATH in $profile !!"
else
# config profile
printf "\n# pipenv setting\n$pipenv_Keyword\n" >> $profile
printf 'eval "$(_PIPENV_COMPLETE=zsh_source pipenv)"\n' >> $profile
fi
fi
Ask_yn "Do you want to install nvm?"; result=$?
if [ $result = 1 ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | $shell
fi
source $profile
Echo_Color g "Done!! $0"