#!/bin/bash

# this is an "end user" script to publish SDR repositories based on
# username, which is the same as the repo name.  users must be in sudoers
# for this to work.  It ultimately calls publishSDR2web.sh (which
# must be run as user "sdr" for rsync over ssh to work.
#
#  --craiger

export PATH=$PATH:/usr/local/bin

#repo name is username
export reponame=`id -u -n`

PROJPATH=project/$reponame

if [ $# -gt 0 ]; then
  REPOPATH=repo/$reponame/$1 
else
  echo "Using default path of 'repo/$reponame' . "
  REPOPATH=repo/$reponame
fi

# run simulation
echo "Running rsync simulation...."
echo ""
echo $PROJPATH:
sudo -u sdr /usr/local/bin/publishSDR2web.sh -p $PROJPATH -n -d
echo ""
echo $REPOPATH:
sudo -u sdr /usr/local/bin/publishSDR2web.sh -p $REPOPATH -n -d

echo    "  "
while true; do
    read -p "Simulation complete -- really sync? (y/n): " yn
    case $yn in
        [Yy]* ) sudo -u sdr /usr/local/bin/publishSDR2web.sh -p $REPOPATH -d ; sudo -u sdr /usr/local/bin/publishSDR2web.sh -p $PROJPATH -d ; sudo -u sdr /usr/local/bin/publishSDR2rsync.sh -p $REPOPATH -d ;  break;;
        [Nn]* ) exit;;
        * ) echo "Please answer y or n.";;
    esac
done


exit
