#!/bin/bash
#
# version: 0.93   2005-02-15
#
# packup_wwwofflebook --copy-all
# packup_wwwofflebook -h | --help
#
# Update the wwwofflebook installation directory with the config of 
# the user-maintainer, then create a tarball in /tmp.
# Soucres wwwofflebook.conf.
# You MUST CONFIGURE this script in the CONFIG section below !
#
# Note that if you want to ship the original package, you don't need this 
# script. Instead, just make a tar.bz2 like:
# tar -cvj  --directory=/opt --file /tmp/wwwofflebook wwwofflebook
# This creates a tarball in /tmp, with a relative directory-root 'wwwofflebook/'.
#
# Options: 
#
# --copy-all 
# Without this commandline option, by default, these files are omitted:
# * Your real purge.conf (for privacy)
# * Your dontget.conf file (because unrelated)
# If you specify --copy-all these files wil becopied also.
# If you really want to ship your private purge.conf, consider to trim the
# created copy manually.


# =================== CONFIG BEGIN
#
CONFIG=/home/michl/.wwwoffle/wwwofflebook.conf
source $CONFIG
# 
# The original installation directory with the running scripts:
PACKAGE_DIR=/opt/wwwofflebook
# Optionally to update with --copy-all: 
PURGECONF=/etc/wwwoffle/purge.conf
DONTGET=/etc/wwwoffle/dontget.conf
#
# Now we can derive some destination pathers:
DEST_CONFIG=$PACKAGE_DIR/userdir/.wwwoffle/wwwofflebook.conf
DEST_PURGECONF=$PACKAGE_DIR/wwwoffledir/purge.conf-please-edit
DEST_DONTGET=$PACKAGE_DIR/wwwoffledir/dontget.conf-example

# Where to place the tarball
tempdir=/tmp
#
# The name (not the arcives internal top directoy) of the tarball: 
tarballname=wwwofflebook        # .tar.bz2 will be appendet
#
# Derived...full pathname of the new tarball
tarball=$tempdir/$tarballname.tar.bz2
#
# HACKING THIS SCRIPT:
# Some useful 'cp' options:
# -v=verbose, -f=force overwrite, -p=preserve attributes and -r=recursive.
# Note that -a equals -dpPR, so it's recursive !
# Copying ais configured to be always asking if to overwrite.
# Use $savecopy (defined in preconfig section below) if you want to copy 
# symliks as file content rather than as links, and no recursion. 
# Use $copy if you want to preserve anything possible including symlinks, 
# and overwrite exisitng files, and copy recursivly.
#
# script defaults
unalias cp 2>/dev/null
safecopy="cp -vfi --preserve=mode,ownership"
copy="cp -vfai"
copy_all=false
#
# commandline
[ "$1" = "--copy-all" ] && copy_all=true
[ "$1" = "-h" ] && exec less $0
#
#
# ==================  MAIN
clear
#
echo -e "\nUpdating the package installation directory:\n"
$copy $CONFIG $DEST_CONFIG
echo
$copy_all && $copy $PURGECONF $DEST_PURGECONF
echo
$copy_all && $copy $DONTGET $DEST_DONTGET
#
# tarball
echo -e "\nCreating tarball $tarball:\n"
tar -cvj  --directory=$PACKAGE_DIR/.. --file=$tarball `basename $PACKAGE_DIR`
#
#
echo ............. done.
