-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktop.sh
executable file
·232 lines (181 loc) · 7.01 KB
/
desktop.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
#!/usr/bin/env bash
# before chroot
# TODO: make UEFI setup
# generic desktop install with i3wm
set -e
#timedatectl set-ntp true
curp=$(dirname "$0")
# load .env
if [ -f "$curp/.env" ]; then
source "$curp/.env"
else
echo "File $curp/.env does not exist!"
echo "Copy $curp/.env.example as $curp/.env and edit it first!"
exit 1
fi
if [ "$AAI_FORMAT" -eq "1" ]; then
parted "$AAI_DEVICE" --script -- mklabel msdos
parted "$AAI_DEVICE" --script -- mkpart primary 0% 100%
mkfs.ext4 -F "$AAI_PARTITION"
fi
mountpoint -q "$AAI_MNT" || mount $AAI_PARTITION "$AAI_MNT"
if [ "$AAI_MIRROR" == "yes" ]; then
cp "$curp/mirrorlist" /etc/pacman.d/mirrorlist
fi
if [ "$AAI_SKIP_INIT" == "no" ]; then
if [ "$(hostname)" == "archiso" ]; then
# do not use host cache on arch iso
pacstrap "$AAI_MNT" base base-devel
else
pacstrap -c "$AAI_MNT" base base-devel
fi
fi
# sync host packages with target
rsync -a /var/cache/pacman/pkg/ "$AAI_MNT"/var/cache/pacman/pkg/
genfstab -U "$AAI_MNT" > "$AAI_MNT"/etc/fstab
# enable multilib
sed -i "/\[multilib\]/,/Include/"'s/^#//' "$AAI_MNT"/etc/pacman.conf
# set temp user pass here
NEW_PASSWORD=pass123
repopkgs=$(cat "${curp}/repo.txt" | grep -v '^#\|^$' | tr '\n' ' ')
arch-chroot "$AAI_MNT" << EOF
set -o errexit
# first update db
pacman -Sy
ln -sf /usr/share/zoneinfo/Europe/Sofia /etc/localtime
hwclock --systohc
# setup locales
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
echo "bg_BG.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
echo "LC_COLLATE=C" >> /etc/locale.conf
echo "$AAI_HOSTNAME" > /etc/hostname
echo "127.0.1.1 ${AAI_HOSTNAME}.localdomain ${AAI_HOSTNAME}" >> /etc/hosts
# speedup AUR packages builds
sed -i 's,#MAKEFLAGS="-j2",MAKEFLAGS="-j\$(nproc)",g' /etc/makepkg.conf
sed -i "s,PKGEXT='.pkg.tar.xz',PKGEXT='.pkg.tar',g" /etc/makepkg.conf
# swap setup
echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.d/99-sysctl.conf
echo "fs.file-max=131072" >> /etc/sysctl.d/99-sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables=0" >> /etc/sysctl.d/99-sysctl.conf
echo "net.bridge.bridge-nf-call-iptables=0" >> /etc/sysctl.d/99-sysctl.conf
echo "net.bridge.bridge-nf-call-arptables=0" >> /etc/sysctl.d/99-sysctl.conf
# ensure br_netfilter module is loaded on boot so rules are applied correctly
echo "br_netfilter" > /etc/modules-load.d/br-netfilter.conf
# disable swap for now
#fallocate -l 16G /swapfile
#chmod 600 /swapfile
#mkswap /swapfile
# pacman
pacman --noconfirm -S $repopkgs
if [ ! -d "/home/$AAI_USER" ]; then
useradd --create-home "$AAI_USER" --shell /usr/bin/zsh
groupadd sudo
usermod -aG video,audio,scanner,lp,sudo,docker $AAI_USER
fi
# ssh daemon
systemctl enable sshd.service
# dhcp client on all interfaaces
systemctl enable dhcpcd.service
# bluetooth service
systemctl enable bluetooth.service
# cron service
systemctl enable cronie.service
# ntp client using systemd
systemctl enable systemd-timesyncd.service
mkdir -pv /work
chown $AAI_USER:$AAI_USER /work
# force sudo to use -A for the install
echo -ne '#!/usr/bin/env bash\necho '"$AAI_PASSWORD"'\n' > /usr/local/bin/spit_pass.sh && chmod +x /usr/local/bin/spit_pass.sh
echo -ne '#!/bin/bash\n SUDO_ASKPASS=/usr/local/bin/spit_pass.sh /usr/bin/sudo -A "\$@"\n' > /usr/local/bin/sudo && chmod +x /usr/local/bin/sudo
EOF
arch-chroot "$AAI_MNT" sh -c "echo \"$AAI_USER:$AAI_PASSWORD\" | chpasswd"
# sync trizen cache
[ -d "/home/$AAI_USER/.cache/trizen" ] && rsync -a /home/$AAI_USER/.cache/trizen "$AAI_MNT"/home/$AAI_USER/.cache
# setup sudoers file
cat>"$AAI_MNT"/etc/sudoers << EOF
root ALL=(ALL) ALL
%sudo ALL=(ALL) ALL
# start vpn without sudo password
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl start [email protected]
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl start [email protected]
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl start [email protected]
# stop vpn without sudo password
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop [email protected]
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop [email protected]
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop [email protected]
$AAI_USER ALL=(ALL) NOPASSWD: /usr/bin/beep
Defaults insults
EOF
if [ "$AAI_INTEL_BL" == "yes" ]; then
cat> "$AAI_MNT"/etc/udev/rules.d/backlight.rules << EOF
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
EOF
fi
aurpkgs=$(cat "${curp}/aur.txt" | grep -v '^#\|^$' | tr '\n' ' ')
# setup user enviroment
arch-chroot "$AAI_MNT" su -l $AAI_USER << EOF
set -o errexit
mkdir -pv /work/dev/personal
[ ! -d /work/dev/personal/i3wmonarch ] && git clone https://github.com/eldiaboloz/i3wmonarch.git /work/dev/personal/i3wmonarch
[ ! -d /work/dev/trizen ] && git clone https://aur.archlinux.org/trizen.git /work/dev/trizen
alias sudo="sudo -A"
cd /work/dev/trizen && makepkg --noconfirm -si
# dummy call so config is created
trizen --help > /dev/null
# persist trizen cache
sed -i 's#/tmp/trizen-$AAI_USER#\$ENV{HOME}/.cache/trizen#' \$HOME/.config/trizen/trizen.conf
# use modifed sudo command
sed -i 's#/usr/bin/sudo#/usr/local/bin/sudo#' \$HOME/.config/trizen/trizen.conf
# @TODO check which of these is required for ok fonts
trizen --noconfirm -S $aurpkgs
cd /work/dev/personal/i3wmonarch && ./scripts/i3wm/create_symlinks.sh && git submodule update --init --recursive
cd /work/dev/personal/i3wmonarch/github.com/nonpop/xkblayout-state && make
cd /work/dev/personal/i3wmonarch/github.com/powerline/fonts && ./install.sh
EOF
# ssh access
mkdir -pv "$AAI_MNT"/root/.ssh
chmod 0700 "$AAI_MNT"/root/.ssh
[ -f "$curp/root_authorized_keys" ] && \
cp "$curp/root_authorized_keys" "$AAI_MNT"/root/.ssh/authorized_keys
# TODO: $HOME/.cache seems to be owned by root
arch-chroot "$AAI_MNT" chown -Rc $AAI_USER:$AAI_USER /home/$AAI_USER
# bootloader - grub
arch-chroot "$AAI_MNT" mkinitcpio -p linux
# add options to restart / shutdown
cat >> "$AAI_MNT"/etc/grub.d/40_custom << 'EOF'
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "System shutdown" {
echo "System shutting down..."
halt
}
menuentry "System restart" {
echo "System rebooting..."
reboot
}
EOF
cat >> "$AAI_MNT"/etc/default/grub << 'EOF'
GRUB_DEFAULT=saved
GRUB_TIMEOUT=5
GRUB_SAVEDEFAULT="true"
GRUB_DISABLE_SUBMENU=y
EOF
arch-chroot "$AAI_MNT" << EOF
grub-install --target=i386-pc "$AAI_DEVICE"
grub-mkconfig -o /boot/grub/grub.cfg
# set root password
NEW_PASSWORD="$AAI_ROOT_PASSWORD"
echo "root:\$NEW_PASSWORD" | chpasswd
echo "root pass in chroot is: \$NEW_PASSWORD"
EOF
# cleanup
rm -v "$AAI_MNT"/usr/local/bin/sudo
rm -v "$AAI_MNT"/usr/local/bin/spit_pass.sh
# revert sudo modification
sed -i 's#/usr/local/bin/sudo#/usr/bin/sudo#' "$AAI_MNT"/home/$AAI_USER/.config/trizen/trizen.conf