fn_select 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # LGSM fn_select function
  3. # Author: Ilija Matoski (ilijamt@gmail.com)
  4. # Website: https://matoski.com
  5. # Version: 010316
  6. # Description: Automatically selects a created server from the available ones defined in the root
  7. # If no server files found <name>.<appid> it will default to the data in the game file
  8. if [ $usesrvcfg -eq 1 ]; then
  9. if [ -z "$appid" ]; then
  10. fn_printwarn "appid not found for $gamename, this is not supported.\n\n"
  11. exit
  12. fi
  13. # get all the available configs for the appid
  14. cfgs=()
  15. filelist=(`find $rootdir -type f -name "*.$appid"`)
  16. for file in "${filelist[@]}"; do
  17. cfg=${file:${#rootdir}+1}
  18. cfg=${cfg:0:${#cfg} - 4}
  19. cfgs+=("$cfg")
  20. done
  21. # create the append extra list for the options
  22. appendextra=$(printf "|%s" "${cfgs[@]}")
  23. appendextra=${appendextra:1}
  24. loadcfg=
  25. invalidcfg=0
  26. reinit=0
  27. # if we don't have any config files proced as normal so skip the next part
  28. if [ ${#cfgs[@]} -eq 1 ]; then
  29. # we have only one config file so we load that one only unless the user specifies it manually, then we verify
  30. loadcfg="${cfgs[0]}";
  31. if [ ! -z "$getsrvcfg" ] && [ ! -f "${getsrvcfg}.${appid}" ]; then
  32. invalidcfg=1
  33. fi
  34. elif [ ${#cfgs[@]} -gt 0 ]; then
  35. # we have more than one files available so we continue on the verification if the file is present
  36. loadcfg="$getsrvcfg";
  37. if [ -z "$getsrvcfg" ] || [ ! -f "${getsrvcfg}.${appid}" ]; then
  38. invalidcfg=1
  39. fi
  40. else
  41. # we don't have anything so we need to continue on without touching anything
  42. reinit=0
  43. loadcfg=
  44. fi
  45. # it's invalid cfg setting
  46. if [ $invalidcfg -eq 1 ]; then
  47. fn_printwarn "$getsrvcfg configuration file doesn't exist, use one of the available ones ($appendextra)\n"
  48. getopt=
  49. fn_getopt
  50. else
  51. if [ ! -z "$loadcfg" ] && [ -f "${getsrvcfg}.${appid}" ]; then
  52. # everything OK, load the config file and reinit the variables
  53. source "${loadcfg}.${appid}"
  54. reinit=1
  55. fi
  56. fi
  57. if [ $reinit -eq 1 ]; then
  58. case "$appid" in
  59. *)
  60. lockselfname=".${servicename}.lock"
  61. servercfg="${servicename}.cfg"
  62. servercfgfullpath="${servercfgdir}/${servercfg}"
  63. scriptlog="${scriptlogdir}/${servicename}-script.log"
  64. consolelog="${consolelogdir}/${servicename}-console.log"
  65. emaillog="${scriptlogdir}/${servicename}-email.log"
  66. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  67. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  68. ;;
  69. esac
  70. fi
  71. fi