Instantly share code, notes, and snippets.

Embed
What would you like to do?
MacGuyver mode for Raspberry Pi
#!/bin/bash
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
apt-get update
apt-get install realvnc-vnc-server dnsmasq -y
cd /usr/local/share/
wget https://github.com/novnc/noVNC/archive/v1.0.0.zip
unzip v1.0.0.zip
rm v1.0.0.zip
mv noVNC-1.0.0 noVNC
cd noVNC
cp vnc.html index.html
cd utils
wget https://github.com/novnc/websockify/archive/v0.8.0.zip
unzip v0.8.0.zip
rm v0.8.0.zip
mv websockify-0.8.0 websockify
{
echo '# MacGuyver settings'
echo 'interface eth0'
echo 'static ip_address=10.0.0.1/24'
echo 'netmask 255.255.255.0'
} >> /etc/dhcpcd.conf
systemctl restart dhcpcd.service
mv /etc/dnsmasq.conf /etc/dnsmasq.default
{
echo 'interface=eth0'
echo 'dhcp-range=10.0.0.2,10.0.0.10,255.255.255.0,12h'
echo 'dhcp-option=3,10.0.0.1'
echo 'dhcp-option=6,10.0.0.1'
} > /etc/dnsmasq.conf
systemctl restart dnsmasq.service
{
echo '[Unit]'
echo 'Description=MacGuyver service (vnc)'
echo 'After=syslog.target network.target'
echo ''
echo '[Service]'
echo 'Type=forking'
echo 'User=pi'
echo 'PAMName=login'
echo 'PIDFile=/home/pi/.vnc/%H:%i.pid'
echo 'ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1'
echo 'ExecStart=/usr/bin/vncserver -Encryption=AlwaysOff -Authentication=None -localhost=1 -depth 24 -geometry 1280x800 :%i'
echo ''
echo '[Install]'
echo 'WantedBy=multi-user.target'
} > /etc/systemd/system/vncMacGuyver@.service
{
echo '[Unit]'
echo 'Description=MacGuyver noVNC service (websockify)'
echo 'After=syslog.target network.target'
echo ''
echo '[Service]'
echo 'ExecStartPre=-/sbin/iptables -A INPUT -i wlan0 -p tcp --dport 80 -j DROP'
echo 'ExecStart=/usr/local/share/noVNC/utils/launch.sh --vnc localhost:590%i --listen 80'
echo ''
echo '[Install]'
echo 'WantedBy=multi-user.target'
} > /etc/systemd/system/novncMacGuyver@.service
systemctl daemon-reload
systemctl enable vncMacGuyver@1.service
systemctl enable novncMacGuyver@1.service
systemctl start vncMacGuyver@1.service
systemctl start novncMacGuyver@1.service
echo ''
echo 'MacGuyver mode installed and enabled'
@davidhoness

This comment has been minimized.

Copy link
Owner Author

davidhoness commented Oct 15, 2018

To Install

  • Install Raspbian Stretch on your SD card.
  • Boot the Raspberry Pi in a conventional setup with keyboard, mouse and monitor.
  • Open a Terminal window and set the correct time.
sudo date -s "YYYY-MM-DD HH:MM:SS"
  • Connect to the Internet through either Ethernet or Wi-Fi.
  • Run these commands in a Terminal window (use copy/paste).
wget https://gist.githubusercontent.com/davidhoness/b5cbb3959bbbf875f65fb0c655ce783e/raw -O install_macguyver.sh
chmod +x install_macguyver.sh
sudo ./install_macguyver.sh
  • Disable boot to desktop on the Raspberry Pi
    Start > Preferences > Raspberry Pi Configuration > Boot - To CLI
  • Shut down.

To use

20170803_095716

  • With a single Ethernet cable connect the Raspberry Pi directly to a host laptop.
    • The host laptop needs an Ethernet port or an Ethernet USB dongle.
  • If the host laptop has a USB 3 charging port this could be used to power the Raspberry Pi as an alternative to a separate power supply.
    • If the RED LED on the Raspberry Pi is seen to be off or blinking switch to separate power supply.
  • The host laptop should be configured to obtain an IP address automatically (usually the default).
  • Open a web browser on the host laptop.
  • Type 10.0.0.1 into the address bar. If nothing happens, just reboot the host laptop and try again.
  • Click Connect.
    • The host laptop does not need an active Internet connection.
    • You can browse the Internet on the Raspberry Pi desktop using it's Wi-Fi.

20170803_095723
macgyver screen shot

To disable

  • Run these commands in a Terminal window.
sudo systemctl stop vncMacGuyver@1.service
sudo systemctl stop novncMacGuyver@1.service
sudo systemctl stop dnsmasq.service
sudo systemctl disable vncMacGuyver@1.service
sudo systemctl disable novncMacGuyver@1.service
sudo systemctl disable dnsmasq.service
sudo nano /etc/dhcpcd.conf
  • Scroll to the bottom and hash-out the static IP lines after # MacGuyver settings
  • Press Ctrl - O followed by Enter to save and then Ctrl - X to quit back to the Terminal.
sudo systemctl restart dhcpcd.service

To re-enable

  • Run these commands in a Terminal window.
sudo nano /etc/dhcpcd.conf
  • Scroll to the bottom and enable the static IP lines after # MacGuyver settings
  • Press Ctrl - O followed by Enter to save and then Ctrl - X to quit back to the Terminal.
  • Run these commands in a Terminal window.
sudo systemctl restart dhcpcd.service
sudo systemctl enable vncMacGuyver@1.service
sudo systemctl enable novncMacGuyver@1.service
sudo systemctl enable dnsmasq.service
sudo systemctl start vncMacGuyver@1.service
sudo systemctl start novncMacGuyver@1.service
sudo systemctl start dnsmasq.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment