genconf.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env bash
  2. ## Creates an initial mtmock.conf and tries to set the
  3. ## SCRIPTDIR and WORLDDIR members.
  4. SCRIPTDIRS="/usr/share/games/minetest/builtin /usr/share/minetest/builtin"
  5. WORLDDIRS=$HOME/.minetest/worlds
  6. help() {
  7. cat <<-_EOF_
  8. usage: $(basename $0) [-h] [-D SRCHDIR]
  9. -h, --help
  10. show this help page
  11. -D SRCHDIR
  12. adds SRCHDIR to the internal list of search directories
  13. To successfully execute the unit tests, the code defined in mtmock.lua
  14. has to be complemented with some directory locations. Those locations
  15. are expected to be defined via the LUA file mtmock.conf. This script
  16. aids in the creation of that file by scanning some predefined directories
  17. for the proper locations and writes the file to the current directory.
  18. _EOF_
  19. exit 0
  20. }
  21. while [ $# -gt 0 ]; do
  22. case $1 in
  23. -h|--help)
  24. help
  25. ;;
  26. -D)
  27. shift
  28. SCRIPTDIRS="$1 ${SCRIPTDIRS}"
  29. WORLDDIRS="$1 ${WORLDDIRS}"
  30. ;;
  31. esac
  32. shift
  33. done
  34. for sd in ${SCRIPTDIRS}; do
  35. if [ -d ${sd}/builtin ]; then
  36. SCRIPTDIR=${sd}/builtin
  37. elif [ -d ${sd}/common ]; then
  38. SCRIPTDIR=${sd}
  39. break
  40. fi
  41. done
  42. for wd in ${WORLDDIRS}; do
  43. if [ -d ${wd}/worlds ]; then
  44. WORLDDIR=${wd}/worlds
  45. elif [ -d ${wd} ]; then
  46. WORLDDIR=${wd}
  47. break
  48. fi
  49. done
  50. if [ -z "${SCRIPTDIR}" ]; then
  51. echo "*** $(basename $0): cannot find minetest LUA script directory" >>/dev/stderr
  52. exit 1
  53. elif [ -z "${WORLDDIR}" ]; then
  54. echo "*** $(basename $0): cannot find minetest world directory" >>/dev/stderr
  55. exit 2
  56. fi
  57. cat >mtmock.conf <<-EOF
  58. -- path to minetest's builtin LUA scrips
  59. mtmock.SCRIPTDIR='${SCRIPTDIR}/'
  60. -- path to minetest's worlds
  61. mtmock.WORLDDIR='${WORLDDIR}/'
  62. -- path to mods
  63. mtmock.MODDIR='$(realpath ../mods)/'
  64. EOF