first version.
[build-srcpkg.git] / bin / etz
blob3c25be973f701d6a2de4fc1f6b8c0c34dc1df3ef
1 #!/bin/bash
2 ############################################################
3 # source: etz
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
5 # date: 20240312
6 ############################################################
7 # Copyright (C) 2022- Free Software Foundation, Inc.
8 # This configure script is free software; the Free Software
9 # Foundation gives unlimited permission to copy, distribute
10 # and modify it.
11 ############################################################
12 # note:
13 # etz is a compressed tar ball file with script code
14 # for self-decompress, and running additional cmd.
15 ############################################################
18 # todoļ¼š
19 # @
20 # @
24 # external sourced cmd.
25 #source <extern-script> --load
27 . shlibinc
30 include args.shlib
32 ##############################
33 # section: public comment info
34 ##############################
38 ##############################
39 # section: variable define
40 ##############################
45 # this comment is used for version id auto update.
47 # @{prog-ver-begin}
48 readonly ETZ_V1=0
49 readonly ETZ_V2=1
50 readonly ETZ_V3=0
51 readonly ETZ_VEXT=
52 readonly ETZ_VER_DATE=20240201
53 # @{prog-ver-end}
55 readonly ETZ_PROG=`basename $0`
57 readonly ETZ_PROG_VERSION="v${ETZ_V1}.${ETZ_V2}\${ETZ_V3:+\".$ETZ_V3\"}\${ETZ_VEXT:+\"$ETZ_VEXT\"}\${ETZ_VER_DATE:+\"-$ETZ_VER_DATE\"}"
58 ETZ_PROG_VERSION_STR="`eval echo $ETZ_PROG_VERSION`
59 Copyright (C) 2023- Free Software Foundation, Inc.
60 This configure script is free software; the Free Software
61 Foundation gives unlimited permission to copy, distribute
62 and modify it.
64 Writen by @{SRCPKG_AUTHOR}(@{SRCPKG_AUTHOR_EMAIL}).
67 ETZ_PROG_BANNER="$ETZ_PROG $ETZ_PROG_VERSION_STR"
68 ETZ_PROG_SYNTAX='Usage: $ETZ_PROG -[${p_shortparam//\|/}]'
69 ETZ_PROG_DESC=" zipped-tarball executalbes.
72 ETZ_PROG_OTHER_DESC="
73 eg:
75 @ create executable ziped-tarball.
77 etz -c <filename>[.etz|.zti] <dir>
79 @ decompress executable ziped-tarball, and running script in it.
81 etz -d <filename>[.etz|.zte|.zti]
83 helper info.
86 ETZ_USAGE_FMT='$ETZ_PROG_BANNER
87 ${ETZ_PROG_SYNTAX}
88 $ETZ_PROG_DESC
89 ${helper}
90 $ETZ_PROG_OTHER_DESC'
94 # do not delete this comment, it is used for var define code intert.
96 # args-var-define-begin
97 # args-var-define-end
101 # desc-str for dev
102 # @ every paramter desc-str-line start with 'param'.
103 # @ every colum start with '|', and seperated by blanks.
104 # @ '|blank' means a blank line dispalyed in helper.
105 # @ follow with a '' quoated string is the option category string.
106 # @ comment '#' in desc-str is also supported, and can be used to
107 # disable some option have not been implemented.
108 # @ desc-str can be in multiple var. and some of them maybe re-used
109 # for other program by 'source xxx --loadshlib'.
111 dev_desc_hdr_str="
112 |prog $0 'this file is an demo or template for utility cmd shell script program.'
115 # @ PARAMETER DEFINE.
116 # this desc str would be referenced in scripttest, consider about opt name space.
117 # =, param name for opt.
118 # %, var name if this opt is enabled.
119 # &, proc func if opt trigged.
120 etz_desc_str="
121 |prog $0 'project build util-program.'
123 |blank '[etz-category]'
124 |param |-c |-- |--- |=<file> |%<shortopt> |&<on_compress> |'compress to file.'
125 |param |-d |-- |--- |=<file> |%<shortopt> |&<on_decompress> |'decompress compressed file and running.'
126 #|param |- |-- |---subcmd |= |%<subcmd> |&<on_subcmd> |'subcmd demo.'
127 #|param |- |-- |---longopt |=<file> |%<longopt> |&<on_longopt> |'long option demo.'
128 dest.'
130 |blank
133 etz_other_desc_str="
134 |blank 'Version & Helper & Debug:'
135 |param |- |-- |---version |= |%<version> |&<on_version> |'output version info of this program.'
136 |param |- |--help |---help |= |%<help> |&<on_help> |'this helper text doc.'
139 # zte header script content
140 zte_hdr_evl='
141 #!/bin/sh
142 CFILE=
143 COFFSET=
144 CSIZE=
145 DFILE=
146 DOFFSET=
147 DSIZE=""
148 DECOMPTYPE="gzip" #
149 DECOMPOPT="xvf" #
151 which tar || echo "tar is not installed." >&2 && exit
152 which $DECOMPTYPE || echo "$DECOMPTYPE is not installed." >&2 && exit
154 dd if="$0" conv=skip_bytes skip=$COFFSET ibs=1 count=$CSIZE obs=2k | tar -$DECOMPOPT -
156 dd if="$0" conv=skip_bytes skip=$DOFFSET ibs=1 count=$DSIZE obs=2k | tar -$DECOMPOPT -
163 ##############################
164 # section: private function
165 ##############################
169 # fsyntax: on_codegen
170 # fdesc: on codegen sub-cmd.
172 on_codegen ()
174 codegen -y
178 # fsyntax: on_subcmd
179 # fdesc: on subcmd sub-cmd.
181 on_subcmd ()
183 # TBD:
188 # fsyntax: on_longopt
189 # fdesc: on longopt sub-cmd.
191 on_longopt ()
193 # TBD:
198 # fsyntax: on_shortopt
199 # fdesc: on shortopt sub-cmd.
201 on_shortopt ()
203 # TBD:
208 # fsyntax: on_version
209 # fdesc: on version sub-cmd.
211 on_version ()
213 eval echo "$ETZ_PROG_VERSION"
215 exit
219 # fsyntax: on_help
220 # fdesc: on help sub-cmd.
222 on_help ()
224 [[ -z $term_width ]] && term_width=80
226 helper="$(opt_helper)"
228 eval ETZ_PROG_SYNTAX="\"$ETZ_PROG_SYNTAX\""
229 eval echo -ne "\"$ETZ_USAGE_FMT\""
231 exit
236 ##############################
237 # section: public function
238 ##############################
242 main_etz ()
244 [[ "$@" =~ '--load' ]] && return
247 # args parsing
249 # prog_opt_dispatch "$@"
250 opt_desc_str_dispatch etz_desc_hdr_str
251 opt_desc_str_dispatch etz_desc_str
252 opt_desc_str_dispatch etz_other_desc_str
253 prog_opt_proc "$@"
255 init_dbglogout 2 testing 20000
256 # set_output_prefix info ""
257 set_auto_newline ""
259 # SRCPKG_DIR="$(pwd)"
260 # TEST_DIR_STR_FMT="$(attr_get catalog::testdir::STR_FMT)"
261 # ALIGN=' '
264 # running action list function for options after init.
265 # the paramter for init will be effact, then execute the
266 # action function.
268 action_list_exec
271 main_etz "$@"
273 if [[ "$@" =~ "--debug" ]]; then
274 declare -g DBGOUTD_OUTPUT=1
276 # does not need to shift args if the --debug option is not the
277 # first option. it will be ignore in process.
278 # shift
281 if [[ $1 != "--loadshlib" ]]; then
282 # main "$@"
283 main_etz "$@"
284 else
285 shift
289 ##############################
290 # section: file tail
291 ##############################