Commit f2afc901 authored by Vitaly Lipatov's avatar Vitaly Lipatov

use mount via sshfs and introduce opbrick for local ops

parent 6d9bb0ba
...@@ -18,8 +18,38 @@ set_host_path() ...@@ -18,8 +18,38 @@ set_host_path()
host="$(echo "$@" | sed -e "s|:.*||g")" host="$(echo "$@" | sed -e "s|:.*||g")"
path="$(echo "$@" | sed -e "s|.*:||g")" path="$(echo "$@" | sed -e "s|.*:||g")"
echo }
echo "$host - $path"
mount_g()
{
for i in $LISTBRICKS ; do
set_host_path "$i"
if [ -d "$MOUNTDIR/$host/$path" ] ; then
echo "Skip mounting $i"
else
echo "Mounting $i..."
mkdir -vp "$MOUNTDIR/$host/$path"
sshfs "$host:$path" "$MOUNTDIR/$host/$path"
fi
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
# 1 - cmd, 2 - file
opbrick()
{
#ssh $host $1 $path$2
$1 "$MOUNTDIR//$host/$path/$2"
} }
...@@ -36,13 +66,11 @@ fi ...@@ -36,13 +66,11 @@ fi
WORKDIR=~/grf WORKDIR=~/grf
mkdir -p $WORKDIR mkdir -p $WORKDIR
# TODO: rewrite in multiple file manner (or dir support?)
sfile="$1" sfile="$1"
[ -n "$sfile" ] || exit [ -n "$sfile" ] || exit
md5sum "$sfile"
stat "$sfile"
# hack
[ -L "$sfile" ] && FLAGSYMLINK=1
# hack
case "$sfile" in case "$sfile" in
/var/ftp/pvt/*) /var/ftp/pvt/*)
FTPROOT=/var/ftp/pvt FTPROOT=/var/ftp/pvt
...@@ -60,39 +88,55 @@ case "$sfile" in ...@@ -60,39 +88,55 @@ case "$sfile" in
fatal "Unknown place $sfile" fatal "Unknown place $sfile"
esac; esac;
# hack # hack: translate to a path on volume
file="$(echo "$sfile" | sed -e "s|$FTPROOT||g")" file="$(echo "$sfile" | sed -e "s|$FTPROOT||g")"
LISTBRICKS="$(get_bricks)" LISTBRICKS="$(get_bricks)"
MOUNTDIR=~/grf-mount
mkdir -p $MOUNTDIR
mount_g
echo
echo "mounted info:"
md5sum "$sfile"
FLAGBROKENFILE=
stat "$sfile" || FLAGBROKENFILE=1
# hack
FLAGSYMLINK=
[ -L "$sfile" ] && FLAGSYMLINK=1
if [ -z "$restore$remove" ] ; then if [ -z "$restore$remove" ] ; then
for i in $LISTBRICKS ; do for brick in $LISTBRICKS ; do
set_host_path "$i" set_host_path "$brick"
echo
echo "$host - $path"
# FIXME: если каталог не смонтировал, df покажет информацию о корне # FIXME: если каталог не смонтировал, df покажет информацию о корне
#ssh $host df $path #ssh $host df $path
# если каталог, показываем также информацию о самом каталоге # если каталог, показываем также информацию о самом каталоге
[ -d "$sfile" ] && ssh $host ls -ld $path$file [ -d "$sfile" ] && opbrick "ls -ld" "$file"
# показываем информацию о файле или содержимом каталога # показываем информацию о файле или содержимом каталога
if ssh $host ls -l $path$file ; then if opbrick "ls -l" "$file" ; then
if [ ! -L "$sfile" ] ; then if [ ! -L "$sfile" ] ; then
ssh $host md5sum $path$file opbrick md5sum "$file"
echo "$file" | grep -q rpm && ssh $host epm checkpkg $path$file echo "$file" | grep -q rpm && opbrick "epm checkpkg" "$file"
else else
echo "skip md5, it is link" echo "skip md5, it is link"
fi fi
fi fi
done done
fi fi
if [ "$remove" = "--allremove" ] ; then if [ "$remove" = "--allremove" ] ; then
for i in $LISTBRICKS ; do for brick in $LISTBRICKS ; do
set_host_path "$i" set_host_path "$brick"
# удаляем локальные размещения # удаляем локальные размещения
# пустых файлов # пустых файлов
ssh $host test -s "$path$file" || ssh $host rm "$path$file" opbrick "test -s" "$file" || opbrick rm -v "$file"
done done
fi fi
...@@ -102,12 +146,12 @@ if [ "$restore" = "--restore" ] ; then ...@@ -102,12 +146,12 @@ if [ "$restore" = "--restore" ] ; then
rm -f $WORKDIR/* rm -f $WORKDIR/*
for i in $LISTBRICKS ; do for i in $LISTBRICKS ; do
set_host_path "$i" set_host_path "$i"
FD=$(ssh $host stat -c "%z" $path$file) FD=$(opbrick 'stat -c %z' "$file")
echo $FD echo $FD
if [ -n "$FD" ] ; then if [ -n "$FD" ] ; then
touch -d "$FD" "$WORKDIR/$host-$COUNT" touch -d "$FD" "$WORKDIR/$host-$COUNT"
if [ -z "$OLDFILE" ] || [ "$OLDFILE" -nt "$WORKDIR/$host-$COUNT" ] ; then if [ -z "$OLDFILE" ] || [ "$OLDFILE" -nt "$WORKDIR/$host-$COUNT" ] ; then
if ssh $host test -s "$path$file" ; then if opbrick "test -s" "$file" ; then
OLDFILE="$WORKDIR/$host-$COUNT" OLDFILE="$WORKDIR/$host-$COUNT"
echo "Select OLDFILE:$OLDFILE" echo "Select OLDFILE:$OLDFILE"
fi fi
...@@ -136,7 +180,7 @@ if [ "$restore" = "--restore" ] ; then ...@@ -136,7 +180,7 @@ if [ "$restore" = "--restore" ] ; then
set_host_path "$i" set_host_path "$i"
# Удаляем всё, кроме OLDFILE # Удаляем всё, кроме OLDFILE
if ! [ "$OLDFILE" = "$WORKDIR/$host-$COUNT" ] ; then if [ -n "$OLDFILE" ] && [ ! "$OLDFILE" = "$WORKDIR/$host-$COUNT" ] ; then
ssh $host rm -fv $path$file ssh $host rm -fv $path$file
fi fi
...@@ -148,3 +192,6 @@ if [ "$restore" = "--restore" ] ; then ...@@ -148,3 +192,6 @@ if [ "$restore" = "--restore" ] ; then
COUNT=$(($COUNT+1)) COUNT=$(($COUNT+1))
done done
fi fi
echo
#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