polemon.org
 

Dieses Shellscript erleichtert es Config-Dateien zu drucken und zu archivieren.

Benutzung:

gather.sh

Usage: gather.sh [OPTIONS]

Options:

    -a [<name>]         Archive files. When <name> is supplied,
    --archive[=<name>]  '<name>.tar.gz' will be the name of the archive.
                        Default is 'docs.tar.gz'.
                        If used with --pdf, then only pdf files are saved.

    -d                  Delete *ps and *pdf files.
    --delete            Probably only useful with --archive.

    -h                  Displays this text.
    --help

    -p                  Print files to line printer (lpr).
    --print

    -v                  Display verbose output.
    --verbose

Die Datei kann hier heruntergeladen werden.

Sourcecode:

gather.sh

  1: #!/bin/bash
  2: #
  3: # gather.sh - gather and archive files
  4: #
  5: # Copyright 2009 Szymon 'Polemon' Bereziak <bereziak@informatik.uni-luebeck.de>
  6: # License: BSD
  7: #
  8:
  9: files=( "/etc/my.cnf"
 10:         "/etc/sysconfig/iptables"
 11:         "/etc/named.conf"
 12:         "/var/named/master/imbs.uk-sh.de"
 13:         "/var/named/master/59.15.10.in-addr.arpa"
 14:         "/etc/httpd/conf/httpd.conf" )
 15:
 16:
 17: # pdf, archive, print, delete, verbose
 18: options=(0 0 0 0 0)
 19:
 20: function archive {
 21:     [ ${options[4]} = "1" ] && echo -n "preparing archive..."
 22:     tmpdir=$(mktemp -d)
 23:     archive="docs"
 24:     [ -n "$1" ] && archive=$1
 25:     mkdir ${tmpdir}/${archive}
 26:     ext="ps"
 27:     [ ${options[0]} = "1" ] && ext="pdf"
 28:
 29:     for file in ${files[@]}; do
 30:         cp ${file##*/}.${ext} ${tmpdir}/${archive}
 31:     done
 32:     [ ${options[4]} = "1" ] && echo "done"
 33:
 34:     [ ${options[4]} = "1" ] && echo -n "making '${archive}.tar.gz'..."
 35:     pushd ${tmpdir} > /dev/null
 36:     tar czf ${archive}.tar.gz ${archive}/
 37:     popd > /dev/null
 38:
 39:     mv ${tmpdir}/${archive}.tar.gz .
 40:     rm -rf ${tmpdir}
 41:     [ ${options[4]} = "1" ] && echo "done"
 42: }
 43:
 44: function mkpdf {
 45:     for file in ${files[@]}; do
 46:         [ ${options[4]} = "1" ] && echo -n "making '${file##*/}.pdf'..."
 47:         ps2pdf ${file##*/}.ps
 48:         [ ${options[4]} = "1" ] && echo "done"
 49:     done
 50: }
 51:
 52: # XXX REMOVE DEBUG LINE
 53: function prlpr {
 54:     for file in ${files[@]}; do
 55:         [ ${options[4]} = "1" ] && echo -n "sending  '${file##*/}.ps' to print queue..."
 56:         echo -n "(lpr ${file##*/}.ps)..."
 57:         [ ${options[4]} = "1" ] && echo "done"
 58:     done
 59: }
 60:
 61: function delf {
 62:     [ ${options[4]} = "1" ] && echo -n "removing  ${1}-files..."
 63:     for file in ${files[@]}; do
 64:         rm ${file##*/}.$1
 65:     done
 66:     [ ${options[4]} = "1" ] && echo "done"
 67: }
 68:
 69: while [ -n "$1" ]; do
 70:     case $1 in
 71:         --pdf)
 72:             # handle pdfs instead of ps
 73:             options[0]="1"
 74:             ;;
 75:         -a)
 76:             # make archive
 77:             if [ ! "${2:0:1}" = "-" ] && [ -n "$2" ]; then
 78:                 shift
 79:                 options[1]=$1
 80:                 shift
 81:             else
 82:                 options[1]="1"
 83:             fi
 84:             ;;
 85:         --archive)
 86:             options[1]="1"
 87:             ;;
 88:         --archive=*)
 89:             options[1]=${1#*=}
 90:             ;;
 91:         -p | --print)
 92:             # print using lpr
 93:             options[2]="1"
 94:             ;;
 95:         -d | --delete)
 96:             # delete files after making
 97:             options[3]="1"
 98:             ;;
 99:         -v | --verbose)
100:             # verbose output
101:             options[4]="1"
102:             ;;
103:         -h | --help)
104:             # display help
105:             cat <<HELPEND
106: gather.sh
107:
108: Usage: gather.sh [OPTIONS]
109:
110: Options:
111:
112:     -a [<name>]         Archive files. When <name> is supplied,
113:     --archive[=<name>]  '<name>.tar.gz' will be the name of the archive.
114:                         Default is 'docs.tar.gz'.
115:                         If used with --pdf, then only pdf files are saved.
116:
117:     -d                  Delete *ps and *pdf files.
118:     --delete            Probably only useful with --archive.
119:
120:     -h                  Displays this text.
121:     --help
122:
123:     -p                  Print files to line printer (lpr).
124:     --print
125:
126:     -v                  Display verbose output.
127:     --verbose
128:
129: HELPEND
130:             exit
131:             ;;
132:         *)
133:             echo "wat?"
134:             ;;
135:     esac
136:
137:     shift
138: done
139:
140: for file in ${files[@]}; do
141:     [ ${options[4]} = "1" ] && echo -n "enscripting $file..."
142:     enscript -q -G --language=PostScript -o${file##*/}.ps $file
143:     [ ${options[4]} = "1" ] && echo "done"
144: done
145:
146: # XXX DEBUG
147: echo ${options[@]}
148:
149: [ ${options[0]} = "1" ] && mkpdf
150:
151: [ ! ${options[1]} = "0" ] && {
152:     [ ! ${options[1]} = "1" ] && archive ${options[1]} || archive
153: }
154:
155: [ ${options[2]} = "1" ] && prlpr
156:
157: [ ${options[0]} = "1" ] && delf "ps"
158:
159: [ ${options[3]} = "1" ] && {
160:     [ ${options[0]} = "1" ] && delf "pdf" || delf "ps"
161: }
 
imbs/gather.sh.txt · Last modified: 2009/12/15 04:49 (external edit)
 
RSS • 2012 © --polemon Powered by: