From 6a19bc56d91550405298de8d3968f6498c2af025 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 2 Aug 2014 18:56:28 +0400 Subject: [PATCH] added abulity to copy multiple flash cards into a single root dir (see: -multi and -last flags) Signed-off-by: Alex A. Naanou --- scripts/sync-flash.sh | 68 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/scripts/sync-flash.sh b/scripts/sync-flash.sh index 88e8c485..80781086 100755 --- a/scripts/sync-flash.sh +++ b/scripts/sync-flash.sh @@ -4,23 +4,62 @@ DATE=`date +%Y%m%d` COUNT=1 TITLE="" -if ! [ -z $2 ] ; then +while true ; do + case "$1" in + -h|-help|--help) + echo "usage: `basename $0` FLAGS DRIVE [TITLE]" + echo + echo " -h|-help print this message and exit." + echo " -m|-multi single base, multiple sub dirs" + echo " for multiple flash cards in a" + echo " single shoot." + echo " -l|-last last flash card in set, run" + echo " process-archive.sh after copying." + echo + exit + ;; + -m|-multi|--multi) + MULTI=1 + shift + ;; + -l|-last|--last) + LAST=1 + COMMON_FLAG=-c + shift + ;; + *) + break + ;; + esac +done + + +if ! [ -z "$2" ] ; then TITLE=" - $2" fi # XXX do a real three digit count... -DIR="./- ${DATE}.00${COUNT}${TITLE}/" - -while [ -e "$DIR" ] ; do - COUNT=$((COUNT+1)) +# single flash card... +if [ -z $MULTI ] ; then DIR="./- ${DATE}.00${COUNT}${TITLE}/" -done + while [ -e "$DIR" ] ; do + COUNT=$((COUNT+1)) + DIR="./- ${DATE}.00${COUNT}${TITLE}/" + done + BASE_DIR=$DIR + +# multiple flash cards shoot... +else + BASE_DIR="./- ${DATE}${TITLE}/" + DIR="${BASE_DIR}/${DATE}.00${COUNT}/" + while [ -e "$DIR" ] ; do + COUNT=$((COUNT+1)) + DIR="${BASE_DIR}/${DATE}.00${COUNT}/" + done +fi -echo "Creating directory: $DIR" -mkdir "$DIR" -echo "Creating directory: done." - +mkdir -vp "$DIR" echo "Copying files from $1..." @@ -28,7 +67,8 @@ cp -Rpfv /mnt/${1}/* "$DIR" echo "Copying files: done." - -echo "Building archive..." -./process-archive.sh "$DIR" -echo "Building archive: done." +if [[ ! $MULTI || $LAST ]] ; then + echo "Building archive..." + ./process-archive.sh $COMMON_FLAG "$BASE_DIR" + echo "Building archive: done." +fi