Skip to content

Instantly share code, notes, and snippets.

@hoffmanc
Last active July 24, 2023 12:49
Show Gist options
  • Save hoffmanc/e2db1de925749c3dc78cf7bb5a747d28 to your computer and use it in GitHub Desktop.
Save hoffmanc/e2db1de925749c3dc78cf7bb5a747d28 to your computer and use it in GitHub Desktop.
chatGPT scriptification of arch install guide
#!/bin/bash
set -e
# Display an introduction message
echo "Welcome to the Arch Linux installation script!"
echo "Please follow the instructions carefully."
# Determine the first wireless interface
wireless_interface=$(ip link | grep -E '^[0-9]+: w' | awk '{print substr($2, 1, length($2)-1)}')
if [ -z "$wireless_interface" ]; then
echo "No wireless interface found. Please make sure you have a wireless adapter installed."
exit 1
fi
echo "Wireless interface found: $wireless_interface"
# Set the keyboard layout and font
loadkeys us
setfont ter-132b
# Update the system clock
timedatectl set-ntp true
# Scan for available access points
echo "Scanning for available access points on $wireless_interface..."
access_points=$(iwlist $wireless_interface scanning | grep 'ESSID:' | awk -F: '{print $2}' | tr -d '"')
if [ -z "$access_points" ]; then
echo "No access points found. Please check your Wi-Fi connection and run the script again."
exit 1
fi
# Print the list of available access points
echo "Available Access Points:"
echo "$access_points"
# Prompt the user to select an access point
read -p "Enter the name or identifier of the desired access point: " selected_ap
# Prompt the user for the password
read -s -p "Enter the password for $selected_ap: " wifi_password
echo
# Configure the wireless connection with wpa_supplicant
echo "Configuring the wireless connection to $selected_ap..."
ip link set $wireless_interface up
wpa_passphrase "$selected_ap" "$wifi_password" > /etc/wpa_supplicant.conf
wpa_supplicant -B -i $wireless_interface -c /etc/wpa_supplicant.conf
# Test internet connectivity
echo "Testing internet connectivity..."
ping -c 3 archlinux.org
if [ $? -ne 0 ]; then
echo "No internet connection. Please check your Wi-Fi settings and run the script again."
exit 1
fi
# Set the keyboard layout and font
loadkeys us
setfont ter-132b
# Update the system clock
timedatectl set-ntp true
# Partition the disks (example: using fdisk)
# Modify this section based on your disk partitioning requirements
fdisk /dev/sda <<EOF
n
p
1
+300M
t
ef
n
p
2
t
2
82
w
EOF
# Format the partitions (example: using ext4 for root partition)
mkfs.ext4 /dev/sda2
# Mount the file systems
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
# Select the mirrors (using reflector for example)
pacman -Sy --noconfirm reflector
reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
# Install essential packages
pacstrap /mnt base linux linux-firmware
# Generate an fstab file
genfstab -U /mnt >> /mnt/etc/fstab
# Change root into the new system
arch-chroot /mnt
# Set the time zone
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
hwclock --systohc
# Configure localization
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "en_US.UTF-8 UTF-8" >> /etc/locale.conf
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
# Prompt the user for the hostname
read -p "Enter the hostname for the system: " hostname
# Set the hostname
echo "$hostname" > /etc/hostname
# Install and configure the boot loader (example: GRUB)
pacman -Sy --noconfirm grub
grub-install --target=i386-pc /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
# Set the root password
echo "Please set the root password:"
passwd
# Optional: Create a new user and set their password
read -p "Do you want to create a new user? (y/n): " create_user
if [[ "$create_user" == "y" || "$create_user" == "Y" ]]; then
read -p "Enter the username for the new user: " username
useradd -m -G wheel "$username"
passwd "$username"
fi
# Make the new user a member of the sudo group
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
# Exit chroot
exit
# Unmount all partitions
umount -R /mnt
# Reboot the system
echo "Installation complete. Rebooting..."
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment