Last active
July 13, 2021 07:25
-
-
Save SocketByte/94013967c11c83cb9f83bda25c6a709d to your computer and use it in GitHub Desktop.
Arch Script Installer (for my personal use, but it's pretty configurable)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Configuration | |
# Partitioning | |
DEVICE="/dev/sdd" # Please make sure it's correct, the script won't ask you for any confirmation. | |
FIRMWARE_MODE=auto # uefi, bios, auto | |
SWAP_SIZE=4096MiB | |
# Time and date | |
TIMEZONE="Europe/Warsaw" | |
# Network and connectivity | |
REFLECTOR=yes | |
REFLECTOR_COUNTRY="Poland" | |
BLUETOOTH=yes | |
BLUETOOTH_AUDIO=yes | |
# Graphics Drivers | |
DRIVER="nouveau" # nouveau, amd, nvidia, nvidia-dkms, intel | |
# Kernel | |
# Be aware that "nvidia" package won't work with custom kernels, use "nvidia-dkms" instead. | |
KERNEL="linux-zen" # linux, linux-hardened, linux-zen, linux-lts | |
# Locale | |
LOCALE="en_US.UTF-8" | |
LOCALE_GEN="en_US.UTF-8 UTF-8" | |
KEYMAP="pl" | |
# Users | |
USER_NAME=user | |
USER_PASSWORD=test | |
ROOT_PASSWORD=test | |
# Bootloader | |
BOOTLOADER="grub" | |
# Desktop Environment | |
DESKTOP_ENVIRONMENT="gnome" | |
# Advanced desktop settings | |
DE_GNOME_PACKAGES="gnome gnome-tweaks firefox" | |
DE_KDE_PACKAGES="plasma konsole dolphin firefox" | |
# Colors | |
GRAY='\033[0;37m' | |
RED='\033[1;31m' | |
GREEN='\033[1;32m' | |
BLUE='\033[1;34m' | |
CYAN='\033[1;36m' | |
WHITE='\033[1;37m' | |
NC='\033[0m' | |
log() { | |
if [ $1 = "Starting" ] || [ $1 = "Installing" ] || [ $1 = "Mounting" ] ; then | |
echo -e " ${GRAY}${1} ${WHITE}${2}" | |
else | |
echo -e "${WHITE}[ ${GREEN}OK ${WHITE}] ${GRAY}${1} ${WHITE}${2}" | |
fi | |
} | |
error() { | |
echo -e "${WHITE}[ ${RED}ERROR ${WHITE}] ${1}" | |
} | |
pac() { | |
arch-chroot /mnt pacman -Syu --noconfirm --needed $1 | |
} | |
echo -e "\n${BLUE}Arch Script Installer" | |
echo -e " ${NC}by SocketByte\n" | |
read -p "Do you want to continue? [y/N] " yn | |
case $yn in | |
[Yy]*) | |
;; | |
Nn]*) | |
exit | |
;; | |
*) | |
exit | |
;; | |
esac | |
echo -e "\n" | |
log "Starting" "Checking for UEFI Firmware Mode compatibility..." | |
# Check for UEFI firmware mode, otherwise fallback to legacy BIOS | |
if [ -e "/sys/firmware/efi/efivars" ]; then | |
PARTITION_MODE=uefi | |
log "Finished" "UEFI Firmware Mode is available." | |
else | |
PARTITION_MODE=bios | |
log "Finished" "UEFI Firmware Mode is not available, falling back to legacy BIOS mode." | |
fi | |
log "Started" "Loading keymaps. (KEYMAP=${KEYMAP})" | |
loadkeys $KEYMAP | |
log "Finished" "Loading Keymaps." | |
log "Started" "Enabling Network Time Protocol." | |
timedatectl set-ntp true | |
log "Finished" "Enabling Network Time Protocol." | |
log "Started" "Setting Timezone. (TIMEZONE=${TIMEZONE})" | |
timedatectl set-timezone $TIMEZONE | |
log "Finished" "Setting Timezone." | |
log "Starting" "Formatting old partitions/Cleaning up..." | |
if [ -d /mnt/boot ]; then | |
umount /mnt/boot | |
umount /mnt | |
fi | |
for v_partition in $(parted -s ${DEVICE} print|awk '/^ / {print $1}') | |
do | |
parted -s $DEVICE rm ${v_partition} | |
done | |
log "Finished" "Formatting old partitions/Cleaning up." | |
PART_PRIMARY="" | |
if [ $PARTITION_MODE = uefi ]; then | |
log "Starting" "Creating partitions... (UEFI)" | |
parted -s $DEVICE "mklabel gpt mkpart efi fat32 1MiB 261MiB mkpart swap linux-swap 261MiB $SWAP_SIZE mkpart primary ext4 $SWAP_SIZE 100% set 1 esp on" | |
log "Finished" "Creating partitions. (UEFI)" | |
PART_PRIMARY="${DEVICE}3" | |
else | |
log "Starting" "Creating partitions... (BIOS)" | |
parted -s $DEVICE "mklabel msdos mkpart primary ext4 4MiB 512MiB mkpart primary ext4 512MiB 100% set 1 boot on" | |
log "Finished" "Creating partitions. (BIOS)" | |
PART_PRIMARY="${DEVICE}2" | |
fi | |
PART_BOOT="${DEVICE}1" | |
PART_SWAP="${DEVICE}2" | |
log "Starting" "Formatting boot partition... (${PART_BOOT})" | |
mkfs.fat -F32 $PART_BOOT | |
log "Finished" "Formatting boot partition." | |
if [ $PARTITION_MODE = uefi ]; then | |
log "Starting" "Formatting swap partition... (${PART_SWAP})" | |
mkswap $PART_SWAP | |
log "Finished" "Formatting swap partition." | |
fi | |
log "Starting" "Formatting primary partition... (${PART_PRIMARY})" | |
mkfs.ext4 $PART_PRIMARY | |
log "Finished" "Formatting primary partition." | |
log "Mounting" "Primary partition... (${PART_PRIMARY})" | |
mount $PART_PRIMARY /mnt | |
log "Mounted" "Primary partition." | |
if [ $PARTITION_MODE = uefi ]; then | |
log "Started" "Enabling Swap." | |
swapon $PART_SWAP | |
log "Finished" "Enabling Swap." | |
fi | |
if [ $REFLECTOR = yes ]; then | |
log "Installing" "Reflector." | |
pacman -Sy --noconfirm --needed "reflector" | |
log "Installed" "Reflector." | |
log "Starting" "Reflector Lookup Service..." | |
reflector --country $REFLECTOR_COUNTRY --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist | |
log "Finished" "Reflector Lookup Service." | |
fi | |
log "Installing" "System Software." | |
pacstrap /mnt base base-devel $KERNEL linux-firmware | |
log "Installed" "System Software." | |
log "Started" "Generating Fstab file." | |
genfstab -U /mnt >> /mnt/etc/fstab | |
log "Finished" "Generating Fstab file." | |
log "Started" "Linking zoneinfo to localtime." | |
arch-chroot /mnt ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime | |
log "Finished" "Linking zoneinfo to localtime." | |
log "Started" "Synchronizing Hardware Clock." | |
arch-chroot /mnt hwclock --systohc | |
log "Finished" "Synchronizing Hardware Clock." | |
log "Starting" "Generating Localization. (${LOCALE_GEN})" | |
echo "${LOCALE_GEN}" > /mnt/etc/locale.gen | |
arch-chroot /mnt locale-gen | |
log "Finished" "Generating Localization." | |
log "Started" "Updating Localization files." | |
echo "LANG=${LOCALE}" > /mnt/etc/locale.conf | |
log "Finished" "Updating Localization files." | |
log "Started" "Updating VConsole Keymap." | |
echo "KEYMAP=${KEYMAP}" > /mnt/etc/vconsole.conf | |
log "Finished" "Updating VConsole Keymap." | |
log "Started" "Updating Hostname." | |
echo "archlinux" > /mnt/etc/hostname | |
log "Finished" "Updating Hostname." | |
log "Started" "Updating Hosts." | |
echo "127.0.0.1 localhost\n::1 localhost\n127.0.1.1 archlinux.localdomain archlinux" > /mnt/etc/hosts | |
log "Finished" "Updating Hosts." | |
log "Installing" "Recommended base packages..." | |
pac "sudo nano neofetch" | |
log "Installed" "Recommended base packages." | |
log "Installing" "Graphics Drivers... (${DRIVER})" | |
case $DRIVER in | |
"nouveau") | |
pac "mesa xf86-video-nouveau" | |
;; | |
"nvidia") | |
pac "nvidia" | |
;; | |
"nvidia-dkms") | |
pac "nvidia-dkms" | |
;; | |
"amd") | |
pac "mesa vulkan-radeon xf86-video-amdgpu libva-mesa-driver mesa-vdpau" | |
;; | |
"intel") | |
pac "mesa vulkan-intel xf86-video-intel" | |
;; | |
esac | |
log "Installed" "Graphics Drivers." | |
log "Started" "Creating and configuring users." | |
log "Starting" "Setting root password..." | |
printf "$ROOT_PASSWORD\n$ROOT_PASSWORD" | arch-chroot /mnt passwd | |
log "Finished" "Setting root password." | |
log "Started" "Adding new user. (${USER_NAME})" | |
arch-chroot /mnt useradd -m $USER_NAME | |
log "Finished" "Adding new user." | |
log "Starting" "Setting user password..." | |
printf "$USER_PASSWORD\n$USER_PASSWORD" | arch-chroot /mnt passwd $USER_NAME | |
log "Finished" "Setting user password." | |
log "Started" "Adding user to sudoers." | |
echo "${USER_NAME} ALL=(ALL) ALL" >> /mnt/etc/sudoers | |
log "Finished" "Adding user to sudoers." | |
log "Finished" "Creating and configuring users." | |
log "Installing" "GRUB and Efibootmgr..." | |
pac "grub efibootmgr" | |
log "Installed" "GRUB and Efibootmgr." | |
if [ $PARTITION_MODE = uefi ]; then | |
log "Started" "Creating EFI boot directory." | |
mkdir /mnt/boot/efi | |
log "Finished" "Creating EFI boot directory." | |
log "Mounting" "EFI boot partition..." | |
arch-chroot /mnt mount ${PART_BOOT} /boot/efi | |
log "Mounted" "EFI boot partition." | |
log "Installing" "GRUB Bootloader..." | |
arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot/efi | |
log "Installed" "GRUB Bootloader." | |
else | |
log "Installing" "GRUB Bootloader..." | |
arch-chroot /mnt grub-install --target=i386-pc ${DEVICE} | |
log "Installed" "GRUB Bootloader." | |
fi | |
log "Starting" "Creating GRUB configuration file..." | |
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg | |
log "Finished" "Creating GRUB configuration file." | |
log "Starting" "Installing Desktop Environment..." | |
case $DESKTOP_ENVIRONMENT in | |
"gnome") | |
log "Started" "Installing GNOME." | |
pac $DE_GNOME_PACKAGES | |
log "Finished" "Installing GNOME." | |
log "Started" "Installing GDM." | |
pac "gdm" | |
log "Finished" "Installing GDM." | |
log "Enabling" "GDM Service." | |
arch-chroot /mnt systemctl enable gdm.service | |
log "Enabled" "GDM Service." | |
;; | |
"kde") | |
log "Started" "Installing KDE." | |
pac $DE_KDE_PACKAGES | |
log "Finished" "Installing KDE." | |
log "Started" "Installing SDDM." | |
pac "sddm" | |
log "Finished" "Installing SDDM." | |
log "Enabling" "SDDM Service." | |
arch-chroot /mnt systemctl enable sddm.service | |
log "Enabled" "SDDM Service." | |
;; | |
esac | |
log "Finished" "Installing Desktop Environment." | |
log "Installing" "NetworkManager." | |
pac "networkmanager" | |
log "Installed" "NetworkManager." | |
log "Enabling" "NetworkManager." | |
arch-chroot /mnt systemctl enable NetworkManager.service | |
log "Enabled" "NetworkManager." | |
if [ $BLUETOOTH = yes ]; then | |
log "Installing" "Bluetooth Support..." | |
pac "bluez bluez-utils" | |
log "Installed" "Bluetooth Support." | |
if [ $BLUETOOTH_AUDIO = yes ]; then | |
log "Installing" "Bluetooth Audio Support..." | |
pac "pulseaudio pulseaudio-bluetooth" | |
log "Installed" "Bluetooth Audio Support." | |
log "Enabling" "Bluetooth Audio Service." | |
arch-chroot /mnt systemctl enable --user pulseaudio | |
arch-chroot /mnt pulseaudio --start | |
log "Enabled" "Bluetooth Audio Service." | |
fi | |
log "Enabling" "Bluetooth Service." | |
arch-chroot /mnt systemctl enable bluetooth.service | |
log "Enabled" "Bluetooth Service." | |
fi | |
log "Starting" "Updating Linux initcpio..." | |
arch-chroot /mnt mkinitcpio -P | |
log "Finished" "Updating Linux initcpio." | |
log "Starting" "Cleaning up..." | |
umount -R /mnt | |
log "Finished" "Cleaning up." | |
echo -e "${GREEN}\n\nArch Script successfully finished.\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment