dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

void-basic-installer.sh (3488B)


      1#!/bin/sh
      2
      3[ "$(id -u)" -ne 0 ] && { echo "This script must be run as root"; exit 1; }
      4
      5
      6usage() {
      7	cat <<_EOF
      8Usage: $progname [glibc|musl]
      9_EOF
     10}
     11
     12partition_format() {
     13	umount /dev/sda*
     14	umount -R /mnt
     15	wipefs -a /dev/sda
     16	dd if=/dev/zero of=/dev/sda bs=8M status=progress
     17	(
     18	echo o		# create a new empty DOS partition table
     19	echo n		# partition 1, primary, 200M
     20	echo p
     21	echo 1
     22	echo
     23	echo +200M
     24	echo n		# partition 2, primary
     25	echo p
     26	echo 2
     27	echo
     28	echo
     29	echo a		# bootable: partition 1
     30	echo 1
     31	echo w		# write table to disk and exit
     32	) | fdisk /dev/sda
     33	sync
     34	mkfs.vfat -F32 /dev/sda1
     35	mkfs.xfs -f /dev/sda2
     36	sync
     37}
     38
     39mount_bootstrap() {
     40	mount /dev/sda2 /mnt
     41	mkdir /mnt/boot
     42	mount /dev/sda1 /mnt/boot
     43	XBPS_ARCH="$XBPS_ARCH" xbps-install -y -S -R "$VOID_REPO" -r /mnt base-system syslinux
     44	for mp in sys dev proc; do
     45		mount --rbind /$mp /mnt/$mp && mount --make-rslave /mnt/$mp
     46	done
     47	cp /etc/resolv.conf /mnt/etc/
     48
     49}
     50
     51chroot_script() {
     52	cat >/mnt/home/chroot_script.sh <<- _CHROOT_SCRIPT_EOF
     53### System configuration
     54sed -i '
     55s/^#HARDWARECLOCK=.*/HARDWARECLOCK="UTC"/
     56s/^#TIMEZONE=.*/TIMEZONE="UTC"/
     57s/^#KEYMAP=.*/KEYMAP="dvorak-programmer"/
     58s/^#FONT=.*/FONT="Lat2-Terminus16"/
     59' /etc/rc.conf
     60if [ "$XBPS_ARCH" = "x86_64" ]; then
     61	sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/default/libc-locales
     62	xbps-reconfigure -f glibc-locales
     63fi
     64echo void-basic >/etc/hostname
     65echo "UUID=$(blkid -o value -s UUID /dev/sda1)\t/boot\tvfat\tdefaults\t0\t0" >>/etc/fstab
     66echo "UUID=$(blkid -o value -s UUID /dev/sda2)\t/\txfs\trw,noatime,discard\t0\t1" >>/etc/fstab
     67echo 'hostonly="yes"' >/etc/dracut.conf.d/hostonly.conf
     68
     69### User
     70useradd -m -s /bin/bash baz
     71echo 'password\npassword' | passwd baz
     72echo 'password\npassword' | passwd
     73echo 'cat /proc/uptime >/tmp/uptime' >>/home/baz/.bash_profile
     74
     75### tty1 autologin
     76cp -r /etc/sv/agetty-tty1 /etc/sv/agetty-autologin-tty1
     77rm /etc/sv/agetty-autologin-tty1/supervise
     78sed -i 's/GETTY_ARGS="--noclear"/GETTY_ARGS="--autologin baz --noclear"/' /etc/sv/agetty-autologin-tty1/conf
     79#rm /etc/runit/runsvdir/current/agetty-tty1
     80#ln -s /etc/sv/agetty-autologin-tty1 /etc/runit/runsvdir/current/agetty-tty1
     81
     82### syslinux
     83mkdir /boot/syslinux
     84cp /usr/lib/syslinux/ldlinux.c32 /boot/syslinux/
     85extlinux --install /boot/syslinux
     86dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/dev/sda
     87cat >/etc/kernel.d/post-install/50-syslinux <<- END_OF_50_SYSLINUX
     88#!/bin/sh
     89PKGNAME="\\\$1"
     90VERSION="\\\$2"
     91cat >/boot/syslinux/syslinux.cfg <<- END_OF_SYSLINUX_CFG
     92PROMPT 1
     93TIMEOUT 50
     94DEFAULT void
     95LABEL void
     96LINUX /vmlinuz-\\\${VERSION}
     97APPEND initrd=/initramfs-\\\${VERSION}.img
     98END_OF_SYSLINUX_CFG
     99END_OF_50_SYSLINUX
    100chmod 754 /etc/kernel.d/post-install/50-syslinux
    101xbps-reconfigure -fa
    102rm /etc/runit/runsvdir/current/agetty-tty1
    103ln -s /etc/sv/agetty-autologin-tty1 /etc/runit/runsvdir/current/agetty-tty1
    104_CHROOT_SCRIPT_EOF
    105chroot /mnt /bin/sh /home/chroot_script.sh
    106rm /mnt/home/chroot_script.sh
    107umount -R /mnt
    108}
    109
    110case $1 in
    111	glibc)
    112		read -p "Press Enter to continue... " reply
    113		[ "$reply" != "" ] && { echo "Stopped."; exit 0; }
    114		XBPS_ARCH="x86_64"
    115		VOID_REPO="https://alpha.de.repo.voidlinux.org/current"
    116		partition_format
    117		mount_bootstrap
    118		chroot_script
    119		;;
    120	musl)
    121		read -p "Press Enter to continue... " reply
    122		[ "$reply" != "" ] && { echo "Stopped."; exit 0; }
    123		XBPS_ARCH="x86_64-musl"
    124		VOID_REPO="https://alpha.de.repo.voidlinux.org/current/musl"
    125		partition_format
    126		mount_bootstrap
    127		chroot_script
    128		;;
    129	*)	usage;;
    130esac
    131