Commit 71d837da authored by Vitaly Lipatov's avatar Vitaly Lipatov

grf: update for list support

parent 8056c4bd
...@@ -20,29 +20,30 @@ set_host_path() ...@@ -20,29 +20,30 @@ set_host_path()
} }
umount_g()
{
for i in $LISTBRICKS ; do
set_host_path "$i"
#echo "Unmounting $i..."
umount -v "$MOUNTDIR/$host/$path"
rmdir "$MOUNTDIR/$host/$path"
done
}
mount_g() mount_g()
{ {
for i in $LISTBRICKS ; do for i in $LISTBRICKS ; do
set_host_path "$i" set_host_path "$i"
if [ -d "$MOUNTDIR/$host/$path" ] ; then if [ -d "NO$MOUNTDIR/$host/$path" ] ; then
echo "Skip mounting $i" echo "Skip mounting $i"
else else
echo "Mounting $i..." echo "Mounting $i..."
mkdir -vp "$MOUNTDIR/$host/$path" mkdir -vp "$MOUNTDIR/$host/$path"
sshfs "$host:$path" "$MOUNTDIR/$host/$path" sshfs "$host:$path" "$MOUNTDIR/$host/$path" || { echo "Error mount" ; umount_g ; exit 1 ; }
fi fi
done done
} }
umount_g()
{
for i in $LISTBRICKS ; do
set_host_path "$i"
#echo "Unmounting $i..."
umount -v "$MOUNTDIR/$host/$path"
rmdir "$MOUNTDIR/$host/$path"
done
}
# use host and path # use host and path
# 1 - cmd, 2 - file # 1 - cmd, 2 - file
...@@ -52,6 +53,12 @@ opbrick() ...@@ -52,6 +53,12 @@ opbrick()
$1 "$MOUNTDIR//$host/$path/$2" $1 "$MOUNTDIR//$host/$path/$2"
} }
sshopbrick()
{
ssh $host $1 $path$2
#$1 "$MOUNTDIR//$host/$path/$2"
}
if [ "$1" = "--allremove" ] || [ "$1" = "--removeNO" ] ; then if [ "$1" = "--allremove" ] || [ "$1" = "--removeNO" ] ; then
remove="$1" remove="$1"
...@@ -68,7 +75,15 @@ mkdir -p $WORKDIR ...@@ -68,7 +75,15 @@ mkdir -p $WORKDIR
# TODO: rewrite in multiple file manner (or dir support?) # TODO: rewrite in multiple file manner (or dir support?)
sfile="$1" sfile="$1"
[ -n "$sfile" ] || exit sdir=
if [ "$1" = "--list" ] ; then
shift
uselist="$1"
# hack for detect
sfile=$(cat "$uselist" | grep ^/ | head -n1)
fi
# hack # hack
case "$sfile" in case "$sfile" in
...@@ -88,25 +103,63 @@ case "$sfile" in ...@@ -88,25 +103,63 @@ case "$sfile" in
fatal "Unknown place $sfile" fatal "Unknown place $sfile"
esac; esac;
# hack: translate to a path on volume
file="$(echo "$sfile" | sed -e "s|$FTPROOT||g")"
LISTBRICKS="$(get_bricks)" LISTBRICKS="$(get_bricks)"
MOUNTDIR=~/grf-mount MOUNTDIR=~/grf-mount
# TODO: move before GVOLUME detect
if [ "$1" = "--umount" ] ; then
umount_g
exit
fi
# check and fix path
if [ -n "$sfile" ] ; then
if [ -d "$sfile" ] ; then
sfile="$sfile/*"
fi
if echo "$sfile" | grep "\*" ; then
sdir="$(dirname "$sfile")"
if [ -d "$sdir" ] ; then
echo "Work with dir $sdir"
else
sdir=
fi
else
echo "Work with single file $sfile"
fi
else
echo "Run with file path as arg"
exit 1
fi
mkdir -p $MOUNTDIR mkdir -p $MOUNTDIR
mount_g mount_g
test_file()
{
local sfile="$1"
echo echo
echo "mounted info:" echo "mounted info for $sfile:"
md5sum "$sfile" [ -z "$restore" ] && md5sum "$sfile"
FLAGBROKENFILE= FLAGBROKENFILE=
stat "$sfile" || FLAGBROKENFILE=1 stat "$sfile" >/dev/null || FLAGBROKENFILE=1
if [ -n "$restore" ] && [ -z "$FLAGBROKENFILE" ] ; then
# skipping, file metainfo is readable
return 0
fi
# hack: translate to a path on volume
file="$(echo "$sfile" | sed -e "s|$FTPROOT||g")"
# hack # hack
FLAGSYMLINK= FLAGSYMLINK=
[ -L "$sfile" ] && FLAGSYMLINK=1 [ -L "$sfile" ] && FLAGSYMLINK=1
stat "$sfile"
if [ -z "$restore$remove" ] ; then if [ -z "$restore$remove" ] ; then
for brick in $LISTBRICKS ; do for brick in $LISTBRICKS ; do
...@@ -122,8 +175,8 @@ for brick in $LISTBRICKS ; do ...@@ -122,8 +175,8 @@ for brick in $LISTBRICKS ; do
# показываем информацию о файле или содержимом каталога # показываем информацию о файле или содержимом каталога
if opbrick "ls -l" "$file" ; then if opbrick "ls -l" "$file" ; then
if [ ! -L "$sfile" ] ; then if [ ! -L "$sfile" ] ; then
opbrick md5sum "$file" sshopbrick md5sum "$file"
echo "$file" | grep -q rpm && opbrick "epm checkpkg" "$file" echo "$file" | grep -q rpm && sshopbrick "epm checkpkg" "$file"
else else
echo "skip md5, it is link" echo "skip md5, it is link"
fi fi
...@@ -175,13 +228,15 @@ if [ "$restore" = "--restore" ] ; then ...@@ -175,13 +228,15 @@ if [ "$restore" = "--restore" ] ; then
ls -l $WORKDIR ls -l $WORKDIR
echo "OLD: $OLDFILE" echo "OLD: $OLDFILE"
if [ -n "$OLDFILE" ] ; then
COUNT=1 COUNT=1
for i in $LISTBRICKS ; do for i in $LISTBRICKS ; do
set_host_path "$i" set_host_path "$i"
# Удаляем всё, кроме OLDFILE # Удаляем всё, кроме OLDFILE
if [ -n "$OLDFILE" ] && [ ! "$OLDFILE" = "$WORKDIR/$host-$COUNT" ] ; then if [ ! "$OLDFILE" = "$WORKDIR/$host-$COUNT" ] ; then
ssh $host rm -fv $path$file opbrick "rm -fv" "$file"
echo "$path$file ($host)" >>grf.removed.list
fi fi
# нулевые с правами 10000 уберём по-другому # нулевые с правами 10000 уберём по-другому
...@@ -191,7 +246,20 @@ if [ "$restore" = "--restore" ] ; then ...@@ -191,7 +246,20 @@ if [ "$restore" = "--restore" ] ; then
COUNT=$(($COUNT+1)) COUNT=$(($COUNT+1))
done done
fi
fi
}
if [ -n "$uselist" ] ; then
cat "$uselist" | grep "^/" | while read sf ; do
test_file "$sf" </dev/null
done
else
# TODO: use find?
for sf in $sfile ; do
test_file "$sf"
done
fi fi
echo echo
#umount_g umount_g
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment