Line 0
Link Here
|
|
|
1 |
#! /bin/sh |
2 |
# |
3 |
# u7z - 7zip file archive Virtual File System for Midnight Commander ( ftp://ftp.ibiblio.org/pub/Linux/utils/file/managers/mc/ ) |
4 |
# |
5 |
# Copyright (C) 2004 Sergiy Niskorodov (sgh at ukrpost dot net) |
6 |
|
7 |
# Written by Sergiy Niskorodov aka SGh |
8 |
# |
9 |
# beta version 4.14.2 (04 Mar 2005) |
10 |
# |
11 |
# 7z for linux can be found on http://sourceforge.net/projects/p7zip/ |
12 |
|
13 |
|
14 |
# Thanks to urar VFS authors andrey joukov 2:5020/337.13@fidonet.org, |
15 |
# christian.gennerat@alcatel.fr, Andrew V. Samoilov <sav@bcs.zp.ua> |
16 |
# I use this script like example |
17 |
|
18 |
|
19 |
# This program is free software; you can redistribute it and/or modify |
20 |
# it under the terms of the GNU General Public License as published by |
21 |
# the Free Software Foundation; either version 2 of the License, or |
22 |
# (at your option) any later version. |
23 |
# |
24 |
# This program is distributed in the hope that it will be useful, |
25 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 |
# GNU General Public License for more details. |
28 |
# |
29 |
# You should have received a copy of the GNU General Public License |
30 |
# along with this program; if not, write to the Free Software |
31 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
32 |
|
33 |
|
34 |
SEVENZ=`which 7za` |
35 |
|
36 |
|
37 |
mc7zfs_list () |
38 |
{ |
39 |
$SEVENZ l "$1" 2> /dev/null | gawk -v uid=${UID-0} ' |
40 |
BEGIN { flag=0 } |
41 |
/^-------/ { flag++; if (flag > 1) exit 0; next } |
42 |
{ |
43 |
if (flag == 0) next |
44 |
|
45 |
year=substr($1, 1, 4) |
46 |
month=substr($1, 6, 2) |
47 |
day=substr($1, 9, 2) |
48 |
date=month "-" day "-" year |
49 |
|
50 |
time=substr($2, 1, 5) |
51 |
|
52 |
if (index($3, "D") != 0) |
53 |
attr="drwxr-xr-x" |
54 |
else |
55 |
if (index($3, ".") != 0) |
56 |
attr="-rw-r--r--" |
57 |
|
58 |
size=$4 |
59 |
|
60 |
$0=substr($0, 54) |
61 |
if (NF > 1) |
62 |
name=$0 |
63 |
else |
64 |
name=$1 |
65 |
|
66 |
gsub(/\\/, "/", name) |
67 |
|
68 |
printf "%s 1 %-8d %-8d %8d %s %s %s\n", attr, uid, 0, size, date, time, name |
69 |
}' |
70 |
} |
71 |
|
72 |
mc7zfs_copyin () |
73 |
{ |
74 |
# preserve pwd. |
75 |
pwd=`pwd` |
76 |
# Create a directory and copy in it the tmp file with the random name |
77 |
dir="$3".dir |
78 |
mkdir "$dir" |
79 |
cd "$dir" |
80 |
mv "$1" . |
81 |
arname=`basename "$1"` |
82 |
di="${2%/*}" |
83 |
# if file is to be written upper in the archive tree, make fake dir |
84 |
if test "$di" != "${2##*/}" ; then |
85 |
# echo asdsad 1>&2 |
86 |
mkdir -p "$di" |
87 |
fi |
88 |
# pwd > /tmp/cdir |
89 |
# echo "$arname $2" > /tmp/ters |
90 |
cp -fp "$3" "$dir/$2" |
91 |
# cp -f "$1" "$3.dir" |
92 |
$SEVENZ a "$arname" "$2" -w >/dev/null 2> /dev/null |
93 |
mv "$arname" "$1" |
94 |
cd $pwd |
95 |
rm -rf "$3.dir" |
96 |
} |
97 |
|
98 |
mc7zfs_copyout () |
99 |
{ |
100 |
dir=tmpdir.${RANDOM} |
101 |
mkdir /tmp/"$dir" |
102 |
# echo "$1 $2 $3" > hers |
103 |
# p7zip 0.91 don't understand filename in subdir without "./" |
104 |
# but in top dir it understand only without "./" |
105 |
FLIST=`$SEVENZ l "$1" 2> /dev/null` |
106 |
echo "$FLIST" | grep "[.][/]" > /dev/null 2>&1 && echo "$2" | grep "\/" > /dev/null 2>&1 && EXFNAME=*./"$2" || EXFNAME="$2" |
107 |
EXFN=`basename "$2"` |
108 |
$SEVENZ e -r- "$1" "$EXFNAME" -o/tmp/"$dir" > /dev/null 2> /dev/null |
109 |
|
110 |
cat /tmp/"$dir"/"$EXFN" > "$3" |
111 |
rm -rf /tmp/"$dir" |
112 |
} |
113 |
|
114 |
mc7zfs_mkdir () |
115 |
{ |
116 |
# Function not fully implemented, because 7z cannot keep empty directories |
117 |
# preserve pwd. |
118 |
pwd=`pwd` |
119 |
# Create a directory and create in it a tmp directory with the good name |
120 |
dir=tmpdir.${RANDOM} |
121 |
mkdir $dir |
122 |
cd $dir |
123 |
mv "$1" . |
124 |
arname=`basename "$1"` |
125 |
mkdir -p "$2" |
126 |
# 7z cannot create an empty directory |
127 |
# touch "$2"/.emptydir |
128 |
$SEVENZ a -r "$arname" "$2" >/dev/null 2>/dev/null |
129 |
# echo "$1" "$2" >error34 |
130 |
# $SEVENZ d ../"$1" "$2/.7zfs" >/dev/null |
131 |
mv "$arname" "$1" |
132 |
cd $pwd |
133 |
rm -rf $dir |
134 |
} |
135 |
|
136 |
mc7zfs_rm () |
137 |
{ |
138 |
$SEVENZ l "$1" 2> /dev/null | grep "[.][\\]" > /dev/null 2>&1 && echo "$2" | grep "\/" > /dev/null 2>&1 && EXFNAME=*./"$2" || EXFNAME="$2" |
139 |
$SEVENZ d "$1" "$EXFNAME" >/dev/null 2> /dev/null |
140 |
} |
141 |
|
142 |
umask 077 |
143 |
|
144 |
cmd="$1" |
145 |
shift |
146 |
|
147 |
case "$cmd" in |
148 |
list) mc7zfs_list "$@" ;; |
149 |
rm) mc7zfs_rm "$@" ;; |
150 |
rmdir) mc7zfs_rm "$@" ;; |
151 |
mkdir) mc7zfs_mkdir "$@" ;; |
152 |
copyin) mc7zfs_copyin "$@" ;; |
153 |
copyout) mc7zfs_copyout "$@" ;; |
154 |
*) exit 1 ;; |
155 |
esac |
156 |
exit 0 |