bin/gentime
#!/bin/bash
#
#{{IS_NOTE
#
# Authors: Tom M. Yeh
# Contributors:
# Create Date: 2001/3/30 05:46PM
# Purpose: Generate the current time
# Description:
# The resolution is hour (so the same JAR file won't be re-zipped
# in the same hour if nothing changed).
# History:
#
#}}IS_NOTE
#
# Copyright (C) 2007 Potix Corporation. All Rights Reserved.
#
#{{IS_RIGHT
# This program is distributed under GPL Version 3.0 in the hope that
# it will be useful, but WITHOUT ANY WARRANTY.
#}}IS_RIGHT
#
function showhelp
{
echo "gentime - generate the current time (up to hour)"
echo "Copyright (C) 2007 Potix Corporation. All Rights Reserved."
echo
echo "Usage:"
echo " gentme [-h] [dstfl]"
echo
echo "dstfl"
echo " The destination file. If omitted, the time is generated to stdout."
echo " If the content of the destination file is the same, the file"
echo " won't be changed."
echo
echo "Note: if the directory doesn't exist, nothing is generated"
}
if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
showhelp
exit 0
fi
stamp=$(date +%Y%m%d%H)
if [ "$1" = "" ] ; then
echo $stamp
exit 0
fi
dstfl=$1
if [ -f $dstfl ] && [ "$(cat $dstfl)" = "$stamp" ] ; then
exit 0
fi
echo Generate build identifier: $stamp
mkdir -p "${dstfl%/*}"
echo $stamp > "$dstfl"