make_lang_addon.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. ignore_directories=( world-1 world-2 bonus-1 bonus-2 bonus-3 menu-principale )
  3. final_destination="https://raw.githubusercontent.com/SuperTux/addons/master/langpacks"
  4. languages=()
  5. outdir=""
  6. RED='\033[0;31m'
  7. NC='\033[0m' # No Color
  8. get_languages() {
  9. langs=()
  10. langs=$(find "$1" -name "*.po" -exec basename {} \; | uniq | cut -d'.' -f1)
  11. languages=($(printf "%s\n" "${langs[@]}" | sort | uniq -c | awk '{ print $2 }'))
  12. }
  13. # Usage: inarray "$value" "${array[@]}"
  14. inarray() { local n=$1 h; shift; for h; do [[ $n = "$h" ]] && return; done; return 1; }
  15. echo "${RED}Gathering available languages...${NC}"
  16. outdir="$1"
  17. langpack_dir="$outdir/langpacks"
  18. get_languages "$outdir"
  19. mkdir -p "$langpack_dir"
  20. REPO_INDEX_FILE="$langpack_dir/index_to_change.nfo"
  21. echo > "$REPO_INDEX_FILE" # Clear file
  22. echo "; ###### LANGUAGE PACKS BEGIN ######" >> "$REPO_INDEX_FILE"
  23. for i in ${languages[@]}; do
  24. echo "${RED}Creating language pack for $i...${NC}"
  25. # create outer directory:
  26. mkdir -p "$langpack_dir/langpack-$i"
  27. #create NFO file:
  28. NFO_FILE="$langpack_dir/langpack-$i/langpack-$i.nfo"
  29. echo "(supertux-addoninfo\n\
  30. (id \"langpack-$i\")\n\
  31. (version 1)\n\
  32. (type \"languagepack\")\n\
  33. (title \"$i\")\n\
  34. (author \"Various\")\n\
  35. (license \"GPL 2+ / CC-by-sa 3.0\")\n\
  36. )" >> "$NFO_FILE"
  37. # create inner directory:
  38. mkdir -p "$langpack_dir/langpack-$i/langpack-$i"
  39. # copy language files:
  40. find "$outdir" -name "$i.po" | while read line; do
  41. basedir=$(dirname "$line")
  42. curr_langpack_dir="$langpack_dir/langpack-$i/langpack-$i"
  43. # Get name of parent directory:
  44. dir_name=$(basename "$basedir")
  45. # Remove supertux.{something} from directory name:
  46. dir_name=${dir_name/supertux./}
  47. # Check if directory is in ignore list:
  48. if inarray "${dir_name}" "${ignore_directories[@]}"; then
  49. continue
  50. fi
  51. # Copy relevant files to the langpack directory:
  52. mkdir -p "$curr_langpack_dir/${dir_name}"
  53. cp "$basedir/$i.po" "$curr_langpack_dir/${dir_name}" 2> /dev/null
  54. done
  55. # zip the language files:
  56. cd "$langpack_dir/langpack-$i"
  57. zip -9 -q -r "$langpack_dir/langpack-$i.zip" "."
  58. cd ..
  59. FILE_HASH=$(md5 -q "$langpack_dir/langpack-$i.zip")
  60. # update add-on info script:
  61. echo "(supertux-addoninfo\n\
  62. (id \"langpack-$i\")\n\
  63. (version 1)\n\
  64. (type \"languagepack\")\n\
  65. (title \"$i\")\n\
  66. (author \"Various\")\n\
  67. (license \"GPL 2+ / CC-by-sa 3.0\")\n\
  68. (url \"$final_destination/langpack-$i.zip\")\n\
  69. (md5 \"$FILE_HASH\")\n\
  70. )" >> "$REPO_INDEX_FILE"
  71. # remove previously created folder:
  72. rm -rf "langpack-$i/"
  73. done
  74. echo "; ###### LANGUAGE PACKS END ######" >> "$REPO_INDEX_FILE"
  75. # end