]> git.ipfire.org Git - thirdparty/bash.git/blame - examples/scripts.v2/arc2tarz
Bash-4.2 patch 45
[thirdparty/bash.git] / examples / scripts.v2 / arc2tarz
CommitLineData
ccc6cda3
JA
1#! /bin/bash
2#
3# original from:
4# arc2tarz: convert arced file to tarred, compressed form.
5# @(#) arc2tarz.ksh 1.0 92/02/16
6# 91/03/28 john h. dubois iii (john@armory.com)
7# 92/02/16 added -h option for help
8#
9# conversion to bash v2 syntax by Chet Ramey
10
11unset ENV
12Usage="Usage: $0 arcfile [-hcg] [ tarzfile ]"
13
14phelp()
15{
16echo "$Usage
17arcfile is the name of an arc file to convert to tarred, compressed form.
18The file must have a .arc extension, but only the base name needs to be
19given. If no output file name is given, it will be created in the current
20directory with the name being the arcfile basename followed by .tar.EXT.
21If the -c option is given, compress will be used, and EXT will be Z.
22The default (also available with -g) is to use gzip, in which case EXT
23is gz. If the basename is too long the extension may be truncated. All
24uppercase letters in the names of files in the archive are moved to lowercase."
25}
26
27compress=gzip
28ext=gz
29
30while getopts "hcg" opt; do
31 case "$opt" in
32 h) phelp; exit 0;;
33 c) compress=compress; ext=Z;;
34 g) compress=gzip ; ext=gz ;;
35 *) echo "$Usage" 1>&2 ; exit 2;;
36 esac
37done
38
39shift $((OPTIND - 1))
40
41if [ $# = 0 ]; then
42 phelp
43 exit 0
44fi
45
46[ -z "$TMP" ] && tmpdir=/tmp/arc2tarz.$$ || tmpdir=$TMP/arc2tarz.$$
47
48case "$1" in
49*.arc) arcfile=$1 ;;
50*) arcfile=$1.arc ;;
51esac
52
53if [ ! -f $arcfile ] || [ ! -r $arcfile ]; then
54 echo "Could not open arc file \"$arcfile\"."
55 exit 1
56fi
57
58case "$arcfile" in
59/*) ;;
60*) arcfile=$PWD/$arcfile ;;
61esac
62
63basename=${arcfile%.arc}
64basename=${basename##*/}
65[ $# -lt 2 ] && tarzname=$PWD/$basename.tar.$ext || tarzname=$2
66
67trap 'rm -rf $tmpdir $tarzname' 1 2 3 6 15
68
69mkdir $tmpdir
70cd $tmpdir
71echo "unarcing files..."
72arc -ie $arcfile
73
74# lowercase
75for f in *; do
76 new=$(echo $f | tr A-Z a-z)
77 if [ "$f" != "$new" ]; then
78 mv $f $new
79 fi
80done
81
82echo "tarring/compressing files..."
83tar cf - * | $compress > $tarzname
84cd -
85rm -rf $tmpdir