-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-ubuntu.sh
executable file
·502 lines (427 loc) · 11.4 KB
/
install-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
#!/usr/bin/env bash
set -e
set -o pipefail
export DEBIAN_FRONTEND=noninteractive
export APT_LISTBUGS_FRONTEND=none
export DEBCONF_NONINTERACTIVE_SEEN=true
export TARGET_USER=${TARGET_USER:-casey}
# Choose a user account to use for this installation
get_user() {
if [ -z "${TARGET_USER-}" ]; then
mapfile -t options < <(find /home/* -maxdepth 0 -printf "%f\\n" -type d)
# if there is only one option just use that user
if [ "${#options[@]}" -eq "1" ]; then
readonly TARGET_USER="${options[0]}"
echo "Using user account: ${TARGET_USER}"
return
fi
# iterate through the user options and print them
PS3='command -v user account should be used? '
select opt in "${options[@]}"; do
readonly TARGET_USER=$opt
break
done
fi
}
check_is_sudo() {
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit
fi
}
setup_sources_min() {
apt-get update || true
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
dirmngr \
gnupg2 \
lsb-release \
software-properties-common \
--no-install-recommends
# turn off translations, speed up apt update
mkdir -p /etc/apt/apt.conf.d
echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/99translations
}
# sets up apt sources
setup_sources() {
setup_sources_min;
add-apt-repository -y ppa:yubico/stable
# tlp: Advanced Linux Power Management
cat <<- EOF > /etc/apt/sources.list.d/tlp.list
# tlp: Advanced Linux Power Management
# http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html
deb http://repo.linrunner.de/debian sid main
EOF
# Create an environment variable for the correct distribution
CLOUD_SDK_REPO="cloud-sdk"
export CLOUD_SDK_REPO
# Add the Cloud SDK distribution URI as a package source
cat <<- EOF > /etc/apt/sources.list.d/google-cloud-sdk.list
deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main
EOF
# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
# Add the Google Chrome distribution URI as a package source
cat <<- EOF > /etc/apt/sources.list.d/google-chrome.list
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
EOF
cat <<- EOF > /etc/apt/sources.list.d/keybase.list
deb http://prerelease.keybase.io/deb stable main
EOF
cat <<- EOF > /etc/apt/sources.list.d/microsoft-prod.list
deb [arch=amd64] https://packages.microsoft.com/ubuntu/19.10/prod eoan main
EOF
cat <<- EOF > /etc/apt/sources.list.d/teams.list
deb [arch=amd64] https://packages.microsoft.com/repos/ms-teams stable main
EOF
cat <<- EOF > /etc/apt/sources.list.d/vscode.list
deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main
EOF
cat <<- EOF > /etc/apt/sources.list.d/slack.list
deb https://packagecloud.io/slacktechnologies/slack/debian/ jessie main
EOF
cat <<- EOF > /etc/apt/sources.list.d/spotify.list
deb http://repository.spotify.com stable non-free
EOF
cat <<- EOF > /etc/apt/sources.list.d/github-cli.list
deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main
EOF
# Import the slack public key
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys DB085A08CA13B8ACB917E0F6D938EC0D038651BD
# Import the keybase key
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 222B85B0F90BE2D24CFEB93F47484E50656D16C7
# Import the spotify keys
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 2EBF997C15BDA244B6EBF5D84773BD5E130D1D45
# Import the microsoft key
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys BC528686B50D79E339D3721CEB3E94ADBE1229CF
# Import the Google Chrome public key
curl https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
# add the yubico ppa gpg key
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 3653E21064B19D134466702E43D5C49532CBA1A9
# add the tlp apt-repo gpg key
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 6B283E95745A6D903009F7CA641EED65CD4E8809
# linrunner
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys BF851E76615EF34A
# github cli
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
}
base_min() {
apt-get update || true
apt-get -y upgrade
apt-get install -y \
adduser \
automake \
bc \
bzip2 \
ca-certificates \
coreutils \
curl \
dnsutils \
expect \
fd-find \
file \
findutils \
gcc \
ninja-build \
git \
gnupg \
gnupg2 \
grep \
gzip \
hostname \
indent \
iptables \
iw \
jq \
less \
locales \
lsof \
make \
mount \
net-tools \
policykit-1 \
silversearcher-ag \
ssh \
strace \
sudo \
tar \
tree \
tzdata \
unzip \
neovim \
emacs-gtk \
wget \
xz-utils \
zip \
plymouth-label \
plymouth-themes \
--no-install-recommends
apt -y autoremove
apt autoclean
apt clean
}
# installs base packages
# the utter bare minimal shit
base() {
base_min;
apt-get update || true
apt-get -y upgrade
apt-get install -y \
apparmor \
autoconf \
automake \
bat \
bluez \
bolt \
bridge-utils \
build-essential \
cgroupfs-mount \
cmake \
cpufrequtils \
curl \
docker.io \
doxygen \
exuberant-ctags \
fwupd \
fwupdate \
fzf \
g++ \
gdm3 \
gettext \
gh \
gnupg-agent \
google-cloud-sdk \
htop \
iproute2 \
iwd \
lastpass-cli \
libimobiledevice6 \
libpam-systemd \
libsecret-1-dev \
libssl-dev \
libtool \
libtool-bin \
lm-sensors \
locate \
lshw \
mpd \
netbase \
netcat \
nftables \
ninja-build \
pcscd \
pinentry-curses \
pkg-config \
prettyping \
printer-driver-brlaser \
psmisc \
rsync \
scdaemon \
software-properties-common \
systemd \
tcptraceroute \
texlive \
traceroute \
unrar \
unzip \
zsh \
--no-install-recommends
setup_sudo
apt -y autoremove
apt autoclean
apt clean
sed -i '/en_US.UTF-8/ s/^# //' /etc/locale.gen
locale-gen
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
sed -i '/WaylendEnable=false/ s/^#\s*//' /etc/gdm3/custom.conf
}
# setup sudo for a user
# because fuck typing that shit all the time
# just have a decent password
# and lock your computer when you aren't using it
# if they have your password they can sudo anyways
# so its pointless
# i know what the fuck im doing ;)
setup_sudo() {
# add user to sudoers
adduser "$TARGET_USER" sudo
# add user to systemd groups
# then you wont need sudo to view logs and shit
gpasswd -a "$TARGET_USER" systemd-journal
gpasswd -a "$TARGET_USER" systemd-network
# create docker group
sudo groupadd -f docker
sudo gpasswd -a "$TARGET_USER" docker
# add go path to secure path
{ \
echo -e "Defaults secure_path=\"/usr/local/go/bin:/home/${TARGET_USER}/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/bcc/tools:/home/${TARGET_USER}/.cargo/bin\""; \
echo -e 'Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy GOPATH EDITOR"'; \
echo -e "${TARGET_USER} ALL=(ALL) NOPASSWD:ALL"; \
echo -e "${TARGET_USER} ALL=NOPASSWD: /sbin/ifconfig, /sbin/ifup, /sbin/ifdown, /sbin/ifquery"; \
} >> /etc/sudoers
# setup downloads folder as tmpfs
# that way things are removed on reboot
# i like things clean but you may not want this
(
set +e
mkdir -p "/home/${TARGET_USER}/Downloads"
echo -e "\\n# tmpfs for downloads\\ntmpfs\\t/home/${TARGET_USER}/Downloads\\ttmpfs\\tnodev,nosuid,size=2G\\t0\\t0" >> /etc/fstab
sudo mount "/home/${TARGET_USER}/Downloads"
chown ${TARGET_USER}:${TARGET_USER} "/home/${TARGET_USER}/Downloads"
echo "Mounted user Download directory as tmpfs"
)
}
# install graphics drivers
install_graphics() {
local system=$1
if [[ -z "$system" ]]; then
echo "You need to specify whether it's intel, geforce or optimus"
exit 1
fi
local pkgs=( xorg xserver-xorg xserver-xorg-input-libinput xserver-xorg-input-synaptics )
case $system in
"intel")
pkgs+=( xserver-xorg-video-intel )
;;
"geforce")
pkgs+=( nvidia-driver-440 )
;;
"optimus")
pkgs+=( nvidia-kernel-dkms bumblebee-nvidia primus )
;;
*)
echo "You need to specify whether it's intel, geforce or optimus"
exit 1
;;
esac
apt update || true
apt -y upgrade
apt install -y "${pkgs[@]}" --no-install-recommends
}
# install stuff for i3 window manager
install_wmapps() {
apt update || true
apt install -y \
alsa-utils \
feh \
i3 \
i3lock-fancy \
i3status \
flameshot \
suckless-tools \
kitty \
rofi \
usbmuxd \
xclip \
compton \
arandr \
adwaita-icon-theme \
breeze-cursor-theme \
breeze-gtk-theme \
breeze-icon-theme \
dunst \
firefox \
gucharmap \
hicolor-icon-theme \
higan \
hub \
inkscape \
google-chrome-stable \
kdeconnect \
lxappearance \
neofetch \
oxygen-icon-theme \
pavucontrol \
pinentry-qt \
remmina \
vlc \
wmctrl \
snapd \
libxcb1-dev \
libxss-dev \
libpulse-dev \
libxcb-screensaver0-dev \
libdbus-1-dev \
libsensors-dev \
spotify-client \
teams \
code-insiders \
keybase \
--no-install-recommends
apt -y autoremove
apt autoclean
apt clean
}
create_zfs_snapshot() {
echo
echo "Creating ZFS Snapshot"
echo
if [[ -z $(command -v zfs) ]]; then
echo "zfs not found, skipping"
return 0
fi
zfs snapshot -r rpool/ROOT@stage0install
}
rollback_zfs_snapshot() {
echo
echo "An error occured during install, rolling back to filesystem state before this install step"
echo
if [[ -z $(command -v zfs) ]]; then
echo "zfs not found, skipping"
return 0
fi
zfs rollback -r rpool/ROOT@stage0install
}
destroy_zfs_snapshot() {
echo
echo "The install step was successful, removing zfs snapshot"
echo
if [[ -z $(command -v zfs) ]]; then
echo "zfs not found, skipping"
return 0
fi
zfs destroy -r rpool/ROOT@stage0install
}
usage() {
echo -e "install.sh\\n\\tThis script installs my basic setup for a debian laptop\\n"
echo "Usage:"
echo " base - setup sources & install base pkgs"
echo " basemin - setup sources & install base min pkgs"
echo " graphics {intel, geforce, optimus} - install graphics drivers"
echo " wm - install window manager/desktop pkgs"
}
main() {
local cmd=$1
if [[ -z "$cmd" ]]; then
usage
exit 1
fi
trap 'rollback_zfs_snapshot' ERR SIGINT
trap 'destroy_zfs_snapshot' EXIT
create_zfs_snapshot
if [[ $cmd == "base" ]]; then
check_is_sudo
get_user
# setup /etc/apt/sources.list
setup_sources
base
elif [[ $cmd == "basemin" ]]; then
check_is_sudo
get_user
# setup /etc/apt/sources.list
setup_sources_min
base_min
elif [[ $cmd == "graphics" ]]; then
check_is_sudo
install_graphics "$2"
elif [[ $cmd == "wm" ]]; then
check_is_sudo
install_wmapps
else
usage
fi
}
main "$@"