#!/bin/sh url="rigadogateway.com" get_fuse () { local name=$1 local pad=$2 # read the fuse and pad the left with zeros to the size of $pad local fuse="0000000000"$(cat /sys/fsl_otp/$name | cut -b 3-) len=$(( ${#fuse} - $pad )) echo ${fuse:$len} } get_sn () { local base=$1 local arena=$(get_fuse HW_OCOTP_GP$base 7) if [[ ${arena:0:2} == "00" ]] ; then # starts with "00", so doesn't start with ascii hex value arena=${arena:2} else # doesn't start with "00", so starts with ascii hex value arena=$(printf "\x${arena:0:2}${arena:2}") fi local build=$(get_fuse HW_OCOTP_GP$(( $base + 1)) 4) local unit=$(get_fuse HW_OCOTP_GP$(( $base + 2)) 5) echo "$arena$build-$unit" } if [[ "$(cat /sys/fsl_otp/HW_OCOTP_GP37)" == "0x0" ]] ; then # No unit serial number set, use board serial number hostname $(get_sn 34).$url else # unit serial number set, use it hostname $(get_sn 37).$url fi