Skip to content

Instantly share code, notes, and snippets.

@dealloc
Last active October 5, 2018 08:47
Show Gist options
  • Save dealloc/fd34e0a08d8fd4ef4df32ca1544ff7e7 to your computer and use it in GitHub Desktop.
Save dealloc/fd34e0a08d8fd4ef4df32ca1544ff7e7 to your computer and use it in GitHub Desktop.
Small shell script that automatically installs Arch (configured to work on my Laptop)
#!/bin/bash
clear
set -e
# Set keyboard
echo "Setting keyboard layout..."
loadkeys be-latin1
# Prompting for variables as required
echo "Getting required data..."
PASSWORD=$(dialog --clear --stdout --backtitle "Arch installer" --no-shadow --title "Enter password for users" --passwordbox "Please enter a strong password for the root user.\n" 8 60 2> /dev/null)
reset
# Connect to wifi
echo "Connecting to WiFi..."
wifi-menu
#Update system clock
echo "Setting NTP system clock..."
timedatectl set-ntp true
# Partition SSD disk
echo "Partitioning SSD..."
parted -s /dev/nvme0n1 mklabel gpt
parted -s /dev/nvme0n1 mkpart primary fat32 1MiB 551MiB
parted -s /dev/nvme0n1 set 1 esp on
parted -s /dev/nvme0n1 mkpart primary ext4 551MiB 100%
# Partition HDD disk
echo "Partitioning HDD..."
parted -s /dev/sda mklabel gpt
parted -s /dev/sda mkpart primary ext4 1MiB 100%
# Format partitions
echo "Formatting partitions..."
yes | mkfs.fat /dev/nvme0n1p1
yes | mkfs.ext4 /dev/nvme0n1p2
yes | mkfs.ext4 /dev/sda1
# Mount filesystems
echo "Mounting filesystems..."
mount /dev/nvme0n1p2 /mnt
mkdir -p /mnt/boot/efi /mnt/home
mount /dev/nvme0n1p1 /mnt/boot/efi
mount /dev/sda1 /mnt/home
# Setting up mirrors
echo "Downloading mirror list..."
curl -s "https://www.archlinux.org/mirrorlist/?country=BE&country=NL" | sed -e 's/^#Server/Server/' > /etc/pacman.d/mirrorlist
# Installing system && packages
echo "Installing packages..."
pacstrap /mnt base base-devel htop tmux zsh
# Generating fstab
echo "Generating fstab"
genfstab -U /mnt >> /mnt/etc/fstab
# Setting locale & keyboard stuff
echo "Generating locale and keyboard configuration..."
arch-chroot /mnt /usr/bin/zsh <<EOF
ln -sf /usr/share/zoneinfo/Europe/Brussels /etc/localtime
hwclock --systohc
sed -i "s/^#en_GB.UTF-8 UTF-8/en_GB.UTF-8 UTF-8/" /etc/locale.gen
locale-gen
echo "LANG=en_GB.UTF-8" > /etc/locale.conf
echo "KEYMAP=be-latin1" > /etc/vconsole.conf
EOF
# Network configuration
echo "Generating networking configuration..."
arch-chroot /mnt /usr/bin/zsh <<EOF
echo "Genesis" > /etc/hostname
cat <<HOSTS > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 genesis.localdomain genesis
HOSTS
EOF
# Installing WiFi packages
echo "Installing WiFi packages..."
arch-chroot /mnt /usr/bin/zsh <<EOF
pacman -S --noconfirm iw wpa_supplicant dialog wpa_actiond
EOF
# Regenerating initramfs
echo "Regenerating initramfs..."
arch-chroot /mnt /usr/bin/zsh <<EOF
mkinitcpio -p linux
EOF
# Setting root password
echo "Setting root password..."
arch-chroot /mnt /usr/bin/zsh <<EOF
echo "root:${PASSWORD}" | chpasswd
EOF
# Installing boot loader
echo "Installing boot loader and microcode pages..."
arch-chroot /mnt /usr/bin/zsh <<EOF
pacman -S --noconfirm intel-ucode grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg
EOF
# Setting up extra users
echo "Adding additional non-root users"
arch-chroot /mnt /usr/bin/zsh <<EOF
useradd -m -g users -G wheel -s /usr/bin/zsh dealloc
echo "dealloc:${PASSWORD}" | chpasswd
EOF
# Finalizing installation
echo "Cleaning up installation..."
umount -R /mnt
echo "Rebooting in 5 seconds..."
sleep 5
reboot now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment