#!/bin/bash

# Autor: Marcus Orthbandt
# Dieses Script generiert die SystemID und speichert, und gibt die aktuelle SystemID zurueck


. /etc/profile


# MAIN

SYSTEMID=""

# Aktuelle File Location
if  [ -f "/etc/xlinux/systemid" ]; then  
  SYSTEMID=$(cat /etc/xlinux/systemid)
fi

# Old File Location
if  [ "x$SYSTEMID" == "x" -a -f "/etc/xlinux_systemid" ]; then  
  SYSTEMID=$(cat /etc/xlinux_systemid)
  echo -n $SYSTEMID > /etc/xlinux/systemid
fi

# Generate New Id
if  [ "x$SYSTEMID" == "x" ]; then  
  UUID=$(stat -f -c %i / )
  #UUID=$(dmidecode -s system-uuid)
  SYSTEMID="${UUID}-$(date +%s)"
  echo -n $SYSTEMID > /etc/xlinux/systemid  
fi


if [ "x$1" == "x" ]; then
  echo -n $SYSTEMID
fi

test -f /etc/xlinux_systemid && rm /etc/xlinux_systemid


exit 0


# Speichern der neuenen SystemID noch nicht....
if [ "x$result" != "x" ]; then
  # Rückmeldung auswerten
  read command value1 value2 value3 <<< $result
  if [ "_$command" == "_set" ]; then
    echo $value1 > /etc/xlinux_hardwareid
  fi
fi

