-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinstall.sh
executable file
·280 lines (209 loc) · 5.51 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
CURRENT_DIR=$PWD
RC_DIR="$HOME/.rc.d"
LOCAL_BIN="$HOME/.local/bin"
PYTHON_VERSION='3.12.2'
BREW_URL='https://raw.githubusercontent.com/Homebrew/install/master/install'
OH_MY_ZSH_URL='https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh'
POWERLINE_FONTS_URL='https://github.com/powerline/fonts.git'
PYENV_URL='https://pyenv.run'
RC_URL='https://github.com/seamile/rc.d.git'
UTILS_URL='https://github.com/seamile/utils.git'
function exist() {
command -v $1 >/dev/null 2>&1
return $?
}
function ensure_rc() {
if [ ! -d $RC_DIR ]; then
git clone $RC_URL $RC_DIR
fi
}
function install_brew() {
echo "exec: install_brew"
if [[ `uname` == 'Darwin' ]] && ! `exist brew`
then
xcode-select --install
ruby -e "$(curl -fsSL $BREW_URL)"
fi
echo 'done!'
}
function install_softwares_for_macos() {
echo "exec: install_softwares_for_macos"
ensure_rc
for pkg in `cat $RC_DIR/packages/cask-pkg`
do
read -p "Do you want to install '$pkg'? (y/n) " confirm
if [[ $confirm == "y" ]]
then
brew cask install $pkg
fi
done
echo "done!"
}
function install_sys_packages() {
echo "exec: install_sys_packages"
ensure_rc
if [[ `uname` == 'Darwin' ]]; then
echo "installing brew packages ..."
brew -v update
brew install `cat $RC_DIR/packages/brew-pkg`
elif `exist apt-get`; then
echo "installing deb packages ..."
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y `cat $RC_DIR/packages/apt-pkg`
elif `exist yum`; then
echo "installing rpm packages ..."
sudo yum update
sudo yum install -y `cat $RC_DIR/packages/yum-pkg`
else
echo 'not found any package installer'
fi
echo 'done!'
}
function install_powerline_fonts() {
echo "exec: install_powerline_fonts"
if [ ! -d $HOME/.powerline-fonts ]; then
git clone --depth=1 $POWERLINE_FONTS_URL $HOME/.powerline-fonts
$HOME/.powerline-fonts/install.sh
else
echo "powerline-fonts is already installed"
fi
echo 'done!'
}
function install_ohmyzsh() {
echo "exec: install_ohmyzsh"
if [ ! -d $HOME/.oh-my-zsh ]; then
bash -c "$(curl -fsSL $OH_MY_ZSH_URL)"
else
echo "oh-my-zsh is already installed"
fi
echo 'done!'
}
function install_pyenv() {
echo "exec: install_pyenv"
if [ ! -d $HOME/.pyenv ]; then
curl $PYENV_URL | bash
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv update
else
echo "pyenv is already installed"
fi
echo 'done!'
}
function install_python() {
echo "exec: install_python"
if ! pyenv versions | grep $PYTHON_VERSION > /dev/null; then
env PYTHON_CONFIGURE_OPTS='--enable-optimizations --with-lto' PYTHON_CFLAGS='-march=native -mtune=native' pyenv install -kv $PYTHON_VERSION
else
echo "Python v$PYTHON_VERSION is already installed"
fi
pyenv global $PYTHON_VERSION
echo 'done!'
}
function install_python_pkg() {
echo "exec: install_python_pkg"
ensure_rc
pyenv global $PYTHON_VERSION
pip install -r $RC_DIR/packages/python-pkg
echo 'done!'
}
function setup_utils() {
echo "exec: setup_utils"
mkdir -p $LOCAL_BIN
cd $LOCAL_BIN
git clone $UTILS_URL utils
for u_path in `find utils -maxdepth 1 -perm -755 -type f`
do
ln -sfv $u_path `basename $u_path`
done
}
function setup_env() {
echo "exec: setup_env"
ensure_rc
# link rc files
cd $HOME
ln -sfv .rc.d/gitconfig .gitconfig
ln -sfv .rc.d/vimrc .vimrc
ln -sfv .rc.d/zshrc .zshrc
ln -sfv .rc.d/bashrc .bashrc
ln -sfv .rc.d/tmux.conf .tmux.conf
ln -sfv .rc.d/myclirc .myclirc
# link aria2
mkdir -p $HOME/.aria2
cd $HOME/.aria2
ln -sfv $RC_DIR/aria2.conf aria2.conf
touch $HOME/.zshrc.local
echo 'done!'
}
function setup_zsh_theme() {
echo "exec: setup_zsh_theme"
ensure_rc
if [ -d "$HOME/.oh-my-zsh/custom/themes" ]; then
cd $HOME/.oh-my-zsh/custom/themes
for name in `ls $RC_DIR/omz-theme`
do
# link zsh themes
ln -sfv $RC_DIR/omz-theme/$name $name
done
else
echo "Please install ohmyzsh first."
exit 1
fi
echo 'done!'
}
function install_all() {
ensure_rc
install_brew
install_sys_packages
install_powerline_fonts
install_ohmyzsh
install_pyenv
install_python
install_python_pkg
setup_utils
setup_env
setup_zsh_theme
}
cat << EOF
select a function code:
===============================
【 1 】 Install brew
【 2 】 Install sys packages
【 3 】 Install powerline fonts
【 4 】 Install oh-my-zsh
【 5 】 Install pyenv
【 6 】 Install python
【 7 】 Install python pkg
【 8 】 Setup utils
【 9 】 Setup env
【 0 】 Setup zsh theme
【 a 】 Install all
【 x 】 Install softwares for macos
【 * 】 Exit
===============================
EOF
if [[ -n $1 ]]; then
choice=$1
echo "exec: $1"
else
read -p "select: " choice
fi
case $choice in
1) install_brew;;
2) install_sys_packages;;
3) install_powerline_fonts;;
4) install_ohmyzsh;;
5) install_pyenv;;
6) install_python;;
7) install_python_pkg;;
8) setup_utils;;
9) setup_env;;
0) setup_zsh_theme;;
a) install_all;;
x) install_softwares_for_macos;;
*) echo 'Bye' && exit;;
esac
cd $CURRENT_DIR