Last active
February 6, 2024 07:59
-
-
Save tve/c40ba59b9ac5f1339dd42e4508fc2bcc to your computer and use it in GitHub Desktop.
Flash SensorStation from rPi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash -e | |
# Flash a SensorStation (Compute Module) attached via USB | |
if [[ -z $1 ]]; then echo "usage: $0 <url>"; exit 1; fi | |
url=$1 | |
zip=$(basename $1) | |
img=$(basename $1 zip)img | |
cd /data | |
if ! [[ -f $zip ]]; then | |
echo Downloading $url | |
wget -nv -O $zip $url | |
fi | |
echo Unmounting | |
umount /run/media/$USER/* 2>/dev/null || true | |
dev=$(lsblk -d -o NAME,VENDOR,SIZE | grep -E 'RPi-MSD.*[2356][0-9]\.[0-9]G' | cut -d" " -f1) | |
if [[ -z $dev ]]; then | |
echo "No device found, running rpiboot" | |
sudo rpiboot | |
sleep 5 | |
dev=$(lsblk -d -o NAME,VENDOR,SIZE | grep -E 'RPi-MSD.*[2356][0-9]\.[0-9]G' | cut -d" " -f1) | |
if [[ -z $dev ]]; then echo "No device found."; exit 1; fi | |
fi | |
dev=/dev/$dev | |
echo "Flashing $dev: $(lsblk -dn -o VENDOR,MODEL,SIZE $dev)" | |
echo "Takes 15-20 minutes!" | |
sleep 5 | |
7z e -so $zip $img | sudo dd of=$dev bs=10M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment