Repository navigation
Expand file tree
/
Copy pathubuntu_init.sh
More file actions
524 lines (422 loc) · 10.9 KB
/
Copy pathubuntu_init.sh
File metadata and controls
524 lines (422 loc) · 10.9 KB
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
#!/bin/bash
_VERSION="1.8"
_INSTALL_V2RAY=true
_CHANGE_APT=true
_CHANGE_PIP=true
_INSTALL_CONDA=true
_INSTALL_POETRY=true
_INSTALL_LSD=true
_DOWNLOAD_DIR="/home/$USER/download"
_V2RAY_STAGE="nodejs" # 1:"nodejs", 2:"docker", 3:"conda"
_DEFAULT_V2RAY_CONFIG=$_DOWNLOAD_DIR/v2ray/config.json
_ORING_APT_REPO=archive.ubuntu.com
_APT_MIRROR=mirrors.ustc.edu.cn
_BASE_APP="language-pack-zh-hans git curl wget aria2 python3 python3-pip zsh jq unzip build-essential htop iftop git-flow libssl-dev pkg-config dnsutils inetutils-ping"
_TIMEZONE="Asia/Shanghai"
_PIP3_MIRROR="https://mirrors.bfsu.edu.cn/pypi/web/simple"
_CONDA_VER=latest
_POETRY_VER=1.1.13
_LOCAL_PROXY=""
echo -e "version: $_VERSION"
echo -e "disable_coredump"
echo "Set disable_coredump false" | sudo tee -a /etc/sudo.conf
echo -e "_DOWNLOAD_DIR: ${_DOWNLOAD_DIR}"
echo -e "_DEFAULT_V2RAY_CONFIG: $_DEFAULT_V2RAY_CONFIG"
function _echo()
{
_NOTIC_='\033[1;34m'
printf "${_NOTIC_} $1 \033[0m \n"
}
function start_v2ray()
{
if [ ${_INSTALL_V2RAY} == "true" ]; then
_echo "install v2ray"
cd $_DOWNLOAD_DIR
wget https://download.fastgit.org/v2fly/v2ray-core/releases/download/v5.0.8/v2ray-linux-64.zip
unzip v2ray-linux-64.zip -d v2ray
read -p "input config.json file, or just enter for ${_DOWNLOAD_DIR}/v2ray/config.json: " DIR
if [ -z $DIR ]; then
DIR=$_DEFAULT_V2RAY_CONFIG
fi
_echo "will use config file: ${DIR}"
cd $_DOWNLOAD_DIR/v2ray
nohup ./v2ray run -c $DIR > runoob.log 2>&1 &
# echo "install strip-json-comments-cli"
# sudo npm install --global strip-json-comments-cli
# echo "install hjson first"
# pip install hjson
# PORT=`hjson -j $DIR | jq '.inbounds[0].port'`
_echo "sleep 5 seconds for v2ray to start up"
sleep 5
_echo "read v2ray log"
tail -n 1 $_DOWNLOAD_DIR/v2ray/runoob.log
_V2RAY_STATUS=$(tail -n 1 $_DOWNLOAD_DIR/v2ray/runoob.log | awk '{print $NF}')
_echo "v2ray status: ${_V2RAY_STATUS}"
if [ $_V2RAY_STATUS == "started" ]; then
read -p "input v2ray port(default 11080): " PORT
#PORT=`strip-json-comments $DIR | jq '.inbounds[0].port'`
if [ -z $PORT ]; then
PORT=11080
fi
_echo "v2ray port is ${PORT}"
_echo "export http and https proxy port"
export http_proxy=http://localhost:${PORT}
export https_proxy=http://localhost:${PORT}
export _LOCAL_PROXY=http://localhost:${PORT}
_echo "test ip using icanhazip"
curl -x localhost:11080 https://icanhazip.com
fi
fi
}
function init()
{
touch ~/.zshrc
mkdir -p $_DOWNLOAD_DIR
}
function config()
{
read -p "install v2ray and set local proxy(y/n)? default y: " _ANS
if [ $_ANS == "n" ]; then
_INSTALL_V2RAY="false"
fi
read -p "all default(y/n)? this will change apt mirror and pip mirror, default y: " _ANS
if [ $_ANS == "n" ]; then
read -p "change apt mirror to $_APT_MIRROR (y/n)? default y: " _ANS
if [ $_ANS == "n" ]; then
_CHANGE_APT="false"
fi
read -p "change pip mirror to $_PIP3_MIRROR (y/n)? default y:" _ANS
if [ $_ANS == "n" ]; then
_CHANGE_PIP="false"
fi
fi
}
# adduser ${_NEW_USER}
# echo -e "set user: ${_NEW_USER} to group sudo"
# usermod -aG sudo ${_NEW_USER}
# echo -e "change to user ${_NEW_USER}"
# su -p ${_NEW_USER}
# whoami
function change_apt()
{
if [ $_CHANGE_APT == "true" ]; then
_echo "change apt repo from ${_ORING_APT_REPO} to ${_APT_MIRROR}"
_REP="s/${_ORING_APT_REPO}/${_APT_MIRROR}/g"
sudo sed -i ${_REP} /etc/apt/sources.list
fi
}
function update_apt()
{
_echo "update apt repo"
sudo apt update
_echo "upgrade all"
}
# sudo apt upgrade -y
function apt_install_base()
{
_echo "install common app: ${_BASE_APP}"
export DEBIAN_FRONTEND=noninteractive
DEBIAN_FRONTEND=nointeractive sudo DEBIAN_FRONTEND=nointeractive apt install -y ${_BASE_APP}
}
function set_chinese_env()
{
_echo "set chinese env"
echo "LANG=\"zh_CN.UTF-8\" \
LANGUAGE=\"zh_CN:zh:en_US:en\"
" | sudo tee -a /etc/environment
sudo echo "en_US.UTF-8 UTF-8 \
zh_CN.UTF-8 UTF-8 \
zh_CN.GBK GBK \
zh_CN GB2312" | sudo tee -a /var/lib/locales/supported.d/local
sudo locale-gen
_echo "install chinese font"
sudo apt-get install -y fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming
}
function change_pip_mirror()
{
if [ $_CHANGE_PIP == "true" ]; then
_echo "change pip mirror"
pip config set global.index-url ${_PIP3_MIRROR}
fi
}
function install_nodejs()
{
if [ $_V2RAY_STAGE == "nodejs" ]; then
start_v2ray
fi
_echo "install nodejs 14"
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
}
function set_timezone()
{
_echo "change timezone to ${_TIMEZONE}"
sudo timedatectl set-timezone ${_TIMEZONE}
}
function install_docker()
{
if [ $_V2RAY_STAGE == "docker" ]; then
start_v2ray
fi
_echo "install docker"
curl -Ssl https://get.docker.com | sudo sh
sudo usermod -aG docker $USER
_echo "install docker compose"
pip install docker-compose
_echo "install lazy docker "
curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash
}
function install_conda()
{
if [ $_V2RAY_STAGE == "conda" ]; then
start_v2ray
fi
if [ ${_INSTALL_CONDA} == "true" ]; then
_echo "install conda version=${_CONDA_VER}"
cd $_DOWNLOAD_DIR
wget "https://repo.continuum.io/miniconda/Miniconda3-${_CONDA_VER}-Linux-x86_64.sh"
bash "Miniconda3-${_CONDA_VER}-Linux-x86_64.sh" -b -p ~/miniconda3
# rm "Miniconda3-${_CONDA_VER}-Linux-x86_64.sh"
# conda update -y conda
# conda init bash
fi
}
function install_poetry()
{
if [ ${_INSTALL_POETRY} == "true" ]; then
_echo "install poetry version=${_POETRY_VER}"
pip install poetry==${_POETRY_VER}
fi
}
function install_neovim()
{
_echo "install neovim"
_echo "uninstall old version first"
sudo apt-get -y autoremove neovim
cd $_DOWNLOAD_DIR
wget https://github.com/neovim/neovim/releases/download/v0.8.2/nvim-linux64.deb
sudo apt-get install -y ./nvim-linux64.deb
}
function install_ezsh()
{
_echo "initiallize ezsh"
git clone https://github.com/jotyGill/ezsh.git /tmp/ezsh
cd /tmp/ezsh
./install.sh -c
cat << EOF >> ~/.zshrc
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:en_US:en
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=
EOF
if [ -z $_LOCAL_PROXY ]; then
_echo "export localproxy: $_LOCAL_PROXY"
export https_proxy=$_LOCAL_PROXY
export http_proxy=$_LOCAL_PROXY
else
_echo "no localproxy"
fi
~/miniconda3/bin/conda init zsh
}
function install_rust()
{
_echo "install rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# sudo apt-get install -y rust-all
}
function install_bat()
{
_echo "install bat"
sudo apt install -y bat
_echo "link bat"
mkdir -p ~/.local/bin
ln -s /usr/bin/batcat ~/.local/bin/bat
}
function install_lsd()
{
if [ $_INSTALL_LSD == "true" ]; then
_echo "download lsd"
cd $_DOWNLOAD_DIR
wget https://github.com/Peltoche/lsd/releases/download/0.23.0/lsd_0.23.0_amd64.deb
_echo "install lsd"
sudo dpkg -i ./lsd_0.23.0_amd64.deb
fi
}
function install_delta()
{
_echo "install delta"
sudo apt-get install -y git-delta
cat << EOF >> ~/.gitconfig
[core]
pager = delta
[interactive]
diffFilter = delta --color-only
[add.interactive]
useBuiltin = false # required for git 2.37.0
[delta]
navigate = true # use n and N to move between diff sections
light = false # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal)
[merge]
conflictstyle = diff3
[diff]
colorMoved = default
EOF
}
function install_fd()
{
_echo "install fd"
sudo apt install -y fd-find
ln -s $(which fdfind) ~/.local/bin/fd
}
function install_du_dust()
{
_echo "install du-dust"
cargo install du-dust
}
function install_ripgrep()
{
_echo "install ripgrep"
sudo apt install -y ripgrep
}
function install_cheat()
{
_echo "install cheat"
cd /tmp \
&& wget https://github.com/cheat/cheat/releases/download/4.3.3/cheat-linux-amd64.gz \
&& gunzip cheat-linux-amd64.gz \
&& chmod +x cheat-linux-amd64 \
&& sudo mv cheat-linux-amd64 /usr/local/bin/cheat
}
function install_tldr()
{
_echo "install tldr"
sudo npm install -g tldr
}
function install_lvim()
{
_echo "install lunarvim"
bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh)
wget https://raw.githubusercontent.com/gowinder/scripts/main/lvim/config.lua -O ~/.config/lvim/config.lua
}
function install_cz()
{
sudo npm install -g commitizen
sudo npm install -g cz-conventional-changelog
sudo npm install -g cz-conventional-changelog
echo '{ "path": "cz-customizable" }' > ~/.czrc
}
function install_dog()
{
_echo "install dog"
mkdir -p /tmp
cd /tmp/
git clone https://github.com/ogham/dog.git /tmp/dog
cd /tmp/dog
cargo update
cargo build --release
sudo cp target/release/dog /usr/local/bin
}
function install_sss()
{
mkdir -p /tmp
cd /tmp
wget https://raw.githubusercontent.com/gnos-project/gnos-sockets/master/sss
chmod +x sss
mv sss /usr/local/bin/
}
function install_duf()
{
cd /tmp
wget https://github.com/muesli/duf/releases/download/v0.8.0/duf_0.8.0_linux_amd64.deb
sudo dpkg -i ./duf_0.8.0_linux_amd64.deb
}
function install_glow()
{
_echo "install glow"
echo 'deb [trusted=yes] https://repo.charm.sh/apt/ /' | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install -y glow
}
function install_zoxide()
{
_echo "install zoxide"
sudo apt install -y zoxide
}
function install_gtop()
{
_echo "install gtop"
sudo npm install -g gtop
}
function install_bandwhich()
{
_echo "install bandwhich"
cargo install bandwhich
sudo ln -s $(which bandwhich) /usr/sbin/bandwhich
}
function install_gping()
{
_echo "install gping"
carge install gping
}
function install_fkill()
{
_echo "install fkill"
sudo npm install -g fkill
}
function update_env()
{
if [ $_INSTALL_LSD == "true" ]; then
_echo "add lsd alias"
cat << EOF >> ~/.zshrc
alias ls="lsd -alh"
eval "$(zoxide init zsh)"
EOF
fi
}
function do_main()
{
init
config
change_apt
update_apt
apt_install_base
set_chinese_env
change_pip_mirror
install_nodejs
set_timezone
install_docker
install_conda
install_poetry
install_neovim
install_rust
install_bat
install_lsd
install_delta
install_fd
install_du_dust
install_ripgrep
install_cheat
install_tldr
install_dog
install_sss
install_duf
install_glow
install_zoxide
install_gtop
install_fkill
install_lvim
install_ezsh
install_cz
update_env
}
do_main