forked from jprochazka/adsb-exchange
-
Notifications
You must be signed in to change notification settings - Fork 2
/
create-uuid.sh
executable file
·42 lines (37 loc) · 1.17 KB
/
create-uuid.sh
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
#!/bin/bash
UUID_FILE="/usr/local/share/flyitalyadsb/flyitalyadsb-uuid"
# Let's make sure the UUID tools are installed...
UUIDGEN=$(command -v uuidgen)
RV=$?
if [ $RV -ne 0 ]; then
echo "Can't find uuidgen in path, trying to install uuidgen..."
apt-get -y install uuid-runtime
UUIDGEN=$(command -v uuidgen)
RV=$?
if [ $RV -ne 0 ]; then
echo "Failed to install uuid-runtime package - need manual intervention!"
sleep 60
exit 10
fi
fi
# Check for a (valid) UUID...
if [ -f $UUID_FILE ]; then
UUID=$(cat $UUID_FILE)
if ! [[ $UUID =~ ^\{?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}\}?$ ]]; then
# Data in UUID file is invalid. Regenerate it!
echo "WARNING: Data in UUID file was invalid. Regenerating UUID."
rm -f $UUID_FILE
UUID=$($UUIDGEN)
echo New UUID: $UUID
echo $UUID > $UUID_FILE
else
echo "Using existing valid UUID ($UUID) from $UUID_FILE"
fi
else
# not found generate uuid and save it
echo "WARNING: No UUID file found, generating new UUID..."
UUID=$($UUIDGEN)
echo New UUID: $UUID
echo $UUID > $UUID_FILE
fi
exit 0