dotfiles

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

voidlinux-installer-base.sh (3594B)


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