69 lines
1.8 KiB
Bash
Executable File
69 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
|
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo "Creating user rushstats"
|
|
echo "---"
|
|
if [id rushstats >/dev/null 2>&1]; then
|
|
echo "rushstats user already exists, skipping."
|
|
else
|
|
useradd -s /sbin/nologin rushstats
|
|
echo "User rushstats created with /sbin/nologin"
|
|
fi
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo "Moving the distributable folder into /srv/gamestats"
|
|
echo "---"
|
|
if [ -d /srv/gamestats ]; then
|
|
echo "/srv/gamestats already exists; removing"
|
|
rm -r /srv/rushstats
|
|
fi
|
|
mkdir /srv/gamestats
|
|
cp -r "$parent_path"/dist/* /srv/gamestats
|
|
cp -r "$parent_path"/loader/* /srv/gamestats
|
|
chown -R rushstats:rushstats /srv/gamestats
|
|
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo "Creating the systemd services."
|
|
echo "---"
|
|
SYSTEMD_SERVICE_FILE=/etc/systemd/system/rushstats.service
|
|
if [ -f $SYSTEMD_SERVICE_FILE ]; then
|
|
echo "Service already exists; removing."
|
|
rm $SYSTEMD_SERVICE_FILE
|
|
fi
|
|
touch $SYSTEMD_SERVICE_FILE
|
|
echo "[Unit]" >> $SYSTEMD_SERVICE_FILE
|
|
echo "Description=Stats Server for Cyberpunk Rush" >> $SYSTEMD_SERVICE_FILE
|
|
echo "After=network.target" >> $SYSTEMD_SERVICE_FILE
|
|
echo "" >> $SYSTEMD_SERVICE_FILE
|
|
echo "[Service]" >> $SYSTEMD_SERVICE_FILE
|
|
echo "Type=simple" >> $SYSTEMD_SERVICE_FILE
|
|
echo "WorkingDirectory=/srv/gamestats"
|
|
echo "ExecStart=node /srv/gamestats/app.js" >> $SYSTEMD_SERVICE_FILE
|
|
echo "Restart=on-failure" >> $SYSTEMD_SERVICE_FILE
|
|
echo "" >> $SYSTEMD_SERVICE_FILE
|
|
echo "[Install]" >> $SYSTEMD_SERVICE_FILE
|
|
echo "WantedBy=multi-user.target" >> $SYSTEMD_SERVICE_FILE
|
|
echo "" >> $SYSTEMD_SERVICE_FILE
|
|
|
|
echo "Created new service."
|
|
echo cat $SYSTEMD_SERVICE_FILE
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo "Reloading daemons and starting service"
|
|
echo "---"
|
|
systemctl daemon-reload
|
|
systemctl enable rushstats.service
|
|
systemctl start rushstats.service
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo "Creating the cron job to refresh the database."
|
|
echo "---"
|