2021-11-11 13:11:38 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-06-25 23:15:16 +02:00
|
|
|
# rc.local
|
|
|
|
#
|
|
|
|
# This script is executed at the end of each multiuser runlevel.
|
|
|
|
# Make sure that the script will "exit 0" on success or any other
|
|
|
|
# value on error.
|
|
|
|
#
|
|
|
|
# In order to enable or disable this script just change the execution
|
|
|
|
# bits.
|
|
|
|
#
|
|
|
|
# By default this script does nothing.
|
|
|
|
|
2021-11-11 13:11:38 +01:00
|
|
|
set -e
|
|
|
|
|
2021-09-07 16:03:42 +02:00
|
|
|
which chromium-browser > /dev/null && [ -d /etc/chromium ] && mv /etc/chromium/ /etc/chromium-browser
|
|
|
|
|
2021-06-25 23:15:16 +02:00
|
|
|
sleep 10
|
|
|
|
|
|
|
|
|
|
|
|
# Print the IP address
|
|
|
|
_IP=$(hostname -I) || true
|
|
|
|
if [ "$_IP" ]; then
|
|
|
|
printf "My IP address is %s\n" "$_IP"
|
|
|
|
fi
|
|
|
|
|
2021-11-11 13:11:38 +01:00
|
|
|
macaddress=$(find /sys/class/net -mindepth 1 -maxdepth 1 ! -name lo -printf "%P: " -execdir cat {}/address \; | cut -f 2 -d ' ')
|
2021-06-25 23:21:43 +02:00
|
|
|
|
|
|
|
#Hostname wird anhand des WLAN0 erstell / kann auch entsprechend auf anderes Geraet umgestellt werden
|
2021-09-07 16:03:42 +02:00
|
|
|
#ip a s wlan1 2&>1 /dev/null ||
|
|
|
|
#Check einbauen der aktive Verbindung prüft
|
|
|
|
if [ -d /home/pi ]; then
|
2021-11-11 13:11:38 +01:00
|
|
|
echo pi$(echo $macaddress | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
2021-09-07 16:03:42 +02:00
|
|
|
else
|
2021-11-11 13:11:38 +01:00
|
|
|
echo thin$(echo $macaddress | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
2021-11-11 12:34:10 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
cp /tmp/hostname /etc/hostname
|
|
|
|
|
|
|
|
# insert/update hosts entry
|
|
|
|
ip_address="127.0.2.1"
|
|
|
|
host_name=$(cat /tmp/hostname)
|
|
|
|
# find existing instances in the host file and save the line numbers
|
|
|
|
matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
|
2021-11-11 13:11:38 +01:00
|
|
|
host_entry="${ip_address}\ ${host_name}\ ${host_name}.lebenshilfe.local"
|
2021-11-11 12:34:10 +01:00
|
|
|
|
|
|
|
echo "Please enter your password if requested."
|
|
|
|
|
|
|
|
if [ ! -z "$matches_in_hosts" ]
|
|
|
|
then
|
|
|
|
echo "Updating existing hosts entry."
|
|
|
|
# iterate over the line numbers on which matches were found
|
|
|
|
while read -r line_number; do
|
|
|
|
# replace the text of each line with the desired host entry
|
2021-11-11 13:11:38 +01:00
|
|
|
sed -i ${line_number}s'/.*/${host_entry}/' /etc/hosts
|
2021-11-11 12:34:10 +01:00
|
|
|
done <<< "$matches_in_hosts"
|
|
|
|
else
|
|
|
|
echo "Adding new hosts entry."
|
|
|
|
echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
|
2021-09-07 16:03:42 +02:00
|
|
|
fi
|
|
|
|
|
2021-06-25 23:15:16 +02:00
|
|
|
|
|
|
|
# set network
|
|
|
|
|
|
|
|
# start X environment
|
|
|
|
if [ -f /boot/client-cfg/xinitrc ]; then
|
2021-09-07 16:03:42 +02:00
|
|
|
if [ -d /home/pi ]; then
|
|
|
|
ln -fs /boot/client-cfg/xinitrc /home/pi/.xinitrc;
|
|
|
|
su -l pi -s /bin/bash -c 'startx -- vt1' &
|
|
|
|
else
|
|
|
|
ln -fs /boot/client-cfg/xinitrc /home/thinnote/.xinitrc;
|
|
|
|
su -l thinnote -s /bin/bash -c 'startx -- vt1' &
|
|
|
|
fi
|
2021-06-25 23:15:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|