From fa02eeb7beed136f97a3abc216064f98f008aaa1 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 27 Jul 2024 14:18:39 +0000 Subject: [PATCH] Updated install script to fix mac addresses --- README.md | 5 +++-- bin/swap-manager.sh | 55 ++++++++++++++++++++++++++++++++++++++++----- install.sh | 40 +++++++++++++++++++++------------ 3 files changed, 79 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e7c2abf..9e2ebe6 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # PiKVM - Pi Zero 2 W The official PiKVM is expensive so I decided take build my own & add some features in the process: +- Static MAC addresses to fix IP changes on reboot while using DHCP - Small "USB dongle" form-factor with minimal connections -- Create access point when network connection is lost for easy access +- Creates access point when network connection is lost for easy configuration - Ethernet connection for wired networks - E-ink display for showing network information -- Configure wireguard from boot partion to create a jumpbox +- Setup wireguard by adding a `wg0.conf` file to the boot partion to create a jumpbox ## Hardware - [Pi Zero 2 W + SD Card](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/) diff --git a/bin/swap-manager.sh b/bin/swap-manager.sh index b702858..0819a45 100755 --- a/bin/swap-manager.sh +++ b/bin/swap-manager.sh @@ -1,9 +1,54 @@ #!/bin/bash +SCRIPT="$(basename $0)" SIZE="1024" -if [ -n "$1" ]; then SIZE="$1"; fi -dd if=/dev/zero of=/swapfile bs=1m count="$SIZE" -chown 600 /swapfile -mkswap /swapfile -swapon /swapfile +show_help() { + cat < /dev/null +if [ "$?" != "0" ]; then + echo "Missing dependencies, cloning..." + git clone https://git.zakscode.com/ztimson/PiKVM.git + cd PiKVM +fi # Static MAC fix -printf "Enable static MAC (y/n): " && read YN -if [ "$YN" =~ [Yy]$ ]; then +echo "" +read -p "Enable static MAC (y/n): " YN +if [ "${YN,,}" == "y" ]; then printf "Define vendor ID (defaults to Intel): " && read MAC_PREFIX if [ -z "$MAC_PREFIX" ]; then MAC_PREFIX="80:86:00"; fi - cat <> /etc/systemd/network/ + files=( + "/etc/systemd/network/eth0.network" + "/etc/systemd/network/wlan0.network" + ) + + for file in "${files[@]}"; do + if [ -n "$(cat $file | grep MACAddress )" ]; then continue; fi + mac_address=$(printf '%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256))) + cat <> "$file" [Link] -MACAddress=$(printf '%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256))) -EOF - - cat <> /etc/systemd/network/ - -[Link] -MACAddress=$(printf '%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256))) +MACAddress=$MAC_PREFIX:$mac_address EOF + done fi -pacman -S cronie python-pipx -pipx install pillow RPI.GPIO spidev +# pacman -S cronie python-pipx +# pipx install pillow RPI.GPIO spidev + +./bin/swap-manager.sh --disable