Skip to content

Instantly share code, notes, and snippets.

@ambalabanov
Created November 2, 2021 04:38
Show Gist options
  • Save ambalabanov/9d10745385561d6ed8f033fc1ded82c8 to your computer and use it in GitHub Desktop.
Save ambalabanov/9d10745385561d6ed8f033fc1ded82c8 to your computer and use it in GitHub Desktop.
arch-base-install.sh
#!/usr/bin/env bash
# stop on errors
set -eu
# variables
DISK='/dev/sda'
FQDN='arch.local'
TIMEZONE='Asia/Yekaterinburg'
TARGET_DIR='/mnt'
COUNTRY=${COUNTRY:-RU}
MIRRORLIST="https://archlinux.org/mirrorlist/?country=${COUNTRY}&protocol=http&protocol=https&ip_version=4&use_mirror_status=on"
CONFIG_SCRIPT='/usr/local/bin/arch-config.sh'
USERN='andrey'
USERC='Andrey Balabanov'
USERP='vagrant'
echo "Creating partitions on ${DISK}.."
parted ${DISK} mklabel gpt
parted ${DISK} mkpart "EFI" fat32 1 501
parted ${DISK} mkpart "root" ext4 501 100%
parted ${DISK} set 1 esp on
mkfs.vfat ${DISK}1
mkfs.ext4 ${DISK}2
echo "Mount filesystems.."
mount /dev/sda2 /mnt/
mkdir -p /mnt/boot/efi
mount /dev/sda1 /mnt/boot/efi
echo "Setting pacman ${COUNTRY} mirrors.."
curl -s "$MIRRORLIST" | sed 's/^#Server/Server/' > /etc/pacman.d/mirrorlist
echo "Bootstrapping the base installation.."
/usr/bin/pacstrap ${TARGET_DIR} base base-devel linux linux-firmware linux-headers vim bash-completion man man-pages grub efibootmgr openssh sudo
echo "Generating fstab.."
/usr/bin/genfstab -pU ${TARGET_DIR} >> "${TARGET_DIR}/etc/fstab"
echo "Network configuring.."
cp -L /etc/resolv.conf ${TARGET_DIR}/etc
cp /etc/systemd/network/* ${TARGET_DIR}/etc/systemd/network
echo "Generating the chroot script.."
/usr/bin/install --mode=0755 /dev/null "${TARGET_DIR}${CONFIG_SCRIPT}"
cat <<-EOF > "${TARGET_DIR}${CONFIG_SCRIPT}"
hostnamectl set-hostname ${FQDN}
hwclock --systohc --utc
timedatectl set-timezone ${TIMEZONE}
timedatectl set-ntp true
sed -i "s/#\(en_US\.UTF-8\)/\1/" /etc/locale.gen
sed -i "s/#\(ru_RU\.UTF-8\)/\1/" /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
sed -i '/^#\[multilib\]/s/^#//g' /etc/pacman.conf
sed -i '/^\[multilib\]/{N;s/\n#/\n/}' /etc/pacman.conf
curl -s "$MIRRORLIST" | sed 's/^#Server/Server/' > /etc/pacman.d/mirrorlist
pacman-key --init
pacman-key --populate archlinux
pacman -Syy
systemctl enable systemd-networkd.service
systemctl enable systemd-resolved.service
systemctl enable sshd.service
useradd --create-home --user-group --groups wheel,audio,video,storage --shell /bin/bash --comment "${USERC}" ${USERN}
echo "${USERN}:${USERP}" | chpasswd
chage -d 0 ${USERN}
sed -i '/^# %wheel ALL=(ALL) ALL$/s/^#//g' /etc/sudoers
EOF
echo "Chrooting.."
/usr/bin/arch-chroot ${TARGET_DIR} ${CONFIG_SCRIPT}
rm "${TARGET_DIR}${CONFIG_SCRIPT}"
echo "Installation complete!"
@ambalabanov
Copy link
Author

/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/ambalabanov/9d10745385561d6ed8f033fc1ded82c8/raw/6ce0408003761e695ee7270d9faa3ba34d2460ab/arch-base-install.sh)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment