Skip to content

Commit

Permalink
improved ls some more and added support for named mirrors to mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
jankom committed Apr 12, 2012
1 parent 94a1abe commit 1d156de
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
15 changes: 9 additions & 6 deletions mtl-ls
Expand Up @@ -5,22 +5,25 @@ showUsage() {
Usage:
ls ~ lists all documents
ls late ~ lists all documents
ls days ~ list add days with date names
ls nondays ~ list add nondays docs
EOF
}

# todo make it accept a pattern like ls
CMD=""
CMD="ls -tr .mtl/*.index | cut -d "." -f 2 | cut -d "/" -f 2"
if [ $# -eq 0 ]; then
CMD="ls -tr .mtl/*.index | cut -d "." -f 2 | cut -d "/" -f 2"
CMD="$CMD"
elif [ $# -eq 1 ]; then #filters
CMD="ls -tr .mtl/*.index | cut -d "." -f 2 | cut -d "/" -f 2"
if [ $1 == "late" ]; then
CMD="$CMD | tail"
fi
if [ $1 == "days" ]; then
elif [ $1 == "days" ]; then
CMD="$CMD | grep '^[0-9]\{4\}\-[0-9]\{2\}*\-[0-9]\{2\}$'"
fi
if [ $1 == "nondays" ]; then
elif [ $1 == "nondays" ]; then
CMD="$CMD | grep -v '^[0-9]\{4\}\-[0-9]\{2\}*\-[0-9]\{2\}$'"
else
CMD=""
fi
fi

Expand Down
79 changes: 46 additions & 33 deletions mtl-mirror
Expand Up @@ -17,52 +17,65 @@ if [ $# -eq 3 ]; then

REM="$3"
if [[ "$3" =~ ^: ]]; then
REM=`cat .mtl/.ghosts | grep "^:\s" | head -n 1 | cut -f 2`
fi


if [[ $REM =~ ":" ]]; then
dest1=`echo $REM | cut -f 1 -d ":"`
dest2=`echo $REM | cut -f 2 -d ":"`
ssh $dest1 "mkdir -p ${dest2}/.mtl/d"
REM=`cat .mtl/.mirrors | grep "^$2" | head -n 1 | cut -f 2`
else
mkdir -p ${REM}/.mtl/d
echo "Failed: No mirror with that name."
REM=""
fi

tempdir="/tmp/mtl/blobs"
mkdir -p ${tempdir}

echo "copying wrk index and src files to $REM"

scp .mtl/${1}* ${REM}/.mtl/.
if [[ $REM != "" ]]; then
if [[ $REM =~ ":" ]]; then
dest1=`echo $REM | cut -f 1 -d ":"`
dest2=`echo $REM | cut -f 2 -d ":"`
ssh $dest1 "mkdir -p ${dest2}/.mtl/d"
else
mkdir -p ${REM}/.mtl/d
fi

tempdir="/tmp/mtl/blobs"
mkdir -p ${tempdir}

echo "copying wrk index and src files to $REM"

scp .mtl/${1}* ${REM}/.mtl/.
#get blobs and copy them
for blob in `cat .mtl/${1}.index | cut -f 1 | uniq`
do
echo "copying blob: $blob to temp"
cp -a .mtl/d/$blob ${tempdir}/.
done
rsync -avz ${tempdir}/. ${REM}/.mtl/d/.
echo "DONE"
for blob in `cat .mtl/${1}.index | cut -f 1 | uniq`
do
echo "copying blob: $blob to temp"
cp -a .mtl/d/$blob ${tempdir}/.
done
rsync -avz ${tempdir}/. ${REM}/.mtl/d/.
echo "DONE"
else
showUsage
fi
else
showUsage
fi
elif [ $# -eq 2 ]; then

REM="$2"
if [[ "$2" =~ ^: ]]; then
REM=`cat .mtl/.ghosts | grep "^:\s" | head -n 1 | cut -f 2`
REM=`cat .mtl/.mirrors | grep "^$2" | head -n 1 | cut -f 2`
echo $REM
fi

if [ $1 == "to" ]; then
echo "rsyncing the mtl dir to $REM"
rsync -avz .mtl/* ${REM}/.mtl
echo "DONE"
elif [ $1 == "from" ]; then
echo "rsyncing the mtl dir from $REM"
rsync -avz ${REM}/.mtl/* .mtl
echo "DONE"
if [[ $REM != "" ]]; then

if [ $1 == "to" ]; then
echo "rsyncing the mtl dir to $REM"
rsync -avz .mtl/* ${REM}/.mtl
echo "DONE"
elif [ $1 == "from" ]; then
echo "rsyncing the mtl dir from $REM"
rsync -avz ${REM}/.mtl/* .mtl
echo "DONE"
else
showUsage
fi
else
showUsage
echo "Failed: No mirror with that name."
REM=""
fi
else
showUsage
Expand Down

0 comments on commit 1d156de

Please sign in to comment.