Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # When this script is launched it will:
- # 1) log into the L4dgoldminers/GMservers github repo and download the server config locally
- # 2) Make sure the local server config is up-to-date with the github config
- # 3) Log any errors or rsync updates to githubsync_rsyncUpdates.log & githubsync_errors.log
- # 4) After it's done it'll correct the server.cfg hostname & rcon_password fields, as well as databases.cfg passwords
- # Note: this script assumes all passwords are the same in database.cfg
- #
- # Installation:
- # change file permission: 'chmod 755 auto-sync.sh'
- # Run script manually first time to make sure it's working.
- # (This means refreshing the directory and checking those two log files)
- #
- # After verifying it's working properly, install on a cron job that executes once a day:
- # Enter the command 'crontab -e' (select "nano" if you're unfamiliar with using the other editors)
- # 0 8 * * * /path/to/auto-sync.sh # Launch auto-sync once per day
- #
- # As an additional step to be sure the cronjob is launching it properly, delete the "githubsync_rsyncUpdates.log"
- # log file and see if it regenerates automatically the next day.
- #
- #==================================================================
- # configuration :
- #github credentials
- github_user=""
- github_pass="" # use a personal access token, passwords will be deprecated
- #L4D2 server credentials
- server_hostname="[GM] "
- server_rcon_password=""
- mysql_password="" # assumes every password in databases.cfg is the same.
- # linux server directory (leave out trailing slash '/')
- local_dir="/root/L4D2/left4dead2" #directory where 'addons/' and 'cfg/' folders exist
- #log file for errors / update status
- LogFile="githubsync_rsyncUpdates.log"
- ErrorFile="githubsync_errors.log"
- # Exclude these files from being synced to the 'addons/' folder
- Excludes_addons="--exclude sourcemod/configs/sourcebans/sourcebans.cfg \
- --exclude sourcemod/configs/sourcebans/sb_admin_groups.cfg \
- --exclude sourcemod/configs/sourcebans/sb_admins.cfg \
- --exclude sourcemod/data/SourceTVDemos \
- --exclude sourcemod/logs \
- --exclude sourcemod/gamedata/core.games \
- --exclude sourcemod/gamedata/sdkhooks.games \
- --exclude sourcemod/gamedata/sdktools.games \
- --exclude sourcemod/gamedata/sm-cstrike.games \
- --exclude sourcemod/gamedata/funcommands.games.txt \
- --exclude sourcemod/gamedata/sm-tf2.games.txt \
- --exclude sourcemod/gamedata/accelerator.games.txt \
- --exclude sourcemod/configs/sourcebans/overrides_backup.cfg \
- --exclude sourcemod/data/sqlite/sourcecomms-queue.sq3 \
- --exclude sourcemod/data/dumps \
- --exclude sourcemod/data/sqlite/sourcebans-queue.sq3"
- # Exclude these files from being synced to the 'cfg/sourcemod' folder
- Excludes_cfg_sourcemod="--exclude Sm_SourceSleuth.cfg"
- # END configuration
- #==================================================================
- date=$(date '+%Y-%m-%d:%H:%M')
- LogCriticalError () {
- echo -e "\n==================== $date ====================\n" >> $ErrorFile
- echo "Error: $1" >> $ErrorFile
- echo "Error: $1"
- rm -rf GMservers
- exit
- }
- # Might be paranoid check. Just in case someone has a folder already named that and is using it...
- [ -d "GMservers/" ] && LogCriticalError "Folder named 'GMservers/' already exists in this directory."
- if ! git clone https://$github_user:$github_pass@github.com/L4dgoldminers/GMservers.git
- then
- LogCriticalError "git clone failed. Check 'github credentials' configuration."
- fi
- databasesCFG="$local_dir/addons/sourcemod/configs/databases.cfg"
- serverCFG="$local_dir/cfg/server.cfg"
- addons_folder="$local_dir/addons/" #keep trailing slash (/) at end
- cfg_folder="$local_dir/cfg/" #keep trailing slash (/) at end
- cfg_sourcemod_folder="$local_dir/cfg/sourcemod/" #keep trailing slash (/) at end
- # validate folders
- if [ "$1" == "newserver" ]; then
- echo "Validating relevant folders for new install of L4D2.." && sleep 3
- [ ! -d "$addons_folder" ] && LogCriticalError "'addons/' folder doesn't exist. Check 'local_dir' variable."
- [ ! -d "$cfg_folder" ] && LogCriticalError "'cfg/' folder doesn't exist. Check 'local_dir' variable."
- else
- [ ! -d "$addons_folder" ] && LogCriticalError "'addons/' folder doesn't exist. Check 'local_dir' variable."
- [ ! -d "$cfg_sourcemod_folder" ] && LogCriticalError "'cfg/sourcemod/' folder doesn't exist. Check 'local_dir' variable."
- [ ! -e "$databasesCFG" ] && LogCriticalError "'$databasesCFG' file doesn't exist. Check 'local_dir' variable."
- [ ! -e "$serverCFG" ] && LogCriticalError "'$serverCFG' file doesn't exist. Check 'local_dir' variable."
- fi
- # validate variables
- [ -z "$server_hostname" ] && LogCriticalError "'server_hostname' variable left blank."
- [ -z "$server_rcon_password" ] && LogCriticalError "'server_rcon_password' variable left blank."
- [ -z "$mysql_password" ] && LogCriticalError "'mysql_password' variable left blank."
- [ -z "$LogFile" ] && LogCriticalError "'LogFile' variable left blank."
- [ -z "$ErrorFile" ] && LogCriticalError "'ErrorFile' variable left blank."
- remote_dir_addons="$(pwd)/GMservers/Server Config/addons/" #keep trailing slash (/) at end
- remote_dir_cfg_sourcemod="$(pwd)/GMservers/Server Config/cfg/sourcemod/" #keep trailing slash (/) at end
- remote_dir_serverCFG="$(pwd)/GMservers/Server Config/cfg/server.cfg"
- Opts="-ahiO --no-perms --no-owner --no-group"
- # log file starts here
- echo -e "\n==================== $date ====================\n\nUpdate check started." >> $LogFile
- if [ "$1" == "newserver" ]; then
- echo "Rsyncing server config to new install of L4D2" && sleep 3
- # rsync 'addons/' folder
- rsync $Opts "$remote_dir_addons" "$addons_folder" >> $LogFile
- # rsync 'cfg/sourcemod/' folder (note: don't rsync 'cfg/' by itself cause it would delete official l4d2 files within cfg/)
- rsync $Opts "$remote_dir_cfg_sourcemod" "$cfg_sourcemod_folder" >> $LogFile
- else
- # rsync 'addons/' folder
- rsync $Opts --delete $Excludes_addons "$remote_dir_addons" "$addons_folder" >> $LogFile
- # rsync 'cfg/sourcemod/' folder (note: don't rsync 'cfg/' by itself cause it would delete official l4d2 files within cfg/)
- rsync $Opts --delete $Excludes_cfg_sourcemod "$remote_dir_cfg_sourcemod" "$cfg_sourcemod_folder" >> $LogFile
- fi
- #server.cfg - replace hostname and rcon_password with correct entries
- mv "$remote_dir_serverCFG" "$serverCFG"
- sed -i "s/RCON_PASS_HERE/$server_rcon_password/" $serverCFG
- sed -i "s/SERVER_HOSTNAME_HERE/$server_hostname/" $serverCFG
- # replace MySQL password in databases.cfg (do this after rsync completes)
- sed -i "s/MYSQL_PASS/$mysql_password/" $databasesCFG
- rm -rf GMservers
- # Remove redundant text from log file
- sed -i "/\.\.t\.\.\.\.\.\./d" $LogFile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement