File: make_html_for_git_docs.sh

package info (click to toggle)
megaglest 3.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,844 kB
  • ctags: 18,191
  • sloc: cpp: 144,280; ansic: 11,861; sh: 3,233; perl: 1,904; python: 1,751; objc: 142; asm: 42; makefile: 24
file content (118 lines) | stat: -rwxr-xr-x 4,356 bytes parent folder | download | duplicates (4)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
#
# Use this script to make autodocumentation for docs in data's repository
# ----------------------------------------------------------------------------
# 2015 Written by filux <heross(@@)o2.pl>
# Copyright (c) 2015-2016 under GNU GPL v3.0+
LANG=C

if [ "$1" = "" ]; then
	techtree="megapack"
else
	techtree="$1"
fi
if [ "$2" = "" ]; then
	rel_path_docs_icons="../../techs"
else
	rel_path_docs_icons="$2"
fi
if [ "$3" = "" ]; then
	rel_path_tech_test="../../../../data/glest_game/techs"
else
	rel_path_tech_test="$3"
fi
if [ "$4" = "" ]; then
	remote_logo="https://megaglest.org/uploads/megaglest2011/logo/logo.png"
else
	remote_logo="$4"
fi
if [ "$5" = "" ]; then
	remote_footer_logo="https://megaglest.org/uploads/megaglest2011/logo/gpl_osi.png"
else
	remote_footer_logo="$5"
fi
SCRIPTDIR="$(dirname "$(readlink -f "$0")")"
cd "$SCRIPTDIR"
rm -rf html; sleep 0.1s
mkdir -p html/images
sed "s|^generate_g3d_images = .*|generate_g3d_images = 0|" "$techtree.ini" > "$techtree-temp.ini"
if [ "$(which curl 2>/dev/null)" != "" ]; then
	if [ "$(grep -c "$remote_logo" "$techtree-temp.ini")" -gt "0" ]; then
		curl -L -s "$remote_logo" -o "html/images/logo.png"
		if [ "$?" -eq "0" ]; then sed -i "s|$remote_logo|images/logo.png|" "$techtree-temp.ini"; sleep 0.1s; fi
	fi
	if [ "$(grep -c "$remote_footer_logo" "$techtree-temp.ini")" -gt "0" ]; then
		curl -L -s "$remote_footer_logo" -o "html/images/footer_logo.png"
		if [ "$?" -eq "0" ]; then sed -i "s|$remote_footer_logo|images/footer_logo.png|" "$techtree-temp.ini"; sleep 0.1s; fi
	fi
else
	echo "Downloading tool 'curl' DOES NOT EXIST on this system, please install it."
fi
./convert_faction_xml2html.pl "$techtree-temp.ini"

cd html
icons_list1="$(grep -o "images/[^/ ]*/[^/ ]*/[^. ]*.bmp" *.html)"
icons_list2="$(grep -o "images/[^/ ]*/[^/ ]*/[^. ]*.jpg" *.html)"
icons_list3="$(grep -o "images/[^/ ]*/[^/ ]*/[^. ]*.png" *.html)"
icons_list="$(echo -e "$icons_list1 $icons_list2 $icons_list3" | xargs)"
echo ">>> replacing icon for (unit='|', upgrade='\', resource='/') ..."
for icon_file in $icons_list; do
	filename="$(echo "$icon_file" | awk -F ':' '{print $1}')"
	icon="$(echo "$icon_file" | awk -F ':' '{print $2}')"

	faction="$(echo "$icon" | awk -F '/' '{print $2}')"
	uu_name="$(echo "$icon" | awk -F '/' '{print $3}')"
	bmp_file="$(echo "$icon" | awk -F '/' '{print $4}')"
	find_file="$(find $rel_path_tech_test/$techtree/factions/$faction -type f -name "$bmp_file")"

	echo "$find_file" | grep -q "factions/$faction/upgrades"
	if [ "$?" -eq "0" ]; then :
		sed -i "s|images/$faction/$uu_name/$bmp_file|$rel_path_docs_icons/$techtree/factions/$faction/upgrades/$uu_name/images/$bmp_file|" "$filename"
		echo -n "\\"
	else
		echo "$find_file" | grep -q "factions/$faction/units"
		if [ "$?" -eq "0" ]; then :
			sed -i "s|images/$faction/$uu_name/$bmp_file|$rel_path_docs_icons/$techtree/factions/$faction/units/$uu_name/images/$bmp_file|" "$filename"
			echo -n "|"
		fi
	fi
	sleep 0.01s
done
icons_list1="$(grep -o "images/resources/[^. ]*.bmp" *.html)"
icons_list2="$(grep -o "images/resources/[^. ]*.jpg" *.html)"
icons_list3="$(grep -o "images/resources/[^. ]*.png" *.html)"
icons_list="$(echo -e "$icons_list1 $icons_list2 $icons_list3" | xargs)"
for icon_file in $icons_list; do
	filename="$(echo "$icon_file" | awk -F ':' '{print $1}')"
	icon="$(echo "$icon_file" | awk -F ':' '{print $2}')"

	bmp_file="$(echo "$icon" | awk -F '/' '{print $3}')"
	res_name="$(echo "$bmp_file" | awk -F '.' '{print $1}')"
	sed -i "s|images/resources/$bmp_file|$rel_path_docs_icons/$techtree/resources/$res_name/images/$bmp_file|" "$filename"
	echo -n "/"
	sleep 0.01s
done
echo

echo ">>> removing not required files ..."
rm -rf css js
find ./images/*/* -type d | xargs rm -rf
rm -rf images/datatables images/resources
find ./images/* -type f -name "*.canon" | xargs rm -f
find ./images/* -type f -name "*.cmapx" | xargs rm -f
find ./images/* -type f -name "*.text" | xargs rm -f

rm -f all.html
all_html_list="$(grep '"all.html"' *.html | awk -F ':' '{print $1}' | xargs)"
for filename in $all_html_list; do
	sed -i '/All Units of all Factions/d' "$filename"
done

if [ "$(which optipng)" != "" ]; then
	echo ">>> optimizing .png files ..."
	find ./images -type f -name '*.png' -exec optipng '{}' \;
else
	echo "Warning: 'optipng' not found"
fi
cd "$SCRIPTDIR"
rm -f "$techtree-temp.ini"