summaryrefslogtreecommitdiff
path: root/make.sh
blob: d5fedba6a415d8efb99dd06dc148808d07c9cc78 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash

LANGS="cs de es fr fi nl ru"
DIST_FILES="ChangeLog COPYING CREDITS FAQ HISTORY INSTALL README README.translators REQUIREMENTS contrib convert.pl install.sh lib locale make.sh template uninstall.sh vdradmind.pl vdradmind.pl.1"
INSTALL_SH=./install.sh
CVS2CL="./cvs2cl.pl"	# get it at http://www.red-bean.com/cvs2cl/
TMPDIR=/tmp


# Print usage information and exit
#
function Usage()
{
	echo "Usage: $0 cvs"
	echo "  cvs       - always use this after a \"cvs update \" or \"cvs checkout\""
	echo "  install   - install VDRAdmin-AM"
	echo "  uninstall - uninstall VDRAdmin-AM"
	echo "  po        - convert .po files to .mo files"
	echo "  dist      - create distribution archive"
	echo "  utf8add   - generate utf8 locales from existing locales"
	echo "  utf8clean - cleanup utf8 locales"
	echo "  cl        - create ChangeLog file."
	exit 1
}

# Print error message and exit.
#
function Error()
{
	[ "$1" ] && echo $*
	exit 1
}

# Compile and install locales.
#
function do_po()
{
	local additional_langs="$(get_utf8_LANGS)"
	local all_langs="$LANGS $additional_langs"
	for L in $all_langs
	do
		[  -d locale/$L/LC_MESSAGES/ ] || mkdir -p locale/$L/LC_MESSAGES/
		msgfmt po/$L.po -o po/$L.mo
		install -m 644 po/$L.mo locale/$L/LC_MESSAGES/vdradmin.mo
		rm -f po/$L.mo
	done
}

# Setup things after CVS checkout or update.
#
function do_cvs()
{
	# Create missing symbolic links
	[ -e uninstall.sh ] || ln -s install.sh uninstall.sh
	[ -e README ] || ln -s INSTALL README
}

# Extract VDRAdmin-AM version from vdradmind.pl
#
function getVersion()
{
	grep "^my \$VERSION" vdradmind.pl | sed -e 's/^[^\"]*\"\([^\"]*\)\".*$/\1/'
}

# Create tar.bz2 for distribution.
#
function do_dist()
{
	local DIST_NAME=vdradmin-am-$(getVersion)
	mkdir -p $TMPDIR/$DIST_NAME
	cp -a $DIST_FILES $TMPDIR/$DIST_NAME
	mkdir -p $TMPDIR/$DIST_NAME/po
	cp -a po/*.po po/*.pot $TMPDIR/$DIST_NAME/po
	(
		cd $TMPDIR
		tar --exclude CVS -cjf $DIST_NAME.tar.bz2 $DIST_NAME
		rm -rf $TMPDIR/$DIST_NAME
	)
	mv $TMPDIR/$DIST_NAME.tar.bz2 .
}

# determine additional (utf8-)languages
#
function get_utf8_LANGS()
{
	(	cd po
		local UTF8LANGS
		local UTF8LANG
		for file in *.utf8.po; do
			[ -e $file ] || continue
			UTF8LANG=${file%.po}
			UTF8LANGS="$UTF8LANGS $UTF8LANG"
		done
		echo $UTF8LANGS
	)
}

# extract original character encoding
#
function getOrigEncoding()
{
	local ENC=$(grep 'msgstr "ISO-8859' $1)
	# strip away "ISO-", because sometimes we need it as "iso"
	ENC=${ENC/'msgstr "ISO-'/}
	ENC=${ENC/'"'/}
	echo $ENC
}


# cleanup utf8 locales
#
function do_utf8_clean()
{
	(cd po && rm -f *.utf8.po*)
}

# generate utf8 locales
#
function do_utf8_generate()
{
	# start clean
	do_utf8_clean

	(	cd po
		local filename
		local encoding
		local newfilename

		# generate utf8 locales for existing translations
		for file in *.po; do
			[ -e $file ] || continue
			filename=${file%.po}
			encoding=iso$(getOrigEncoding $filename.po)
			newfilename=$(echo $filename | tr [:lower:] [:upper:])
			if [ "${encoding}" = "iso8859-1" ]; then
    		# just copy
				cp $filename.po ${filename}_$newfilename.utf8.po ;
			else
				# convert
				iconv -f $encoding -t utf-8 $filename.po > ${filename}_$newfilename.utf8.po
			fi
		done

		# generate us_US.utf8.po from POT template
		msginit -i vdradmin.pot -o en_US.utf8.po -l en_US.utf8 --no-translator

		# map ISO-8859-1 encoding to UTF-8 instead of the respective "old" encodings
		for file in $(ls *.utf8.po); do
			encoding=ISO-$(getOrigEncoding $file)
    	sed -e 's:msgstr "'$encoding'":msgstr "UTF-8":g' $file > $file.tmp
    	mv $file.tmp $file
		done
	)
}

# create ChangeLog file.
#
function do_cl()
{
	[ -x $CVS2CL ] || Error "Missing $CVS2CL (http://www.red-bean.com/cvs2cl/)"
	$CVS2CL --FSF --separate-header --no-wrap --no-times --tagdates --log-opts "-d>2006-07-08"
}

[ "$1" ] || Usage
[ -x $INSTALL_SH ] || Error "$INSTALL_SH not found!"

while [ $1 ]
do
	case $1 in
		cvs)
			do_cvs
			;;

		install)
			$INSTALL_SH -c
			;;

		uninstall)
			$INSTALL_SH -u
			;;

		po)
			do_po
			;;

		dist)
			do_utf8_clean
			do_cvs
			do_po
			do_cl
			do_dist
			;;

		utf8add)
			do_utf8_generate
			;;

		utf8clean)
			do_utf8_clean
			;;

		cl)
			do_cl;
			;;

		*)
			Error "Unknown command \"$1\""
			;;
	esac
	shift
done