#!/usr/bin/bash
# File: mergeall-data-to-plug-update.sh
#--------------------------------------------------------
# Run the main Mergeall script on Android to make $plug
# the same as $data.  This automatically propagates all 
# changes from your $data content copy to your $plug copy.
# This uses path variables set in your ~/.bash_profile.
# See _README.html for all general usage instructions.
#--------------------------------------------------------

# Load current path settings
source ~/.bash_profile

# Run in work folder for logs
pushd $work > /dev/null
echo "Starting: $PWD"

# Route logfile output here
logdir=Admin-Mergeall

# Filename passed as arg else generated
if [ $# == 1 ]
then
    logname=$1
else
    logname=mergeall-$(date +%Y%m%d-%H%M%S).txt
fi

# Create logfiles dir if needed
if [ ! -e $logdir ] 
then
    mkdir $logdir
    echo "Created $logdir"
fi

# Run and save log, py's -u may or may not help tails
python -u Mergeall-source/mergeall.py \
    $data \
    $plug \
    -auto -backup -quiet -skipcruft \
        > $logdir/$logname

# Back to starting dir
popd > /dev/null
echo "Finished: $PWD"
