#!/bin/bash set -e CHROOT_USER=torus CHROOT_GROUP=torus INSTALL_DIR=/opt/torus HOME_DIR=/home/torus SOCK_PATH=$HOME_DIR/torus.sock DATA_PATH=$HOME_DIR/torus.dat PID_PATH=/var/run/torus.pid if [ "$EUID" -ne 0 ]; then exit 1 fi if ! id "$CHROOT_USER" &>/dev/null; then useradd -r -m -s /bin/bash "$CHROOT_USER" fi passwd -d "$CHROOT_USER" 2>/dev/null || usermod -p "" "$CHROOT_USER" mkdir -p "$INSTALL_DIR" mkdir -p "$HOME_DIR" mkdir -p /var/www/ascii.town cp -f client server image merge meta "$INSTALL_DIR/" chmod +x "$INSTALL_DIR"/* if [ -f default8x16.psfu ]; then mkdir -p "$HOME_DIR/usr/share/torus" cp -f default8x16.psfu "$HOME_DIR/usr/share/torus/" fi if [ -f explore.html ] && [ -f index.html ]; then cp -f explore.html index.html /var/www/ascii.town/ chown -R "$CHROOT_USER:$CHROOT_GROUP" /var/www/ascii.town fi chown -R "$CHROOT_USER:$CHROOT_GROUP" "$HOME_DIR" chown -R "$CHROOT_USER:$CHROOT_GROUP" "$INSTALL_DIR" cat > /etc/systemd/system/torus.service << EOF [Unit] Description=Torus ASCII Art Server After=network.target [Service] Type=forking User=$CHROOT_USER Group=$CHROOT_GROUP ExecStart=$INSTALL_DIR/server -d $DATA_PATH -p $PID_PATH -s $SOCK_PATH Restart=always RestartSec=10 StandardOutput=journal StandardError=journal [Install] WantedBy=multi-user.target EOF if ! grep -q "Match User $CHROOT_USER" /etc/ssh/sshd_config; then cat >> /etc/ssh/sshd_config << EOF Match User $CHROOT_USER PasswordAuthentication yes PermitEmptyPasswords yes ForceCommand $INSTALL_DIR/client -s $SOCK_PATH DisableForwarding yes MaxSessions 1 EOF fi echo "--------------------------------" echo "passwd -d $CHROOT_USER" echo "systemctl restart sshd" echo "systemctl enable --now torus" echo "systemctl status torus"