flash-one.sh: remove image's default pi user (was colliding with adamcarr uid, broke sudo)
This commit is contained in:
@@ -9,8 +9,6 @@ DEV=$2
|
|||||||
IMG=/tmp/opencode/raspios-lite.img
|
IMG=/tmp/opencode/raspios-lite.img
|
||||||
PUBKEY=/home/adamcarr/.ssh/id_ed25519.pub
|
PUBKEY=/home/adamcarr/.ssh/id_ed25519.pub
|
||||||
PASSFILE=/home/adamcarr/code/personal/pi-swarm/configs/node-password.txt
|
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; }
|
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=$(( 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?"
|
(( 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)
|
MODEL=$(lsblk -dn -o MODEL /dev/$DEV | head -1)
|
||||||
SERIAL=$(lsblk -dn -o SERIAL /dev/$DEV | head -1)
|
SERIAL=$(lsblk -dn -o SERIAL /dev/$DEV | head -1)
|
||||||
echo "Target: /dev/$DEV ${SIZE_GB}GB model=$MODEL serial=$SERIAL"
|
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
|
# enable ssh on first boot
|
||||||
touch $B/ssh
|
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
|
# hostname
|
||||||
echo "$NODE" > $R/etc/hostname
|
echo "$NODE" > $R/etc/hostname
|
||||||
sed -i "s/^127.0.1.1.*/127.0.1.1 $NODE/" $R/etc/hosts
|
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
|
ln -s /usr/share/zoneinfo/America/Los_Angeles $R/etc/localtime
|
||||||
echo "America/Los_Angeles" > $R/etc/timezone
|
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
|
# user adamcarr (uid 1000), password from passfile, groups like the old nodes
|
||||||
HASH=$(openssl passwd -6 "$(cat $PASSFILE)")
|
HASH=$(openssl passwd -6 "$(cat $PASSFILE)")
|
||||||
echo "adamcarr:x:1000:1000:Adam Carr:/home/adamcarr:/bin/bash" >> $R/etc/passwd
|
echo "adamcarr:x:1000:1000:Adam Carr:/home/adamcarr:/bin/bash" >> $R/etc/passwd
|
||||||
|
|||||||
Reference in New Issue
Block a user