forked from parallella/parallella-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flenv.sh
executable file
·50 lines (42 loc) · 1.18 KB
/
flenv.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
43
44
45
46
47
48
49
50
#!/bin/bash
# Utility/example to read environment settings from a Parallella flash memory
# 5/22/14 Fred Huettig
#
# Option: -all - list all var's from flash
set -e
FLASHNODE=/dev/mtd0
MKARGS="b 31 0"
ENVSTART=5111814
ENVSIZE=1024
SKUVAR="AdaptevaSKU"
if [ ! -b $FLASHNODE -a ! -c $FLASHNODE ] ; then
if [ -e $FLASHNODE ] ; then
echo "ERROR: Something's in the way of $FLASHNODE"
exit 1
fi
sudo mknod $FLASHNODE $MKARGS
echo "Created node $FLASHNODE"
fi
ENV=`tail -c +$ENVSTART $FLASHNODE | head -c $ENVSIZE | tr -s "\0" "\n"`
if [ "$ENV" == "" ] ; then
echo "Can't read from flash, did you sudo?"
exit 2;
fi
ENV+=$'\n' # Make sure there is a \n at the end
# I'm sure there is a more efficient way to do this,
# but the following should be reasonably portable
if [ "$1" = "-all" ] ; then
ETEMP=$ENV
while [ "$ETEMP" ] ; do
echo "> ${ETEMP%%$'\n'*}"
ETEMP="${ETEMP#*$'\n'}"
done
fi
# Find our SKU, first check if it's there at all:
if [[ "$ENV" =~ $SKUVAR= ]] ; then
AdaptevaSKU="${ENV#*$SKUVAR=}"
AdaptevaSKU="${AdaptevaSKU%%$'\n'*}"
echo "Our SKU is: $AdaptevaSKU"
else
echo "It's very likely our SKU is SKUA101040, but not certain"
fi