Updated install script to fix mac addresses
This commit is contained in:
parent
35ef009b0d
commit
fa02eeb7be
@ -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/)
|
||||
|
@ -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
|
||||
show_help() {
|
||||
cat <<EOF
|
||||
Usage: $SCRIPT [OPTION] [SIZE]
|
||||
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
|
||||
|
36
install.sh
36
install.sh
@ -8,27 +8,39 @@ fi
|
||||
|
||||
# Setup
|
||||
rw
|
||||
./bin/swap-manager.sh
|
||||
|
||||
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
|
||||
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 <<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]
|
||||
MACAddress=$(printf '%02X:%02X:%02X' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256)))
|
||||
EOF
|
||||
|
||||
cat <<EOF >> /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
|
||||
|
Loading…
Reference in New Issue
Block a user