#!/bin/bash -e #use this script with sudo and image link as argument. #Ensure that destination address of DD points to your SD card if [ -z "$2" ] ; then echo Usage: $0 URL DEVICE echo echo Example: echo " $0 https://aws1-vgateway-images.s3.amazonaws.com/raspberrypi-ubuntu-18.04.3-arm64.s.kcH5u5bc7841GJHsGG095vMN.img.zip /dev/sdb" exit 1 fi url="$1" device="$2" if [[ ! $url =~ ^https://s3\..*\.amazonaws.com/.* ]] && [[ ! -f $url ]] ; then echo ERROR: URL $url is invalid exit 2 fi if [ ! -b $device ] ; then echo ERROR: $device is not a block device exit 3 fi # ensure nothing is mounted mounts=`grep $device /proc/mounts |cut -f1 -d' '` if [ -n "$mounts" ] ; then echo ERROR: $device in use: $mounts are mounted, aborting. exit 4 fi # Support local files downloadCmd="curl --fail $url" if [[ -f "$url" ]] ; then downloadCmd="pv $url" fi # Ensure user doesn't need to enter the password when running 'sudo dd' sudo -v time { $downloadCmd | funzip | sudo dd of=$device bs=32M sync } sudo eject $device