-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_linux.sh
executable file
·374 lines (336 loc) · 11.1 KB
/
config_linux.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
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
#!/bin/bash
########################################################################
# File Name: config_linux.sh
# Author: zioer
# mail: next4nextjob@gmail.com
# Created Time: 2021年02月01日 星期一 23时20分14秒
#
# 安装Linux系统后的桌面环境配置工作
# 主要配置内容:
# 1. 修改软件源-让安装软件包速度最快
# 2. 配置基础环境:例如默认zsh、配置zshrc文件、VIM环境、tmux配置、自定义Python环境
# 3. 配置桌面主题环境:
# 4. 安装软件包工具: 浏览器、图片软件、输入法、Wine
########################################################################
gui_type="unknown" # 桌面环境类型检测 kde/gnome/xfce/unknown
default_confirm="no"
python_install_path="$HOME/anaconda3" # Python3 默认安装路径
# set -e # 命令执行失败就中止继续执行
######################################
#
# 检测操作系统模块
#
######################################
os_type="" # Linux操作系统分支类型
os_ver="" # Linux系统版本号
pac_cmd="" # 包管理命令
pac_cmd_ins="" # 包管理命令
cpu_arc="" # CPU架构类型,仅支持x86_64
prompt(){
# 提示确认函数,如果使用 -y 参数不进行提示
msg="$@" # 提示的信息
if [ "$default_confirm" != "yes" ] ; then
echo -e "$msg (y/N)\c"
read str_answer
if [ "$str_answer" = "y" -o "$str_answer" = "Y" ] ; then
echo "已确认"
return 0
else
echo "已取消"
return 1
fi
else
echo "$msg"
fi
return 0
}
check_sys() {
# 检查系统类型
if [ -f /etc/os-release ] ; then
. /etc/os-release
case "$ID" in
centos)
os_type="$ID"
pac_cmd="yum"
pac_cmd_ins="$pac_cmd install -y"
;;
opensuse*)
os_type="$ID"
pac_cmd="zypper"
pac_cmd_ins="$pac_cmd install -y"
;;
ubuntu|debian)
os_type="$ID"
pac_cmd="apt-get"
pac_cmd_ins="$pac_cmd install -y"
;;
manjaro|arch*)
os_type="$ID"
pac_cmd="pacman"
pac_cmd_ins="$pac_cmd -S --needed --noconfirm "
;;
*)
os_type="unknown"
pac_cmd=""
pac_cmd_ins=""
;;
esac
fi
if [ -z "$pac_cmd" ] ; then
return 1
fi
cpu_arc="`uname -m`"
if [ "$cpu_arc" != "x86_64" ] ; then
echo "invalid cpu arch:[$cpu_arc]"
return 2
fi
return 0
}
add_aur(){
# 添加AUR源配置
if grep ustc /etc/pacman.conf >/dev/null
then
echo "已经添加了中国科学技术大学的AUR源"
else
cat <<END | sudo tee -a /etc/pacman.conf
[archlinuxcn]
SigLevel = Optional TrustAll
# 中国科学技术大学
Server = https://mirrors.ustc.edu.cn/archlinuxcn/\$arch
END
fi
sudo pacman -Sy && sudo $pac_cmd_ins archlinuxcn-keyring yay
}
config_repo(){
# 配置软件源
echo
prompt "更新选择软件源"
str_ret="$?"
if [ "$str_ret" != "0" ] ; then
# 取消继续执行
return "$str_ret"
fi
case "$os_type" in
manjaro)
# 测试并选择延迟最低的镜像源地址(通过-c参数选择国家)
sudo pacman-mirrors -g -c China
# 更新软件源本地缓存并升级软件包版本
sudo pacman -Syu --noconfirm
add_aur
;;
*)
echo "$os_type 系统类型不支持!"
;;
esac
}
copy_file(){
src_file="$1"
dst_file="$2"
if [ -f "$dst_file" ] ; then
prompt "$dst_file 文件已存在,是否覆盖"
if [ "$?" = "0" ] ; then
mv $dst_file $dst_file.`date +%Y%m%d%H%M%S`
cp -f $src_file $dst_file
fi
else
cp $src_file $dst_file
fi
}
install_anaconda()
{
which anaconda >/dev/null
if [ "$?" = "0" ] ; then
echo "Anaconda3 is already installed!"
return 0
fi
# install anaconda python environment
ver="2021.05"
prompt "开始下载 Anaconda3... ver:[$ver], file size : 500MB+"
wget -c https://repo.anaconda.com/archive/Anaconda3-${ver}-Linux-x86_64.sh
prompt "开始安装 Anaconda3...(默认安装位置为: ${python_install_path})"
if [ "$?" != "0"] ; then
read tmp_input
if [ "$tmp_input" != "" -a -r `basename $tmp_input` ] ; then
python_install_path=$tmp_input
else
echo "无效目录[$tmp_input],已经使用默认目录[$python_install_path]安装"
fi
fi
sh Anaconda3-${ver}-Linux-x86_64.sh -p ${python_install_path} -b
. ${python_install_path}/etc/profile.d/conda.sh
conda init zsh
}
config_rc(){
# 配置基础资源环境
# 配置zsh、 vim、 tmux、 Anaconda3环境
echo
prompt "安装基础环境"
str_ret="$?"
if [ "$str_ret" != "0" ] ; then
# 取消继续执行
return "$str_ret"
fi
case "$os_type" in
manjaro)
# 添加fcitx输入法环境变量配置文件
copy_file ./dotfiles/xprofile $HOME/.xprofile
# 配置 oh-my-zsh
sudo ${pac_cmd_ins} zsh
user_name=`whoami`
zsh_path=`which zsh`
prompt "更换用户 [$user_name] 的默认shell 为 [$zsh_path]"
sudo chsh -s $zsh_path $user_name
prompt "安装oh-my-zsh"
sudo ${pac_cmd_ins} curl git
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
wget -O install-ohmyz.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh ./install-ohmyz.sh --unattended --skip-chsh --keep-zshrc
# clone
font_tmp_dir=/tmp/zsh_fonts
git clone https://github.com/powerline/fonts.git --depth=1 $font_tmp_dir
# install
cd $font_tmp_dir && sh ./install.sh && cd - && rm -rf $font_tmp_dir
copy_file ./dotfiles/zshrc $HOME/.zshrc
# 配置 vim
prompt "开始安装VIM"
sudo $pac_cmd_ins vim
copy_file ./dotfiles/vimrc $HOME/.vimrc
prompt "开始配置Vundle插件管理器"
mkdir -p $HOME/.vim/bundle/
git clone https://github.com/VundleVim/Vundle.vim.git $HOME/.vim/bundle/Vundle.vim
prompt "开始安装VIM插件"
vim +PluginInstall +qall
# 配置 tmux
sudo $pac_cmd_ins tmux
copy_file ./dotfiles/tmux.conf $HOME/.tmux.conf
;;
*)
echo "$os_type 系统类型不支持!"
;;
esac
}
check_desktop_env(){
# 检查桌面环境 , 返回 0 表示支持当前桌面环境, 返回 1 表示不支持
case "$XDG_CURRENT_DESKTOP" in
KDE)
gui_type="kde"
;;
*)
gui_type="unknown"
return 1
;;
esac
return 0
}
config_desktop_theme(){
# 安装配置桌面主题
echo
prompt "开始安装桌面主题"
str_ret="$?"
if [ "$str_ret" != "0" ] ; then
# 取消继续执行
return "$str_ret"
fi
case "$gui_type" in
kde*|KDE*)
# 安装 latte-dock
sudo $pac_cmd_ins latte-dock numix-icon-theme-git
# 主题下载
mkdir -p ./themes
prompt "安装全局主题-[WhiteSur-kde]"
str_ret="$?"
if [ "$str_ret" = "0" ] ; then
git clone https://github.com/vinceliuice/WhiteSur-kde.git themes/WhiteSur-kde
cd themes/WhiteSur-kde && sh ./install.sh && cd -
cd themes/WhiteSur-kde/sddm && sudo sh ./install.sh && cd -
prompt "安装Icons主题-[WhiteSur-icon-theme]"
git clone https://github.com/vinceliuice/WhiteSur-icon-theme.git themes/WhiteSur-icon-theme
cd themes/WhiteSur-icon-theme && sh ./install.sh && cd -
fi
prompt "安装主题-[McMojave-circle]"
str_ret="$?"
if [ "$str_ret" = "0" ] ; then
git clone https://github.com/vinceliuice/McMojave-circle.git themes/McMojave-circle
cd themes/McMojave-circle && sh ./install.sh --all && cd -
fi
prompt "安装GRUB2主题-[grub2-themes]"
str_ret="$?"
if [ "$str_ret" = "0" ] ; then
git clone https://github.com/vinceliuice/grub2-themes.git themes/grub2-themes
cd themes/grub2-themes && sudo ./install.sh -b -t whitesur && cd -
fi
# 主题设置
echo "当前系统安装的主题列表:"
lookandfeeltool -l
your_theme="com.github.vinceliuice.WhiteSur"
echo -e "输入需要应用的主题(default:WhiteSur):\c"
read str_answer
if [ "$str_answer" != "" ] ; then
your_theme="$str_answer"
fi
lookandfeeltool -a $your_theme
echo "=============================================================="
echo "="
echo "= 更多主题设置可以使用 systemsettings 图形界面进行设置"
echo "="
echo "=============================================================="
;;
*)
echo "$os_type 系统类型不支持!"
;;
esac
}
config_software_package(){
# 安装必备的软件包资源
# 安装列表: 网络工具包 , 中文输入法, 谷歌Chrome浏览器, 网易云音乐
echo
prompt "开始安装必备的软件包资源,浏览器、中文输入法、网易云音乐等"
str_ret="$?"
if [ "$str_ret" != "0" ] ; then
# 取消继续执行
return "$str_ret"
fi
case "$os_type" in
manjaro)
yay -S --needed --noconfirm git net-tools fcitx fcitx-configtool fcitx-cloudpinyin fcitx-googlepinyin google-chrome netease-cloud-music
sudo $pac_cmd_ins gcc make cmake
;;
*)
echo "$os_type 系统类型不支持!"
;;
esac
}
main(){
check_sys
check_desktop_env
config_repo
config_software_package
config_rc
install_anaconda # 下载安装 Anaconda3 环境
config_desktop_theme
}
usage(){
# 使用帮助信息
cat <<END
Usage:
`basename $0` [-y]
Brief:
-y : 使用默认yes确认一切,不需要人工交互确认,默认情况下是确认安装的每一个环节
END
}
############ 开始执行入口 ######
while getopts hyb:c: arg_val
do
case "$arg_val" in
y)
default_confirm="yes"
;;
*)
usage
exit 0
;;
esac
done
prompt "准备开始安装!"
main
prompt "安装配置过程结束!"