ly/Makefile: Sort variables
[sunny256-utils.git] / pakkings
blobe4c48894e115cd343ff0498ba2a10515fa1b11e0
1 #!/usr/bin/env bash
3 #=======================================================================
4 # pakkings
5 # File ID: c31a44fa-001f-11e5-84cd-1fba44bd8d3d
7 # Unpack all gzip files in a directory tree and move them into one big
8 # .tar.gz file. For times when you for example realise you've got more
9 # than 39000 IRC logs since 2004. True story.
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later.
13 #=======================================================================
15 progname=pakkings
16 VERSION=0.2.0
18 ARGS="$(getopt -o "\
22 " -l "\
23 help,\
24 quiet,\
25 verbose,\
26 version,\
27 " -n "$progname" -- "$@")"
28 test "$?" = "0" || exit 1
29 eval set -- "$ARGS"
31 opt_help=0
32 opt_quiet=0
33 opt_verbose=0
34 while :; do
35 case "$1" in
36 -h|--help) opt_help=1; shift ;;
37 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
38 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
39 --version) echo $progname $VERSION; exit 0 ;;
40 --) shift; break ;;
41 *) echo $progname: Internal error >&2; exit 1 ;;
42 esac
43 done
44 opt_verbose=$(($opt_verbose - $opt_quiet))
46 if test "$opt_help" = "1"; then
47 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
48 cat <<END
50 Usage: $progname [options] DIRECTORY [DIRECTORIES [...]]
52 Options:
54 -h, --help
55 Show this help.
56 -q, --quiet
57 Be more quiet. Can be repeated to increase silence.
58 -v, --verbose
59 Increase level of verbosity. Can be repeated.
60 --version
61 Print version information.
63 END
64 exit 0
67 for dir in "$@"; do
68 test -d "$dir" || { echo $progname: $dir: Not a directory >&2; continue; }
69 test -e "$dir.tar.gz" && { echo $progname: $dir.tar.gz already exists >&2; continue; }
70 label=$(suuid -t c_$progname -c "$progname: Pack $dir")
71 if test -z "$label"; then
72 echo $progname: Could not create UUID for tar volume label >&2
73 exit 1
75 echo
76 if test -n "$(git config --get annex.uuid)"; then
77 echo ========= ga edit $dir
78 ga edit "$dir"
80 echo ========= gunzip -r $dir
81 gunzip -r "$dir"
82 echo === tar $dir
83 tar czf "$dir.tar.gz" --label=$label --remove-files "$dir"
84 done