#!/bin/sh
set -e

rc-update add devfs sysinit
rc-update add dmesg sysinit
rc-update add udev sysinit
rc-update add udev-trigger sysinit
rc-update add udev-settle sysinit

rc-update add udev-postmount default

rc-update add hwclock boot
rc-update add modules boot
rc-update add sysctl boot
rc-update add hostname boot
rc-update add bootmisc boot
rc-update add syslog boot
rc-update add klogd boot
rc-update add networking boot
rc-update add seedrng boot
rc-update add zfs-import boot
rc-update add zfs-mount boot
rc-update add tler boot

rc-update add mount-ro shutdown
rc-update add killprocs shutdown

rc-update add acpid default
rc-update add cronie default
rc-update add local default
rc-update add openntpd default
rc-update add smartd default
rc-update add zfs-zed default
rc-update add sshd default
rc-update add tailscale default
rc-update add srvmonitor default
rc-update add ksmbd default

adduser -h /dev/null -s /sbin/nologin -D -H -u 1000 filippo
chpasswd -e <<'EOF'
root:$6$twsDxnP.TG2M8J4l$7lte7E/ImK4UwoursD7qQCC7XMUothIDb9FTH1MncxYbGQDUQPkC/9pxleTwPxEs3nbatApszxuwc4yj6ucdX1
EOF

sed -i 's/^ ?-nobackups/-nobackups/' /etc/joe/joerc
sed -i 's/^ ?-nodeadjoe/-nodeadjoe/' /etc/joe/joerc

# For zpool-import. https://abyssdomain.expert/@filippo/113382158651811946
zgenhostid 000f300d

# Remove the human-unfriendly /dev/disk/by-id WWN symlinks.
# https://github.com/eudev-project/eudev/issues/289
cat /usr/lib/udev/rules.d/60-persistent-storage.rules | \
    grep -v 'SYMLINK+="disk/by-id/nvme-$attr{wwid}' | \
    grep -v 'SYMLINK+="disk/by-id/wwn-' > /etc/udev/rules.d/60-persistent-storage.rules
