bpakk: Sync against Lib/std/sh and add some info
[sunny256-utils.git] / bpakk
blobfffb0d8fef217bf34c98a7bbfafd978dbe360c71
1 #!/bin/sh
3 #==============================================================================
4 # bpakk
5 # File ID: 2a4e251e-7b6f-11df-b25f-00219bfade9b
7 # Pack stdin with gzip and encapsulate it in base64.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=bpakk
14 VERSION=0.0.0
16 std_w=8
18 opt_decode=0
19 opt_help=0
20 opt_quiet=0
21 opt_verbose=0
22 opt_w=$std_w
24 while test -n "$1"; do
25 case "$1" in
26 -d|--decode) opt_decode=1; shift ;;
27 -h|--help) opt_help=1; shift ;;
28 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
29 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
30 -w) opt_w="$2"; shift 2 ;;
31 --version) echo $progname $VERSION; exit 0 ;;
32 --) shift; break ;;
34 if printf '%s\n' "$1" | grep -q ^-; then
35 echo "$progname: $1: Unknown option" >&2
36 exit 1
37 else
38 break
40 break ;;
41 esac
42 done
43 opt_verbose=$(($opt_verbose - $opt_quiet))
45 if test "$opt_help" = "1"; then
46 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
47 cat <<END
49 Pack stdin with gzip and encapsulate it in base64.
51 Usage: $progname [options]
53 Options:
55 -d, --decode
56 Decode gzipped base64.
57 -h, --help
58 Show this help.
59 -q, --quiet
60 Be more quiet. Can be repeated to increase silence.
61 -v, --verbose
62 Increase level of verbosity. Can be repeated.
63 -w SIZE
64 Create base64 using SIZE character chunks. To get one long chunk,
65 use 0. Default: $std_w.
66 --version
67 Print version information.
69 END
70 exit 0
73 if [ "$opt_decode" = "1" ]; then
74 base64 -di | gunzip --stdout --force
75 exit
78 gzip -9 | base64 -w $opt_w | tr '\n' ' ' | sed 's/ $//'
79 echo
81 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :