File: tempfile.sh

package info (click to toggle)
xdg-utils 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,268 kB
  • ctags: 321
  • sloc: sh: 7,394; perl: 274; makefile: 190; xml: 32
file content (47 lines) | stat: -rw-r--r-- 837 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Created 7/14/2006 by Tom Whipple <tom.whipple@intel.com>

## create a globally unique identifier (GUID)
## note that this is LIKELY to be unique, but not 100% guaranteed.
get_guid() {
	prefix=$1
	now=`date '+%F-%H%M%S.%N'`
	GUID="$prefix$now-$RANDOM"
}

get_tmpsubdir() {
	if [ ! -z "$1" ] ; then
		tmp="$1"
	else
		tmp=${TMPDIR-/tmp}
	fi
	if [ -z "$GUID" ] ; then
		get_guid
	fi
	TMPSUBDIR="$tmp/$GUID-$$"
	(umask 000 && mkdir -p $TMPSUBDIR) || {
		echo "Could not create temporary directory!" >&2 
		exit 255
	}
}

get_shortid() {
	seqfile=$1

	today=`date '+%m-%d'`

	if [ -f "$seqfile" ] ; then	
		seqdate=`cat $seqfile | cut -d '+' -f 1 -`
		if [ "$today" = "$seqdate" ] ; then
			seq=$(( `cat $seqfile | cut -d '+' -f 2 -` + 1 ))
		else
			seq=1
		fi
	else
		seq=1
	fi

	SHORTID="$today+$seq"
	echo "$SHORTID" > "$seqfile"
	
}