void

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

vps (7264B)

      1 #!/bin/bash
      2 # enter the void (vps) - developed by acidvegas (https://git.acid.vegas/void)
      3 
      4 # Notes:
      5 # 	MUSL builds for Void Linux are having an issue where `su` is segfaulting or returning "Bad address"
      6 #
      7 # Bootstrap:
      8 # 	xbps-install -Su && xbps-install -u xbps && xbps-install wget nano && wget https://git.supernets.org/acidvegas/void/raw/branch/master/scripts/vps && chmod +x vps && ./vps root
      9 
     10 set -xev
     11 
     12 # Configuration
     13 ARCH=x86_64 # x86_64 or x86_64-musl
     14 DRIVE=/dev/vda
     15 SSH_KEY="ssh-ed25519 REDACTED acidvegas@paloalto"
     16 SWAP_SIZE=$((1 * 1024)) # 1GB
     17 TIMEZONE="America/New_York"
     18 USERNAME=supernets
     19 
     20 # Let's dynamically set the hostname so we don't have to hardcode it
     21 echo "Hostname:"
     22 read HOSTNAME
     23 
     24 setup_root() {
     25 	xbps-install -y parted
     26 	wipefs -a -f $DRIVE
     27 	parted --script $DRIVE mklabel msdos
     28 	parted --script $DRIVE mkpart primary ext4 1MiB 100%
     29 	parted --script $DRIVE set 1 boot on
     30 	mkfs.ext4 ${DRIVE}1
     31 	mkdir -p /mnt
     32 	mount ${DRIVE}1 /mnt
     33 	mkdir -p /mnt/var/db/xbps/keys
     34 	cp /var/db/xbps/keys/* /mnt/var/db/xbps/keys/
     35 	REPO=https://repo-default.voidlinux.org/current
     36 	[ $ARCH = 'x86_64-musl' ] && REPO=$REPO/musl
     37 	XBPS_ARCH=$ARCH xbps-install -y -S -r /mnt -R "$REPO" base-system linux
     38 	cp vps /mnt/root/
     39 	xchroot /mnt /bin/bash
     40 }
     41 
     42 setup_chroot() {
     43 	passwd
     44 
     45 	xbps-install -u xbps
     46 	xbps-remove -y base-system openssh
     47 	xbps-install -Syu curl dropbear git htop incus incus-client incus-tools iptables nano net-tools runit-iptables tmux socklog-void wget
     48 
     49 	# Set up networking
     50 	IP_ADDR=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
     51 	GATEWAY=$(ip route show default | awk '/default/ {print $3}')
     52 	printf "ip link set eth0 up\nip addr add ${IP_ADDR}/24 dev eth0\nip route add default via $GATEWAY\n" > /etc/rc.local
     53 	printf "printf \"nameserver 208.67.222.222\\\nnameserver 208.67.220.220\\\nnameserver 2620:119:35::35\\\nnameserver 2620:119:53::53\" > /etc/resolv.conf" >> /etc/rc.local
     54 
     55 	echo "$HOSTNAME" > /etc/hostname
     56 	echo 'export PS1="\e[38;5;237m\T\e[0m \e[38;5;196m\u@\h\e[0m \e[38;5;226m\w\e[0m : "' > /root/.bashrc
     57 	printf "set boldtext\nset minibar\nset nohelp\nset nowrap\nset quickblank\nset tabsize 4\nunbind ^J main\nset selectedcolor black,red\ninclude \"/usr/share/nano/*.nanorc\"\n" > /etc/nanorc
     58 	printf "\nexport HISTFILE=/dev/null\nexport LESSHISTFILE=/dev/null\nexport PYTHONHISTFILE=/dev/null\n" >> /etc/profile
     59 	printf "Defaults lecture = always\nDefaults lecture_file = /etc/sudoers.d/sudoers.lecture\nroot ALL=(ALL) ALL\n%%wheel ALL=(ALL) ALL\n" > /etc/sudoers
     60 	printf "\n\033[1m     \033[32m\"Bee\" careful    \033[34m__\n       \033[32mwith sudo!    \033[34m// \ \n                     \\\\\\_/ \033[33m//\n   \033[35m''-.._.-''-.._.. \033[33m-(||)(')\n                     '''\033[0m\n" > /etc/sudoers.d/sudoers.lecture
     61 	printf '#!/bin/sh\nexec 2>&1\n[ -r conf ] && . ./conf\nexec dropbear -K 0 -p %s -R -w -t -T 1 -F 2>&1\n' "$(shuf -i 10000-65534 -n 1)" > /etc/sv/dropbear/run
     62 	echo "hsts=0" >> /etc/wgetrc
     63 	>/var/log/lastlog && chattr +i /var/log/lastlog
     64 
     65 	# Enable services (Using the runit dir because the system is not running yet)
     66 	ln -s /etc/sv/socklog-unix/ /etc/runit/runsvdir/default/
     67 	ln -s /etc/sv/nanoklogd/    /etc/runit/runsvdir/default/
     68 	ln -s /etc/sv/dropbear/     /etc/runit/runsvdir/default/
     69 	ln -s /etc/sv/incus         /etc/runit/runsvdir/default/
     70 	ln -s /etc/sv/incus-user    /etc/runit/runsvdir/default/
     71 	ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime
     72 
     73 	touch /swapfile
     74 	dd if=/dev/zero of=/swapfile bs=1M count=${SWAP_SIZE} status=progress
     75 	chmod 0600 /swapfile
     76 	mkswap /swapfile && swapon /swapfile
     77 
     78 	hwclock --systohc
     79 	chsh -s /bin/bash
     80 
     81 	useradd -m -s /bin/bash $USERNAME && passwd $USERNAME
     82 	gpasswd -a $USERNAME _incus
     83 	gpasswd -a $USERNAME _incus-admin
     84 	printf "root:1000000:65536\n$USERNAME:165536:65536" > /etc/subgid
     85 	printf "root:1000000:65536\n$USERNAME:165536:65536" > /etc/subuid
     86 	cp vps /home/$USERNAME/ && chown $USERNAME:$USERNAME /home/$USERNAME/vps
     87 
     88 	if [ ! $ARCH = 'x86_64-musl' ]; then
     89 		xbps-reconfigure -f glibc-locales
     90 	fi
     91 	
     92 	# Setup fstab
     93 	echo "UUID=$(blkid -s UUID -o value ${DRIVE}1) / ext4 rw,errors=remount-ro,noatime 0 1" > /etc/fstab
     94 	echo "tmpfs           /tmp        tmpfs   defaults,nosuid,nodev   0 0" >> /etc/fstab
     95 	echo "/swapfile none swap sw 0 0" >> /etc/fstab
     96 	echo "proc /proc proc defaults,hidepid=2 0 0" >> /etc/fstab
     97 	mount -o remount /proc
     98 
     99 	# Add the official SuperNETs seal of HARD FUCKIGN CORE INTERNET USAGE into the MOTD
    100 	{
    101 		echo -e ""
    102 		echo -e "      \033[37;104m                                  \033[0m        \033[0m"
    103 		echo -e "    \033[37;104m    \033[37;101m                              \033[37;104m    \033[0m      \033[0m"
    104 		echo -e "  \033[37;104m    \033[37;101m      \033[37;103m  \033[37;101m    \033[37;103m        \033[37;101m    \033[37;103m  \033[37;101m        \033[37;104m    \033[0m    \033[0m"
    105 		echo -e "\033[37;104m    \033[37;101m      \033[37;103m  \033[37;101m    \033[37;103m            \033[37;101m      \033[37;103m  \033[37;101m      \033[37;104m    \033[0m  \033[0m"
    106 		echo -e "\033[37;104m    \033[37;101m    \033[37;103m    \033[37;101m    \033[37;103m                      \033[37;101m    \033[37;104m    \033[0m  \033[0m"
    107 		echo -e "  \033[37;104m    \033[37;101m    \033[37;103m  \033[37;101m                      \033[37;103m    \033[37;101m  \033[37;104m    \033[0m    \033[0m"
    108 		echo -e "    \033[37;104m    \033[37;101m                              \033[37;104m    \033[0m      \033[0m"
    109 		echo -e "      \033[37;104m    \033[37;101m    \033[37;103m              \033[37;101m        \033[37;104m    \033[0m        \033[0m"
    110 		echo -e "        \033[37;104m    \033[37;101m      \033[37;103m  \033[37;101m  \033[37;103m      \033[37;101m      \033[37;104m    \033[0m          \033[0m"
    111 		echo -e "          \033[37;104m    \033[37;101m                  \033[37;104m    \033[0m            \033[0m"
    112 		echo -e "            \033[37;104m    \033[37;101m    \033[37;103m      \033[37;101m    \033[37;104m    \033[0m              \033[0m"
    113 		echo -e "              \033[37;104m    \033[37;101m    \033[37;103m  \033[37;101m    \033[37;104m    \033[0m                \033[0m"
    114 		echo -e "                \033[37;104m    \033[37;101m      \033[37;104m    \033[0m                  \033[0m"
    115 		echo -e "┏┓┳┳┏┓┏┓┳┓        \033[37;104m    \033[37;101m  \033[37;104m    \033[0m         ┳┓┏┓┏┳┓┏┓"
    116 		echo -e "┗┓┃┃┣┛┣ ┣┫          \033[37;104m      \033[0m           ┃┃┣  ┃ ┗┓"
    117 		echo -e "┗┛┗┛┻ ┗┛┛┗            \033[37;104m  \033[0m\033[0m             ┛┗┗┛ ┻ ┗┛"
    118 		echo -e ""
    119 	} > /etc/motd
    120 
    121 	# Set up user SSH keys
    122 	mkdir -p /home/$USERNAME/.ssh
    123 	echo "$SSH_KEY" > /home/$USERNAME/.ssh/authorized_keys
    124 	chmod 700 $HOME/.ssh && chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh
    125 	chmod 400 $HOME/.ssh/authorized_keys && chattr +i $HOME/.ssh/authorized_keys && chattr +i $HOME/.ssh
    126 
    127 	xbps-install -Sy grub
    128 	grub-install $DRIVE
    129 	grub-mkconfig -o /boot/grub/grub.cfg
    130 
    131 	xbps-reconfigure -fa
    132 }
    133 
    134 
    135 setup_user() {
    136 	echo 'export PS1="\e[38;5;237m\T\e[0m \e[38;5;196m\u@\h\e[0m \e[38;5;226m\w\e[0m : "' > ~/.bashrc
    137 }
    138 
    139 
    140 [ $1 = "root"   ] && setup_root
    141 [ $1 = "chroot" ] && setup_chroot
    142 [ $1 = "user"   ] && setup_user