Last active
August 26, 2016 19:33
-
-
Save wturnerharris/5a0353ff4841d4e039ca to your computer and use it in GitHub Desktop.
Multi-user runlevel script (rc.local) for rPi #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# | |
# 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. | |
# Print the IP address | |
_IP=$(hostname -I) || true | |
if [ "$_IP" ]; then | |
printf "My IP address is %s\n" "$_IP" | |
fi | |
# Wait for the TV-screen to be turned on... | |
while ! $( tvservice --dumpedid /tmp/edid | fgrep -qv 'Nothing written!' ); do | |
bHadToWaitForScreen=true; | |
printf "===> Screen is not connected, off or in an unknown mode, waiting for it to become available...\n" | |
sleep 10; | |
done; | |
printf "===> Screen is on, extracting preferred mode...\n" | |
_DEPTH=32; | |
_XRES=1080 | |
_YRES=1920 | |
_GROUP=CEA | |
_MODE=16 | |
#eval $( edidparser /tmp/edid | fgrep 'preferred mode' | tail -1 | sed -Ene 's/^.+(DMT|CEA) \(([0-9]+)\) ([0-9]+)x([0-9]+)[pi]? @.+/_GROUP=\1;_MODE=\2;_XRES=\3;_YRES=\4;/p' ); | |
#printf "===> Resetting screen to preferred mode: %s-%d (%dx%dx%d)...\n" $_GROUP $_MODE $_XRES $_YRES $_DEPTH | |
tvservice --explicit="$_GROUP $_MODE" | |
sleep 1; | |
printf "===> Resetting frame-buffer to %dx%dx%d...\n" $_XRES $_YRES $_DEPTH | |
fbset --all --geometry $_XRES $_YRES $_XRES $_YRES $_DEPTH -left 0 -right 0 -upper 0 -lower 0; | |
sleep 1; | |
echo "===> Ethernet going down." | |
ifdown eth0 | |
ifconfig eth0 10.0.2.1 netmask 255.255.255.0 | |
echo "===> Configuring ethernet forwarding..." | |
sysctl -w net.ipv4.ip_forward=1 | |
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE | |
if [ -f /boot/xinitrc ]; then | |
echo "===> Linking xinitrc and starting X..."; | |
ln -fs /boot/xinitrc /home/pi/.xinitrc; | |
su - pi -c 'startx' & | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Find IP/MAC address
In case you have to re-connect the WiFi to a different network and your only means is to ssh over ethernet, you might need to find out the IP and/or MAC address of the device over ethernet. While good ol
arp
utility could get the job done, I ended up using another similar utility calledarp-scan
, which is more robust in that it actually does the scanning and pinging directly within the utility whereasarp
can only return known addresses of devices that recently connected. You can get around that by pinging every device in the range of IP addresses on the network, but that is exhausting.brew install arp-scan
arp-scan --interface=en0 --localnet | grep Raspberry
Profit!
Additional Considerations
I should also note that if you know the networking device's manufacturer, then you could search with
arp
and grep for the manufacturer's prefix code, which is the first 24 bits (or the first six digits excluding the colons) of the address. This could narrow things down for you. This might mean searching for possible manufacturer codes using the IEEE registry, which shows that Raspberry Pi Foundation is registered with theb8:27:eb
.