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