2021-04-12 08:10:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
function generate_hostname() {
|
|
|
|
mac=$( ifconfig |grep eth0 | grep -io '[0-9a-f:]\{15\}[0-9a-f]\{2\}' )
|
|
|
|
mac=${mac//:}
|
|
|
|
nic=${mac:6}
|
|
|
|
nic=$(( 16#$nic ))
|
|
|
|
let length=32
|
|
|
|
|
|
|
|
for i in 4 3 2 1 0; do
|
|
|
|
let div=$length**$i
|
|
|
|
let idx=$nic/$div
|
|
|
|
let nic=$nic%$div
|
|
|
|
|
|
|
|
if [ $idx = 0 ] ; then
|
|
|
|
res=a
|
|
|
|
elif [ $idx = 1 ] ; then
|
|
|
|
res=b
|
|
|
|
elif [ $idx = 2 ] ; then
|
|
|
|
res=c
|
|
|
|
elif [ $idx = 3 ] ; then
|
|
|
|
res=d
|
|
|
|
elif [ $idx = 4 ] ; then
|
|
|
|
res=e
|
|
|
|
elif [ $idx = 5 ] ; then
|
|
|
|
res=f
|
|
|
|
elif [ $idx = 6 ] ; then
|
|
|
|
res=g
|
|
|
|
elif [ $idx = 7 ] ; then
|
|
|
|
res=h
|
|
|
|
elif [ $idx = 8 ] ; then
|
|
|
|
res=i
|
|
|
|
elif [ $idx = 9 ] ; then
|
|
|
|
res=j
|
|
|
|
elif [ $idx = 10 ] ; then
|
|
|
|
res=k
|
|
|
|
elif [ $idx = 11 ] ; then
|
|
|
|
res=m
|
|
|
|
elif [ $idx = 12 ] ; then
|
|
|
|
res=n
|
|
|
|
elif [ $idx = 13 ] ; then
|
|
|
|
res=p
|
|
|
|
elif [ $idx = 14 ] ; then
|
|
|
|
res=q
|
|
|
|
elif [ $idx = 15 ] ; then
|
|
|
|
res=r
|
|
|
|
elif [ $idx = 16 ] ; then
|
|
|
|
res=s
|
|
|
|
elif [ $idx = 17 ] ; then
|
|
|
|
res=t
|
|
|
|
elif [ $idx = 18 ] ; then
|
|
|
|
res=u
|
|
|
|
elif [ $idx = 19 ] ; then
|
|
|
|
res=v
|
|
|
|
elif [ $idx = 20 ] ; then
|
|
|
|
res=w
|
|
|
|
elif [ $idx = 21 ] ; then
|
|
|
|
res=x
|
|
|
|
elif [ $idx = 22 ] ; then
|
|
|
|
res=y
|
|
|
|
elif [ $idx = 23 ] ; then
|
|
|
|
res=z
|
|
|
|
elif [ $idx = 24 ] ; then
|
|
|
|
res=2
|
|
|
|
elif [ $idx = 25 ] ; then
|
|
|
|
res=3
|
|
|
|
elif [ $idx = 26 ] ; then
|
|
|
|
res=4
|
|
|
|
elif [ $idx = 27 ] ; then
|
|
|
|
res=5
|
|
|
|
elif [ $idx = 28 ] ; then
|
|
|
|
res=6
|
|
|
|
elif [ $idx = 29 ] ; then
|
|
|
|
res=7
|
|
|
|
elif [ $idx = 30 ] ; then
|
|
|
|
res=8
|
|
|
|
elif [ $idx = 31 ] ; then
|
2021-12-08 18:55:30 +00:00
|
|
|
res=9
|
2021-04-12 08:10:21 +00:00
|
|
|
fi
|
|
|
|
basex="$basex${res}"
|
|
|
|
done
|
|
|
|
|
|
|
|
old_hostname=$( cat /etc/hostname )
|
|
|
|
new_hostname=unknown-$basex
|
|
|
|
|
|
|
|
if [ $old_hostname = raspberrypi3-64 ]
|
|
|
|
then
|
|
|
|
new_hostname=rpi3-$basex
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $old_hostname = raspberrypi4-64 ]
|
|
|
|
then
|
2021-12-08 18:55:30 +00:00
|
|
|
new_hostname=rpi4-$basex
|
2021-04-12 08:10:21 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo $new_hostname > /etc/hostname
|
|
|
|
}
|
|
|
|
|
|
|
|
FLAG="/var/local/firstboot.log"
|
|
|
|
|
|
|
|
if [ ! -f $FLAG ]; then
|
|
|
|
echo "First boot"
|
|
|
|
touch $FLAG
|
|
|
|
|
|
|
|
generate_hostname
|
|
|
|
generate_avahi_service
|
|
|
|
|
|
|
|
|
|
|
|
reboot
|
|
|
|
fi
|