#!/bin/sh

# install per-user-runsvdir in ~/sv
# drop available services in ~/.config/sv
# and link to ~/sv to enable them

zuser=
[ -z "$zuser" ] && echo "User is not set, please edit the script accordingly." && exit 1

install -d /etc/sv/runsvdir-$zuser
install -m755 sv/runsvdir/run /etc/sv/runsvdir-$zuser/run
sed -i -e "s/\@USER\@/$zuser/g" /etc/sv/runsvdir-$zuser/run
install -m755 sv/runsvdir/finish /etc/sv/runsvdir-$zuser/finish
sed -i -e "s/\@USER\@/$zuser/g" /etc/sv/runsvdir-$zuser/finish
ln -sf /run/runit/supervise.runsvdir-$zuser /etc/sv/runsvdir-$zuser/supervise

# force-enable Wayland on nvidia GPUs
ln -s /dev/null /etc/udev/rules.d/61-gdm.rules

# Set ulimit and vm.max_map_count
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
echo "$zuser hard nofile 524288" >> /etc/security/limits.conf
echo "$zuser soft nofile 524288" >> /etc/security/limits.conf
