fn_select 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if [ -z "$getsrvcfg" ]; then
  48. fn_printwarn "configuration file not specified, use one of the available ones ($appendextra)\n"
  49. else
  50. fn_printwarn "$getsrvcfg configuration file does not exist, use one of the available ones ($appendextra)\n"
  51. fi
  52. getopt=
  53. fn_getopt
  54. else
  55. if [ ! -z "$loadcfg" ] && [ -f "${getsrvcfg}.${appid}" ]; then
  56. # everything OK, load the config file and reinit the variables
  57. source "${loadcfg}.${appid}"
  58. reinit=1
  59. fi
  60. fi
  61. if [ $reinit -eq 1 ]; then
  62. case "$appid" in
  63. *)
  64. lockselfname=".${servicename}.lock"
  65. servercfg="${servicename}.cfg"
  66. servercfgfullpath="${servercfgdir}/${servercfg}"
  67. scriptlog="${scriptlogdir}/${servicename}-script.log"
  68. consolelog="${consolelogdir}/${servicename}-console.log"
  69. emaillog="${scriptlogdir}/${servicename}-email.log"
  70. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  71. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  72. ;;
  73. esac
  74. fi
  75. fi