Created
April 13, 2018 07:15
-
-
Save moolen/41f2ee6b313734486f2f4d5acb1624d1 to your computer and use it in GitHub Desktop.
archlinux installer
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
#!/bin/bash | |
set -ex | |
DIR=$(dirname $0) | |
echo "starting installer.." | |
DEVICE=${DEVICE:-/dev/sda} | |
DEVICE_CRYPT_PASS=${DEVICE_CRYPT_PASS:-1234} | |
TIMEZONE=${TIMEZONE:-Europe/Berlin} | |
HOSTNAME=${HOSTNAME:-archbox} | |
SWAP_SIZE=${SWAP_SIZE:-2G} | |
ROOT_PASS=${ROOT_PASS:-arch} | |
MYUSERNAME=${MYUSERNAME:-arch} | |
MYUSERPASS=${MYUSERPASS:-arch} | |
PACKAGES=${PACKAGES:$(cat $DIR/pkglist)} | |
function error { | |
echo $1 | |
exit 1 | |
} | |
function main { | |
ping -c 1 8.8.8.8 || error "couldl not ping 8.8.8.8" | |
[ -e ${DEVICE} ] || error "device $DEVICE does not exist" | |
setup_disk | |
setup_fs | |
setup_encryption | |
bootstrap_arch | |
} | |
function setup_disk { | |
sgdisk -Z ${DEVICE} | |
sgdisk -n 0:0:+100M -t 0:ef00 -c 0:"efi" ${DEVICE} | |
sgdisk -n 0:0:+250M -t 0:8300 -c 0:"boot" ${DEVICE} | |
sgdisk -n 0:0:0 -t 0:8300 -c 0:"root" ${DEVICE} | |
sgdisk -p ${DEVICE} | |
partprobe ${DEVICE} | |
fdisk -l ${DEVICE} | |
} | |
function setup_fs { | |
mkfs.vfat -F32 /dev/sda1 | |
mkfs.ext2 -F /dev/sda2 | |
} | |
function setup_encryption { | |
echo ${DEVICE_CRYPT_PASS} | cryptsetup --key-file=- -c aes-xts-plain64 -y --use-random luksFormat /dev/sda3 | |
echo ${DEVICE_CRYPT_PASS} | cryptsetup --key-file=- luksOpen /dev/sda3 luks | |
# create encrypted partitions | |
pvcreate /dev/mapper/luks | |
vgcreate vg0 /dev/mapper/luks | |
lvcreate --size ${SWAP_SIZE} vg0 --name swap | |
lvcreate -l +100%FREE vg0 --name root | |
# fs on devicemapper | |
mkfs.ext4 -F /dev/mapper/vg0-root | |
mkswap /dev/mapper/vg0-swap | |
mount /dev/mapper/vg0-root /mnt | |
swapon /dev/mapper/vg0-swap | |
} | |
function bootstrap_arch { | |
mkdir /mnt/boot | |
mount /dev/sda2 /mnt/boot | |
mkdir /mnt/boot/efi | |
mount /dev/sda1 /mnt/boot/efi | |
pacstrap /mnt base base-devel grub-efi-x86_64 zsh vim git efibootmgr dialog wpa_supplicant | |
genfstab -pU /mnt >> /mnt/etc/fstab | |
echo "tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0" > /mnt/etc/fstab | |
cat << EOF > /mnt/opt/installer.sh | |
#!/bin/bash | |
set -ex | |
[ -f /etc/localtime ] && rm /etc/localtime | |
ln -s /usr/share/zoneinfo/${TIMEZONE} /etc/localtime | |
hwclock --systohc --utc | |
echo ${HOSTNAME} > /etc/hostname | |
echo LANG=en_US.UTF-8 >> /etc/locale.conf | |
echo LANGUAGE=en_US >> /etc/locale.conf | |
echo LC_ALL=C >> /etc/locale.conf | |
echo root:${ROOT_PASS} | chpasswd | |
useradd -m -g users -G wheel -s /bin/zsh ${MYUSERNAME} | |
echo ${MYUSERNAME}:${MYUSERPASS} | chpasswd | |
sed -i 's/MODULES=()/MODULES=(ext4)/g' /etc/mkinitcpio.conf | |
sed -i 's/HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)/HOOKS=(base udev autodetect modconf block encrypt lvm2 filesystems keyboard fsck)/g' /etc/mkinitcpio.conf | |
mkinitcpio -p linux | |
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ArchLinux | |
sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="cryptdevice=\/dev\/sdX3:luks:allow-discards"/g' /etc/default/grub | |
grub-mkconfig -o /boot/grub/grub.cfg | |
EOF | |
cat << EOF > /mnt/home/${MYUSERNAME}/user_installer.sh | |
git clone https://aur.archlinux.org/package-query.git | |
cd package-query | |
makepkg -si | |
cd .. | |
git clone https://aur.archlinux.org/yaourt.git | |
cd yaourt | |
makepkg -si | |
cd .. | |
yaourt -Sy ${PACKAGES} --noconfirm | |
EOF | |
chmod +x /mnt/opt/installer.sh | |
chmod +x /mnt/opt/user_installer.sh | |
arch-chroot /mnt /opt/installer.sh | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment