installed_progs.t: Python checks stdout too, 150 ok
[sunny256-utils.git] / upd
blob02e292e21f066fa2bc87010d0cd9c848e7306070
1 #!/usr/bin/env bash
3 #=======================================================================
4 # upd
5 # File ID: 27f00bc8-0903-11de-ac56-000475e441b9
7 # List all directories in the subtree, sorted by size
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=upd
14 VERSION=0.2.0
16 ARGS="$(getopt -o "\
20 " -l "\
21 help,\
22 quiet,\
23 verbose,\
24 version,\
25 " -n "$progname" -- "$@")"
26 test "$?" = "0" || exit 1
27 eval set -- "$ARGS"
29 opt_help=0
30 opt_quiet=0
31 opt_verbose=0
32 while :; do
33 case "$1" in
34 -h|--help) opt_help=1; shift ;;
35 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
36 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
37 --version) echo $progname $VERSION; exit 0 ;;
38 --) shift; break ;;
39 *) echo $progname: Internal error >&2; exit 1 ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 List all directories in the subtree, sorted by size
50 Usage: $progname [options]
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 DUFILE=du.dat
69 echo \# $(
70 suuid -m -t upd -w o --raw -c "<c_upd> <host>$(
71 hostname)</host> <directory>$(/bin/pwd)</directory> </c_upd>"
72 ) >$DUFILE
73 grep -q '^# ........-....-....-....-............$' $DUFILE || {
74 echo upd: Error generating uuid, aborting. >&2
75 exit 1
77 du --si -x |
78 sort -h |
79 perl -e '
80 while (<>) {
81 s/^(\d{3,})/commify($1)/ge;
82 print;
84 sub commify {
85 my $Str = reverse $_[0];
86 $Str =~ s/(\d\d\d)(?=\d)(?!\d*\,)/$1\./g;
87 return scalar reverse $Str;
88 }' >>$DUFILE
89 echo -n "# smsum:" >>$DUFILE
90 echo $(smsum <$DUFILE) >>$DUFILE
91 chmod 600 $DUFILE
92 chown sunny.sunny $DUFILE
93 rm -f $DUFILE.gz
94 afv $DUFILE
95 tail -n 200 $DUFILE