void/scripts/vps
2024-06-06 15:09:38 -04:00

142 lines
7.1 KiB
Bash
Executable File

#!/bin/bash
# enter the void (vps) - developed by acidvegas (https://git.acid.vegas/void)
# Notes:
# MUSL builds for Void Linux are having an issue where `su` is segfaulting or returning "Bad address"
#
# Bootstrap:
# 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
set -xev
# Configuration
ARCH=x86_64 # x86_64 or x86_64-musl
DRIVE=/dev/vda
SSH_KEY="ssh-ed25519 REDACTED acidvegas@paloalto"
SWAP_SIZE=$((1 * 1024)) # 1GB
TIMEZONE="America/New_York"
USERNAME=supernets
# Let's dynamically set the hostname so we don't have to hardcode it
echo "Hostname:"
read HOSTNAME
setup_root() {
xbps-install -y parted
wipefs -a -f $DRIVE
parted --script $DRIVE mklabel msdos
parted --script $DRIVE mkpart primary ext4 1MiB 100%
parted --script $DRIVE set 1 boot on
mkfs.ext4 ${DRIVE}1
mkdir -p /mnt
mount ${DRIVE}1 /mnt
mkdir -p /mnt/var/db/xbps/keys
cp /var/db/xbps/keys/* /mnt/var/db/xbps/keys/
REPO=https://repo-default.voidlinux.org/current
[ $ARCH = 'x86_64-musl' ] && REPO=$REPO/musl
XBPS_ARCH=$ARCH xbps-install -y -S -r /mnt -R "$REPO" base-system linux
cp vps /mnt/root/
xchroot /mnt /bin/bash
}
setup_chroot() {
passwd
xbps-install -u xbps
xbps-remove -y base-system openssh
xbps-install -Syu curl dropbear git htop incus incus-client incus-tools iptables nano net-tools runit-iptables tmux socklog-void wget
# Set up networking
IP_ADDR=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
GATEWAY=$(ip route show default | awk '/default/ {print $3}')
printf "ip link set eth0 up\nip addr add ${IP_ADDR}/24 dev eth0\nip route add default via $GATEWAY\n" > /etc/rc.local
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
echo "$HOSTNAME" > /etc/hostname
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
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
printf "\nexport HISTFILE=/dev/null\nexport LESSHISTFILE=/dev/null\nexport PYTHONHISTFILE=/dev/null\n" >> /etc/profile
printf "Defaults lecture = always\nDefaults lecture_file = /etc/sudoers.d/sudoers.lecture\nroot ALL=(ALL) ALL\n%%wheel ALL=(ALL) ALL\n" > /etc/sudoers
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
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
echo "hsts=0" >> /etc/wgetrc
>/var/log/lastlog && chattr +i /var/log/lastlog
# Enable services (Using the runit dir because the system is not running yet)
ln -s /etc/sv/socklog-unix/ /etc/runit/runsvdir/default/
ln -s /etc/sv/nanoklogd/ /etc/runit/runsvdir/default/
ln -s /etc/sv/dropbear/ /etc/runit/runsvdir/default/
ln -s /etc/sv/incus /etc/runit/runsvdir/default/
ln -s /etc/sv/incus-user /etc/runit/runsvdir/default/
ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime
touch /swapfile
dd if=/dev/zero of=/swapfile bs=1M count=${SWAP_SIZE} status=progress
chmod 0600 /swapfile
mkswap /swapfile && swapon /swapfile
hwclock --systohc
chsh -s /bin/bash
useradd -m -s /bin/bash $USERNAME && passwd $USERNAME
gpasswd -a $USERNAME _incus
gpasswd -a $USERNAME _incus-admin
printf "root:1000000:65536\n$USERNAME:165536:65536" > /etc/subgid
printf "root:1000000:65536\n$USERNAME:165536:65536" > /etc/subuid
cp vps /home/$USERNAME/ && chown $USERNAME:$USERNAME /home/$USERNAME/vps
if [ ! $ARCH = 'x86_64-musl' ]; then
xbps-reconfigure -f glibc-locales
fi
# Setup fstab
echo "UUID=$(blkid -s UUID -o value ${DRIVE}1) / ext4 rw,errors=remount-ro,noatime 0 1" > /etc/fstab
echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0" >> /etc/fstab
echo "/swapfile none swap sw 0 0" >> /etc/fstab
echo "proc /proc proc defaults,hidepid=2 0 0" >> /etc/fstab
mount -o remount /proc
# Add the official SuperNETs seal of HARD FUCKIGN CORE INTERNET USAGE into the MOTD
{
echo -e ""
echo -e " \033[37;104m \033[0m \033[0m"
echo -e " \033[37;104m \033[37;101m \033[37;104m \033[0m \033[0m"
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"
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"
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"
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"
echo -e " \033[37;104m \033[37;101m \033[37;104m \033[0m \033[0m"
echo -e " \033[37;104m \033[37;101m \033[37;103m \033[37;101m \033[37;104m \033[0m \033[0m"
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"
echo -e " \033[37;104m \033[37;101m \033[37;104m \033[0m \033[0m"
echo -e " \033[37;104m \033[37;101m \033[37;103m \033[37;101m \033[37;104m \033[0m \033[0m"
echo -e " \033[37;104m \033[37;101m \033[37;103m \033[37;101m \033[37;104m \033[0m \033[0m"
echo -e " \033[37;104m \033[37;101m \033[37;104m \033[0m \033[0m"
echo -e "┏┓┳┳┏┓┏┓┳┓ \033[37;104m \033[37;101m \033[37;104m \033[0m ┳┓┏┓┏┳┓┏┓"
echo -e "┗┓┃┃┣┛┣ ┣┫ \033[37;104m \033[0m ┃┃┣ ┃ ┗┓"
echo -e "┗┛┗┛┻ ┗┛┛┗ \033[37;104m \033[0m\033[0m ┛┗┗┛ ┻ ┗┛"
echo -e ""
} > /etc/motd
# Set up user SSH keys
mkdir -p /home/$USERNAME/.ssh
echo "$SSH_KEY" > /home/$USERNAME/.ssh/authorized_keys
chmod 700 $HOME/.ssh && chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh
chmod 400 $HOME/.ssh/authorized_keys && chattr +i $HOME/.ssh/authorized_keys && chattr +i $HOME/.ssh
xbps-install -Sy grub
grub-install $DRIVE
grub-mkconfig -o /boot/grub/grub.cfg
xbps-reconfigure -fa
}
setup_user() {
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
}
[ $1 = "root" ] && setup_root
[ $1 = "chroot" ] && setup_chroot
[ $1 = "user" ] && setup_user