void/vps

100 lines
4.1 KiB
Bash
Executable File

#!/bin/bash
# enter the void (vps) - developed by acidvegas (https://git.acid.vegas/void)
# xbps-install -Su && xbps-install -u xbps && xbps-install wget && wget https://git.supernets.org/acidvegas/void/raw/branch/master/vps && chmod +x vps && ./vps root
set -xev
# Configuration
ARCH=x86_64-musl # x86_64 or x86_64-musl
DRIVE=/dev/vda
HOSTNAME=blackhole
SSH_PORT=22 # Change me
SWAP_SIZE=4 # In GB (set to 0 to disable)
TIMEZONE="America/New_York"
USERNAME=acidvegas
setup_root() {
xbps-install parted
wipefs -a $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 -S -r /mnt -R "$REPO" base-system linux
cp vps /mnt/root/
xchroot /mnt /bin/bash
}
setup_chroot() {
passwd
xbps-install -u xbps
xbps-install -Su
xbps-remove base-system openssh
xbps-install curl dropbear git iptables nano net-tools tmux socklog-void wget
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
>/var/log/lastlog && chattr +i /var/log/lastlog
printf '#!/bin/sh\nexec 2>&1\n[ -r conf ] && . ./conf\nexec dropbear -K 0 -p '"$SSH_PORT"' -R -m -w -t -T 1 -F 2>&1\n' > /etc/sv/dropbear/run
printf "\nexport HISTFILE=/dev/null\nexport LESSHISTFILE=/dev/null\nexport PYTHONHISTFILE=/dev/null\n" >> /etc/profile
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
echo "hsts=0" >> /etc/wgetrc
#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
echo "proc /proc proc defaults,hidepid=2 0 0" >> /etc/fstab
mount -o remount /proc
ln -s /etc/sv/socklog-unix/ /etc/runit/runsvdir/default/ # We use this instead of /var/service because the system is not currently running
ln -s /etc/sv/nanoklogd/ /etc/runit/runsvdir/default/
ln -s /etc/sv/dropbear/ /etc/runit/runsvdir/default/
ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime
hwclock --systohc
useradd -m -s /bin/bash $USERNAME && passwd $USERNAME
cp vps /home/$USERNAME/ && chown $USERNAME:$USERNAME /home/$USERNAME/vps
if [ ! $ARCH = 'x86_64-musl' ]; then
echo "en_US.UTF-8 UTF-8" > /etc/default/libc-locales
echo "LANG=en_US.UTF-8" > /etc/locale.conf
xbps-reconfigure -f glibc-locales
fi
echo "$HOSTNAME" > /etc/hostname
echo "UUID=$(blkid -s UUID -o value ${DRIVE}1) / ext4 rw,errors=remount-ro,noatime 0 1" > /etc/fstab
touch /swapfile
dd if=/dev/zero of=/swapfile bs=1M count=$SWAP_SIZE status=progress
chmod 0600 /swapfile
mkswap /swapfile && swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
xbps-install -Sy grub
grub-install $DRIVE
grub-mkconfig -o /boot/grub/grub.cfg
xbps-reconfigure -fa
}
setup_user() {
mkdir -p $HOME/.ssh
printf "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBgw6zK6LghGq/6fdMGFKfH9fr+qCOASlD+Xi7Zoe7Ps acidvegas@blackhole" > $HOME/.ssh/authorized_keys
chmod 700 $HOME/.ssh && chown -R $USER $HOME/.ssh
chmod 400 $HOME/.ssh/authorized_keys && chattr +i $HOME/.ssh/authorized_keys && chattr +i $HOME/.ssh
}
[ $1 = "root" ] && setup_root
[ $1 = "chroot" ] && setup_chroot
[ $1 = "user" ] && setup_user