Update raspi-flash script

main
Ian Mancini 4 years ago
parent 9b44c4eec4
commit 5b03dba607

@ -5,7 +5,6 @@ shopt -s extglob
# TODO: Add help message # TODO: Add help message
# TODO: Add parameter to set $DOWNLOADS_DIR # TODO: Add parameter to set $DOWNLOADS_DIR
DOWNLOADS_DIR="$HOME/Downloads/os" DOWNLOADS_DIR="$HOME/Downloads/os"
URL="https://downloads.raspberrypi.org/os_list_imagingutility_v2.json" URL="https://downloads.raspberrypi.org/os_list_imagingutility_v2.json"
@ -50,7 +49,7 @@ extract() {
echo "Checking sha256 hashes" echo "Checking sha256 hashes"
sum=$(sha256sum "$3" | cut -f 1 -d ' ') sum=$(sha256sum "$3" | cut -f 1 -d ' ')
if [ "$sum" = "$4" ]; then if [ "$sum" = "$4" ]; then
echo "Checksum matches" echo "Checksum matches"
else else
echo "Checksum doesn't match. Remove file and download again" echo "Checksum doesn't match. Remove file and download again"
exit 1 exit 1
@ -62,12 +61,12 @@ flash() {
sudo dd bs=4M status=progress oflag=sync if="$1" of="$2" sudo dd bs=4M status=progress oflag=sync if="$1" of="$2"
} }
# TODO: Improve this filter, it's a mess # TODO: Improve this messy filter
read -rd '' FILTER << EOF || true read -rd '' FILTER << EOF || true
(.os_list[] | select(has("url"))), (.os_list[] | select(.subitems) | .subitems[]) (.os_list[] | select(has("url"))), (.os_list[] | select(.subitems) | .subitems[])
| select(any(.name; contains("Raspberry Pi OS"))) | select(any(.name; contains("Raspberry Pi OS")))
| { | {
name, url, extract_sha256, extract_size: (.extract_size / 1024 / 1024 | round), name, url, extract_sha256, extract_size: (.extract_size / 1024 / 1024 | round),
image_download_size: (.image_download_size / 1024 / 1024 | round), release_date image_download_size: (.image_download_size / 1024 / 1024 | round), release_date
} }
EOF EOF
@ -124,7 +123,7 @@ DEVICE_SELECTION=$(echo "$DEVICES" | fzf)
printf "Will flash %s (%s) to %s\n" \ printf "Will flash %s (%s) to %s\n" \
"${SELECTION_DATA[0]}" "${SELECTION_DATA[1]}" "$DEVICE_SELECTION" "${SELECTION_DATA[0]}" "${SELECTION_DATA[1]}" "$DEVICE_SELECTION"
read -rp "Continue? [Y/n]" confirm read -rp "Continue? [Y/n]" confirm
confirm=${confirm:-Y} confirm=${confirm:-Y}
if [[ $confirm =~ [yY] ]]; then if [[ $confirm =~ [yY] ]]; then
@ -134,6 +133,7 @@ if [[ $confirm =~ [yY] ]]; then
sudo umount "$partition" || true sudo umount "$partition" || true
done done
flash "$DOWNLOADS_DIR/$IMG_FILENAME" "$DEVICE_SELECTION" flash "$DOWNLOADS_DIR/$IMG_FILENAME" "$DEVICE_SELECTION"
sync
else else
exit 1 exit 1
fi fi
@ -157,9 +157,11 @@ enable_wifi=${enable_wifi:-Y}
if [[ $enable_wifi =~ [yY] ]]; then if [[ $enable_wifi =~ [yY] ]]; then
read -rp "Network name: " ssid read -rp "Network name: " ssid
read -rsp "Password (hidden): " psk read -rsp "Password (hidden): " psk
printf "\n"
read -rp "Country (Two letters. Example: AR): " country read -rp "Country (Two letters. Example: AR): " country
sudo rm /mnt/raspi-flash/wpa_supplicant.conf [ -f /mnt/raspi-flash/wpa_supplicant.conf ] && \
sudo bash -c 'cat > /mnt/raspi-flash/wpa_supplicant.conf' <<EOF sudo rm /mnt/raspi-flash/wpa_supplicant.conf
sudo bash -c 'cat > /mnt/raspi-flash/wpa_supplicant.conf' <<EOF
country=$country country=$country
update_config=1 update_config=1
ctrl_interface=/var/run/wpa_supplicant ctrl_interface=/var/run/wpa_supplicant
@ -173,6 +175,7 @@ network={
EOF EOF
fi fi
sudo umount "$DEVICE_SELECTION"1 sudo umount "$DEVICE_SELECTION"
sudo rmdir /mnt/raspi-flash sudo rmdir /mnt/raspi-flash
echo "Finished successfully!" echo "Finished successfully!"

Loading…
Cancel
Save