download_doom_map.ksh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. set +x
  3. function show_usage {
  4. printf "Usage: %s [options [parameters]]\n" "$0"
  5. printf "\n"
  6. printf "Options:\n"
  7. printf " -u|--url [file download url]\n"
  8. printf " -f|--file [file name already downloaded in /tmp directory]\n"
  9. printf " -n|--name [directory name]\n"
  10. printf " -i|--iwad [doom|doom2|tnt|plutonia|heretic|hexen]\n"
  11. printf " -e|--engine [vanilla|nolimit|boom|mbf21|zdoom]\n"
  12. printf "\n"
  13. printf " -h|--help, Print help\n"
  14. exit
  15. }
  16. if [ "$1" == "--help" ] || [ "$1" == "-h" ];then
  17. show_usage
  18. fi
  19. if [ -z "$1" ]; then
  20. show_usage
  21. fi
  22. while [ -n "$1" ]; do
  23. case "$1" in
  24. --url|-u)
  25. shift
  26. echo "INFO: download url: $1"
  27. param_download_url=$1
  28. ;;
  29. --file|-f)
  30. shift
  31. echo "INFO: already downloaded file name: $1"
  32. param_already_downloaded_file_name=$1
  33. ;;
  34. --name|-n)
  35. shift
  36. echo "INFO: map name: $1"
  37. param_map_name=$1
  38. ;;
  39. --game|-i)
  40. shift
  41. echo "INFO: iwad: $1"
  42. param_iwad=$1
  43. ;;
  44. --engine|-e)
  45. shift
  46. echo "INFO: engine: $1"
  47. param_engine=$1
  48. ;;
  49. *)
  50. show_usage
  51. ;;
  52. esac
  53. shift
  54. done
  55. ### Configuration
  56. if [ -z "$param_download_url" ] && [ -z "$param_already_downloaded_file_name" ]; then
  57. show_usage
  58. fi
  59. if [ -z "$param_map_name" ]; then
  60. show_usage
  61. fi
  62. if [ -z "$param_iwad" ]; then
  63. show_usage
  64. fi
  65. if [ -z "$param_engine" ]; then
  66. show_usage
  67. fi
  68. config_base_dir=$HOME/games/doom
  69. config_download_file_path=$config_base_dir/wads/$param_iwad/$param_engine/$param_map_name
  70. ### check parameter values
  71. doom_game="doom doom2 tnt plutonia heretic hexen"
  72. echo "$doom_game" | tr ' ' '\n' | while read -r item; do
  73. if [ "$item" = "$param_iwad" ]; then touch match; fi
  74. done
  75. if [ ! -f match ]; then echo "ERROR: $param_iwad is not a valid option, valid options are: $doom_game"; exit 1; fi; rm match
  76. engine="vanilla nolimit boom mbf21 zdoom"
  77. echo "$engine" | tr ' ' '\n' | while read -r item; do
  78. if [ "$item" = "$param_engine" ]; then touch match; fi
  79. done
  80. if [ ! -f match ]; then echo "ERROR: $param_engine is not a valid option, valid options are: $engine"; exit 1; fi; rm match
  81. ### Script
  82. if [ -d $config_download_file_path ]; then
  83. echo "WARNING: map directory $config_download_file_path already exists"
  84. ls -lahF $config_download_file_path
  85. exit 0
  86. fi
  87. if [ ! -f /tmp/$param_already_downloaded_file_name ] && [ -z "$param_download_url" ]; then
  88. cd /tmp || return
  89. curl -OL "$param_download_url"
  90. echo "INFO: file downloaded to $config_download_file_path directory"
  91. fi
  92. if [ -f /tmp/$param_download_url ]; then
  93. cd || return
  94. mkdir -p $config_download_file_path
  95. cd $config_download_file_path
  96. cp -v /tmp/$param_download_url .
  97. ls -lahF $config_download_file_path
  98. echo "INFO: file moved to $config_download_file_path directory"
  99. fi