Skip to content

Instantly share code, notes, and snippets.

@drejohnson
Last active March 8, 2020 05:07
Show Gist options
  • Save drejohnson/2d4c9ead0b8bf556ec4bb25a439fd2b5 to your computer and use it in GitHub Desktop.
Save drejohnson/2d4c9ead0b8bf556ec4bb25a439fd2b5 to your computer and use it in GitHub Desktop.
#!/bin/bash
encryption_passphrase=""
root_password=""
user_password=""
hostname=""
user_name=""
continent_city=""
swap_size="16"
echo "Updating system clock"
timedatectl set-ntp true
timedatectl set-timezone $continent_city
echo "Setting up cryptographic volume"
printf "%s" "$encryption_passphrase" | cryptsetup -h sha512 -s 512 --use-random --type luks2 luksFormat /dev/nvme0n1p2
printf "%s" "$encryption_passphrase" | cryptsetup luksOpen /dev/nvme0n1p2 cryptlvm
echo "Creating physical volume"
pvcreate /dev/mapper/cryptlvm
echo "Creating volume volume"
vgcreate vg0 /dev/mapper/cryptlvm
echo "Creating logical volumes"
lvcreate -L +"$swap_size"GB vg0 -n swap
lvcreate -l +100%FREE vg0 -n root
echo "Setting up / partition"
yes | mkfs.ext4 /dev/vg0/root
mount /dev/vg0/root /mnt
echo "Setting up /boot partition"
yes | mkfs.fat -F32 /dev/nvme0n1p1
mkdir /mnt/boot
mount /dev/nvme0n1p1 /mnt/boot
echo "Setting up swap"
yes | mkswap /dev/vg0/swap
swapon /dev/vg0/swap
echo "Installing Arch Linux"
yes '' | pacstrap /mnt base base-devel linux linux-headers linux-lts linux-lts-headers linux-firmware lvm2 device-mapper e2fsprogs intel-ucode xf86-video-intel cryptsetup mesa networkmanager wget man-db man-pages nano vi diffutils bluez bluez-utils pulseaudio-bluetooth pulseaudio alsa-utils vim git zsh zsh-completions zsh-autosuggestions openssh tlp powertop fwupd sof-firmware cryfs shadowsocks-libev intel-media-driver vulkan-intel vulkan-icd-loader
echo "Generating fstab"
genfstab -U /mnt >> /mnt/etc/fstab
echo "Configuring new system"
arch-chroot /mnt /bin/bash <<EOF
echo "Setting system clock"
ln -fs /usr/share/zoneinfo/$continent_city /etc/localtime
hwclock --systohc --localtime
echo "Setting locales"
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
locale-gen
echo "Adding persistent keymap"
echo "KEYMAP=us" > /etc/vconsole.conf
echo "Setting hostname"
echo $hostname > /etc/hostname
echo "Setting root password"
echo -en "$root_password\n$root_password" | passwd
echo "Creating new user"
useradd -m -G wheel -s /bin/bash $user_name
usermod -a -G video $user_name
echo -en "$user_password\n$user_password" | passwd $user_name
echo "Generating initramfs"
sed -i 's/^HOOKS.*/HOOKS=(base systemd autodetect keyboard sd-vconsole modconf block sd-encrypt sd-lvm2 filesystems fsck)/' /etc/mkinitcpio.conf
sed -i 's/^MODULES.*/MODULES=(ext4 intel_agp i915)/' /etc/mkinitcpio.conf
mkinitcpio -p linux
mkinitcpio -p linux-lts
echo "Setting up systemd-boot"
bootctl --path=/boot install
mkdir -p /boot/loader/
touch /boot/loader/loader.conf
tee -a /boot/loader/loader.conf << END
default arch
timeout 1
editor 0
END
mkdir -p /boot/loader/entries/
touch /boot/loader/entries/arch.conf
tee -a /boot/loader/entries/arch.conf << END
title ArchLinux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options rd.luks.name=$(blkid -s UUID -o value /dev/nvme0n1p2)=cryptlvm root=/dev/vg0/root resume=/dev/vg0/swap rd.luks.options=discard i915.fastboot=1 quiet rw
END
touch /boot/loader/entries/archlts.conf
tee -a /boot/loader/entries/archlts.conf << END
title ArchLinux
linux /vmlinuz-linux-lts
initrd /intel-ucode.img
initrd /initramfs-linux-lts.img
options rd.luks.name=$(blkid -s UUID -o value /dev/nvme0n1p2)=cryptlvm root=/dev/vg0/root resume=/dev/vg0/swap rd.luks.options=discard i915.fastboot=1 quiet rw
END
echo "Setting up Pacman hook for automatic systemd-boot updates"
mkdir -p /etc/pacman.d/hooks/
touch /etc/pacman.d/hooks/systemd-boot.hook
tee -a /etc/pacman.d/hooks/systemd-boot.hook << END
[Trigger]
Type = Package
Operation = Upgrade
Target = systemd
[Action]
Description = Updating systemd-boot
When = PostTransaction
Exec = /usr/bin/bootctl update
END
echo "Blacklist incompatible hda_intel and soc_skl modules"
tee -a /etc/modprobe.d/blacklist.conf << END
blacklist snd_hda_intel
blacklist snd_soc_skl
END
echo "Configure PulseAudio's to load Alsa modules with the correct device and channnel settings"
tee -a /etc/pulse/default.pa << END
load-module module-alsa-sink device=hw:0,0 channels=4
load-module module-alsa-source device=hw:0,7 channels=4
END
echo "Enabling periodic TRIM"
systemctl enable fstrim.timer
echo "Enabling NetworkManager"
systemctl enable NetworkManager
echo "Adding user as a sudoer"
echo '%wheel ALL=(ALL) ALL' | EDITOR='tee -a' visudo
EOF
umount -R /mnt
swapoff -a
echo "ArchLinux is ready. You can reboot now!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment