an eink camera running on an rpi zero 2 w
at main 1.9 kB view raw
1#!/usr/bin/env bash 2# setup_gadget_mode.sh - Script to configure USB gadget mode on a Raspberry Pi SD card 3 4# Check if SD card boot partition is provided 5if [ $# -lt 1 ]; then 6 if [ -d "/run/media/$(whoami)/bootfs" ]; then 7 BOOT_PARTITION="/run/media/$(whoami)/bootfs" 8 else 9 echo "Usage: $0 /path/to/sd_card_boot_partition" 10 exit 1 11 fi 12else 13 BOOT_PARTITION=$1 14fi 15 16# Verify the boot partition exists 17if [ ! -d "$BOOT_PARTITION" ]; then 18 echo "Error: Boot partition not found at $BOOT_PARTITION" 19 exit 1 20fi 21 22echo "Configuring USB gadget mode on $BOOT_PARTITION..." 23 24# Modify config.txt to enable dwc2 overlay 25CONFIG_FILE="$BOOT_PARTITION/config.txt" 26if [ -f "$CONFIG_FILE" ]; then 27 if ! grep -q "dtoverlay=dwc2" "$CONFIG_FILE"; then 28 echo "Adding dtoverlay=dwc2 to config.txt..." 29 echo "dtoverlay=dwc2" >> "$CONFIG_FILE" 30 else 31 echo "dtoverlay=dwc2 already exists in config.txt" 32 fi 33else 34 echo "Error: config.txt not found in boot partition" 35 exit 1 36fi 37 38# Modify cmdline.txt to load required modules 39CMDLINE_FILE="$BOOT_PARTITION/cmdline.txt" 40if [ -f "$CMDLINE_FILE" ]; then 41 if ! grep -q "modules-load=dwc2,g_ether" "$CMDLINE_FILE"; then 42 echo "Adding modules-load=dwc2,g_ether to cmdline.txt..." 43 sed -i 's/$/ modules-load=dwc2,g_ether/' "$CMDLINE_FILE" 44 else 45 echo "modules-load=dwc2,g_ether already exists in cmdline.txt" 46 fi 47else 48 echo "Error: cmdline.txt not found in boot partition" 49 exit 1 50fi 51 52# Create empty ssh file to enable SSH 53SSH_FILE="$BOOT_PARTITION/ssh" 54if [ ! -f "$SSH_FILE" ]; then 55 echo "Creating empty ssh file to enable SSH..." 56 touch "$SSH_FILE" 57else 58 echo "SSH already enabled" 59fi 60 61echo "USB gadget mode configuration complete!" 62echo "Now you can insert the SD card into your Raspberry Pi and boot it." 63echo "After booting, you should be able to connect via: ssh ink@inky.local" 64echo "Default password: inkycamera"