Skip to content

Instantly share code, notes, and snippets.

@BoltsJ
Last active May 21, 2023 02:18
Show Gist options
  • Save BoltsJ/02216f0f779a510f09625d428af76987 to your computer and use it in GitHub Desktop.
Save BoltsJ/02216f0f779a510f09625d428af76987 to your computer and use it in GitHub Desktop.
#!/bin/bash
# !!!!!!!!!!!!!!
# !!!! READ !!!!
# !!!!!!!!!!!!!!
# This script creates an unprivileged user to run the FoundryVTT daemon and
# adds a systemd unit file to run the daemon on startup. You will need to have
# the foundry zip for linux in the directory you run this script from and you
# will need to edit the variables to suit your preferences.
# For setting up storage on a raspberry pi, instead of relying on the auto-
# mount feature, you'll want to set up a boot-time mount
# https://www.raspberrypi.org/documentation/configuration/external-storage.md
# has more info on that.
# I reccomend that you set up a storage device as a Linux native filesystem,
# such as ext4 so that permissions are managed properly.
set -e
# IMPORTANT!!!!
# Change these as necessary
install_path="/media/DATA"
foundry_zip=foundryvtt-0.7.5.zip
# This can probably stay the same
foundry_user=foundryvtt
# Install node and unzip
curl -sL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs unzip
# Ensure the path exists
mkdir -p "${install_path}/foundryvtt"
mkdir -p "${install_path}/foundrydata"
# Create unprivileged user to run the daemon
if ! getent passwd ${foundry_user}
then
useradd -d "${install_path}/foundrydata" -r -s /usr/sbin/nologin ${foundry_user}
usermod -L ${foundry_user}
fi
# Create the systemd unit file
cat > foundryvtt.service << EOF
[Unit]
Description=Foundry VTT
After=network.target
[Service]
User=${foundry_user}
ExecStart=node "${install_path}/foundryvtt/resources/app/main.js" --dataPath="${install_path}/foundrydata"
Restart=always
[Install]
WantedBy=multi-user.target
EOF
install -m644 foundryvtt.service /etc/systemd/system/
systemctl daemon-reload
# Install foudry data to the path and set ownership
unzip -d "${install_path}/foundryvtt" ${foundry_zip}
chown -R foundryvtt:foundryvtt "${install_path}/foundryvtt"
chown -R foundryvtt:foundryvtt "${install_path}/foundrydata"
# Enable on boot and start server
systemctl enable foundryvtt.service
echo "Node and foundryvtt are installed"
systemctl start foundryvtt.service
echo "----------------------"
echo "Installed successfully"
echo "----------------------"
echo "http://$(hostname -I | sed 's/ //'):30000"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment