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