ut4-server-ctl.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. #!/bin/bash
  2. # The 'All You Need' Unreal Tournament 4 Server (HUB) Script
  3. # ==========================================================
  4. # This script is everything you need for hosting your own UT4
  5. # server! The way this works is you have a root server directory with this
  6. # script inside it. There's separate directories for config files, maps,
  7. # mutators, and rulesets for the provided game types. You always edit the files
  8. # in those directories and then run this script to deploy the server. This
  9. # includes:
  10. #
  11. # (*) Automatic downloading of the latest <server.zip> from Epic
  12. # (*) Installing the game configuration files, the mutators, the maps into the
  13. # instance
  14. # (*) Uploading all .pak package files to the redirect and automatic
  15. # generation of the required hashes for Game.ini
  16. # (*) The only thing that's left is for you to configure your gametypes,
  17. # add some maps, mutators, and get to fraggin'!!!
  18. #
  19. # Remote and Multiple Instances
  20. # -----------------------------
  21. # This script is designed to take files (maps, mutators, config) from
  22. # a project directory and deploy them to two remote servers, the game
  23. # instance and the redirect. Alternatively, these could be the same
  24. # computer but the redirect should be distinct from the game server
  25. # or downloads will make everyone lag. There is no restriction on
  26. # where you put the project directory but you need a place for
  27. # this script, all the maps, mutators to reside. You put maps,
  28. # rulesets, and configuration in this project directory and then run
  29. # this script to generate the instance, deploy to the server instance,
  30. # and deploy to the redirect. This is also used to manage multiple
  31. # server instances without as much duplication of effort. You need
  32. # enough hard drive space to store all the files for the server which
  33. # could be 10-20GB if you put lots of stuff on your HUB.
  34. # Rulesets:
  35. # ---------
  36. # Management of the rulesets (which provide the pre-populated gametypes, including
  37. # all the selected mutators, the map rotation, game options, and mutator
  38. # options) is greatly improved. There's some provided rulesets and some Disable.json
  39. # files which remove the pre-populated ones. You manage each rule as a .json configuration
  40. # file in the ./files/rulesets directory. The main part that is not automated
  41. # is the Resource Path for maps to put them in the rotation. You can get these from
  42. # UTCC, or from hosting a lan game with that map on your local game client,
  43. #
  44. # After you start a map, <alt>+<tab> to go to the UT4 console window and copy/paste
  45. # the name from the logs. It will be the big line and look like:
  46. #
  47. # ...Game=/?
  48. #
  49. # It will make sense when you see the files.
  50. #
  51. # UPDATE: or better yet there is a script on the forums that will extract the required resource names
  52. # from a directory of paks.
  53. #
  54. # What You Need:
  55. # -------------
  56. # (1) A Server
  57. # What you need to actually host this somewhere is a server to run the hub.
  58. # Ideally this is a machine with it's own internet line else it may slow
  59. # down when you watch NetFlix. Cloud hosting providers will provide you
  60. # a perfect machine for a fee/month.
  61. #
  62. # (2) A Redirect
  63. # On the same note as giving the server it's own internet line, content
  64. # from the server is sent to gamers from a third-party server. You additionally
  65. # need a 'redirect' server to host the files. This can be another server or I've
  66. # seen many public redirects which would be happy to spread some of that
  67. # Unreal Tournament Love. In case, we use a second cloud server.
  68. #
  69. # (3) A good attitude. You're almost done. There's just a few commands to learn
  70. # that this script provides. You need to put this script in the right directory
  71. # and then edit that directory path to the right place. After that, you can
  72. # invoke the script to install and configure your instance.
  73. #
  74. # Usage and Directions:
  75. # ---------------------
  76. #
  77. # Edit the exported parameters at the top of this file. You
  78. # certainly need to point this to your relevant servers or
  79. # be prepared to perform the file transfer manually. All
  80. # work is done in the PROJECT_DIR variable so you can see the files
  81. # in there. Use the source code as reference.
  82. #
  83. # Relevant directories (starting from PROJECT_DIR as base):
  84. #
  85. # - base Vanilla UT4 server as downloaded
  86. #
  87. # - files Custom Maps, mutators, rulesets, and config
  88. #
  89. # - instance Generated UT4 server application
  90. # (for transfer if moving to a remot eserver)
  91. # (YOU shouldn't need to edit this folder as
  92. # it gets updated by the script)
  93. #
  94. # Requirements: Linux server with installed dependencies, including wget,
  95. # scp, unzip, and sed. These utilities are used for the various file transfers
  96. # and operations, and will be installed on almost every Linux distribution by
  97. # default.
  98. #
  99. # Credits: Script modeled after the code in the unrelated easy-rsa
  100. # script which I found to be helpful in writing this script.
  101. #
  102. # Last tested with UT4 server: <version number>
  103. # Last updated: 2019-05-05
  104. # Configurable parameters (EDIT THESE):
  105. # -------------------------------------
  106. # Local directory to do everything in -- Point to a directory on the server
  107. # to be the base directory, storing all the UT4 files. If you don't care,
  108. # then just use /home/ut4/serv like provided.
  109. # Some good places that make sense, though technically anywhere will work:
  110. # * /home/ut4
  111. # * /opt/ut4
  112. # * /srv/ut4
  113. ####
  114. ####
  115. # BELOW has been moved to vars-dallas
  116. # ----------------------------------------
  117. #
  118. export PROJECT_DIR="/home/mathew/dev/zavage/ut4-server-ctl"
  119. #
  120. # # For creating RedirectReferences= Lines
  121. # export REDIRECT_PROTOCOL="https"
  122. # export REDIRECT_URL="ut4-redirect.zavage.net"
  123. #
  124. # # Remote server, if applicable, to upload instance and paks
  125. # # Only used for upload-redirects and upload-server commands.
  126. # # Format: username@host:/directory/on/remote/server
  127. # export REMOTE_GAME_HOST="ut4-linode:/home/ut4/serv"
  128. # export REMOTE_REDIRECT_HOST="mathewguest.com:/srv/ut4-redirect"
  129. # BELOW HERE, DEFAULTS SHOULD BE FINE. FEEL FREE TO EDIT IF YOU
  130. # KNOW WHAT YOU'RE DOING
  131. # Latest Linux Server.zip:
  132. export DOWNLOAD_URL="https://s3.amazonaws.com/unrealtournament/ShippedBuilds/%2B%2BUT%2BRelease-Next-CL-3525360/UnrealTournament-Server-XAN-3525360-Linux.zip"
  133. export DOWNLOAD_FILENAME="UnrealTournament-Server-XAN-3525360-Linux.zip"
  134. # If MD5 hash is provided, will verify the download:
  135. export DOWNLOAD_MD5="cad730ad6793ba6261f9a341ad7396eb"
  136. export SKIP_VALIDATE="false" # anything but 'true' will interactively ask
  137. # the user for variables.
  138. usage()
  139. {
  140. cat <<"EOF"
  141. Unreal Tournament 4 Server Build and Deploy Script
  142. A list of commands is shown below.
  143. List commands and usage:
  144. ./ut4-server-ctl.sh
  145. Show help for a specific command:
  146. ./ut4-server-ctl.sh --help <COMMAND>
  147. Here is the list of sub-commands with short syntax reminder:
  148. ./ut4-server-ctl.sh 1click-deploy
  149. ./ut4-server-ctl.sh clean-instance
  150. ./ut4-server-ctl.sh create-directories
  151. ./ut4-server-ctl.sh download-linux-server
  152. ./ut4-server-ctl.sh download-logs
  153. ./ut4-server-ctl.sh generate-instance
  154. ./ut4-server-ctl.sh start-server
  155. ./ut4-server-ctl.sh stop-server
  156. ./ut4-server-ctl.sh upload-redirects
  157. ./ut4-server-ctl.sh upload-server
  158. Typical Usage:
  159. 1) You need to either configure the remote server hostnames (both game server and remote redirect server)
  160. in the vars files. Edit vars with a text editor, or edit the defaults in this file, or manually type
  161. them interactively when prompted* (coming soon).
  162. e.g.:
  163. PROJECT_DIR="/path/to/this/script/directory/on/local/machine"
  164. REMOTE_GAME_HOST="54.123.456.10"
  165. REMOTE_GAME_DIR="/home/ut4/hub-instance"
  166. REMOTE_REDIRECT_HOST="45.321.654.10"
  167. REMOTE_REDIRECT_DIR="/srv/ut4-redirect/"
  168. 2) You need to download the latest Linux Server release from Epic. Do
  169. this with the 'download-server' command.
  170. e.g.:
  171. ./ut4-server-ctl.sh download-server
  172. 3) Add and configure custom maps, mutators, rulesets, and hub configuration to your *local* project folder.
  173. This is done by modifying the files in the project directory. With the current environment variables,
  174. this is set to be:
  175. "$PROJECT_DIR"
  176. This is the fun part! Connect with UTCC or UTZONE.DE (unaffiliated) to find custom content to put on
  177. your hub.
  178. 4) 1click-deploy to update the remote hub and redirect with your latest content. You're done! Rinse and repeat.
  179. e.g.:
  180. ./ut4-server-ctl.sh 1click-deploy
  181. Alternatively, this command is equivalent to running the separate commands. If you'd like more fine-grained
  182. control, you can run them individually.
  183. ./ut4-server-ctl.sh generate-instance
  184. ./ut4-server-ctl.sh upload-redirects
  185. ./ut4-server-ctl.sh upload-server
  186. ./ut4-server-ctl.sh restart-server
  187. EOF
  188. }
  189. cmd_help()
  190. {
  191. cmd="$1"
  192. case "$cmd" in
  193. 1click-deploy)
  194. cat <<"EOF"
  195. 1click-deploy)
  196. Executes all the commands needed to update a remote game server. This is
  197. equivalent to running these 3 commands:
  198. 1 - generate-instance (installing config, maps, and mutators)
  199. 2 - upload-server (copying hub instance to remote game server)
  200. 3 - upload-redirects (copying customized content to remote redirect server)
  201. EOF
  202. ;;
  203. clean-instance)
  204. cat <<"EOF"
  205. clean-instance)
  206. This command will delete all files on the generated instance on the LOCAL machine.
  207. Useful for if you ever delete a map or mutator and wan't it off the server. To do that,
  208. modify the files you need, clean-instance, and then generate-instance from scratch.
  209. EOF
  210. ;;
  211. create-directories)
  212. cat <<"EOF"
  213. EOF
  214. ;;
  215. download-linux-server)
  216. cat <<"EOF"
  217. download-linux-server)
  218. Downloads the latest Linux server release from Epic.
  219. EOF
  220. ;;
  221. download-logs)
  222. cat <<"EOF"
  223. download-logs)
  224. Downloads the instance logs from the remote game server while clearing
  225. them on the server.
  226. EOF
  227. ;;
  228. generata-instance)
  229. cat <<"EOF"
  230. generate-instance)
  231. Installs the game configuration, maps, and mutators into the *local*
  232. instance directory. The next step after this has been done is to
  233. upload-server to copy the instance directory to the remote game server.
  234. EOF
  235. ;;
  236. restart-server)
  237. cat <<"EOF"
  238. restart-server)
  239. Equivalent to stop-server + start-server.
  240. EOF
  241. ;;
  242. start-server)
  243. cat <<"EOF"
  244. start-server)
  245. Turns on the remote game server Unreal Tournament 4 Linux Hub instance. Will run in
  246. an infinite loop until stopped.
  247. EOF
  248. ;;
  249. stop-server)
  250. cat <<"EOF"
  251. stop-server)
  252. Turns off and kills all remote game server instances.
  253. EOF
  254. ;;
  255. upload-redirects)
  256. cat <<"EOF"
  257. upload-redirects)
  258. Uploads customized content and sanitized server configuration to remote
  259. redirect server.
  260. EOF
  261. ;;
  262. upload-server)
  263. cat <<"EOF"
  264. upload-server)
  265. Installs the generated UT4 Hub instance to the configured remote game
  266. server.
  267. EOF
  268. ;;
  269. ""|help|-h|--help|--usage)
  270. usage
  271. ;;
  272. *)
  273. echo "Unknown command '$cmd'. Invoke script for usage help."
  274. ;;
  275. esac
  276. }
  277. oneclick_deploy()
  278. {
  279. generate_instance
  280. upload_redirects
  281. upload_server
  282. }
  283. clean_instance()
  284. {
  285. _UT4_print Clearing .pak folder...
  286. (set -x # NOTE(MG) set -x echoes all commands that the script does.
  287. # The user will be able to see the computed commands as the
  288. # script runs them.
  289. rm -rv "$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Content/Paks/*
  290. )
  291. }
  292. create_directories()
  293. {
  294. (set -x
  295. mkdir -p "$PROJECT_DIR"/base
  296. mkdir -p "$PROJECT_DIR"/files/config
  297. mkdir -p "$PROJECT_DIR"/files/maps
  298. mkdir -p "$PROJECT_DIR"/files/mutators
  299. mkdir -p "$PROJECT_DIR"/files/rulesets
  300. mkdir -p "$PROJECT_DIR"/files/unused
  301. )
  302. }
  303. download_linux_server()
  304. {
  305. cd "$PROJECT_DIR"/base
  306. # Only download server when hasn't already been downloaded
  307. if [ ! -f "$PROJECT_DIR"/base/"$DOWNLOAD_FILENAME" ] ; then
  308. _UT4_print "Downloading Linux Server Archive..."
  309. (set -x
  310. wget "$DOWNLOAD_URL" --show-progress
  311. )
  312. _UT4_print "Verifying archive is the file we're expecting"
  313. md5=$(md5sum "$DOWNLOAD_FILENAME" | cut -d' ' -f1)
  314. if [ "$md5" != "$DOWNLOAD_MD5" ] ; then
  315. server.zip echo Downloaded '"$DOWNLOAD_FILENAME"' checksum FAILED.
  316. echo The downloaded zip was not the exact file we\'re expecting.
  317. echo Refusing to continue.
  318. return 1
  319. else
  320. echo The downloaded zip checksum matched what we expected: "$DOWNLOAD_MD5"
  321. fi
  322. else
  323. _UT4_print "UT4 Server .zip already downloaded"
  324. _UT4_print "You need to invoke this command manually if you want to delete these files. (Being extra safe)"
  325. _UT4_print "DELETE COMMAND (manual): cd "$PROJECT_DIR"/base && rm -rv *" && cd -
  326. cd - >/dev/null
  327. return 1
  328. fi
  329. # Extract ut4 linux server into ./base (with overwrite)
  330. _UT4_print "Extracting archive..."
  331. (set -x
  332. unzip -o "$DOWNLOAD_FILENAME"
  333. # rm "$DOWNLOAD_FILENAME"
  334. )
  335. cd - >/dev/null
  336. }
  337. download_logs()
  338. {
  339. _UT4_print "Downloading the game logs from the server (clearing them also)"
  340. # Transfer log directory files from remote game server to local:
  341. (set -x
  342. rsync -ravzp "$REMOTE_GAME_HOST":"$REMOTE_GAME_DIR"/LinuxServer/UnrealTournament/Saved/Logs/ "$CONFIG_DIR"/downloaded-logs/
  343. )
  344. # Delete logs on remote game server if successfully transferred to local:
  345. if [ $? -eq 0 ] ; then
  346. (set -x
  347. :
  348. # ssh "$REMOTE_GAME_HOST" rm "$REMOTE_GAME_DIR"'/LinuxServer/UnrealTournament/Saved/Logs/* -r'
  349. )
  350. fi
  351. }
  352. generate_instance()
  353. {
  354. _UT4_print "Generating server instance from custom files..."
  355. (set -x
  356. rsync -ravzp "$PROJECT_DIR"/base/LinuxServer "$PROJECT_DIR"/instance/
  357. cp "$PROJECT_DIR"/start-server.sh "$PROJECT_DIR"/instance/
  358. cp "$PROJECT_DIR"/stop-server.sh "$PROJECT_DIR"/instance/
  359. )
  360. # _first_run
  361. _install_config
  362. _install_paks
  363. _install_redirect_lines
  364. _install_rulesets
  365. }
  366. restart_server()
  367. {
  368. stop_server
  369. start_server
  370. }
  371. start_server()
  372. {
  373. _UT4_print "Starting server!!"
  374. (set -x
  375. nohup ssh "$REMOTE_GAME_HOST" "$REMOTE_GAME_DIR"/start-server.sh &
  376. )
  377. }
  378. stop_server()
  379. {
  380. _UT4_print "Stopping all servers!"
  381. (set -x
  382. ssh "$REMOTE_GAME_HOST" "$REMOTE_GAME_DIR"/stop-server.sh
  383. )
  384. }
  385. upload_redirects()
  386. {
  387. PAKS_DIR="$PROJECT_DIR"/files
  388. _UT4_print "Uploading redirects (maps, mutators, etc.) to download server"
  389. (set -x
  390. rsync -rvz --delete --exclude "*.md5" --exclude 'unused' --exclude ".KEEP" --exclude Mods.db "$PAKS_DIR"/ "$REMOTE_REDIRECT_HOST"
  391. )
  392. # _UT4_print "Uploading md5sum files to redirect"
  393. # mkdir /tmp/ut4-md5sums
  394. # for f in $(ls "$PAKS_DIR"); do
  395. # md5sum "$PAKS_DIR"/"$f" | cut -d' ' -f1 > /tmp/ut4-md5sums/"$f".md5
  396. # done
  397. # rsync -rvz --exclude ".KEEP" /tmp/ut4-md5sums/ "$REMOTE_REDIRECT_HOST"
  398. # Hide admin password from redirect:
  399. # TODO(MG) hardcoded paths and hostname >.<
  400. # (on the server)
  401. gameini="/srv/ut4-redirect.zavage.net/config/Game.ini"
  402. engineini="/srv/ut4-redirect.zavage.net/config/Engine.ini"
  403. (set -x
  404. ssh mathewguest.com sed -i /ServerInstanceID=/c\ServerInstanceID=Hidden "$gameini"
  405. ssh mathewguest.com sed -i /RconPassword=/c\RconPassword=Hidden "$engineini"
  406. rsync -vz "$PROJECT_DIR"/ut4-server-ctl.sh "$REMOTE_REDIRECT_HOST"
  407. )
  408. # Fix permissions for redirect:
  409. (set -x
  410. ssh mathewguest.com 'chown http.http /srv/ut4-redirect.zavage.net -R'
  411. )
  412. }
  413. upload_server()
  414. {
  415. _UT4_print "Uploading customized server"
  416. # Exclude everything we don't want to be
  417. # overwritten on the server instance.
  418. # (Hint: uncomment --dry-run to safely verify command works as intended)
  419. (set -x
  420. rsync -ravzp \
  421. --delete \
  422. --exclude ".KEEP" \
  423. --exclude "Mods.db" \
  424. --exclude "Mod.ini" \
  425. --exclude "Logs" \
  426. --exclude "ut4-server.log" \
  427. --exclude "Saved/*.ai" \
  428. --exclude "Saved/Crashes/*" \
  429. --exclude "Saved/Logs/*" \
  430. "$PROJECT_DIR"/instance/ \
  431. "$REMOTE_GAME_HOST":"$REMOTE_GAME_DIR"
  432. rsync -avzp "$PROJECT_DIR"/ut4-server-ctl.sh "$REMOTE_GAME_HOST":"$REMOTE_GAME_DIR"
  433. scp "$PROJECT_DIR"/instance/ut4-server.service "$REMOTE_GAME_HOST":/etc/systemd/system/
  434. ssh "$REMOTE_GAME_HOST" chown ut4.ut4 "$REMOTE_GAME_DIR" -R
  435. )
  436. }
  437. _first_run()
  438. {
  439. _UT4_print "Starting instance once to get UID."
  440. _UT4_print "Unfortunately, this takes 20 seconds. Just wait."
  441. (set -x
  442. cd "$PROJECT_DIR"/instance/LinuxServer/Engine/Binaries/Linux
  443. chmod 770 UE4Server-Linux-Shipping
  444. ./UE4Server-Linux-Shipping UnrealTournament UT-Entry?Game=Lobby -log &>/dev/null &
  445. cd - >/dev/null
  446. )
  447. _UT4_print "sleeping 20 seconds and then we'll kill the server we started just now."
  448. sleep 20
  449. stop_server
  450. # TODO(MG) get uid and export
  451. }
  452. _install_config()
  453. {
  454. f="Game.ini"
  455. _UT4_print Installing file: "$f"
  456. (set -x
  457. cp "$CONFIG_DIR"/"$f" "$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Saved/Config/LinuxServer/
  458. )
  459. f="Engine.ini"
  460. _UT4_print Installing file: "$f"
  461. (set -x
  462. cp "$CONFIG_DIR"/"$f" "$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Saved/Config/LinuxServer/
  463. )
  464. }
  465. _install_paks()
  466. {
  467. _UT4_print Installing maps...
  468. (set -x
  469. rsync -ravzp "$PROJECT_DIR"/files/maps/ "$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Content/Paks/
  470. )
  471. _UT4_print Installing mutators...
  472. (set -x
  473. rsync -ravzp "$PROJECT_DIR"/files/mutators/ "$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Content/Paks/
  474. )
  475. }
  476. _install_redirect_lines()
  477. {
  478. _UT4_print Generating redirect references...
  479. MOD_DIR="$PROJECT_DIR"/files
  480. shopt -s nocaseglob
  481. echo > /tmp/ut4-server-ctl-references
  482. for f in "$MOD_DIR"/**/*.pak ; do
  483. # f = full path
  484. RELATIVE_PATH=${f#"$MOD_DIR"/} # <- Trims /root/path/up/until/$MOD_DIR
  485. # example output: maps/DM-Rankin.pak
  486. # mutators/GodMode.pak
  487. BASENAME=$(basename "$f") # DM-Rankin.pak
  488. # Exclusions:
  489. # - exclude the UnrealTournament pak
  490. if [ "$BASENAME" = "UnrealTournament-LinuxServer.pak" ] ; then
  491. continue
  492. fi
  493. # Exclude any files in the 'unused' directory:
  494. FIRSTDIR=$(echo "$RELATIVE_PATH" | cut -d'/' -f1)
  495. if [ "$FIRSTDIR" = "unused" ] ; then
  496. continue
  497. fi
  498. MD5=$(md5sum "$f"| cut -d' ' -f1)
  499. EXTENSION="${BASENAME##*.}" # .pak
  500. FILENAME="${BASENAME%.*}" # DM-Rankin
  501. # line continues that way --> --> -->
  502. LINE="RedirectReferences=(PackageName=\""$FILENAME"\",PackageURLProtocol=\"$REDIRECT_PROTOCOL\",PackageURL=\""$REDIRECT_URL"/"$RELATIVE_PATH"\",PackageChecksum=\""$MD5"\")"
  503. echo "$LINE"
  504. echo "$LINE" >> /tmp/ut4-server-ctl-references
  505. done
  506. _UT4_print Installing redirect references into Game.ini...
  507. FILENAME="$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Saved/Config/LinuxServer/Game.ini
  508. LINE_NUMBER=17 # TODO(MG) Not hard-coded
  509. # Delete
  510. sed -i '/RedirectReferences/d' "$FILENAME"
  511. # Insert into Game.ini
  512. awk '1; NR==11 {system("cat /tmp/ut4-server-ctl-references")}' "$FILENAME" > /tmp/ut4-server-ctl-game.ini
  513. cp /tmp/ut4-server-ctl-game.ini "$FILENAME"
  514. cat "$FILENAME"
  515. }
  516. _install_rulesets()
  517. {
  518. _UT4_print Concatenating rulesets for game modes...
  519. SRC_DIR="$PROJECT_DIR"/files/rulesets
  520. OUT_DIR="$PROJECT_DIR"/instance/LinuxServer/UnrealTournament/Saved/Config/Rulesets
  521. OUT_FILENAME="$OUT_DIR"/ruleset.json
  522. mkdir -pv "$OUT_DIR"
  523. echo OUT_FILENAME="$OUT_FILENAME"
  524. echo {\"rules\":[ > "$OUT_FILENAME"
  525. for f in "$SRC_DIR"/*.json ; do
  526. cat "$f" >> $OUT_FILENAME
  527. done
  528. echo "]}" >> "$OUT_FILENAME"
  529. echo output ruleset is at "$OUT_FILENAME"
  530. }
  531. _validate_env_vars()
  532. {
  533. # TODO(MG) Add which user we are running this under
  534. _UT4_print Are these environment variables correct?
  535. echo 'PROJECT_DIR: '"$PROJECT_DIR"
  536. echo
  537. echo 'DOWNLOAD_URL: '"$DOWNLOAD_URL"
  538. echo 'DOWNLOAD_FILENAME: '"$DOWNLOAD_FILENAME"
  539. echo 'DOWNLOAD_MD5: '"$DOWNLOAD_MD5"
  540. echo 'REDIRECT_PROTOCOL: '"$REDIRECT_PROTOCOL"
  541. echo 'REDIRECT_URL: '"$REDIRECT_URL"
  542. echo 'REMOTE_GAME_HOST: '"$REMOTE_GAME_HOST"
  543. echo 'REMOTE_GAME_DIRECTORY: '"$REMOTE_GAME_DIR"
  544. echo 'REMOTE_REDIRECT_HOST: '"$REMOTE_REDIRECT_HOST"
  545. echo
  546. read -p "Continue with above configuration? " -n 1 -r
  547. echo
  548. if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
  549. exit 1
  550. fi
  551. }
  552. # Wrapper prints colored log messages which stand out to communicate what
  553. # the script is doing to the user.
  554. _UT4_print()
  555. {
  556. RED='\033[0;31m'
  557. NC='\033[0m'
  558. echo -e "UT4>${RED} "$@" ${NC}"
  559. }
  560. main()
  561. {
  562. cmd="$1"
  563. _validate_env_vars
  564. case "$cmd" in
  565. 1click-instance)
  566. shift
  567. oneclick_deploy "$@"
  568. exit "$?";;
  569. clean-instance)
  570. shift
  571. clean_instance "$@"
  572. exit "$?";;
  573. create-directories)
  574. shift
  575. create_directories "$@"
  576. exit "$?";;
  577. download-linux-server)
  578. shift
  579. download_linux_server "$@"
  580. exit "$?";;
  581. download-logs)
  582. shift
  583. download_logs "$@"
  584. exit "$?";;
  585. generate-instance)
  586. shift
  587. generate_instance "$@"
  588. exit "$?";;
  589. restart-server)
  590. shift
  591. restart_server "$@"
  592. exit "$?";;
  593. start-server)
  594. shift
  595. start_server "$@"
  596. exit "$?";;
  597. stop-server)
  598. shift
  599. stop_server "$@"
  600. exit "$?";;
  601. upload-redirects)
  602. shift
  603. upload_redirects "$@"
  604. exit "$?";;
  605. upload-server)
  606. shift
  607. upload_server "$@"
  608. exit "$?";;
  609. ""|help|-h|--help|--usage)
  610. shift
  611. cmd_help "$@"
  612. exit 0;;
  613. *)
  614. cmd_help "$@"
  615. exit 1;;
  616. esac
  617. }
  618. main "$@"