| 1 | #! /bin/bash
|
|---|
| 2 | #
|
|---|
| 3 | # original from:
|
|---|
| 4 | # @(#) uuenc.ksh 1.0 93/09/18
|
|---|
| 5 | # 93/09/18 john h. dubois iii (john@armory.com)
|
|---|
| 6 | #
|
|---|
| 7 | # conversion to bash v2 syntax by Chet Ramey
|
|---|
| 8 |
|
|---|
| 9 | istrue()
|
|---|
| 10 | {
|
|---|
| 11 | test 0 -ne "$1"
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | isfalse()
|
|---|
| 15 | {
|
|---|
| 16 | test 0 -eq "$1"
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | phelp()
|
|---|
| 20 | {
|
|---|
| 21 | echo "$name: uuencode files.
|
|---|
| 22 | $Usage
|
|---|
| 23 | For each filename given, $name uuencodes the file, using the final
|
|---|
| 24 | component of the file's path as the stored filename in the uuencoded
|
|---|
| 25 | archive and, with a .${SUF} appended, as the name to store the archive in.
|
|---|
| 26 | Example:
|
|---|
| 27 | $name /tmp/foo
|
|---|
| 28 | The file /tmp/foo is uuencoded, with \"foo\" stored as the name to uudecode
|
|---|
| 29 | the file into, and the output is stored in a file in the current directory
|
|---|
| 30 | with the name \"foo.${SUF}\".
|
|---|
| 31 | Options:
|
|---|
| 32 | -f: Normally, if the file the output would be stored in already exists,
|
|---|
| 33 | it is not overwritten and an error message is printed. If -f (force)
|
|---|
| 34 | is given, it is silently overwritten.
|
|---|
| 35 | -h: Print this help."
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | name=${0##*/}
|
|---|
| 39 | Usage="Usage: $name [-hf] <filename> ..."
|
|---|
| 40 | typeset -i force=0
|
|---|
| 41 |
|
|---|
| 42 | SUF=uu
|
|---|
| 43 |
|
|---|
| 44 | while getopts :hf opt; do
|
|---|
| 45 | case $opt in
|
|---|
| 46 | h) phelp; exit 0;;
|
|---|
| 47 | f) force=1;;
|
|---|
| 48 | +?) echo "$name: options should not be preceded by a '+'." 1>&2 ; exit 2;;
|
|---|
| 49 | ?) echo "$name: $OPTARG: bad option. Use -h for help." 1>&2 ; exit 2;;
|
|---|
| 50 | esac
|
|---|
| 51 | done
|
|---|
| 52 |
|
|---|
| 53 | # remove args that were options
|
|---|
| 54 | shift $((OPTIND - 1))
|
|---|
| 55 |
|
|---|
| 56 | if [ $# -lt 1 ]; then
|
|---|
| 57 | echo "$Usage\nUse -h for help." 1>&2
|
|---|
| 58 | exit
|
|---|
| 59 | fi
|
|---|
| 60 |
|
|---|
| 61 | for file; do
|
|---|
| 62 | tail=${file##*/}
|
|---|
| 63 | out="$tail.${SUF}"
|
|---|
| 64 | if isfalse $force && [ -a "$out" ]; then
|
|---|
| 65 | echo "$name: $out: file exists. Use -f to overwrite." 1>&2
|
|---|
| 66 | else
|
|---|
| 67 | uuencode $file $tail > $out
|
|---|
| 68 | fi
|
|---|
| 69 | done
|
|---|