-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare_ubuntu.sh
executable file
·510 lines (459 loc) · 12.5 KB
/
prepare_ubuntu.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
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
#!/bin/bash
## dependency: prepare_ubuntu_user.sh
cd `dirname $0`
. ./common.sh
usage="
Enhances bare-bones Ubuntu installation with several tricks.
It adds a new user,
fixes locale,
installs byobu, htop and mcedit
The script must be run as a root.
Usage:
$(basename $0) <user-name> [--apt-proxy IP:PORT] [--wormhole] [--need-apt-update]
where
--wormhole - Install magic wormhole (app for easy sending files)
-p|--apt-proxy - Address of the existing apt-cacher with port, e.g. 192.168.1.0:3142.
--need-apt-update - If the flag is set the script will assume the apt cache needs apdate.
--private_key_path - This argument gets handled to 'prepare_ubuntu_user' for the first given user.
--external-key - Sets external public key to access the account. It
<cipher> <key> <name> populates authorized_keys
--debug - Flag that sets debugging mode.
--log - Path to the log file that will log all meaningful commands
--repo-path - Path to the common repository
--user <username> - Additional user to install the tricks to. Can be specified
multiple times, each time adding another user.
--no-sudo-password - If set, sudo will not ask for password
--cli-improved - Install all the following recommended command line tools:
--bat - cat replacement (bat)
--ping - prettyping (ping),
--gping - gping (https://github.com/orf/gping)
--fzf - fzf (for bash ctr+r)
--htop - htop
--diff - diff-so-fancy (diff),
--find - fd (replaces find)
--du - ncdu (replaces du),
--bandwidth - bandwidth (Terminal bandwidth utilization tool),
--tldr - tldr,
--ag - ag (the silver searcher),
--rg - ripgrep,
--entr - entr (watch),
--noti - noti (notification when something is done)
--dust - non-interactive replacement to du
--aptitude - aptitude
--mc - mc (Midnight Commander)
--git-extra - git extra (https://github.com/unixorn/git-extra-commands)
--liquidprompt - liquidprompt
--byobu - byobu
--hexyl - hexyl (a hex editor)
--autojump - autojump (cd replacement)
--dtrx - Do The Right eXtraction (untar/unzip/unrar/etc. replacement)
Example:
$(basename $0) --apt-proxy 192.168.10.2:3142
"
dir_resolve()
{
cd "$1" 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status
echo "`pwd -P`" # output full, link-resolved path
}
mypath=${0%/*}
mypath=`dir_resolve $mypath`
cd $mypath
users=()
pattern='^--.*$'
if [[ ! "$1" =~ $pattern ]]; then
users+=("$1")
shift
fi
debug=0
wormhole=0
repo_path=""
install_bat=0
install_ping=0
install_gping=0
install_fzf=0
install_htop=0
install_diff=0
install_find=0
install_du=0
install_bandwidth=0
install_tldr=0
install_ag=0
install_rg=0
install_entr=0
install_noti=0
install_dust=0
install_aptitude=0
install_mc=0
install_git_extra=0
install_liquidprompt=0
install_byobu=0
install_hexyl=0
install_autojump=0
install_dtrx=0
user_opts=""
while [[ $# > 0 ]]
do
key="$1"
shift
case $key in
--debug)
debug=1
;;
--help)
echo "$usage"
exit 0
;;
--log)
log=$1
shift
;;
--repo-path)
repo_path="$1"
shift
;;
--apt-proxy)
aptproxy=$1
shift
;;
--no-sudo-password)
user_opts="${user_opts} --no-sudo-password $1"
;;
--external-key)
user_opts="${user_opts} --external-key $1 $2 $3"
shift
shift
shift
;;
--private-key-path)
private_key_path="--private-key-path $1"
shift
;;
--users)
users+=("$1")
shift
;;
--wormhole)
wormhole=1
;;
--need-apt-update)
flag_need_apt_update=1
;;
--cli-improved)
install_bat=1
user_opts="${user_opts} --bat"
install_ping=1
install_gping=1
user_opts="${user_opts} --ping"
user_opts="${user_opts} --gping"
install_fzf=1
user_opts="${user_opts} --fzf"
install_htop=1
install_diff=1
user_opts="${user_opts} --diff"
install_find=1
install_du=1
user_opts="${user_opts} --du"
install_tldr=1
install_rg=1
install_bandwidth=1
install_entr=1
install_noti=1
install_dust=1
install_mc=1
install_dtrx=1
install_aptitude=1
install_liquidprompt=1
user_opts="${user_opts} --liquidprompt"
install_byobu=1
install_hexyl=1
install_autojump=1
user_opts="${user_opts} --autojump"
;;
--bat)
install_bat=1
user_opts="${user_opts} --bat"
;;
--ping)
install_ping=1
user_opts="${user_opts} --ping"
;;
--gping)
install_gping=1
user_opts="${user_opts} --gping"
;;
--fzf)
install_fzf=1
user_opts="${user_opts} --fzf"
;;
--htop)
install_htop=1
;;
--diff)
install_diff=1
user_opts="${user_opts} --diff"
;;
--find)
install_find=1
;;
--du)
install_du=1
user_opts="${user_opts} --du"
;;
--bandwidth)
install_bandwidth=1
;;
--tldr)
install_tldr=1
;;
--ag)
install_ag=1
;;
--rg)
install_rg=1
;;
--entr)
install_entr=1
;;
--noti)
install_noti=1
;;
--dust)
install_dust=1
;;
--mc)
install_mc=1
;;
--aptitude)
install_aptitude=1
;;
--git-extra)
install_git_extra=1
user_opts="${user_opts} --git-extra"
;;
--liquidprompt)
install_liquidprompt=1
user_opts="${user_opts} --liquidprompt"
;;
--byobu)
install_byobu=1
;;
--hexyl)
install_hexyl=1
;;
--autojump)
install_autojump=1
user_opts="${user_opts} --autojump"
;;
--dtrx)
install_dtrx=1
user_opts="${user_opts} --dtrx"
;;
-*)
echo "Error: Unknown option: $1" >&2
echo "$usage" >&2
;;
esac
done
users+=("$USER")
if [ -n "$debug" ]; then
if [ -z "$log" ]; then
log=/dev/stdout
fi
fi
if check_for_root; then
return 1
fi
install_apt_package wget wget
install_apt_package jq jq
if [ -n "$aptproxy" ]; then
$loglog
echo "Acquire::http::Proxy \"http://$aptproxy\";" | sudo tee /etc/apt/apt.conf.d/90apt-cacher-ng >/dev/null
flag_need_apt_update=1
fi
if ! grep -q LC_ALL /etc/default/locale 2>/dev/null; then
sudo tee /etc/default/locale <<EOF
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
EOF
logexec sudo locale-gen en_US.UTF-8
logexec sudo locale-gen pl_PL.UTF-8
fi
do_update
do_upgrade
install_apt_packages bash-completion curl
# install_byobu=1
if [ "${install_bat}" == "1" ]; then
version=$(get_latest_github_release_name sharkdp/bat skip_v)
link=$(get_latest_github_release_link sharkdp/bat bat_${version}_$(cpu_arch).deb bat_${version}_$(cpu_arch).deb )
install_apt_package_file bat_${version}_$(cpu_arch).deb bat $link
fi
if [ "${install_ping}" == "1" ]; then
plik=$(get_cached_file prettyping https://raw.githubusercontent.com/denilsonsa/prettyping/master/prettyping)
install_script "${plik}" /usr/local/bin/prettyping root
fi
if [ "${install_gping}" == "1" ]; then
add_apt_source_manual gping "deb http://packages.azlux.fr/debian/ buster main" https://azlux.fr/repo.gpg.key gping.gpg.key
install_apt_packages gping
fi
if [ "${install_fzf}" == "1" ]; then
if ! install_apt_package fzf; then
get_git_repo https://github.com/junegunn/fzf.git /usr/local/lib
logexec sudo /usr/local/lib/fzf/install --all --xdg
fi
fi
if [ "${install_htop}" == "1" ]; then
install_apt_package htop
fi
if [ "${install_dtrx}" == "1" ]; then
if ! install_apt_package dtrx; then
install_pip3_packages dtrx
fi
fi
if [ "${install_diff}" == "1" ]; then
plik=$(get_cached_file diff-so-fancy https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/third_party/build_fatpack/diff-so-fancy)
install_script "${plik}" /usr/local/bin/diff-so-fancy
fi
if [ "${install_find}" == "1" ]; then
install_gh_deb sharkdp/fd fd
# fd_arch=$(cpu_arch)
# if [ "${fd_arch}" == "arm64" ]; then
# fd_arch="armhf"
# fi
# file="fd_$(get_latest_github_release_name sharkdp/fd skip_v)_$(cpu_arch).deb"
# link=$(get_latest_github_release_link sharkdp/fd ${file} ${file})
# install_apt_package_file ${file} fd $link
fi
set -x
if [ "${install_du}" == "1" ]; then
cached_file=$(get_cached_file ncdu.tar.gz https://dev.yorhel.nl/download/ncdu-1.14.tar.gz)
tmp=$(mktemp -d)
skip_timestamp=1
uncompress_cached_file ${cached_file} $tmp
install_apt_packages build-essential libncurses5-dev
logexec pushd ${tmp}/ncdu
logexec ./configure
logexec make
logexec sudo make install
logexec popd
fi
set +x
if [ "${install_bandwidth}" == "1" ]; then
install_gh_binary imsnif/bandwhich /usr/local/share bandwhich
#
# _arch=$(cpu_arch)
# if [ "${_arch}" == "amd64" ]; then
# _arch="x86_64-unknown-linux-musl"
# fi
# version=$(get_latest_github_release_name imsnif/bandwhich)
# file="bandwhich-v${version}-${_arch}.tar.gz"
# link="https://github.com/imsnif/bandwhich/releases/download/${version}/${file}"
# filepath=$(get_cached_file ${file} ${link})
# get_from_cache_and_uncompress_file ${filepath} bandwhich ${link} "/usr/local/bin/bandwhich" root
fi
if [ "${install_dust}" == "1" ]; then
install_gh_binary bootandy/dust /usr/local/share dust
# _arch=$(cpu_arch)
# if [ "${_arch}" == "amd64" ]; then
# _arch="x86_64-unknown-linux-gnu"
# elif [ "${_arch}" == "arm64" ]; then
# _arch="arm-unknown-linux-gnueabihf"
# fi
# version=$(get_latest_github_release_name bootandy/dust)
# file="dust-${version}-${_arch}.tar.gz"
# link="https://github.com/bootandy/dust/releases/download/${version}/${file}"
# filepath=$(get_cached_file ${file} ${link})
# get_from_cache_and_uncompress_file ${filepath} ${link} "/usr/local/share/dust" root
# make_symlink /usr/local/share/dust-${version}-x86_64-unknown-linux-gnu/dust /usr/local/bin/dust
fi
if [ "${install_tldr}" == "1" ]; then
install_apt_packages python3-pip
install_pip3_packages tldr
fi
if [ "${install_ag}" == "1" ]; then
install_apt_packages silversearcher-ag
fi
if [ "${install_rg}" == "1" ]; then
install_apt_packages ripgrep
# install_gh_deb BurntSushi/ripgrep ripgrep
if $?; then
install_gh_binary BurntSushi/ripgrep /usr/local/share rg "" "" "" "" rg
fi
# _arch=$(cpu_arch)
# if [ "${_arch}" == "arm64" ]; then
# _arch="arm-unknown-linux-gnueabihf"
# fi
# version=$(get_latest_github_release_name BurntSushi/ripgrep)
# file="ripgrep-${version}-${_arch}.tar.gz"
# link="https://github.com/BurntSushi/ripgrep/releases/download/${version}/${file}"
# filepath=$(get_cached_file ${file} ${link})
# get_from_cache_and_uncompress_file ${filepath} ${link} "/usr/local/share/ripgrep" root
# make_symlink /usr/local/share/ripgrep/ripgrep /usr/local/bin/ripgrep
# add_ppa x4121/ripgrep
# install_apt_packages ripgrep
fi
if [ "${install_entr}" == "1" ]; then
get_cached_file entr-4.2.tar.gz http://entrproject.org/code/entr-4.2.tar.gz
tmp=$(mktemp -d)
pushd $tmp
uncompress_cached_file entr-4.2.tar.gz eradman
logexec cd eradman
install_apt_packages build-essential
logexec ./configure
logexec make
logexec sudo make install
logexec popd
fi
if [ "${install_noti}" == "1" ]; then
install_apt_packages golang-go
go get -u github.com/variadico/noti/cmd/noti
fi
if [ "${install_mc}" == "1" ]; then
install_apt_package mc
fi
if [ "${install_aptitude}" == "1" ]; then
install_apt_package aptitude
fi
if [ "${install_git_extra}" == "1" ]; then
get_git_repo https://github.com/unixorn/git-extra-commands.git /usr/local/lib git-extra-commands
fi
if [ "${install_liquidprompt}" == "1" ]; then
install_apt_packages liquidprompt
logexec sudo -H liquidprompt_activate
fi
if [ "${install_byobu}" == "1" ]; then
install_apt_package byobu
fi
if [ "${install_hexyl}" == "1" ]; then
install_gh_deb sharkdp/hexyl hexyl
# file="hexyl_$(get_latest_github_release_name sharkdp/hexyl skip_v)_$(cpu_arch).deb"
# link=$(get_latest_github_release_link sharkdp/hexyl ${file} ${file})
# install_apt_package_file ${file} hexyl $link
# install_apt_package_file fd-musl_7.1.0_amd64.debhexyl_0.3.1_amd64.deb hexyl https://github.com/sharkdp/hexyl/releases/download/v0.3.1/hexyl_0.3.1_amd64.deb
fi
if [ "${install_autojump}" == "1" ]; then
install_apt_package autojump
fi
if [ "${wormhole}" == "1" ]; then
if ! which wormhole >/dev/null; then
if install_apt_package python3-pip; then
logexec sudo -H pip3 install --upgrade pip
fi
install_apt_packages build-essential python3-dev libffi-dev libssl-dev
logexec sudo -H pip3 install magic-wormhole
fi
fi
if [ -n "$users" ] ; then
if [ -n "$debug" ]; then
user_opts="--debug ${user_opts}"
fi
if [ -n "$log" ]; then
user_opts="--log ${log} ${user_opts}"
fi
pushd "$DIR"
# set -x
bash -x ./prepare_ubuntu_user.sh ${users[0]} ${user_opts} ${private_key_path}
for user in ${users[@]:1}; do
sudo -H -u ${user} -- bash -x ./prepare_ubuntu_user.sh ${user} ${user_opts}
done
popd
fi