-
Notifications
You must be signed in to change notification settings - Fork 4
/
bootstrap-2-manjaro.sh
140 lines (120 loc) · 4.38 KB
/
bootstrap-2-manjaro.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
#!/bin/bash
set -eo pipefail
# set -x
self_path=$(dirname "$(readlink -e "$0")")
usage() {
cat <<EOF
Usage: $0 hostname firstuser --yes [--restore-from-backup]
"http_proxy" environment variable:
the environment variable "http_proxy" will be used if set
and must follow the format "http://1.2.3.4:1234"
EOF
exit 1
}
restore_warning() {
echo "WARNING: --restore-from-backup: $@"
}
# parse args
if test "$3" != "--yes"; then usage; fi
hostname=$1; firstuser=$2; shift 3
restore_backup=false
if test "$1" = "--restore-from-backup"; then restore_backup=true; shift; fi
# if http_proxy is set, reexport for sub-processes
if test "$http_proxy" != ""; then export http_proxy; fi
# include library
. "$self_path/bootstrap-library.sh"
export LANG="en_US.UTF-8"
export LC_MESSAGES="POSIX"
export LANGUAGE="en_US:en"
export KEYMAP="us"
export TIMEZONE="Etc/UTC"
if $restore_backup; then
restore_warning "not setting locale, locale-messages, keymap, timezone and hostname"
else
echo "calling systemd-firstboot to set locale, locale-messages, keymap, timezone and hostname"
systemd-firstboot --locale="$LANG" --locale-messages="$LC_MESSAGES" \
--keymap="$KEYMAP" --timezone="$TIMEZONE" --hostname="$hostname"
fi
echo "create fstab, crypttab, zpool cache"
create_fstab "manjaro"
create_crypttab
create_zpool_cachefile
if $restore_backup; then
restore_warning "not overwriting /etc/modprobe.d/zfs.conf"
else
configure_module_zfs
fi
if $restore_backup; then
restore_warning "not creating first user $firstuser"
else
echo "create first user: $firstuser"
useradd -m -G lp,network,power,sys,wheel -s /bin/bash $firstuser
cp -a /etc/skel/.[!.]* "/home/$firstuser/"
mkdir -p "/home/$firstuser/.ssh"
cp /root/.ssh/authorized_keys "/home/$firstuser/.ssh/authorized_keys"
chmod 700 "/home/$firstuser/.ssh"
chown "$firstuser:$firstuser" -R "/home/$firstuser/."
fi
echo "setup sudo for wheel group"
tee /etc/sudoers.d/wheel << EOF
## allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL
EOF
if test "$(find /etc/systemd/network/ -type f -print -quit)" != ""; then
echo "found files in '/etc/systemd/network/', enable systemd-networkd systemd-resolved"
systemctl enable systemd-networkd systemd-resolved
fi
echo "setup sshd"
if $restore_backup; then
restore_warning "not overwriting /etc/ssh/sshd"
else
configure_sshd
fi
systemctl enable sshd
if is_zfs "$(by_partlabel ROOT)"; then
echo "setup zfs mounts"
systemctl enable zfs.target zfs-import-cache zfs-mount zfs-import.target
fi
echo "setup initrd ramdisk"
initrd_hooks="base udev autodetect modconf keyboard keymap block"
# XXX plymouth does not play well with native zfs encrypted volume
# initrd_hooks="base udev autodetect modconf keyboard keymap plymouth block"
if is_mdadm "$(by_partlabel ROOT)"; then initrd_hooks="$initrd_hooks mdadm_udev"; fi
if is_luks "$(by_partlabel ROOT)"; then initrd_hooks="$initrd_hooks encrypt"; fi
if is_lvm "$(by_partlabel ROOT)"; then initrd_hooks="$initrd_hooks lvm2"; fi
if is_zfs "$(by_partlabel ROOT)"; then
initrd_hooks="$initrd_hooks zfs filesystems"
else
initrd_hooks="$initrd_hooks filesystems fsck"
fi
if grep -E -q "^HOOKS=" /etc/mkinitcpio.conf 2> /dev/null; then
sed -i -r "s/^HOOKS=.+/HOOKS=($initrd_hooks)/g" /etc/mkinitcpio.conf
else
echo "HOOKS=($initrd_hooks)" >> /etc/mkinitcpio.conf
fi
mkinitcpio -P
echo "setup bootloader"
# see https://wiki.archlinux.org/title/silent_boot
# XXX sdboot_options: always escape "/", because it is used as sed replace
sdboot_options="quiet"
# splash loglevel=3 rd.udev.log_level=3 vt.global_cursor_default=0"
if grep -E -q "^LINUX_OPTIONS=" /etc/sdboot-manage.conf 2> /dev/null; then
sed -i -r "s/^LINUX_OPTIONS=.+/LINUX_OPTIONS=\"$sdboot_options\"/g" /etc/sdboot-manage.conf
else
echo "LINUX_OPTIONS=\"$sdboot_options\"" >> /etc/sdboot-manage.conf
fi
bootctl install
sdboot-manage gen
if test "$(by_partlabel EFI | wc -w)" = "2"; then
efi_src=$(get_efi1_mountpath)
efi_dest=$(get_efi2_mountpath)
echo "setup efi-sync from $efi_src to $efi_dest"
install_efi_sync $efi_src $efi_dest "$self_path/bootstrap-library.sh"
efi_sync $efi_src $efi_dest
fi
unit_files=$(systemctl --no-pager --no-legend list-unit-files)
printf "%s" "$unit_files" | grep -q "^gdm.service" && err=$? || err=$?
if test "$err" -eq "0"; then
echo "enable Gnome Display Service"
systemctl enable gdm.service
fi