OLD | NEW |
(Empty) | |
| 1 ## Created 7/14/2006 by Tom Whipple <tom.whipple@intel.com> |
| 2 |
| 3 ## create a globally unique identifier (GUID) |
| 4 ## note that this is LIKELY to be unique, but not 100% guaranteed. |
| 5 get_guid() { |
| 6 prefix=$1 |
| 7 now=`date '+%F-%H%M%S.%N'` |
| 8 GUID="$prefix$now-$RANDOM" |
| 9 } |
| 10 |
| 11 get_tmpsubdir() { |
| 12 if [ ! -z "$1" ] ; then |
| 13 tmp="$1" |
| 14 else |
| 15 tmp=${TMPDIR-/tmp} |
| 16 fi |
| 17 if [ -z "$GUID" ] ; then |
| 18 get_guid |
| 19 fi |
| 20 TMPSUBDIR="$tmp/$GUID-$$" |
| 21 (umask 000 && mkdir -p $TMPSUBDIR) || { |
| 22 echo "Could not create temporary directory!" >&2 |
| 23 exit 255 |
| 24 } |
| 25 } |
| 26 |
| 27 get_shortid() { |
| 28 seqfile=$1 |
| 29 |
| 30 today=`date '+%m-%d'` |
| 31 |
| 32 if [ -f "$seqfile" ] ; then |
| 33 seqdate=`cat $seqfile | cut -d '+' -f 1 -` |
| 34 if [ "$today" = "$seqdate" ] ; then |
| 35 seq=$(( `cat $seqfile | cut -d '+' -f 2 -` + 1 )) |
| 36 else |
| 37 seq=1 |
| 38 fi |
| 39 else |
| 40 seq=1 |
| 41 fi |
| 42 |
| 43 SHORTID="$today+$seq" |
| 44 echo "$SHORTID" > "$seqfile" |
| 45 |
| 46 } |
| 47 |
OLD | NEW |