#!/bin/sh

# mk_release
# Copyright (C) 2017, 2018, 2020 Joseph Rosevear, San Diego CA, USA.

# $1 relative or absolute path to source dir.
# $2 date name, e.g., "170803aa".
# $3 software name, SAM.
# $4 alternate install target

# Example use:

#    mk_release 170803aa tool

# Note.  Ideally, only make releases of dirs that have changed.
# Don't forget to update README with release notes.



# Joseph Rosevear 181007 I abandoned use of --exclude-from=exclude,
# because I can't get it to work.  It used to work!  Instead I'll do
# the selecting first with rsync, then a separate tar operation.

# To accomplish this I

#    1.  Uncommented lines below for running mirror.

#    2.  Changed the cd line to operate on $env_scratch/target instead
#    of $env_scratch.

#    3.  Commented out the tar line

#       tar cvvzf $env_scratch/$3.$2.tar.gz $1 --exclude-from=exclude 

#     and wrote a new one

#       tar cvvzf $env_scratch/$3.$2.tar.gz . 



# Joseph Rosevear 200323 I put the execution of tar and the prompt re
# README into an if-block, thus making it optional.

# Joseph Rosevear 200324 I added $4, alternate install target.


# Define target
target=$env_scratch
if [ \( "$4" != "" \) -a \
     \( -d "$4" \) ]; then
     
   target="$4"
fi

# Ask user if target is OK.
echo "OK to install to $target (y/n) ?"

read answer
if [ "$answer" != "y" ]; then

   echo "Goodbye."
   exit
fi


# mirror to target
bound /home/joe/config/private/other
tools; mirror
mirror $1 $target
bye; bye; bye

cd $target

# Joseph Rosevear 180325 I changed this line.  I think the first
# version was wrong.
# tar czf ../../releases/$2.$1.tar.gz $2
# tar czf ../../releases/$2.$1.tar.gz $1
# tar cztf $env_scratch/$3.$2.tar.gz target 
# tar czf $env_scratch/$3.$2.tar.gz $1 --exclude-from=$1/exclude 
# tar cvvzf $env_scratch/$3.$2.tar.gz $1 --exclude-from=exclude 

# Run tar?
echo "Run tar (y/n) ?"
read answer

if [ "$answer" = "y" ]; then

   tar cvvzf $env_scratch/$3.$2.tar.gz . 
   echo "Did you update README?" 
fi
