├── README.md ├── pi-setup.sh ├── vnc.plist └── vnc.sh /README.md: -------------------------------------------------------------------------------- 1 | # Pi-otg 2 | 3 | This will enable a one wire, plug and play solution between the Raspberry Pi 4 and a Macbook. The Raspberry Pi automatically hands out a dhcp address so you do not have to fiddle with assigning one yourself. When the USB otg interface comes up there is a listener that launches a VNC session automatically. Simply plug your Pi into your Macbook and it plops you into its desktop. 4 | 5 | 6 | Video: http://i.imgur.com/AQnWGGg.mp4 7 | 8 | # Installation Instructions (Run everything as root) 9 | **Macbook side:** 10 | * Copy vnc.sh to /Library/Scripts/ 11 | * Run chmod 755 /Library/Scripts/vnc.sh 12 | * Copy vnc.plist to /Library/LaunchAgents/ 13 | * Run chmod 600 /Library/LaunchAgents/vnc.plist 14 | * Run sudo launchctl load /Library/LaunchAgents/vnc.plist to start the watchdog 15 | 16 | **Raspberry Pi side** 17 | * Run pi-setup.sh 18 | -------------------------------------------------------------------------------- /pi-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "loading module" 3 | sed -i 's/$/ modules-load=dwc2/' /boot/cmdline.txt 4 | echo "dtoverlay=dwc2" >> /boot/config.txt 5 | echo "libcomposite" >> /etc/modules 6 | echo "denyinterfaces usb0" >> /etc/dhcpcd.conf 7 | 8 | echo "installing dnsmasq" 9 | apt-get -y install dnsmasq 10 | 11 | echo "configuring dnsmasq" 12 | touch /etc/dnsmasq.d/usb 13 | echo "interface=usb0" >> /etc/dnsmasq.d/usb 14 | echo "dhcp-range=192.168.150.2,192.168.150.6,255.255.255.248,1h" >> /etc/dnsmasq.d/usb 15 | echo "dhcp-option=3" >> /etc/dnsmasq.d/usb 16 | echo "leasefile-ro" >> /etc/dnsmasq.d/usb 17 | 18 | echo "creating interface" 19 | touch /etc/network/interfaces.d/usb0 20 | echo "auto usb0" >> /etc/network/interfaces.d/usb0 21 | echo "allow-hotplug usb0" >> /etc/network/interfaces.d/usb0 22 | echo "iface usb0 inet static" >> /etc/network/interfaces.d/usb0 23 | echo " address 192.168.150.1" >> /etc/network/interfaces.d/usb0 24 | echo " netmask 255.255.255.248" >> /etc/network/interfaces.d/usb0 25 | modprobe g_ether 26 | service dnsmasq restart 27 | 28 | echo "modifying rc.local. A backup is saved if anything messes up" 29 | cp /etc/rc.local /etc/rc.local.bak 30 | sed -i '$ d' /etc/rc.local 31 | echo "modprobe g_ether" >>/etc/rc.local 32 | echo "exit 0" >> /etc/rc.local 33 | ifup usb0 34 | 35 | echo "installing tightvnc" 36 | apt-get -y install tightvncserver 37 | 38 | echo "configuring tightvnc service" 39 | touch /etc/systemd/system/tightvncserver.service 40 | echo "[Unit]" >> /etc/systemd/system/tightvncserver.service 41 | echo "Description=TightVNC remote desktop server" >> /etc/systemd/system/tightvncserver.service 42 | echo "After=sshd.service" >> /etc/systemd/system/tightvncserver.service 43 | echo "" >> /etc/systemd/system/tightvncserver.service 44 | echo "[Service]" >> /etc/systemd/system/tightvncserver.service 45 | echo "Type=dbus" >> /etc/systemd/system/tightvncserver.service 46 | echo "ExecStart=/usr/bin/tightvncserver :1" >> /etc/systemd/system/tightvncserver.service 47 | echo "User=pi" >> /etc/systemd/system/tightvncserver.service 48 | echo "Type=forking" >> /etc/systemd/system/tightvncserver.service 49 | echo "" >> /etc/systemd/system/tightvncserver.service 50 | echo "[Install]" >> /etc/systemd/system/tightvncserver.service 51 | echo "WantedBy=multi-user.target" >> /etc/systemd/system/tightvncserver.service 52 | chown root:root /etc/systemd/system/tightvncserver.service 53 | chmod 755 /etc/systemd/system/tightvncserver.service 54 | su - pi -c "tightvncserver" 55 | systemctl start tightvncserver.service 56 | systemctl enable tightvncserver.service 57 | -------------------------------------------------------------------------------- /vnc.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.asb 7 | OnDemand 8 | 9 | ProgramArguments 10 | 11 | /Library/Scripts/vnc.sh 12 | 13 | WatchPaths 14 | 15 | /Library/Preferences/SystemConfiguration 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /vnc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function alert { 4 | osascript -e "display notification \"$1\" with title \"Starting VNC Session\" sound name \"Hero\"" 5 | } 6 | 7 | #Set default values 8 | prev_eth_status="Off" 9 | eth_status="Off" 10 | 11 | #Get adapter name 12 | eth_name=`networksetup -listnetworkserviceorder | grep "(Hardware Port: RNDIS" | cut -f6 -d' ' | sed 's/.$//'` 13 | 14 | 15 | # Determine previous ethernet status 16 | # If file prev_eth_on exists, ethernet was active last time we checked 17 | if [ -f "/var/tmp/prev_eth_on" ]; then 18 | prev_eth_status="On" 19 | fi 20 | 21 | # Check actual current ethernet status 22 | if ([ "`ifconfig $eth_name | grep "status: active"`" != "" ]); then 23 | eth_status="On" 24 | fi 25 | 26 | # Determine whether ethernet status changed 27 | if [ "$prev_eth_status" != "$eth_status" ]; then 28 | 29 | if [ "$eth_status" = "On" ]; then 30 | sleep 5 31 | alert "Happy Programming." 32 | /Applications/VNC\ Viewer.app/Contents/MacOS/vncviewer 192.168.150.1:1 33 | else 34 | alert "Failed" 35 | fi 36 | fi 37 | 38 | # Update ethernet status 39 | if [ "$eth_status" == "On" ]; then 40 | touch /var/tmp/prev_eth_on 41 | else 42 | if [ -f "/var/tmp/prev_eth_on" ]; then 43 | rm /var/tmp/prev_eth_on 44 | fi 45 | fi 46 | 47 | exit 0 48 | --------------------------------------------------------------------------------