-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchsetup.sh
364 lines (299 loc) · 10 KB
/
archsetup.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
#!/usr/bin/bash
set -e
RAW_GITHUB="https://raw.githubusercontent.com"
REPO="jwalk9000/archbase.btrfs/main"
#LOCALREPO="" # <-- set this to the path of the local repo if you are using locally. DO NOT INCLUDE THE ROOT '/'.
#if [ $LOCALREPO != "" ]; then # WIP - this is not yet implemented.
# RAW_GITHUB=""
# REO=$LOCALREPO
source <(curl -s $RAW_GITHUB/$REPO/functions.sh)
source <(curl -s $RAW_GITHUB/$REPO/colors.sh)
# Install script dependencies
PKGDEPS=(
"jq"
"fzf"
)
pacman -Sy
info_print "=> Installing script dependencies"
for PKG in "${PKGDEPS[@]}"; do
if ! pacman -Qs "$PKG" > /dev/null ; then
pacman -S --noconfirm "$PKG"
fi
done
#####################################################
# Script variables -- some of these can be pre-set #
# and the respective prompts can be skipped by #
# commenting them out with a #. #
# #
# Note: It is not recommended to preset Credentials #
# in a script #
# #
#####################################################
HOSTNAME="" # Example: "archbase"
ROOT_PASS=""
NEW_USER="" # All lowercase, for example: "john"
USER_PASS=""
SUDO_GROUP="" # 'true' or blank
LOCALE="" # Example: "en_US.UTF-8"
TIMEZONE="" # Example: "America/New_York"
BOOTLOADER="grub" # 'grub' 'systemd-boot' or 'rEFInd'
MICROCODE="" # 'intel-ucode' 'amd-ucode' or blank
KERNEL_PKG="" # on of: 'linux' 'linux-lts' 'linux-hardened' 'linux-zen'
INSTALL_DISK="" # Example: "/dev/sda"
INSTALL_GPU_DRIVERS="" # 'true' or blank
DESKTOP_CHOICE="" # 'true' or blank
AUTOLOGIN_CHOICE="" # 'true' or blank
########################################
# Enable other services here if needed #
########################################
ENABLE_SVCS=(
"NetworkManager"
"sshd"
#"sddm" # example exra service
)
# Display the header at the start
display_header
# Greet the user
greet_user
until display_warning; do : ; done
# Set hostname
until set_hostname; do : ; done
# Set root password
until set_root_password; do : ; done
# Create a new user
until create_new_user; do : ; done
# Select locale
until select_locale; do : ; done
# Select timezone
until select_timezone; do : ; done
# Choose a kernel to install
until choose_kernel; do : ; done
# Detect and install microcode
until microcode_detector; do : ; done
# Select additional packages to install
until user_packages; do : ; done
# offer to enable automatic loggin
until autologin_setup; do : ; done
# offer to enable Destop environment setup
until desktop_environment; do : ; done
# Detect and install GPU drivers
until gpu_drivers; do : ; done
# Choose a bootloader to install
until choose_bootloader; do : ; done
# Select target disk
until target_disk; do : ; done
# Unmount any existing partitions on the target disk
until unmount_partitions; do : ; done
# Erase existing partitions on the target disk
until erase_partitions; do : ; done
# Start the installation process
install_message
# Partition the disk
if [ -d /sys/firmware/efi/efivars ]; then
(
echo g # Create a new empty GPT partition table
echo n # Add a new partition
echo 1 # Partition number
echo # First sector (Accept default: 1MiB)
echo +512M # Last sector (Accept default: varies)
echo t # Change partition type
echo 1 # EFI System
echo n # Add a new partition
echo 2 # Partition number
echo # First sector (Accept default: varies)
echo # Last sector (Accept default: varies)
echo w # Write changes
) | fdisk "$INSTALL_DISK"
partprobe "$INSTALL_DISK"
# Format the partitions
if [[ "$INSTALL_DISK" == *"nvme"* ]]; then
EFI_PART="${INSTALL_DISK}p1"
BTRFS_PART="${INSTALL_DISK}p2"
else
EFI_PART="${INSTALL_DISK}1"
BTRFS_PART="${INSTALL_DISK}2"
fi
info_print "=> Formatting EFI partition as FAT32"
sleep 1
mkfs.fat -F 32 "$EFI_PART"
else
(
echo o # Create a new empty DOS partition table
echo n # Add a new partition
echo p # Primary partition
echo 1 # Partition number
echo # First sector (Accept default: 1MiB)
echo # Last sector (Accept default: varies)
echo a # Make partition bootable
echo 1 # Partition number
echo w # Write changes
) | fdisk "$INSTALL_DISK"
partprobe "$INSTALL_DISK"
# Format the partitions
if [[ "$INSTALL_DISK" == *"nvme"* ]]; then
BTRFS_PART="${INSTALL_DISK}p1"
else
BTRFS_PART="${INSTALL_DISK}1"
fi
fi
info_print "=> Formatting primary partition as Btrfs"
sleep 1
mkfs.btrfs -f "$BTRFS_PART"
# Create and mount Btrfs subvolumes
info_print "=> Mounting $BTRFS_PART to /mnt"
sleep 1
mount "$BTRFS_PART" /mnt
info_print "=> Creating BTRFS subvolumes"
sleep 1
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@snapshots
info_print "=> BTRFS subvolumes /@, /@home, and @/snapshots created"
sleep 1
info_print "=> Unmounting /mnt to re-mount subvolumes"
sleep 1
umount /mnt
info_print "=> Remounting subvolumes"
sleep 1
mount -o subvol=@ "$BTRFS_PART" /mnt
mkdir -p /mnt/home
mount -o subvol=@home "$BTRFS_PART" /mnt/home
mkdir -p /mnt/.snapshots
mount -o subvol=@snapshots "$BTRFS_PART" /mnt/.snapshots
# Mount EFI partition
if [ -d /sys/firmware/efi/efivars ]; then
info_print "=> Mounting EFI partition at /mnt/boot"
sleep 1
mkdir -p /mnt/boot
mount "$EFI_PART" /mnt/boot
fi
# Install the base system and user-selected packages
install_message
info_print "=> Installing base system with $KERNEL_PKG, essential packages ad any additional packages"
sleep 1
#info_print "=> Installing base $KERNEL_PKG $MICROCODE linux-firmware btrfs-progs base-devel git curl nano openssh networkmanager pciutils usbutils $EFIBOOTMGR $USERPKGS $INSTALL_GPU_DRIVERS" # These two lines are for troubleshooting package installation.
#read -p "Press enter to continue"
pacstrap /mnt base $KERNEL_PKG $MICROCODE linux-firmware btrfs-progs base-devel git curl nano openssh networkmanager pciutils usbutils $EFIBOOTMGR $USERPKGS $INSTALL_GPU_DRIVERS
# Generate the fstab file
install_message
info_print "=> Generating the fstab file"
genfstab -U /mnt >> /mnt/etc/fstab
# Export the configuration variables
export HOSTNAME
export ROOT_PASS
export NEW_USER
export USER_PASS
export SUDO_GROUP
export LOCALE
export TIMEZONE
export BOOTLOADER
export INSTALL_DISK
# Chroot into the new system and configure it
info_print "=> Configuring the new system"
arch-chroot /mnt /bin/bash <<EOF
# Set the timezone
ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
hwclock --systohc
# Set the locale
echo "$LOCALE UTF-8" >> /etc/locale.gen
echo "LANG=$LOCALE" > /etc/locale.conf
locale-gen
# Set the hostname
echo "$HOSTNAME" > /etc/hostname
{
echo "127.0.0.1 localhost"
echo "::1 localhost"
echo "127.0.1.1 $HOSTNAME.localdomain $HOSTNAME"
} >> /etc/hosts
# Set the root password
echo "root:$ROOT_PASS" | chpasswd
# Create the new user
if [ $SUDO_GROUP == "true" ]; then
useradd -m -G wheel -s /bin/bash $NEW_USER
echo "$NEW_USER ALL=(ALL) ALL" > /etc/sudoers.d/$NEW_USER
else
useradd -m -s /bin/bash $NEW_USER
fi
echo "$NEW_USER:$USER_PASS" | chpasswd
# Enable essential services
systemctl enable NetworkManager
systemctl enable sshd
# Install the bootloader
if [ -d /sys/firmware/efi/efivars ]; then
case "$BOOTLOADER" in
"systemd-boot")
bootctl --path=/boot install
;;
"rEFInd")
pacman -S --noconfirm refind
refind-install
mkrlconf --root /mnt --subvol @ --output /mnt/boot/refind_linux.conf
;;
*)
pacman -S --noconfirm grub
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg
;;
esac
else
pacman -S --noconfirm grub
grub-install --target=i386-pc "$INSTALL_DISK"
grub-mkconfig -o /boot/grub/grub.cfg
fi
EOF
# Enable services
for SVC in "${ENABLE_SVCS[@]}"; do
arch-chroot /mnt systemctl enable "$SVC"
done
#Install a desktop environment scripts if selected
if [ $DESKTOP_CHOICE == "true" ]; then
mkdir -p /mnt/home/$NEW_USER/firstBoot
info_print "=> Installing firstBoot scripts"
sleep 1
FB_FILES=(
"firstBoot.sh"
"gui_options.json"
)
info_print "=> Downloading and installing firstBoot scripts"
sleep 1
for FILE in "${FB_FILES[@]}"; do
curl -s "$RAW_GITHUB/$REPO/firstBoot/$FILE" | sed "s/user_placeholder/$NEW_USER/g" > /mnt/home/$NEW_USER/firstBoot/$FILE
done
info_print "=> Setting permissions for firstBoot scripts"
sleep 1
for FILE in "${FB_FILES[@]}"; do
chmod +x /mnt/home/$NEW_USER/firstBoot/$FILE
done
info_print "=> checking that the firstBoot directory was populated"
ls -l /mnt/home/$NEW_USER/firstBoot
sleep 3
# Change ownership to the new user
#chown -R $NEW_USER:$NEW_USER /mnt/home/$NEW_USER/firstBoot
arch-chroot /mnt chown -R $NEW_USER:$NEW_USER /home/$NEW_USER/firstBoot
# Add the firstBoot script to the system path
echo "export PATH=\$PATH:/home/$NEW_USER/firstBoot" >> /mnt/home/$NEW_USER/.bashrc
fi
# Enable automatic login for the new user
if [ $AUTOLOGIN_CHOICE == "true" ]; then
mkdir -p /mnt/etc/systemd/system/[email protected]
cat <<EOL > /mnt/etc/systemd/system/[email protected]/override.conf
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin $NEW_USER --noclear %I \$TERM
EOL
fi
# Unmount the partitions
display_header
info_print "=> Unmounting new installation"
sleep 1.5
umount -R /mnt
display_header
info_print "============================================================================"
info_print " Base system installation complete."
info_print " Next steps:"
info_print " "
info_print " 1) Reboot into the new system."
info_print " 2) If you chose to install a desktop you can run ${INPUT}firstBoot${INFO} once logged in."
info_print "============================================================================"
read -rp "Please remove the boot media and press [Enter] to reboot..."
reboot