made the script interactive... (still a bit messy but works...)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-08-05 04:24:50 +04:00
parent 6a19bc56d9
commit b7ff1dc1ba

View File

@ -18,13 +18,17 @@ while true ; do
echo echo
exit exit
;; ;;
-i|--interactive)
INTERACTIVE=1
shift
;;
-m|-multi|--multi) -m|-multi|--multi)
MULTI=1 MULTI=1
shift shift
;; ;;
-l|-last|--last) -l|-last|--last)
LAST=1 LAST=1
COMMON_FLAG=-c
shift shift
;; ;;
*) *)
@ -33,42 +37,107 @@ while true ; do
esac esac
done done
if ! [ -z "$2" ] ; then if ! [ -z "$2" ] ; then
TITLE=" - $2" TITLE=" - $2"
fi fi
# XXX do a real three digit count... DRIVE=${1}
# single flash card...
if [ -z $MULTI ] ; then while true ; do
DIR="./- ${DATE}.00${COUNT}${TITLE}/" if [[ $INTERACTIVE || ! $DRIVE ]] ; then
while [ -e "$DIR" ] ; do INTERACTIVE=1
COUNT=$((COUNT+1)) echo "Select/toggle an option:"
echo "0) Multi flash card mode is `[[ $MULTI ]] && echo "on" || echo "off"`"
echo "1) Directoy description is: \"$TITLE\"."
if [[ ! $DRIVE ]] ; then
echo "a-z) type a drive letter."
else
echo "a-z) type a new drive letter."
echo "Enter) copy drive ${DRIVE}"
fi
echo "2) build."
echo "3) quit."
read -p ": " RES
case $RES in
# toggle multi mode...
0)
MULTI=`[[ ! $MULTI ]] && echo 1 || echo ""`
continue
;;
1)
read -p "new description: " TITLE
TITLE=" - $TITLE"
continue
;;
# continue with same drive or ask again...
"")
if [[ ! $DRIVE ]] ; then
echo "ERR: need a drive to copy from, no defaults."
echo
continue
fi
DRIVE=$DRIVE
;;
2)
LAST=1
break
;;
3)
exit
;;
# new drive letter...
*)
DRIVE=$RES
;;
esac
fi
# XXX do a real three digit count...
# single flash card...
if [ -z $MULTI ] ; then
DIR="./- ${DATE}.00${COUNT}${TITLE}/" DIR="./- ${DATE}.00${COUNT}${TITLE}/"
done while [ -e "$DIR" ] ; do
BASE_DIR=$DIR COUNT=$((COUNT+1))
DIR="./- ${DATE}.00${COUNT}${TITLE}/"
done
BASE_DIR=$DIR
# multiple flash cards shoot... # multiple flash cards shoot...
else else
BASE_DIR="./- ${DATE}${TITLE}/" BASE_DIR="./- ${DATE}${TITLE}/"
DIR="${BASE_DIR}/${DATE}.00${COUNT}/"
while [ -e "$DIR" ] ; do
COUNT=$((COUNT+1))
DIR="${BASE_DIR}/${DATE}.00${COUNT}/" DIR="${BASE_DIR}/${DATE}.00${COUNT}/"
done while [ -e "$DIR" ] ; do
COUNT=$((COUNT+1))
DIR="${BASE_DIR}/${DATE}.00${COUNT}/"
done
fi
mkdir -vp "$DIR"
echo "Copying files from $1..."
cp -Rpfv /mnt/${DRIVE}/* "$DIR"
echo "Copying files: done."
# exit interactive mode...
if [[ ! $INTERACTIVE || $LAST ]] ; then
break
fi
done
if [[ $LAST ]] ; then
COMMON_FLAG=-c
fi fi
mkdir -vp "$DIR"
echo "Copying files from $1..."
cp -Rpfv /mnt/${1}/* "$DIR"
echo "Copying files: done."
if [[ ! $MULTI || $LAST ]] ; then if [[ ! $MULTI || $LAST ]] ; then
echo "Building archive..." echo "Building archive..."
./process-archive.sh $COMMON_FLAG "$BASE_DIR" ./process-archive.sh $COMMON_FLAG "$BASE_DIR"
echo "Building archive: done." echo "Building archive: done."
fi fi