11#! /usr/bin/env bash
22
33myname=$( basename " $0 " )
4+ scriptdir=$( dirname " $( readlink -f " $0 " ) " )
45
56die ()
67{
@@ -13,7 +14,7 @@ prompt_usage()
1314 cat<< END
1415Usage:
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
1920to some non-determinism in zimwriterfs the produced small.zim most likely will
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' ) ]]
3031then
3132 prompt_usage
3233fi
3334
3435mode=$1
36+ source_dir=$2
37+ output_dir=$3
3538
36- cd " $( dirname " $0 " ) "
3739
3840if [ " $mode " == ' --all' ]
3941then
40- rm -f small.zim
42+ rm -f $output_dir / small.zim
4143 zimwriterfs --withoutFTIndex \
4244 -w main.html \
4345 -f favicon.png \
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'
5355fi
5456
57+ cd $output_dir
58+
5559printf " 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
6165zimfilesize=$( 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
6569encode_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
185189dirent1_address=$( encode_uint64 $(( dirent_ptrs[0 ])) )
186190dirent2_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
196200title1_dirent_index=$( encode_uint32 $(( title_index[0 ])) )
197201title2_dirent_index=$( encode_uint32 $(( title_index[1 ])) )
0 commit comments