Skip to content

Commit 15ebe95

Browse files
committed
Update create_test_zimfiles to work with different output directory.
1 parent 665daaf commit 15ebe95

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

scripts/create_test_zimfiles

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
myname=$(basename "$0")
4+
scriptdir=$(dirname "$(readlink -f "$0")")
45

56
die()
67
{
@@ -13,7 +14,7 @@ prompt_usage()
1314
cat<<END
1415
Usage:
1516
16-
$myname --all|--only-derived-zimfiles
17+
$myname --all|--only-derived-zimfiles <source_directory> <output_directory>
1718
1819
'$myname --all' creates/re-generates all ZIM files, including small.zim. Due
1920
to some non-determinism in zimwriterfs the produced small.zim most likely will
@@ -26,18 +27,19 @@ END
2627
exit 1
2728
}
2829

29-
if [[ $# -ne 1 || ( "$1" != '--all' && "$1" != '--only-derived-zimfiles' ) ]]
30+
if [[ $# -ne 3 || ( "$1" != '--all' && "$1" != '--only-derived-zimfiles' ) ]]
3031
then
3132
prompt_usage
3233
fi
3334

3435
mode=$1
36+
source_dir=$2
37+
output_dir=$3
3538

36-
cd "$(dirname "$0")"
3739

3840
if [ "$mode" == '--all' ]
3941
then
40-
rm -f small.zim
42+
rm -f $output_dir/small.zim
4143
zimwriterfs --withoutFTIndex \
4244
-w main.html \
4345
-f favicon.png \
@@ -46,12 +48,14 @@ then
4648
-d "N/A" \
4749
-c "N/A" \
4850
-p "N/A" \
49-
small_zimfile_data \
50-
small.zim \
51+
$source_dir \
52+
$output_dir/small.zim \
5153
&& echo 'small.zim was successfully created' \
5254
|| die 'Failed to create small.zim'
5355
fi
5456

57+
cd $output_dir
58+
5559
printf "BEGINZIM" > small.zim.embedded \
5660
&& cat small.zim >> small.zim.embedded \
5761
&& printf "ENDZIM" >> small.zim.embedded \
@@ -60,7 +64,7 @@ printf "BEGINZIM" > small.zim.embedded \
6064

6165
zimfilesize=$(wc -c < small.zim)
6266

63-
zimheader=$(./inspectzim --header small.zim|tail -n +2)
67+
zimheader=$($scriptdir/inspectzim --header small.zim|tail -n +2)
6468

6569
encode_integer_as_printf_fmt_string()
6670
{
@@ -180,7 +184,7 @@ create_broken_zim_file invalid.outofbounds_first_clusterptr.zim \
180184
"$outofzimfile" \
181185
$((cluster_ptr_pos))
182186

183-
dirent_ptrs=($(./inspectzim --dirent_ptr_table small.zim|tail -n +2))
187+
dirent_ptrs=($($scriptdir/inspectzim --dirent_ptr_table small.zim|tail -n +2))
184188

185189
dirent1_address=$(encode_uint64 $((dirent_ptrs[0])))
186190
dirent2_address=$(encode_uint64 $((dirent_ptrs[1])))
@@ -191,7 +195,7 @@ create_broken_zim_file invalid.nonsorted_dirent_table.zim \
191195
"$dirent1_address" \
192196
$((url_ptr_pos+8))
193197

194-
title_index=($(./inspectzim --title_index small.zim|tail -n +2))
198+
title_index=($($scriptdir/inspectzim --title_index small.zim|tail -n +2))
195199

196200
title1_dirent_index=$(encode_uint32 $((title_index[0])))
197201
title2_dirent_index=$(encode_uint32 $((title_index[1])))

0 commit comments

Comments
 (0)