Update raspi-flash

main
Ian Mancini 2 years ago
parent 05238c9556
commit 2275596bd4

@ -56,7 +56,7 @@ extract() {
continue=${continue:-Y} continue=${continue:-Y}
if [[ $continue =~ [yY] ]]; then if [[ $continue =~ [yY] ]]; then
echo "Extracting..." echo "Extracting..."
unzip "$DOWNLOADS_DIR/$1" -d "$DOWNLOADS_DIR" unxz --keep "$DOWNLOADS_DIR/$1"
else exit 1; fi else exit 1; fi
} }
@ -88,8 +88,8 @@ IMAGE_SELECTION_CSV=$(echo "$JSON" \
declare -a SELECTION_DATA declare -a SELECTION_DATA
IFS=',' read -ra SELECTION_DATA <<< "$IMAGE_SELECTION_CSV" IFS=',' read -ra SELECTION_DATA <<< "$IMAGE_SELECTION_CSV"
ZIP_FILENAME=$(basename "${SELECTION_DATA[2]}") ARCHIVE_FILENAME=$(basename "${SELECTION_DATA[2]}")
IMG_FILENAME=${ZIP_FILENAME/zip/img} IMG_FILENAME=$(basename "$ARCHIVE_FILENAME" .xz)
should_download=FALSE should_download=FALSE
should_extract=FALSE should_extract=FALSE
@ -99,7 +99,7 @@ echo "Checking for files"
if [ -d "$DOWNLOADS_DIR" ]; then if [ -d "$DOWNLOADS_DIR" ]; then
if [ -f "$DOWNLOADS_DIR/$IMG_FILENAME" ]; then if [ -f "$DOWNLOADS_DIR/$IMG_FILENAME" ]; then
echo "Found extracted image: $IMG_FILENAME" echo "Found extracted image: $IMG_FILENAME"
elif [ -f "$DOWNLOADS_DIR/$ZIP_FILENAME" ]; then elif [ -f "$DOWNLOADS_DIR/$ARCHIVE_FILENAME" ]; then
should_extract=TRUE should_extract=TRUE
else else
should_download=TRUE; should_extract=TRUE should_download=TRUE; should_extract=TRUE
@ -110,8 +110,8 @@ else
should_download=TRUE; should_extract=TRUE should_download=TRUE; should_extract=TRUE
fi fi
[ $should_download = TRUE ] && download "$ZIP_FILENAME" "${SELECTION_DATA[3]}M" "${SELECTION_DATA[2]}" [ $should_download = TRUE ] && download "$ARCHIVE_FILENAME" "${SELECTION_DATA[3]}M" "${SELECTION_DATA[2]}"
[ $should_extract = TRUE ] && extract "$ZIP_FILENAME" "${SELECTION_DATA[4]}M" [ $should_extract = TRUE ] && extract "$ARCHIVE_FILENAME" "${SELECTION_DATA[4]}M"
compare_checksum "$DOWNLOADS_DIR/$IMG_FILENAME" "${SELECTION_DATA[5]}" compare_checksum "$DOWNLOADS_DIR/$IMG_FILENAME" "${SELECTION_DATA[5]}"
# NOTE: Is there a cleaner way to do this? # NOTE: Is there a cleaner way to do this?
@ -166,12 +166,11 @@ if [[ $enable_wifi =~ [yY] ]]; then
[ -f /mnt/raspi-flash/wpa_supplicant.conf ] && \ [ -f /mnt/raspi-flash/wpa_supplicant.conf ] && \
sudo rm /mnt/raspi-flash/wpa_supplicant.conf sudo rm /mnt/raspi-flash/wpa_supplicant.conf
sudo bash -c 'cat > /mnt/raspi-flash/wpa_supplicant.conf' <<EOF sudo bash -c 'cat > /mnt/raspi-flash/wpa_supplicant.conf' <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=$country country=$country
update_config=1 update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={ network={
scan_ssid=1
ssid="$ssid" ssid="$ssid"
psk="$psk" psk="$psk"
} }
@ -179,6 +178,15 @@ network={
EOF EOF
fi fi
echo "Setup user:"
read -rp "User name: " username
read -rsp "User password (hidden): " userpassword
printf "\n"
[ -f /mnt/raspi-flash/userconf.txt ] && sudo rm /mnt/raspi-flash/userconf.txt
sudo bash -c 'cat > /mnt/raspi-flash/userconf.txt' <<EOF
$username:$(echo $userpassword | openssl passwd -6 -stdin)
EOF
sudo umount "$DEVICE_SELECTION" sudo umount "$DEVICE_SELECTION"
sudo rmdir /mnt/raspi-flash sudo rmdir /mnt/raspi-flash

Loading…
Cancel
Save