-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·452 lines (364 loc) · 11.9 KB
/
init
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
#!/usr/bin/env bash
#
# This main project script which configure/install my Debian environment (dotfiles).
# Configures the necessary tools for development and convenience.
# Minimalistic environment and instruments with old-school fonts.
#
# Be careful when running this script on your main machine,
# it does not create backup dotfiles and may erase your current working environment.
#
# After the $ ./init --xfce OR $ ./init --xfce-hotkeys
# need to session restart.
#
set -ex
umask 077
check_package()
{
dpkg -l | awk '{print $2}' | grep ^$1$ &>/dev/null && return 0 || return 1
}
# ----------------------------------
mark_start="# ----"
mark_end="# ---- Don't write after this"
mark_s_file()
{
echo -e "\n$mark_start\n" >> $1
}
mark_e_file()
{
echo -e "\n$mark_end" >> $1
}
bold_message()
{
echo -e "\e[96m*** ----- $1 ----- ***\e[0m"
}
remove_marked_lines()
{
if grep "^$mark_start" $1; then
sed -i "/$mark_start/Q" $1 # remove all lines after pattern
sed -i '$ d' $1 # remove last empty line
fi
}
usage()
{
cat << EOF
Usage: $(basename $0) [option]
[option]
--ftp ftp server installation
/etc/vsftpd.conf
--initd operations before shutdown/reboot
/etc/init.d/clean-env script - amnesia
--hosts hosts installation
/etc/hosts
--sysctl kernel parameters installation
/etc/sysctl.conf
--sources.list the latest up-to-date Debian repositories
sources.list installation
--install-packages install useful packages
--clean-home cleanup home directory
configure user-dirs.*
--bashrc ~/.bashrc, ~/.profile extra rules installation
append rules to the current content of ~/.bashrc, ~/.profile
--bash-completion enable bash completion
--locales generate 'en_US' 'ru_RU' locales
--xfce full xfce installation (desktop session)
all ~/.config/xfce4/xfconf/xfce-perchannel-xml files
--xfce-hotkeys xfce keyboard shortcuts installation
configure only 'xfce4-keyboard-shortcuts.xml'
--xfce-terminal xfce terminal emulator installation (xfce4-terminal)
~/.config/xfce4/terminal/terminalrc + colorschemes
--mc midnight commander installation
--tmux terminal multiplexer installation
--vim vim text editor installation with plugins
--mousepad mousepad text editor installation
--gdb gdb debugger installation
--neomutt mail client neomutt installation
--newsboat rss feed reader installation
--dircolors dircolors installation
--local-bin ~/.local/bin installation
--local-share ~/.local/share installation
--gitconfig ~/.gitconfig installation
-h, --help show this help and exit
EOF
exit 0
}
# ----------------------------------
for arg in "$@"; do
case "$arg" in
"--ftp")
bold_message "FTP server installation"
if check_package vsftpd; then
if [ ! -d /srv/ftp/upload ]; then
sudo mkdir /srv/ftp/upload
sudo chmod 777 /srv/ftp/upload
fi
sudo cp -v ./root/etc/vsftpd.conf /etc/vsftpd.conf
sudo systemctl restart vsftpd.service
else
>&2 echo "Please, install 'vsftpd' package"
exit 1
fi
;;
"--initd")
bold_message "init.d script for user home directory (amnesia)"
sudo cp -v ./root/etc/init.d/clean-env /etc/init.d
sudo ln -s /etc/init.d/clean-env /etc/rc5.d/S00clean-env &>/dev/null | true
sudo ln -s /etc/init.d/clean-env /etc/rc6.d/K00clean-env &>/dev/null | true
sudo systemctl daemon-reload
sudo systemctl restart clean-env.service
;;
"--hosts")
bold_message "Hosts installation"
sudo cp -v ./root/etc/hosts /etc/hosts
sudo sed -i "s/<MY-HOSTNAME>/$(hostname)/" /etc/hosts &>/dev/null
;;
"--sysctl")
bold_message "Kernel parameters installation"
sudo cp -v ./root/etc/sysctl.conf /etc/sysctl.conf
sudo sysctl -p
echo "Core file size: $(ulimit -c)"
;;
"--sources.list")
bold_message "sources.list installation"
sudo cp -v ./root/etc/apt/sources.list /etc/apt/
;;
"--install-packages")
main=(nano mousepad vim vim-gtk3 gdb tmux mc git git-lfs tig neomutt newsboat \
galculator gparted gcc make strace xsel ripgrep bash-completion pkg-config \
valgrind locales sudo ssh sshpass systemd-coredump moreutils coreutils \
binutils diffutils mawk gawk perl perl-base psmisc dialog whiptail \
exuberant-ctags hwinfo indent wipe patch patchutils fakeroot file python-pip \
python3-pip ca-certificates openssl gpg dnsutils traceroute whois tcpdump \
nmap wget curl netcat net-tools dirmngr nfs-common gettext shc tree lsof)
deb=(apt-file dpkg-dev devscripts lintian cdbs debootstrap pbuilder \
dconf-cli automake autoconf dh-make debhelper build-essential autotools-dev \
quilt debconf-utils adequate piuparts licensecheck reportbug \
how-can-i-help equivs debconf aptitude duck blhc gobject-introspection)
doc=(man-db mandoc manpages manpages-dev manpages-ru manpages-ru-dev \
manpages-posix manpages-posix-dev linux-doc gcc-doc gcc-base-doc info)
fonts=(font-manager xfonts-terminus fonts-unifont fonts-hack fonts-glasstty \
fonts-ibm-plex)
other=(task-russian task-russian-desktop gnome-screensaver telegram-desktop \
audacious cowsay oneko simplescreenrecorder)
packs=("${main[*]}" "${deb[*]}" "${doc[*]}" "${fonts[*]}" "${other[*]}")
bold_message "Install useful packages"
sudo apt-get update
if ! check_package eatmydata; then
>&2 echo "Please, install 'eatmydata' package"
exit 1
fi
set +e
for p in ${packs[*]}; do
if ! check_package $p; then
sudo eatmydata apt-get -y install $p
echo -e "$?\n"
fi
done
set -e
sudo mandb
sudo apt-file update
;;
"--clean-home")
bold_message "Cleanup $HOME"
trash_dirs=(Видео Общедоступные Шаблоны Документы \
Videos Public Templates Documents)
# I don't need these dirs =)
for dir in ${trash_dirs[*]}; do
[ -d ~/$dir ] && rm -ri ~/$dir
done
mkdir ~/sources &>/dev/null | true
ls ~
cp -v ./.config/user-dirs.dirs ~/.config
cp -v ./.config/user-dirs.locale ~/.config
;;
"--bashrc")
bold_message "Bash read extra rules installation"
remove_marked_lines ~/.bashrc
mark_s_file ~/.bashrc
cat ./.bashrc >> ~/.bashrc
mark_e_file ~/.bashrc
remove_marked_lines ~/.profile
mark_s_file ~/.profile
cat ./.profile >> ~/.profile
mark_e_file ~/.profile
cp -v ./.vv ~/
cp -v ./.dput.cf ~/
;;
"--bash-completion")
bold_message "Enable bash completion"
if check_package bash-completion; then
sudo perl -i -pe '$i++ if /^#if ! shopt -oq posix;/; s/^#// if $i==1; $i=0 if /^fi/' \
/etc/bash.bashrc
else
>&2 echo "Please, install 'bash-completion' package"
exit 1
fi
;;
"--locales")
bold_message "Generate locales"
if check_package locales; then
# for the shell, I use 'en_US.UTF-8' (look '--bashrc')
# for the interface 'en_US.UTF-8'
for loc in en_US.UTF-8 ru_RU.UTF-8; do
if ! grep ^$loc /etc/locale.gen &>/dev/null; then
echo "$loc UTF-8" | sudo tee -a /etc/locale.gen
sudo locale-gen
fi
done
# all interface all users
echo LANG="en_US.UTF8" | sudo tee /etc/default/locale
else
>&2 echo "Please, install 'locales' package"
exit 1
fi
;;
"--xfce")
# XDG_DATA_DIRS not set in ssh session
#if echo "$XDG_DATA_DIRS" | grep 'xfce' &>/dev/null; then
bold_message "XFCE installation"
if check_package xfce4; then
cp -v ./.config/xfce4/xfconf/xfce-perchannel-xml/* \
~/.config/xfce4/xfconf/xfce-perchannel-xml
else
>&2 echo "Current desktop environment not 'xfce'"
exit 1
fi
# max brightness for laptops
device_name=$(find /sys/class/backlight/ -mindepth 1)
if [ ! -z "$device_name" ]; then
max_brightness=$(cat $device_name/max_brightness)
echo $max_brightness | sudo tee $device_name/brightness
fi
;;
"--xfce-hotkeys")
bold_message "XFCE keyboard shortcuts installation"
if check_package xfce4; then
cp -v ./.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml \
~/.config/xfce4/xfconf/xfce-perchannel-xml
else
>&2 echo "Current desktop environment not 'xfce'"
exit 1
fi
;;
"--xfce-terminal")
bold_message "XFCE terminal emulator installation"
if check_package xfce4-terminal; then
mkdir ~/.config/xfce4/terminal &>/dev/null | true
cp -v ./.config/xfce4/terminal/terminalrc ~/.config/xfce4/terminal
mkdir -p ~/.local/share/xfce4/terminal/colorschemes &>/dev/null | true
cp -v ./.local/share/xfce4/terminal/colorschemes/* ~/.local/share/xfce4/terminal/colorschemes
else
>&2 echo "Please, install 'xfce4-terminal' package"
exit 1
fi
;;
"--mc")
bold_message "Midnight Commander installation"
if check_package mc; then
mkdir -p ~/.config/mc &>/dev/null | true
sudo mkdir -p /root/.config/mc &>/dev/null | true
cp -v ./.config/mc/{ini,panels.ini,hotlist} ~/.config/mc
sudo cp -v ./.config/mc/{ini,panels.ini} /root/.config/mc
else
>&2 echo "Please, install 'mc' package"
exit 1
fi
;;
"--tmux")
bold_message "Tmux installation"
if check_package tmux; then
cp -v ./.tmux.conf ~/.tmux.conf
else
>&2 echo "Please, install 'tmux' package"
exit 1
fi
;;
"--vim")
bold_message "Vim installation with plugins"
if check_package vim; then
plug_vim=~/.vim/autoload/plug.vim
if [ ! -e $plug_vim ]; then
curl -fLo $plug_vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
cp -v ./.vimrc ~/.vimrc
vim +PlugClean +PlugInstall +q +q
else
>&2 echo "Please, install 'vim' package"
exit 1
fi
;;
"--mousepad")
bold_message "Mousepad installation"
if check_package mousepad; then
# How export mousepad configuration ? Commands:
# $ dconf dump /org/xfce/mousepad/ > mousepad.settings
# $ dconf load /org/xfce/mousepad/ < mousepad.settings
cp -v ./.config/dconf/mousepad.settings ~/.config/dconf
dconf load /org/xfce/mousepad/ < ~/.config/dconf/mousepad.settings
else
>&2 echo "Please, install 'mousepad' package"
exit 1
fi
;;
"--gdb")
bold_message "Gdb installation"
if check_package gdb; then
if [ ! -e ~/.gdbinit ]; then
wget -P ~/ https://git.io/.gdbinit
pip install pygments --break-system-packages
fi
remove_marked_lines ~/.gdbinit
mark_s_file ~/.gdbinit
cat ./.gdbinit >> ~/.gdbinit
mark_e_file ~/.gdbinit
else
>&2 echo "Please, install 'gdb' package"
exit 1
fi
;;
"--neomutt")
bold_message "Neomutt installation"
if check_package neomutt; then
cp -v ./.neomuttrc ~/
cp -v ./.signature ~/
else
>&2 echo "Please, install 'neomutt' package"
exit 1
fi
;;
"--newsboat")
bold_message "RSS feed reader installation"
if check_package newsboat; then
mkdir ~/.newsboat &>/dev/null | true
cp -v ./.newsboat/* ~/.newsboat
else
>&2 echo "Please, install 'newsboat' package"
exit 1
fi
;;
"--dircolors")
bold_message "dircolors installation"
cp -v ./.dircolors ~/
;;
"--local-bin")
bold_message "~/.local/bin installation"
mkdir ~/.local/bin &>/dev/null | true
cp -v ./.local/bin/* ~/.local/bin
;;
"--local-share")
bold_message "~/.local/share installation"
mkdir ~/.local/share &>/dev/null | true
cp -rv ./.local/share/* ~/.local/share
;;
"--gitconfig")
bold_message "~/.gitconfig installation"
if check_package git; then
cp -v ./.gitconfig ~/
else
>&2 echo "Please, install 'git' package"
exit 1
fi
;;
"-h" | "--help") usage ;;
esac
done