forked from shagu/arch-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-install.sh
executable file
·386 lines (309 loc) · 13.5 KB
/
arch-install.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
#!/bin/bash
function progress() {
echo $2 | dialog --title "Installation" --gauge "$1" 0 40 0
}
# clean previous install attempts
umount -R /mnt &> /dev/null || true
cryptsetup luksClose /dev/mapper/* &> /dev/null || true
KEYMAP=$(dialog --clear --title "Keymap" --inputbox "Please enter your keymap" 0 0 "" 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
loadkeys $KEYMAP
USERNAME=$(dialog --clear --title "Username" --inputbox "Please enter your username" 0 0 "" 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
HOSTNAME=$(dialog --clear --title "Hostname" --inputbox "Please enter your hostname" 0 0 "" 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
ROOTDEV=$(dialog --clear --title "Harddisk" --radiolist "Please select the target device" 0 0 0 \
$(ls /dev/sd? /dev/mmcblk? /dev/nvme?n? -1 2> /dev/null | while read line; do
echo "$line" "$line" on; done) 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
if grep "mmcblk" <<< $ROOTDEV &> /dev/null; then
RDAPPEND=p
fi
if grep "nvme" <<< $ROOTDEV &> /dev/null; then
RDAPPEND=p
fi
if dialog --clear --title "UEFI" --yesno "Use UEFI Boot?" 0 0 3>&1 1>&2 2>&3; then
UEFI=y
else
UEFI=n
fi
if dialog --clear --title "Reuse" --yesno "Do you want to reuse an existing installation?" 0 0 3>&1 1>&2 2>&3; then
WIPE=n
else
WIPE=y
fi
DESKTOP=$(dialog --clear --title "Desktop" --radiolist "Please select your Desktop" 0 0 0 \
1 "MATE" on\
2 "KDE" off\
3 "GNOME" off\
4 "CINNAMON" off\
5 "XFCE" off\
6 "DEEPIN" off 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
TWEAKS=$(dialog --clear --title "Tweaks" --checklist "Select Custom Tweaks" 0 0 4 \
OPTIMUS "Install NVIDIA Hybrid Graphic Drivers" off\
FIX_PCI "Fix bad PCI Events (RazerBlade2017)" off\
FIX_GPD "Fix Display Rotation (GPD Win)" off 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
for item in $TWEAKS; do
if [ "$item" = "OPTIMUS" ]; then
OPTIMUS=y
elif [ "$item" = "FIX_PCI" ]; then
CUSTOM_CMDLINE="pci=noaer button.lid_init_state=open"
elif [ "$item" == "FIX_GPD" ]; then
CUSTOM_CMDLINE="$CUSTOM_CMDLINE fbcon=rotate:1 dmi_product_name=GPD-WINI55"
fi
done
while ! [ "$USERPW" = "$USERPW2" ] || [ -z "$USERPW" ]; do
USERPW=$(dialog --clear --title "User Password" --insecure --passwordbox "Enter your user password" 0 0 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
USERPW2=$(dialog --clear --title "User Password" --insecure --passwordbox "Repeat your user password" 0 0 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
done
while ! [ "$DISKPW" = "$DISKPW2" ] || [ -z "$DISKPW" ]; do
DISKPW=$(dialog --clear --title "Disk Encryption" --insecure --passwordbox "Enter your disk encryption password" 0 0 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
DISKPW2=$(dialog --clear --title "Disk Encryption" --insecure --passwordbox "Repeat your disk encryption password" 0 0 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
done
INSTALL_OPTIMUS="bumblebee mesa lib32-virtualgl nvidia lib32-nvidia-utils primus lib32-primus bbswitch"
INSTALL_BASE="vim openssh wget htop ncdu screen zsh net-tools unp debootstrap unrar unzip p7zip rfkill bind-tools rsnapshot lxc php php-gd lua mariadb-clients libmariadbclient"
INSTALL_DESKTOP="mpv youtube-dl git fuseiso atom chromium firefox vlc ffmpeg gimp blender owncloud-client wine wine-mono wine_gecko steam libreoffice ttf-liberation ttf-ubuntu-font-family ttf-droid ttf-dejavu ttf-freefont noto-fonts-emoji alsa-utils samba lib32-libpulse gst-plugins-ugly gst-plugins-bad gst-libav android-tools pulseaudio-zeroconf noto-fonts picard inkscape audacity pidgin virtualbox virtualbox-host-modules-arch keepassx2"
INSTALL_DESKTOP_GTK="easytag wireshark-gtk gtk-recordmydesktop openshot gcolor2 meld paprefs evolution"
INSTALL_DESKTOP_QT="kid3 wireshark-qt qt-recordmydesktop"
# Setup Variables
case $DESKTOP in
"1")
DESKTOP="MATE"
DESKTOP_APPS="mate mate-extra lightdm-gtk-greeter-settings networkmanager pulseaudio network-manager-applet blueman gvfs-smb gvfs-mtp"
DESKTOP_DM="lightdm"
DESKTOP_MISC="${INSTALL_DESKTOP_GTK} totem gnome-keyring awesome wireshark-gtk"
;;
"2")
DESKTOP="KDE"
DESKTOP_APPS="plasma kde-applications kde-l10n-de"
DESKTOP_DM="sddm"
DESKTOP_MISC="${INSTALL_DESKTOP_QT}"
;;
"3")
DESKTOP="GNOME"
DESKTOP_APPS="gnome gnome-extra networkmanager"
DESKTOP_DM="gdm"
DESKTOP_MISC="${INSTALL_DESKTOP_GTK}"
;;
"4")
DESKTOP="CINNAMON"
DESKTOP_APPS="gnome gnome-extra networkmanager cinnamon nemo"
DESKTOP_DM="gdm"
DESKTOP_MISC="${INSTALL_DESKTOP_GTK}"
;;
"5")
DESKTOP="XFCE"
DESKTOP_APPS="xfce4 xfce4-goodies lightdm-gtk-greeter-settings networkmanager pulseaudio network-manager-applet blueman gvfs-smb gvfs-mtp"
DESKTOP_DM="lightdm"
DESKTOP_MISC="${INSTALL_DESKTOP_GTK} totem gnome-keyring awesome wireshark-gtk"
;;
"6")
DESKTOP="DEEPIN"
DESKTOP_APPS="deepin deepin-extra networkmanager"
DESKTOP_DM="lightdm"
DESKTOP_MISC="${INSTALL_DESKTOP_GTK} gedit gtk-engine-murrine iw redshift zssh gvfs-smb gvfs-mtp gvfs-goa gvfs-afc"
;;
esac
cat > /tmp/install-summary.log << EOF
Simple Arch Linux Installer
===========================
Username: $USERNAME
Hostname: $HOSTNAME
Device: $ROOTDEV
Wipe: $WIPE
Desktop: $DESKTOP
Display Manager: $DESKTOP_DM
Packages
========
$INSTALL_BASE
$INSTALL_DESKTOP
$DESKTOP_MISC
$DESKTOP_APPS
$INSTALL_OPTIMUS
Hit Ctrl-C to abort, Return to continue ...
EOF
dialog --clear --title "Summary" --textbox /tmp/install-summary.log 0 0 3>&1 1>&2 2>&3
if test $? -eq 1; then exit 1; fi
progress "Setting Up Disk" 0
if [ "$WIPE" = "y" ]; then
progress "Deleting MBR Record" 1
dd if=/dev/zero of=${ROOTDEV} bs=4M conv=fsync count=1
if [ "$UEFI" = "y" ]; then
progress "Create GPT Partitiontable" 2
parted ${ROOTDEV} -s mklabel gpt &> /dev/tty2
progress "Create Boot Partition" 3
parted ${ROOTDEV} -s mkpart ESP fat32 1MiB 513MiB &> /dev/tty2
parted ${ROOTDEV} -s set 1 boot on &> /dev/tty2
progress "Formatting Boot Partition as FAT32" 4
mkfs.fat -F 32 -n EFIBOOT ${ROOTDEV}${RDAPPEND}1 &> /dev/tty2
else
progress "Create MSDOS Partitiontable" 2
parted ${ROOTDEV} -s mklabel msdos &> /dev/tty2
progress "Create Boot Partition" 3
parted ${ROOTDEV} -s mkpart primary 1MiB 513MiB &> /dev/tty2
parted ${ROOTDEV} -s set 1 boot on &> /dev/tty2
progress "Formatting Boot Partition as EXT4" 4
mkfs.ext4 -F ${ROOTDEV}${RDAPPEND}1 -L boot &> /dev/tty2
fi
progress "Create System Partition" 5
parted ${ROOTDEV} -s mkpart primary 513MiB 100% &> /dev/tty2
progress "Create DM-Crypt Container" 6
echo -n "${DISKPW}" | cryptsetup -c aes-xts-plain64 -s 512 luksFormat ${ROOTDEV}${RDAPPEND}2 - &> /dev/tty2
echo -n "${DISKPW}" | cryptsetup luksOpen ${ROOTDEV}${RDAPPEND}2 cryptlvm -d - &> /dev/tty2
progress "Setup LVM Volumes" 7
pvcreate /dev/mapper/cryptlvm &> /dev/tty2
vgcreate lvm /dev/mapper/cryptlvm &> /dev/tty2
lvcreate -L 50G lvm -n system &> /dev/tty2
lvcreate -l 100%FREE lvm -n home &> /dev/tty2
progress "Formatting Root Partition as EXT4" 8
mkfs.ext4 -F /dev/mapper/lvm-system -L system &> /dev/tty2
progress "Formatting Home Partition as EXT4" 9
mkfs.ext4 -F /dev/mapper/lvm-home -L home &> /dev/tty2
else
if [ "$UEFI" = "y" ]; then
progress "Formatting Boot Partition as FAT32" 2
mkfs.fat -F 32 -n EFIBOOT ${ROOTDEV}${RDAPPEND}1 &> /dev/tty2
else
progress "Formatting Boot Partition as EXT4" 4
mkfs.ext4 -F ${ROOTDEV}${RDAPPEND}1 -L boot &> /dev/tty2
fi
progress "Unlocking DM-Crypt Container" 6
if ! echo -n "${DISKPW}" | cryptsetup luksOpen ${ROOTDEV}${RDAPPEND}2 cryptlvm -d - ; then
cryptsetup luksOpen ${ROOTDEV}${RDAPPEND}2 cryptlvm || exit 1 &> /dev/tty2
fi
progress "Load LVM Volumes" 8
vgchange -ay &> /dev/tty2
sleep 1
progress "Formatting Root Partition as EXT4" 9
mkfs.ext4 -F /dev/mapper/lvm-system -L system &> /dev/tty2
fi
progress "Mounting /root to /mnt" 10
mount /dev/mapper/lvm-system /mnt &> /dev/tty2
progress "Mounting /boot to /mnt/boot" 15
mkdir /mnt/boot &> /dev/tty2
mount ${ROOTDEV}${RDAPPEND}1 /mnt/boot &> /dev/tty2
progress "Mounting /home to /mnt/home" 20
mkdir /mnt/home &> /dev/tty2
mount /dev/mapper/lvm-home /mnt/home &> /dev/tty2
progress "Installing Target: Base System" 25
sed -i "s/#Color/Color/" /etc/pacman.conf &> /dev/tty2
while ! pacstrap /mnt base &> /dev/tty2; do
echo "Failed: repeating" &> /dev/tty2
done
progress "Configure Base System" 30
genfstab -p /mnt > /mnt/etc/fstab
cat > /mnt/etc/locale.gen << EOF
de_DE.UTF-8 UTF-8
en_GB.UTF-8 UTF-8
en_US.UTF-8 UTF-8
EOF
echo LANG=de_DE.UTF-8 > /mnt/etc/locale.conf
cat > /mnt/etc/vconsole.conf << EOF
KEYMAP="$KEYMAP"
FONT=Lat2-Terminus16
FONT_MAP=
EOF
ln -sf /usr/share/zoneinfo/Europe/Berlin /mnt/etc/localtime &> /dev/tty2
echo $HOSTNAME > /mnt/etc/hostname
sed -i "s/#Color/Color/" /mnt/etc/pacman.conf &> /dev/tty2
sed -i '/#\[multilib\]/,/#Include = \/etc\/pacman.d\/mirrorlist/ s/#//' /mnt/etc/pacman.conf &> /dev/tty2
sed -i "s/block filesystems/block keymap encrypt lvm2 filesystems/" /mnt/etc/mkinitcpio.conf &> /dev/tty2
sed -i "s/MODULES=\"\"/MODULES=\"i915\"/" /mnt/etc/mkinitcpio.conf &> /dev/tty2
progress "Generating Locales" 35
arch-chroot /mnt /bin/bash -c "locale-gen" &> /dev/tty2
progress "Installing Target: Updates" 40
arch-chroot /mnt /bin/bash -c "while ! pacman -Syu --noconfirm; do echo repeat...; done" &> /dev/tty2
progress "Installing Target: Base Utils" 45
arch-chroot /mnt /bin/bash -c "while ! pacman -S --noconfirm base-devel cmake linux-headers ${INSTALL_BASE}; do echo repeat...; done" &> /dev/tty2
progress "Installing Target: Boot" 50
arch-chroot /mnt /bin/bash -c "while ! pacman -S --noconfirm efibootmgr dosfstools gptfdisk grub-bios; do echo repeat...; done" &> /dev/tty2
progress "Installing Target: Desktop ($DESKTOP)" 55
arch-chroot /mnt /bin/bash -c "while ! pacman -S --noconfirm xorg xorg-apps xf86-input-evdev xf86-input-synaptics ${DESKTOP_APPS}; do echo repeat...; done" &> /dev/tty2
progress "Installing Target: Applications" 60
arch-chroot /mnt /bin/bash -c "while ! pacman -S --noconfirm ${INSTALL_DESKTOP} ${DESKTOP_MISC}; do echo repeat...; done" &> /dev/tty2
if [ "${OPTIMUS}" = "y" ]; then
progress "Installing Target: Optimus Drivers" 65
arch-chroot /mnt /bin/bash -c "while ! pacman -S --noconfirm ${INSTALL_OPTIMUS}; do echo repeat...; done" &> /dev/tty2
fi
progress "Configuring Desktop" 70
# disable wine filetype associations
sed "s/-a //g" -i /mnt/usr/share/wine/wine.inf &> /dev/tty2
if ! [ "$DESKTOP" = "KDE" ]; then
echo "QT_QPA_PLATFORMTHEME=gtk2" >> /mnt/etc/environment
fi
if [ "$DESKTOP" = "KDE" ]; then
cat > /mnt/etc/sddm.conf << EOF
[Autologin]
Relogin=false
Session=
User=
[General]
HaltCommand=
RebootCommand=
[Theme]
Current=breeze
CursorTheme=breeze_cursors
[Users]
MaximumUid=65000
MinimumUid=1000
EOF
fi
if [ "$DESKTOP" = "DEEPIN" ]; then
sed -i "s/#greeter-session=.*/greeter-session=lightdm-deepin-greeter/" /mnt/etc/lightdm/lightdm.conf &> /dev/tty2
fi
progress "Rebuild Initramfs" 75
arch-chroot /mnt /bin/bash -c "mkinitcpio -p linux" &> /dev/tty2
if [ "$UEFI" = "y" ]; then
progress "Installing UEFI Bootloader to ${ROOTDEV}${RDAPPEND}1" 80
arch-chroot /mnt /bin/bash -c "efibootmgr -c -d ${ROOTDEV} -p 1 -l \vmlinuz-linux -L \"Arch Linux\" -u \"initrd=/initramfs-linux.img cryptdevice=${ROOTDEV}${RDAPPEND}2:cryptlvm root=/dev/mapper/lvm-system rw ${CUSTOM_CMDLINE}\"" &> /dev/tty2
else
progress "Installing GRUB Bootloader to ${ROOTDEV}${RDAPPEND}1" 80
sed -i "s|GRUB_CMDLINE_LINUX=\"\"|GRUB_CMDLINE_LINUX=\"cryptdevice=${ROOTDEV}${RDAPPEND}2:cryptlvm ${CUSTOM_CMDLINE}\"|" /mnt/etc/default/grub &> /dev/tty2
arch-chroot /mnt /bin/bash -c "grub-install ${ROOTDEV}; grub-mkconfig -o /boot/grub/grub.cfg" &> /dev/tty2
fi
progress "Setting up User: ${USERNAME}" 85
arch-chroot /mnt /bin/bash -c "useradd -m ${USERNAME}" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "usermod -a -G audio,video,storage,optical,network,users,wheel,games,rfkill,scanner,power,lp,vboxusers ${USERNAME}" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "gpasswd -a ${USERNAME} bumblebee" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "gpasswd -a ${USERNAME} ${DESKTOP_DM}" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "echo \"${USERNAME}:${USERPW}\" | chpasswd" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "echo \"root:${USERPW}\" | chpasswd" &> /dev/tty2
ln -s /home/${USERNAME}/.bashrc /mnt/root/.bashrc &> /dev/tty2
ln -s /home/${USERNAME}/.zshrc /mnt/root/.zshrc &> /dev/tty2
ln -s /home/${USERNAME}/.vimrc /mnt/root/.vimrc &> /dev/tty2
progress "Configuring systemd Services" 90
arch-chroot /mnt /bin/bash -c "systemctl enable ${DESKTOP_DM}" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "systemctl enable NetworkManager" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "systemctl enable bluetooth" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "systemctl enable avahi-daemon" &> /dev/tty2
arch-chroot /mnt /bin/bash -c "systemctl enable bumblebeed" &> /dev/tty2
ln -s /dev/null /mnt/etc/udev/rules.d/80-net-setup-link.rules &> /dev/tty2
progress "Installing Firstrun Service" 95
cat > /mnt/etc/systemd/system/firstrun.service << EOF
[Unit]
Description=Firstrun Service
[Service]
ExecStart=/firstrun.sh
[Install]
WantedBy=multi-user.target
EOF
cat > /mnt/firstrun.sh << EOF
#!/bin/bash
# Locale
localectl set-keymap $KEYMAP
localectl set-x11-keymap $KEYMAP
localectl set-locale LANG=de_DE.UTF-8
rm -f /etc/systemd/system/firstrun.service /firstrun.sh
EOF
chmod +x /mnt/firstrun.sh &> /dev/tty2
arch-chroot /mnt /bin/bash -c "systemctl enable firstrun.service" &> /dev/tty2
progress "Syncing Disks" 100
sync
dialog --title "Installtion" --msgbox "Installation completed. Press Enter to reboot into the new system." 0 0
reboot