Delete obsolete Unicode version 15.1.0
[sunny256-utils.git] / bpakk
blob6950d71dd215a0a83491910139ca32add9352b44
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_size=8
18 opt_decode=0
19 opt_help=0
20 opt_quiet=0
21 opt_size=$std_size
22 opt_verbose=0
23 opt_wrap=0
25 while test -n "$1"; do
26 case "$1" in
27 -d|--decode) opt_decode=1; shift ;;
28 -h|--help) opt_help=1; shift ;;
29 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
30 -s|--size) opt_size="$2"; shift 2 ;;
31 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
32 -w|--wrap) opt_wrap="$2"; shift 2 ;;
33 --version) echo $progname $VERSION; exit 0 ;;
34 --) shift; break ;;
36 if printf '%s\n' "$1" | grep -q ^-; then
37 echo "$progname: $1: Unknown option" >&2
38 exit 1
39 else
40 break
42 break ;;
43 esac
44 done
45 opt_verbose=$(($opt_verbose - $opt_quiet))
47 if test "$opt_help" = "1"; then
48 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
49 cat <<END
51 Pack stdin with gzip and encapsulate it in base64.
53 Usage: $progname [options]
55 Options:
57 -d, --decode
58 Decode gzipped base64.
59 -h, --help
60 Show this help.
61 -q, --quiet
62 Be more quiet. Can be repeated to increase silence.
63 -s SIZE, --size SIZE
64 Create base64 using SIZE character chunks. To get one long chunk,
65 use 0. Default: $std_size.
66 -v, --verbose
67 Increase level of verbosity. Can be repeated.
68 -w WIDTH, --wrap WIDTH
69 Wrap lines to WIDTH length. If "-" is specified, use terminal size.
70 --version
71 Print version information.
73 END
74 exit 0
77 if [ "$opt_decode" = "1" ]; then
78 base64 -di | gunzip --stdout --force
79 exit
82 (gzip -9 | base64 -w $opt_size | tr '\n' ' ' | sed 's/ $//'; echo) \
83 | if [ "$opt_wrap" = "0" ]; then
84 cat
85 else
86 [ "$opt_wrap" = "-" ] && opt_wrap=$(tput cols)
87 fold -s -w $opt_wrap
90 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :