Updated install script to fix mac addresses
This commit is contained in:
		| @@ -1,11 +1,12 @@ | |||||||
| # PiKVM - Pi Zero 2 W | # PiKVM - Pi Zero 2 W | ||||||
|  |  | ||||||
| The official PiKVM is expensive so I decided take build my own & add some features in the process: | 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 | - 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 | - Ethernet connection for wired networks | ||||||
| - E-ink display for showing network information | - 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 | ## Hardware | ||||||
|  - [Pi Zero 2 W + SD Card](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/) |  - [Pi Zero 2 W + SD Card](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/) | ||||||
|   | |||||||
| @@ -1,9 +1,54 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
|  |  | ||||||
|  | SCRIPT="$(basename $0)" | ||||||
| SIZE="1024" | SIZE="1024" | ||||||
| if [ -n "$1" ]; then SIZE="$1"; fi |  | ||||||
|  |  | ||||||
| dd if=/dev/zero of=/swapfile bs=1m count="$SIZE" | show_help() { | ||||||
| chown 600 /swapfile |     cat <<EOF | ||||||
| mkswap /swapfile | Usage: $SCRIPT [OPTION] [SIZE] | ||||||
| swapon /swapfile | Manage swap space on Arch Linux | ||||||
|  |  | ||||||
|  | Options: | ||||||
|  |   -h, --help       Show this help message and exit | ||||||
|  |   --disable        Remove the swap file | ||||||
|  |   SIZE             Size of the swap file in MB (default: 1024) | ||||||
|  |  | ||||||
|  | Examples: | ||||||
|  |   $SCRIPT 2048           Create a 2GB swap file | ||||||
|  |   $SCRIPT --disable      Remove the existing swap file | ||||||
|  | EOF | ||||||
|  | } | ||||||
|  |  | ||||||
|  | disable_swap() { | ||||||
|  |   if [ -e /swapfile ]; then | ||||||
|  |     swapoff /swapfile | ||||||
|  |     rm -f /swapfile | ||||||
|  |     echo "SWAP removed" | ||||||
|  |   else | ||||||
|  |     echo "SWAP doesn't exist" | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  |  | ||||||
|  | enable_swap() { | ||||||
|  |   if [ -e /swapfile ]; then | ||||||
|  |      echo "Error: SWAP already exists" | ||||||
|  |      exit 1 | ||||||
|  |   fi | ||||||
|  |   echo "Creating SWAP..." | ||||||
|  |   dd if=/dev/zero of=/swapfile bs=1M count="$SIZE" | ||||||
|  |   chmod 600 /swapfile | ||||||
|  |   mkswap /swapfile | ||||||
|  |   swapon /swapfile | ||||||
|  |   echo "$SIZE MB SWAP created" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # Parse command-line arguments | ||||||
|  | if [[ "$1" == "--disable" ]]; then | ||||||
|  |   disable_swap | ||||||
|  |   exit 0 | ||||||
|  | elif [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then | ||||||
|  |   show_help | ||||||
|  |   exit 0 | ||||||
|  | fi | ||||||
|  | if [ -n "$1" ]; then SIZE="$1"; fi | ||||||
|  | enable_swap | ||||||
|   | |||||||
							
								
								
									
										40
									
								
								install.sh
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								install.sh
									
									
									
									
									
								
							| @@ -8,27 +8,39 @@ fi | |||||||
|  |  | ||||||
| # Setup | # Setup | ||||||
| rw | rw | ||||||
| git clone https://git.zakscode.com/ztimson/PiKVM.git | ./bin/swap-manager.sh | ||||||
| cd PiKVM |  | ||||||
|  | git status > /dev/null | ||||||
|  | if [ "$?" != "0" ]; then | ||||||
|  |   echo "Missing dependencies, cloning..." | ||||||
|  |   git clone https://git.zakscode.com/ztimson/PiKVM.git | ||||||
|  |   cd PiKVM | ||||||
|  | fi | ||||||
|  |  | ||||||
| # Static MAC fix | # Static MAC fix | ||||||
| printf "Enable static MAC (y/n): " && read YN | echo "" | ||||||
| if [ "$YN" =~ [Yy]$ ]; then | read -p "Enable static MAC (y/n): " YN | ||||||
|  | if [ "${YN,,}" == "y" ]; then | ||||||
|   printf "Define vendor ID (defaults to Intel): " && read MAC_PREFIX |   printf "Define vendor ID (defaults to Intel): " && read MAC_PREFIX | ||||||
|   if [ -z "$MAC_PREFIX" ]; then MAC_PREFIX="80:86:00"; fi |   if [ -z "$MAC_PREFIX" ]; then MAC_PREFIX="80:86:00"; fi | ||||||
|  |  | ||||||
|   cat <<EOF >> /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 <<EOF >> "$file" | ||||||
|  |  | ||||||
| [Link] | [Link] | ||||||
| MACAddress=$(printf '%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256))) | MACAddress=$MAC_PREFIX:$mac_address | ||||||
| EOF |  | ||||||
|  |  | ||||||
|   cat <<EOF >> /etc/systemd/network/ |  | ||||||
|  |  | ||||||
| [Link] |  | ||||||
| MACAddress=$(printf '%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256))) |  | ||||||
| EOF | EOF | ||||||
|  |   done | ||||||
| fi | fi | ||||||
|  |  | ||||||
| pacman -S cronie python-pipx | # pacman -S cronie python-pipx | ||||||
| pipx install pillow RPI.GPIO spidev | # pipx install pillow RPI.GPIO spidev | ||||||
|  |  | ||||||
|  | ./bin/swap-manager.sh --disable | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user