void

- enter the void 🪐
git clone git://git.acid.vegas/archlinux.git
Log | Files | Refs | Archive

enterthevoid (6793B)

      1 #!/bin/bash
      2 # enter the void - developed by acidvegas (https://git.acid.vegas/void)
      3 
      4 set -xev
      5 
      6 # Configuration
      7 ARCH=x86_64 # x86_64 or x86_64-musl
      8 CPU=intel # amd or intel
      9 DRIVE=/dev/sdb # can be a single drive or an array if using raidz with zfs
     10 HOSTNAME=blackhole
     11 SWAP_SIZE=4 # In GB (set to 0 to disable)
     12 ROOT_FS=btrfs # btrfs or ext4
     13 TIMEZONE=America/New_York
     14 USERNAME=acidvegas
     15 WIFI_SSID= # Leave blank if you don't want to use wifi
     16 WIFI_PASS=
     17 WIFI_DEV=wlan0
     18 
     19 if [ -d /sys/firmware/efi ]; then
     20 	BOOT_OPTION=UEFI
     21 else
     22 	BOOT_OPTION=BIOS
     23 fi
     24 
     25 
     26 check_config() {
     27 	if [ ! $ARCH = "x86_64" ] && [ ! $ARCH = "x86_64-musl" ]; then
     28 		printf "invalid ARCH\n" && exit 1
     29 	elif [ ! $CPU = "amd" ] && [ ! $CPU = "intel" ]; then
     30 		printf "invalid CPU\n" && exit 1
     31 	elif [ ! -b $DRIVE ]; then
     32 		printf "invalid DRIVE\n" && exit 1
     33 	elif [ -z $HOSTNAME ]; then
     34 		printf "invalid HOSTNAME\n" && exit 1
     35 	elif ! [ "$SWAP_SIZE" -eq "$SWAP_SIZE" ] 2>/dev/null; then
     36 		printf "invalid SWAP_SIZE\n" && exit 1
     37 	elif [ ! $ROOT_FS = "btrfs" ] && [ ! $ROOT_FS = "ext4" ] && [ ! $ROOT_FS = "zfs" ]; then
     38 		printf "invalid ROOT_FS\n" && exit 1
     39 	elif [ ! -f /usr/share/zoneinfo/$TIMEZONE ]; then
     40 		printf "invalid TIMEZONE\n" && exit 1
     41 	elif [ -z $USERNAME ]; then
     42 		printf "invalid USERNAME\n" && exit 1
     43 	elif [ ! -z $WIFI_SSID ]; then
     44 		if [ -z $(ip addr | grep '^[0-9]:' | awk '{print $2}' | tr -d ':' | grep $WIFI_DEV) ]; then
     45 			printf "invalid WIFI_DEV\n" && exit 1
     46 		fi
     47 	fi
     48 }
     49 
     50 
     51 setup_network() {
     52 	if [ ! -z "$WIFI_SSID" ]; then
     53 		if rfkill list wifi | grep -q 'Soft blocked: yes\|Hard blocked: yes'; then
     54 			printf "Wifi is blocked, attempting to unblock... (make sure to handle this after reboot)\n"
     55 			rfkill unblock wifi
     56 		fi
     57 		wpa_passphrase "$WIFI_SSID" "$WIFI_PASS" | wpa_supplicant -i $WIFI_DEV -c /dev/stdin
     58 	fi
     59 }
     60 
     61 
     62 setup_partition() {
     63 	xbps-install -u xbps
     64 	xbps-install -Su
     65 	xbps-install parted
     66 
     67 	wipefs -a $DRIVE
     68 	if [ $BOOT_OPTION = "UEFI" ]; then
     69 		parted $DRIVE --script mklabel gpt
     70 		parted $DRIVE --script mkpart primary fat32 1MiB 513MiB
     71 		parted $DRIVE --script set 1 esp on
     72 		parted $DRIVE --script mkpart primary $ROOT_FS 513MiB 100%
     73 		partprobe $DRIVE
     74 		mkfs.vfat ${DRIVE}1
     75 		if [ $ROOT_FS = "btrfs" ]; then
     76 			mkfs.btrfs -f ${DRIVE}2
     77 			mount ${DRIVE}2 /mnt
     78 			btrfs subvolume create /mnt/@
     79 			btrfs subvolume create /mnt/@home
     80 			btrfs subvolume create /mnt/@snapshots
     81 			umount /mnt
     82 			mount -o subvol=@ ${DRIVE}2 /mnt
     83 			mkdir -p /mnt/{home,snapshots}
     84 			mount -o subvol=@home ${DRIVE}2 /mnt/home
     85 			mount -o subvol=@snapshots ${DRIVE}2 /mnt/snapshots
     86 		elif [ $ROOT_FS = "ext4" ]; then
     87 			mkfs.ext4 ${DRIVE}2
     88 			mount ${DRIVE}2 /mnt
     89 		fi
     90 		mkdir -p /mnt/boot/efi
     91 		mount ${DRIVE}1 /mnt/boot/efi
     92 	elif [ $BOOT_OPTION = "BIOS" ]; then
     93 		parted $DRIVE --script mklabel msdos
     94 		parted $DRIVE --script mkpart primary $ROOT_FS 1MiB 100%
     95 		parted $DRIVE --script set 1 boot on
     96 		partprobe $DRIVE
     97 		if [ $ROOT_FS = "btrfs" ]; then
     98 			mkfs.btrfs -f ${DRIVE}1
     99 			mount ${DRIVE}1 /mnt
    100 			btrfs subvolume create /mnt/@
    101 			btrfs subvolume create /mnt/@home
    102 			btrfs subvolume create /mnt/@snapshots
    103 			umount /mnt
    104 			mount -o subvol=@ ${DRIVE}1 /mnt
    105 			mkdir -p /mnt/{home,snapshots}
    106 			mount -o subvol=@home ${DRIVE}1 /mnt/home
    107 			mount -o subvol=@snapshots ${DRIVE}1 /mnt/snapshots
    108 		elif [ $ROOT_FS = "ext4" ]; then
    109 			mkfs.ext4 ${DRIVE}1
    110 			mount ${DRIVE}1 /mnt
    111 		fi
    112 	fi
    113 }
    114 
    115 
    116 setup_install() {
    117 	REPO=https://repo-default.voidlinux.org/current
    118 	if [ $ARCH = 'x86_64-musl' ]; then
    119 		REPO=$REPO/musl
    120 	fi
    121 
    122 	mkdir -p /mnt/var/db/xbps/keys
    123 	cp /var/db/xbps/keys/* /mnt/var/db/xbps/keys/
    124 
    125 	XBPS_ARCH=$ARCH xbps-install -S -r /mnt -R "$REPO" base-system linux
    126 
    127 	printf "entering chroot...remember to run setup_chroot() inside the chroot!\n"
    128 	xchroot /mnt /bin/bash
    129 }
    130 
    131 
    132 setup_chroot() {
    133 	passwd
    134 	xbps-install -u xbps
    135 	xbps-install -Su
    136 
    137 	if [ $CPU = "intel" ]; then
    138 		xbps-install void-repo-nonfree
    139 		xbps-install -Su
    140 		xbps-install intel-ucode
    141 		ln -sf /etc/sv/intel-ucode /etc/runit/runsvdir/default/
    142 	elif [ $CPU = "amd" ]; then
    143 		xbps-install linux-firmware-amd
    144 	fi
    145 
    146 	useradd -m -s /bin/bash $USERNAME && passwd $USERNAME && gpasswd -a $USERNAME wheel
    147 	ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
    148 	ln -sf /etc/sv/dhcpcd /etc/runit/runsvdir/default/
    149 	hwclock --systohc
    150 	printf "$HOSTNAME\n" > /etc/hostname
    151 	printf "HOSTNAME=\"$HOSTNAME\"\nHARDWARECLOCK=\"UTC\"\nTIMEZONE=\"$TIMEZONE\"\nKEYMAP=us\n" > /etc/rc.conf
    152 
    153 	if [ $ARCH = 'x86_64' ]; then
    154 		printf "en_US.UTF-8 UTF-8\n" > /etc/default/libc-locales
    155 		printf "LANG=en_US.UTF-8\n" > /etc/locale.conf
    156 		xbps-reconfigure -f glibc-locales
    157 	fi
    158 
    159 	if [ $BOOT_OPTION = "UEFI" ]; then
    160 		if [ $ROOT_FS = "btrfs" ]; then
    161 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}2) /          $ROOT_FS defaults,noatime,subvol=@  0 1\n"
    162 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}2) /home      $ROOT_FS defaults,subvol=@home      0 1\n"
    163 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}2) /snapshots $ROOT_FS defaults,subvol=@snapshots 0 1\n"
    164 		elif [ $ROOT_FS = "ext4" ]; then
    165 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}2) / $ROOT_FS defaults,noatime 0 1\n"
    166 		fi
    167 		printf "UUID=$(blkid -s UUID -o value ${DRIVE}1) /boot/efi vfat defaults,noatime 0 1\n"
    168 	elif [ $BOOT_OPTION = "BIOS" ]; then
    169 		if [ $ROOT_FS = "btrfs" ]; then
    170 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}1) /          btrfs defaults,noatime,subvol=@  0 1\n"
    171 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}1) /home      btrfs defaults,subvol=@home      0 1\n"
    172 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}1) /snapshots btrfs defaults,subvol=@snapshots 0 1\n"
    173 		elif [ $ROOT_FS = "ext4" ]; then
    174 			printf "UUID=$(blkid -s UUID -o value ${DRIVE}1) / $ROOT_FS defaults,noatime  0 1\n"
    175 		fi
    176 	fi > /etc/fstab
    177 
    178 	printf "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0\n" >> /etc/fstab
    179 
    180 	if [ $SWAP_SIZE -gt 0 ]; then
    181 		touch /swapfile
    182 		if [ $ROOT_FS = "btrfs" ]; then
    183 			chattr +C /swapfile # Needed?
    184 		fi
    185 		dd if=/dev/zero of=/swapfile bs=1M count=${SWAP_SIZE}k status=progress
    186 		chmod 0600 /swapfile
    187 		mkswap /swapfile
    188 		swapon /swapfile
    189 		printf "/swapfile none swap sw 0 0\n" >> /etc/fstab
    190 	fi
    191 
    192 	if [ $BOOT_OPTION = "UEFI" ]; then
    193 		xbps-install gummiboot
    194 		gummiboot install
    195 		cp /boot/efi/EFI/GRUB/grubx64.efi /boot/efi/EFI/boot/bootx64.efi # copy the EFI for tricking compatability
    196 	elif [ $BOOT_OPTION = "BIOS" ]; then
    197 		xbps-install grub
    198 		grub-install /dev/$DRIVE
    199 	fi
    200 
    201 	xbps-reconfigure -fa
    202 	exit
    203 }
    204 
    205 
    206 
    207 if [ "$#" -ne 1 ]; then
    208 	printf "usage: $0 [install|partition|chroot|final]\n"
    209 	exit 1
    210 fi
    211 
    212 check_config
    213 
    214 case "$1" in
    215     network)   setup_network ;;
    216     partition) setup_partition ;;
    217     install)   setup_install ;;
    218     chroot)    setup_chroot ;;
    219     final)     umount -R /mnt; reboot ;;
    220     *)         printf "usage: $0 [install|partition|chroot|final]\n"; exit 1 ;;
    221 esac