extfs cleanups
- From: Adam Byrtek 'alpha' <alpha student uci agh edu pl>
- To: mc-devel gnome org
- Subject: extfs cleanups
- Date: Thu, 5 Dec 2002 18:21:48 +0100
Sorry, I've forgotten to attach the files.
--
_.|._ |_ _. : Adam Byrtek, alpha@(irc.pl|debian.org)
(_|||_)| |(_| : gg 1802819, pgp 0xB25952C0
| : jid alpha.jabberpl.org
#! /bin/sh
#
# Written by andrey joukov
# (C) 1996 2:5020/337 13 fidonet org
# Updated by christian gennerat alcatel fr 1999
# Andrew V. Samoilov <sav bcs zp ua> 2000
# beta version 2.0
# Updated by Adam Byrtek <alpha debian org>, Dec 2002
# (error handling, binaries detection, unnecessary output redirected
# to /dev/null, debug, some cleanups and fixes)
#DEBUG=YES
# throw error message to stderr
die ()
{
echo $1 >&2
exit 1
}
mcrarfs_list ()
{
$UNRAR v -c- "$1" | $AWK -v uid=${UID-0} '
BEGIN { flag=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
/^-------/ { flag++; if (flag > 1) exit 0; next }
{
if (flag == 0) next
if ( !/ [0-9][0-9]:[0-9][0-9] /) str = $0 # there is no time spec in this line
else {
if (str ~ /^\^/)
str=substr(str, 2)
split($4, a, "-")
if (a[3] < 50)
a[3] = 2000 + a[3]
else
a[3] = 1900 + a[3]
if (index($6, "D") != 0)
$6="drwxr-xr-x"
else
if (index($6, ".") != 0)
$6="-rw-r--r--"
printf "%s 1 %-8d %-8d %8d %3s %2d %4d %s %s\n", $6, uid, 0, $1, substr(date, (a[2]-1)*3+1, 3), a[1], a[3], $5, str
}
}' 2>/dev/null || die "List: archive error."
}
mcrarfs_copyin ()
{
if [ -z $RAR ]; then
die "Copyin: binary 'rar' not found, sorry."
fi
# copyin by christian gennerat alcatel fr
# preserve pwd. It is clean, but is it necessary?
pwd=`pwd`
# Create a directory and copy in it the tmp file with the good name
mkdir $3.dir &> /dev/null || die "Copyin: permision denied."
cd $3.dir
di="${2%/*}"
# if file is to be written upper in the archive tree, make fake dir
if test "$di" != "${2##*/}" ; then
mkdir -p "$di"
fi
# (cp -p) to preserve date, but $2 is dated now! [ -p breaks mode - alpha ]
cp $3 "$3.dir/$2"
$RAR a "$1" "$2" &>/dev/null || die "Copyin: archive error. Delete $3.dir"
cd $pwd
rm -rf $3.dir
}
mcrarfs_copyout ()
{
$UNRAR p -c- -inul "$1" "$2" > $3 2>/dev/null || die "Copyout: archive error."
}
mcrarfs_mkdir ()
{
if [ -z $RAR ]; then
die "Mkdir: binary 'rar' not found, sorry."
fi
# preserve pwd. It is clean, but is it necessary?
pwd=`pwd`
# Create a directory and create in it a tmp directory with the good name
dir=tmpdir.${RANDOM}
mkdir $dir &>/dev/null || die "Mkdir: permision denied."
cd $dir
mkdir -p "$2"
# rar cannot create an empty directory
touch "$2"/.rarfs
$RAR a -r "$1" "$2" &>/dev/null || die "Mkdir: archive error. Delete $dir."
$RAR d "$1" "$2"/.rarfs &>/dev/null || die "Mkdir: archive error. Delete $dir."
cd $pwd
rm -rf $dir
}
mcrarfs_rm ()
{
if [ -z $RAR ]; then
die "Rm: binary 'rar' not found, sorry."
fi
$RAR d "$1" "$2" &>/dev/null || die "Rm: archive error"
}
# debug
if [ $DEBUG == YES ]; then
echo $0 $1 $2 $3 $4 >> /tmp/mcdebug
fi
# chceck neccesary binaries
# prefer unrar (freeware)
UNRAR=`type -p unrar`
if [ -z $UNRAR ]; then
UNRAR=`type -p rar`
if [ -z $UNRAR ]; then
die "Binary 'rar/unrar' not found, sorry."
fi
fi
RAR=`type -p rar`
AWK=`type -p awk`
if [ -z $AWK ]; then
AWK=`type -p mawk`
if [ -z $AWK ]; then
AWK=`type -p gawk`
if [ -z $AWK ]; then
die "Binary 'awk/mawk/gawk' not found, sorry."
fi
fi
fi
umask 077
# uncomment this line for debugging
#echo "`date +%T` ${0##*/} $1 $2 to=$3 tmp=$4" >>/tmp/${0##*/}.log
case "$1" in
list) mcrarfs_list "$2"; exit 0;;
rm) mcrarfs_rm "$2" "$3" ; exit 0;;
rmdir) mcrarfs_rm "$2" "$3" ; exit 0;;
mkdir) mcrarfs_mkdir "$2" "$3" ; exit 0;;
copyin) mcrarfs_copyin "$2" "$3" $4; exit 0;;
copyout) mcrarfs_copyout "$2" "$3" $4; exit 0;;
esac
exit 1
#! /bin/sh
#
# Zoo file system
# Copyright ? U. N. Known
#
# This filesystem is _dangerous_. It used to create symlinks in filesystem
# with zoo file, it used to happily delete file from your filesystem.
# Now it is 'only' very ugly (it creates temporary files in ~/.mc/
# Updated by Adam Byrtek <alpha debian org>, Dec 2002
# (error handling, binaries detection, unnecessary output redirected
# to /dev/null, some cleanups and fixes)
#DEBUG=YES
# throw error message to stderr
die ()
{
echo $1 >&2
exit 1
}
mczoofs_list ()
{
$ZOO l $1 | $AWK -v uid=${UID-0} '
BEGIN { hyphens=0 }
/^---/ { if (hyphens > 0) exit 0; hyphens=1; next }
/^[^\ ]/ { next }
{
if (NF < 8)
next
if ($8 ~ /^\^/)
$8=substr($8, 2)
if ($6 > 50)
$6=$6 + 1900
else
$6=$6 + 2000
split($7, a, ":")
if ($8 ~ /\/$/)
printf "drwxr-xr-x 1 %-8d %-8d %8d %s %2d %4d %02d:%02d %s\n", uid, 0, $1, $5, $4, $6, a[1], a[2], $8
else
printf "-rw-r--r-- 1 %-8d %-8d %8d %s %2d %4d %02d:%02d %s\n", uid, 0, $1, $5, $4, $6, a[1], a[2], $8
}' 2>/dev/null || die "List: archive error."
exit 0
}
mczoofs_copyout ()
{
$ZOO xp $1 $2 | tail +6l > $3 2> /dev/null || die "Copyout: archive error."
exit 0
}
# debug
if [ $DEBUG == YES ]; then
echo $0 $1 $2 $3 $4 >> /tmp/mcdebug
fi
# chceck neccesary binaries
ZOO=`type -p zoo`
if [ -z $ZOO ]; then
die "Binary 'zoo' not found, sorry. $1"
fi
AWK=`type -p awk`
if [ -z $AWK ]; then
AWK=`type -p mawk`
if [ -z $AWK ]; then
AWK=`type -p gawk`
if [ -z $AWK ]; then
die "Binary 'awk/mawk/gawk' not found, sorry."
fi
fi
fi
# zoo is stupid and won't be happy when the name has no extension.
# we have to do a small trick :)
if echo $2 | grep '\.zoo$' &>/dev/null; then
ARCHIVE=$2
else
SYMLINK=/tmp/mc-uzoo-tmp.zoo
ln -fs $2 $SYMLINK &>/dev/null || die "Error. Is your /tmp writable?"
trap 'rm -f $SYMLINK &>/dev/null' 0 1 2 3 5 13 15
ARCHIVE=$SYMLINK
fi
umask 077
case "$1" in
list) mczoofs_list $ARCHIVE; exit $?;;
copyout) mczoofs_copyout $ARCHIVE $3 $4; exit $?;;
esac
exit 1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]