aboutsummaryrefslogtreecommitdiff
path: root/aux/lib.sh
blob: b47812dc760d487adf3ef0af24039706907568fb (about) (plain) (blame)
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
#!/bin/sh

#
# Generally, utilities that I expected to exist in POSIX, but don't.
#

uuid() {
	# Taken from:
	# https://serverfault.com/a/799198
	od -xN20 /dev/urandom |
		head -n1 |
		awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
}

tmpname() {
	echo 'mkstemp(template)' | m4 -D template="${TMPDIR:-/tmp}/m4-tmpname."
}

mkstemp() {
	name="$(tmpname)"
	touch "$name"
	echo "$name"
}

mkdtemp() {
	name="$(tmpname)"
	rm -f "$name"
	mkdir "$name"
	echo "$name"
}