Skip to content

Instantly share code, notes, and snippets.

@markski1
Last active May 3, 2023 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markski1/c3d63ef32c9c07cbee6da2708f3406e5 to your computer and use it in GitHub Desktop.
Save markski1/c3d63ef32c9c07cbee6da2708f3406e5 to your computer and use it in GitHub Desktop.
## Based on Nbjohnston86's simple_tes3mp_deploy script.
## Just fixes a few bugs dealing with files.
## https://github.com/Nbjohnston86/simple_tes3mp_deploy/
## any error will stop the script.
set -e
## parameter 1: tes3mp binaries
if [ -z "$1" ]
then
echo "Error: Needs tar'd and compressed server files location, relative to current working directory"
exit 1
fi
## parameter 2: username
if [ -z "$2" ]
then
echo "Error: Needs user to create and assign files to"
exit 1
fi
serverfiles="$1"
serverUserName="$2"
serverDestination='/opt/TES3MP'
coreServerExtractedFolderName='TES3MP-server'
coreServeConfigFile="$serverDestination/tes3mp-server-default.cfg"
tes3mpServiceFile='tes3mp.service'
systemdLocation='/etc/systemd/system'
## Extract TES3MP files
echo "Extracting TES3MP files from given sources."
tar -xf $serverfiles
## Testing this script, I need to create the destination folder before moving to it. Oops.
mkdir $serverDestination
## As of the making of this script, I am using what is the default name of the folder
## To move it. If this changes, this script will need to be updated.
## The common place I've seen people put 'Universal' applications is /opt
## The original instructions put it in their home folder. I am blatantly ignoring that.
cp -r $coreServerExtractedFolderName/* $serverDestination
## Cleanup, Cleanup
echo "Cleaning up Extracted folders."
rm -rf $coreServerExtractedFolderName
## Is it more dangerous this way? You absolutely have to specify a parameter at the top for it to get this far, though.
## Next we need to create the user that will run TES3MP,
echo "Create $serverUserName user here."
useradd -m $serverUserName
## Set up the service account's password
echo "Enter Password for $serverUserName:"
passwd $serverUserName
## The new user needs to own the files its using
chown $serverUserName:$serverUserName $serverDestination
chown -R $serverUserName:$serverUserName $serverDestination/*
## A previous version of this line was flawed, and did not give ownership to the user
## As a result, it would run, but no users could be created. Oops.
echo "Create TES3MP files here"
## This section is responsible for creating the systemd file needed to run this as a service.
echo "Create SystemD service file here"
## Create line-by-line systemd file
echo "[Unit]" >> $tes3mpServiceFile
echo "Description=TES3MP Server" >> $tes3mpServiceFile
echo "" >> $tes3mpServiceFile
echo "[Service]" >> $tes3mpServiceFile
echo "WorkingDirectory=/opt/TES3MP/" >> $tes3mpServiceFile
echo "User=$serverUserName" >> $tes3mpServiceFile
echo "Group=$serverUserName" >> $tes3mpServiceFile
echo "Restart=always" >> $tes3mpServiceFile
echo "RemainAfterExit=yes" >> $tes3mpServiceFile
echo "" >> $tes3mpServiceFile
echo "ExecStart=/opt/TES3MP/tes3mp-server" >> $tes3mpServiceFile
echo "" >> $tes3mpServiceFile
echo "[Install]" >> $tes3mpServiceFile
echo "WantedBy=multi-user.target" >> $tes3mpServiceFile
echo "" >> $tes3mpServiceFile
## Move it to the systemd folder
mv $tes3mpServiceFile $systemdLocation
## Final Instructions to the user :D
echo "============================================================================================================="
echo "Basic Setup Complete, you may now turn the server on using:"
echo "sudo systemctl start $tes3mpServiceFile"
echo "This of course, requires sudo privileges, which you needed to run this file, so have fun!"
echo "Oh, and this script did NOT set the password to the server, to do that, go to:"
echo "$coreServeConfigFile"
echo "Open this file by using the text editor of your choice. If you're using Ubuntu, like me, I like to use gedit."
echo ""
echo "If you encounter issues after this, you may be lacking some important packages,"
echo "I installed them outside this script because I don't think this script should do that."
echo "The packages I had to install were: luajit liblua5.1 libluajit-5.1"
echo "And using Ubuntu (What I developed this script against), they can be installed with the following command:"
echo "sudo apt-get install luajit liblua5.1 libluajit-5.1"
echo "============================================================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment