-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·734 lines (649 loc) · 28 KB
/
init.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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -eo pipefail
unalias -a
_get_home () {
# cf. <https://superuser.com/a/484330>
getent passwd "$1"|cut -d: -f6
}
# This script needs to run as the superuser. However, it also needs to run as
# the user. sudo solves this problem by setting the environmental variable
# ``SUDO_USER`` to "the login name of the user who invoked sudo"[^1], and so,
# if this script is executed as the superuser with sudo, the following code
#
# su "$SUDO_USER" << LF
# echo 'Hello, world!'
# LF
#
# would execute ``echo "Hello, world!"`` as the user. This script could also
# be executed as a user other than the superuser with sudo with the
# ``-u user, --user=user`` option of sudo, but then, in the above code, su
# might (interactively) prompt for a password (but all commands in this script
# must be non-interactive), and, to run as the superuser, the script would have
# to execute ``su << LF`` instead of the first line of the above code, which,
# unless the user is the superuser, would also prompt for a password.
#
# terminal-logger uses ``HOME`` to determine where to look for a
# ``.terminal-logger`` directory, and trash-put appears to do the same to
# determine where to look for a ``Trash`` directory. If terminal-logger does
# not find a ``.terminal-logger`` directory at ``"$HOME/.terminal-logger"``, it
# makes one. This new directory has the same owner as the user as which
# terminal-logger runs. If the user were to run this script as the superuser
# with sudo, but not on a login shell, ``HOME`` would still be the user's home
# directory, not that of the superuser. Therefore, when this script would
# first invoke terminal-logger, terminal-logger would look in the user's home
# directory for a ``.terminal-logger`` directory, not find one, and make a new
# ``.terminal-logger`` directory under the user's home directory but owned by
# the superuser. When the user later invokes terminal-logger, terminal-logger
# would find this directory and try to open the ``lock`` file, which is in the
# directory (at ``$HOME/.terminal-logger/lock``). However, since the directory
# would be owned by the superuser, and terminal-logger is running as the user,
# terminal-logger would not have permission to open the ``lock`` file. A
# similar problem would occur with trash-put, which appears to make a ``Trash``
# directory at ``"$HOME/.local/share/Trash"`` if it does not find one there and
# tries to open directories under this directory. Therefore, the user must
# also execute this script on a login shell. The script actually runs as the
# user by executing ``sudo -iu "$SUDO_USER" bash << LF`` instead of
# ``su "$SUDO_USER" << LF``, since the later would execute with ``HOME`` as the
# superuser's home directory, not that of the user.
#
# [^1]: cf. "ENVIRONMENT". To read this section, type
#
# man sudo
#
# and move to the first match of "ENVIRONMENT".
(($EUID == 0)) && [[ $HOME == $(_get_home 0) ]] && [[ -n $SUDO_USER ]] || {
echo "$0: You must invoke sudo to execute this program as the superuser on a login shell"
exit 1
}
# Install terminal-logger. This script needs terminal-logger first to upgrade
# all of the installed software and then to install stow, which this script
# needs first to configure APT.
sudo -iu "$SUDO_USER" bash << LF
#
# mkdir -p github.com/m5w
# cd github.com/m5w
#
# The directory github.com/m5w/init should already exist.
cd github.com/m5w
git clone \
'https://github.com/m5w/terminal-logger.git'
LF
_sudo_home="$(_get_home "$SUDO_USER")"
cd "$_sudo_home/github.com/m5w/terminal-logger"
install -Dt /usr/local/bin terminal-logger
sudo -iu "$SUDO_USER" bash << LF
mkdir .terminal-logger
LF
# Upgrade all of the installed software.
#
# terminal-logger apt-get -q update
#
# The user should have had to have run
#
# sudo apt-get update
#
# before installing git, which the user should have had to install before
# downloading this script. Because the upgrade script performs this redundant
# and thus unnecessary update, this script does not use the upgrade script
# here.
terminal-logger apt-get -qy dist-upgrade
terminal-logger apt-get -qy --purge autoremove
# Install stow.
terminal-logger apt-get -qy install stow
# Configure APT. It is necessary for APT to have the following configuration
# item[^1]
#
# APT::Get::quiet "true";
#
# for the user to "Install drivers that are appropriate for automatic
# installation"[^2] by executing
# ``terminal-logger ubuntu-drivers autoinstall``, since ubuntu-drivers appears
# to invoke apt-get, but "-q" cannot be passed to the apt-get instance that
# ubuntu-drivers uses.
#
# This script also needs "Source code" to be "Downloadable from the
# Internet"[^3] to execute ``terminal-logger apt-get -y build-dep vim``.
#
# [^1]: cf. "-q, --quiet". To read this section, execute the following command
#
# man apt-get
#
# and move to the first match of "-q, --quiet".
#
# [^2]: cf. "Available commands". To read this section, execute the following
# command.
#
# ubuntu-drivers --help
#
# [^3]: cf. "Kubuntu Software". To read this section, execute the following
# command.
#
# kdesudo software-properties-kde
cd /etc/apt
git clone \
'https://github.com/m5w/etc-apt-stow.git' \
stow
#
# rm sources.list
#
# System files should be preserved, just in case.
terminal-logger apt-get -qy install trash-cli
sudo -iu "$SUDO_USER" bash << LF
mkdir -p .local/share/Trash
cd .local/share/Trash
mkdir files info
LF
trash-put sources.list
cd stow
stow apt
# "-q" is no longer necessary.
terminal-logger apt-get update
# Install SMART Monitoring Tools.
terminal-logger apt-get -y install \
bsd-mailx \
smartmontools \
ssmtp
# Configure SMART Monitoring Tools.
cd /etc
git clone \
'https://github.com/m5w/etc-stow.git' \
stow
trash-put smartd.conf
cd stow
stow smartd
# Configure GNU GRUB.
cd /etc/default
git clone \
'https://github.com/m5w/etc-default-stow.git' \
stow
trash-put grub
cd stow
stow grub
update-grub
# Install NTP.
terminal-logger apt-get -y install \
ntp \
ntp-doc
# Set the clock.
service ntp stop
ntpd -gq
service ntp start
# Install the backup and upgrade scripts.
sudo -iu "$SUDO_USER" bash << LF
git clone --recursive \
'https://github.com/m5w/stow.git'
LF
cd "$_sudo_home/stow/backup"
install -Dt /usr/local/bin backup
cd "../upgrade"
install -Dt /usr/local/bin upgrade
# Install VirtualBox.
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://www.virtualbox.org/download/oracle_vbox.asc'
wget \
'https://www.virtualbox.org/download/oracle_vbox_2016.asc'
LF
terminal-logger apt-key add "$_sudo_home/Downloads/oracle_vbox.asc"
terminal-logger apt-key add "$_sudo_home/Downloads/oracle_vbox_2016.asc"
cd /etc/apt/sources.list.d
cat > virtualbox.list << LF
deb http://download.virtualbox.org/virtualbox/debian xenial contrib
LF
terminal-logger apt-get update
terminal-logger apt-get -y install \
dkms \
virtualbox-5.1
# Install TeX Live 2017.
terminal-logger apt-get -y install \
gnuplot \
gnuplot-doc \
perl-doc \
python3-pygments
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz'
mkdir install-tl-unx
cd install-tl-unx
tar xf ../install-tl-unx.tar.gz --strip-components=1
ln -s ~/github.com/m5w/init/texlive.profile
LF
EDITOR=ed visudo -f /etc/sudoers.d/install-tl << LF
a
$SUDO_USER $(hostname) = NOPASSWD: $_sudo_home/Downloads/install-tl-unx/install-tl
.
wq
LF
sudo -iu "$SUDO_USER" bash << LF
cd Downloads/install-tl-unx
sudo ./install-tl --profile=texlive.profile
LF
rm /etc/sudoers.d/install-tl
# Configure TeX Live 2017.
# XZ Utils 5.2
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://superb-dca2.dl.sourceforge.net/project/lzmautils/xz-5.2.2.tar.gz'
tar xf xz-5.2.2.tar.xz
cd xz-5.2.2
./configure
make
LF
cd "$_sudo_home/Downloads/xz-5.2.2"
make install
ldconfig
sudo -iu "$SUDO_USER" bash << LF
tlmgr init-usertree
LF
# Install vim.
terminal-logger apt-get -y build-dep vim
terminal-logger apt-get -y install \
python-dbg \
python-dev \
python-doc
sudo -iu "$SUDO_USER" bash << LF
cd github.com/m5w
git clone \
'https://github.com/m5w/vim.git'
cd vim
git remote add upstream \
'https://github.com/vim/vim.git'
./configure \
--with-features=huge \
--enable-luainterp=yes \
--enable-perlinterp=yes \
--enable-pythoninterp=yes \
--enable-tclinterp=yes \
--enable-rubyinterp=yes \
--enable-gui=gtk2 \
--with-python-config-dir=\
/usr/lib/python2.7/config-x86_64-linux-gnu
make
LF
cd "$_sudo_home/github.com/m5w/vim"
make install
# Configure vim.
# ClangFormat
sudo -iu "$SUDO_USER" bash << LF
cd stow
stow clang-format
LF
terminal-logger apt-get -y install clang-format
# Eclipse
terminal-logger apt-get -y install openjdk-8-doc
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://mirrors.xmission.com/eclipse/technology/epp/downloads/release/neon/3/eclipse-java-neon-3-linux-gtk-x86_64.tar.gz'
LF
cd "$_sudo_home/Downloads"
tar xf eclipse-java-neon-3-linux-gtk-x86_64.tar.gz -C /opt
# to-do: Eclim
terminal-logger apt-get -y install openjdk-8-jdk
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://github.com/ervandew/eclim/releases/download/2.6.0/eclim_2.6.0.jar'
LF
# vim-plug
terminal-logger apt-get -y install curl
# YCM-Generator
terminal-logger apt-get -y install clang
# color_coded
terminal-logger apt-get -y install \
build-essential \
cmake \
cmake-doc \
libclang-3.9-dev \
libclang1-3.9-dbg \
libncurses5-dbg \
libncurses5-dev \
libpthread-workqueue-dev \
zlib1g-dbg \
zlib1g-dev
_vim_version="$(vim --version)"
_liblua_version_pattern='-llua([0-9]\.[0-9])'
[[ $_vim_version =~ $_liblua_version_pattern ]]
terminal-logger apt-get -y install "liblua${BASH_REMATCH[1]}-dev"
# YouCompleteMe
terminal-logger apt-get -y install \
python3-dbg \
python3-dev \
python3-doc
terminal-logger apt-get -y install \
ca-certificates-mono \
mono-complete \
mono-dbg \
mono-devel \
mono-xsp4 \
referenceassemblies-pcl
# vim-flake8
terminal-logger apt-get -y install flake8
sudo -iu "$SUDO_USER" bash << LF
mkdir -p .vim/after
cd .vim/after
mkdir -p ftplugin syntax/tex
cd ~/stow
stow vim
vim +qa
LF
# yapf
terminal-logger apt-get -y install python3-pip
terminal-logger pip3 -q install yapf
# Configure GNU Bash and Git.
sudo -iu "$SUDO_USER" bash << LF
trash-put \
.bashrc \
.profile
cd .config
trash-put \
kglobalshortcutsrc \
khotkeysrc \
konsolerc \
kwinrulesrc \
powerdevilrc \
powermanagementprofilesrc
cd ../stow
stow \
bash \
git \
kglobalshortcuts \
khotkeys \
klipper \
konsole \
kwinrules \
powerdevil \
powermanagementprofiles
LF
# Configure Git for the superuser.
cd
git clone --recursive \
'https://github.com/m5w/root-stow.git' \
stow
cd stow
stow git
# Install KeePass.
terminal-logger apt-get -y install \
keepass2 \
keepass2-doc \
xdotool
# Install Apertium.
terminal-logger apt-get -y install \
automake \
flex \
flex-doc \
gawk \
gawk-doc \
libpcre3-dbg \
libpcre3-dev \
libtool \
libtool-doc \
libxml2-dbg \
libxml2-dev \
libxml2-doc \
pkg-config \
subversion \
xsltproc
sudo -iu "$SUDO_USER" bash << LF
mkdir -p svn.code.sf.net/p/apertium/svn/trunk
LF
for _directory in \
lttoolbox \
apertium \
apertium-lex-tools
do
sudo -iu "$SUDO_USER" bash << LF
cd svn.code.sf.net/p/apertium/svn/trunk
svn co \
"https://svn.code.sf.net/p/apertium/svn/trunk/$_directory"
cd "$_directory"
./autogen.sh
make
LF
cd "$_sudo_home/svn.code.sf.net/p/apertium/svn/trunk/$_directory"
make install
ldconfig
done
sudo -iu "$SUDO_USER" bash << LF
cd svn.code.sf.net/p/apertium/svn/trunk
svn co \
'https://svn.code.sf.net/p/apertium/svn/trunk/apertium-tools'
LF
# Install Matxin.
terminal-logger apt-get -y install \
libxslt1-dbg \
libxslt1-dev
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://apertium.projectjj.com/apt/install-nightly.sh'
chmod +x install-nightly.sh
LF
"$_sudo_home/Downloads/install-nightly.sh"
terminal-logger apt-get -y install \
foma-bin \
libfoma0-dev
# upstream
sudo -iu "$SUDO_USER" bash << LF
cd github.com
mkdir matxin
cd matxin
git clone \
'https://github.com/matxin/matxin.git'
cd matxin
./autogen.sh
make
LF
cd "$_sudo_home/github.com/matxin/matxin"
make install
# origin
sudo -iu "$SUDO_USER" bash << LF
cd github.com/m5w
git clone \
'https://github.com/m5w/matxin.git'
cd matxin
git remote add upstream \
'https://github.com/matxin/matxin.git'
./autogen.sh
make
LF
# matxin-lineariser
sudo -iu "$SUDO_USER" bash << LF
cd github.com
mkdir moses-smt
cd moses-smt
git clone \
'https://github.com/moses-smt/mosesdecoder.git'
LF
terminal-logger apt-get -y install \
python3-matplotlib \
python3-nltk \
python3-numpy
terminal-logger pip3 -q install scikit-learn
terminal-logger apt-get -y install \
ant \
ant-doc
sudo -iu "$SUDO_USER" bash << LF
cd github.com/matxin
git clone \
'https://github.com/matxin/matxin-lineariser.git'
cd matxin-lineariser/tg
ant
LF
sudo -iu "$SUDO_USER" bash << LF
cd github.com
mkdir ufal
cd ufal
git clone \
'https://github.com/ufal/udpipe.git'
cd udpipe/src
make
LF
# matxin-lat
sudo -iu "$SUDO_USER" bash << LF
cd github.com/m5w
git clone \
'https://github.com/m5w/matxin-lat.git'
LF
# matxin-lat-eng
sudo -iu "$SUDO_USER" bash << LF
cd github.com/m5w
git clone \
'https://github.com/m5w/matxin-lat-eng.git'
cd matxin-lat-eng
lt-comp lr matxin-lat-eng.lat-eng.dix lat-eng.autobil.bin
matxin-preprocess-transfer matxin-lat-eng.lat-eng.t1x lat-eng.t1x.bin
LF
# matxin-eng
sudo -iu "$SUDO_USER" bash << LF
cd github.com/m5w
git clone \
'https://github.com/m5w/matxin-eng.git'
cd matxin-eng
lt-comp rl matxin-eng.eng.dix eng.autogen.bin
matxin-preprocess-generate matxin-eng.eng.gnx eng.gnx.bin
LF
# Install SPASM-ng.
terminal-logger apt-get -y install \
libgmp-dev \
libssl-dev \
libssl-doc
sudo -iu "$SUDO_USER" bash << LF
cd github.com
mkdir alberthdev
cd alberthdev
git clone \
'https://github.com/alberthdev/spasm-ng.git'
cd spasm-ng
make
LF
cd "$_sudo_home/github.com/alberthdev/spasm-ng"
make install
# Install BinPac8x.
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget -O binpac8x.zip \
'https://www.cemetech.net/scripts/countdown.php?/win/asm/binpac8x.zip&path=archives'
mkdir binpac8x
cd binpac8x
unzip ../binpac8x.zip
chmod +x binpac8x.py
LF
cd "$_sudo_home/Downloads/binpac8x"
install -Dt /usr/local/bin binpac8x.py
# Install the Arduino IDE.
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://downloads.arduino.cc/arduino-1.8.5-linux64.tar.xz'
tar xf arduino-1.8.5-linux64.tar.xz
cd arduino-1.8.5
./install.sh
LF
# Install Riot.
sudo -iu "$SUDO_USER" bash << LF
cd Downloads
wget \
'https://riot.im/packages/debian/repo-key.asc'
LF
terminal-logger apt-key add "$_sudo_home/Downloads/repo-key.asc"
cd /etc/apt/sources.list.d
cat > riot.list << LF
deb https://riot.im/packages/debian xenial main
LF
terminal-logger apt-get update
terminal-logger apt-get -y install riot-web
# Install WeeChat.
terminal-logger apt-get -y install \
weechat \
weechat-doc \
weechat-scripts
sudo -iu "$SUDO_USER" bash << LF
mkdir -p .weechat/perl/autoload
cd .weechat/perl/autoload
ln -s /usr/share/weechat/perl/iset.pl
LF
# Install Spotify.
terminal-logger apt-key adv \
--keyserver \
'hkp://keyserver.ubuntu.com:80' \
--recv-keys \
0DF731E45CE24F27EEEB1450EFDC8610341D9410
cd /etc/apt/sources.list.d
cat > spotify.list << LF
deb http://repository.spotify.com stable non-free
LF
terminal-logger apt-get update
terminal-logger apt-get -y install spotify-client
# Install packages.
terminal-logger apt-get -y install \
acpidump \
avahi-utils \
baobab \
bleachbit \
chkrootkit \
cifs-utils \
clang-tidy \
dconf-cli \
dos2unix \
easytag \
flashplugin-installer \
geda \
gimp \
git-doc \
git-gui \
git-svn \
gnome-disk-utility \
gstreamer1.0-fluendo-mp3 \
gufw \
idle3 \
iotop \
libboost-all-dev \
libboost-dbg \
libboost-doc \
lilypond \
lilypond-doc \
lldb \
markdown \
nasm \
ngspice \
ngspice-doc \
p7zip-full \
pandoc \
pastebinit \
pavucontrol \
proot \
python-visual \
python3-lxml \
python3-pyftpdlib \
qemu-user \
redshift-gtk \
screen \
tcl-doc \
thunderbird \
tilp2 \
timidity \
usb-creator-kde \
valgrind
cat << \LF
# Installing drivers may fail.
sudo terminal-logger ubuntu-drivers autoinstall
java -jar ~/Downloads/eclim_2.6.0.jar
# Installing steam requires (interactively) accepting a license agreement.
sudo terminal-logger apt-get install steam
LF