„etc/rc.local“ ändern
Überarbeitet. Jetzt wird die macadresse von 1. Netzwerkgerät für den Namen genommen. Muss noch sauber gemacht werden!
This commit is contained in:
parent
72c250bcaf
commit
f831f85dfd
20
etc/rc.local
20
etc/rc.local
@ -1,5 +1,4 @@
|
|||||||
#!/bin/sh -e
|
#!/usr/bin/env bash
|
||||||
#
|
|
||||||
# rc.local
|
# rc.local
|
||||||
#
|
#
|
||||||
# This script is executed at the end of each multiuser runlevel.
|
# This script is executed at the end of each multiuser runlevel.
|
||||||
@ -11,6 +10,8 @@
|
|||||||
#
|
#
|
||||||
# By default this script does nothing.
|
# By default this script does nothing.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
which chromium-browser > /dev/null && [ -d /etc/chromium ] && mv /etc/chromium/ /etc/chromium-browser
|
which chromium-browser > /dev/null && [ -d /etc/chromium ] && mv /etc/chromium/ /etc/chromium-browser
|
||||||
|
|
||||||
sleep 10
|
sleep 10
|
||||||
@ -22,18 +23,15 @@ if [ "$_IP" ]; then
|
|||||||
printf "My IP address is %s\n" "$_IP"
|
printf "My IP address is %s\n" "$_IP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set hostname
|
macaddress=$(find /sys/class/net -mindepth 1 -maxdepth 1 ! -name lo -printf "%P: " -execdir cat {}/address \; | cut -f 2 -d ' ')
|
||||||
#if [ -f /boot/client-cfg/hostname.txt ]; then
|
|
||||||
# hostname --file /boot/client-cfg/hostname.txt
|
|
||||||
#fi
|
|
||||||
|
|
||||||
#Hostname wird anhand des WLAN0 erstell / kann auch entsprechend auf anderes Geraet umgestellt werden
|
#Hostname wird anhand des WLAN0 erstell / kann auch entsprechend auf anderes Geraet umgestellt werden
|
||||||
#ip a s wlan1 2&>1 /dev/null ||
|
#ip a s wlan1 2&>1 /dev/null ||
|
||||||
#Check einbauen der aktive Verbindung prüft
|
#Check einbauen der aktive Verbindung prüft
|
||||||
if [ -d /home/pi ]; then
|
if [ -d /home/pi ]; then
|
||||||
echo pi$(cat /sys/class/net/wlan0/address | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
echo pi$(echo $macaddress | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
||||||
else
|
else
|
||||||
echo thin$(cat /sys/class/net/wlan0/address | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
echo thin$(echo $macaddress | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp /tmp/hostname /etc/hostname
|
cp /tmp/hostname /etc/hostname
|
||||||
@ -43,7 +41,7 @@ ip_address="127.0.2.1"
|
|||||||
host_name=$(cat /tmp/hostname)
|
host_name=$(cat /tmp/hostname)
|
||||||
# find existing instances in the host file and save the line numbers
|
# find existing instances in the host file and save the line numbers
|
||||||
matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
|
matches_in_hosts="$(grep -n $host_name /etc/hosts | cut -f1 -d:)"
|
||||||
host_entry="${ip_address} ${host_name} ${host_name}.lebenshilfe.local"
|
host_entry="${ip_address}\ ${host_name}\ ${host_name}.lebenshilfe.local"
|
||||||
|
|
||||||
echo "Please enter your password if requested."
|
echo "Please enter your password if requested."
|
||||||
|
|
||||||
@ -53,15 +51,13 @@ then
|
|||||||
# iterate over the line numbers on which matches were found
|
# iterate over the line numbers on which matches were found
|
||||||
while read -r line_number; do
|
while read -r line_number; do
|
||||||
# replace the text of each line with the desired host entry
|
# replace the text of each line with the desired host entry
|
||||||
sudo sed -i '' "${line_number}s/.*/${host_entry} /" /etc/hosts
|
sed -i ${line_number}s'/.*/${host_entry}/' /etc/hosts
|
||||||
done <<< "$matches_in_hosts"
|
done <<< "$matches_in_hosts"
|
||||||
else
|
else
|
||||||
echo "Adding new hosts entry."
|
echo "Adding new hosts entry."
|
||||||
echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
|
echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Fuer eth0, wenn kein WLAN vorhanden ist. Kann dann auskommentiert werden.
|
|
||||||
#echo rpi$(cat /sys/class/net/eth0/address | sed s'/://g') > /tmp/hostname && hostname --file /tmp/hostname
|
|
||||||
|
|
||||||
# set network
|
# set network
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user