From 0625ef6feb82796ace7e182d0d6cd4852e45341d Mon Sep 17 00:00:00 2001 From: Adam Carr Date: Sat, 19 Sep 2026 12:29:55 -0700 Subject: [PATCH] flash-one.sh: remove image's default pi user (was colliding with adamcarr uid, broke sudo) --- scripts/flash-one.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/flash-one.sh b/scripts/flash-one.sh index 6abfaad..17410dd 100755 --- a/scripts/flash-one.sh +++ b/scripts/flash-one.sh @@ -9,8 +9,6 @@ DEV=$2 IMG=/tmp/opencode/raspios-lite.img PUBKEY=/home/adamcarr/.ssh/id_ed25519.pub PASSFILE=/home/adamcarr/code/personal/pi-swarm/configs/node-password.txt -EEPROM_UPD=/tmp/opencode/netboot/pieeprom-revert.upd -EEPROM_SIG=/tmp/opencode/netboot/pieeprom-revert.sig fail() { echo "ERROR: $*" >&2; exit 1; } @@ -24,6 +22,9 @@ SIZE_BYTES=$(cat /sys/block/$DEV/size 2>/dev/null) || fail "cannot read /sys/blo SIZE_GB=$(( SIZE_BYTES * 512 / 1024 / 1024 / 1024 )) (( SIZE_GB >= 200 && SIZE_GB <= 300 )) || fail "device is ${SIZE_GB}GB, expected ~240GB - wrong stick or wrong port?" +P1_SIZE=$(lsblk -dn -o SIZE /dev/${DEV}1 2>/dev/null | tr -dc 0-9) +[[ "$P1_SIZE" == "512M" ]] && fail "boot partition is already 512M - this stick was already flashed. Plugged in the right one?" + MODEL=$(lsblk -dn -o MODEL /dev/$DEV | head -1) SERIAL=$(lsblk -dn -o SERIAL /dev/$DEV | head -1) echo "Target: /dev/$DEV ${SIZE_GB}GB model=$MODEL serial=$SERIAL" @@ -54,13 +55,6 @@ mount /dev/${DEV}2 $R # enable ssh on first boot touch $B/ssh -# planck020 only: its EEPROM is stuck in network-boot mode, these files -# tell the bootloader to flip it back to normal on first power-up -if [ "$NODE" = "planck020" ]; then - cp $EEPROM_UPD $B/pieeprom.upd - cp $EEPROM_SIG $B/pieeprom.sig -fi - # hostname echo "$NODE" > $R/etc/hostname sed -i "s/^127.0.1.1.*/127.0.1.1 $NODE/" $R/etc/hosts @@ -70,6 +64,14 @@ rm -f $R/etc/localtime ln -s /usr/share/zoneinfo/America/Los_Angeles $R/etc/localtime echo "America/Los_Angeles" > $R/etc/timezone +# remove image's locked default 'pi' user (imager normally renames it; +# leaving it in place would collide with adamcarr's uid and break sudo) +sed -i "/^pi:/d" $R/etc/passwd $R/etc/shadow +awk -F: -v OFS=: ' + {r=""; n=split($4,m,","); for(i=1;i<=n;i++){ if(m[i]!="pi" && m[i]!="") r=r (r==""?"":",") m[i] }; $4=r} + {print}' $R/etc/group > $R/etc/group.new && mv $R/etc/group.new $R/etc/group +rm -rf $R/home/pi + # user adamcarr (uid 1000), password from passfile, groups like the old nodes HASH=$(openssl passwd -6 "$(cat $PASSFILE)") echo "adamcarr:x:1000:1000:Adam Carr:/home/adamcarr:/bin/bash" >> $R/etc/passwd