Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # File: imageWriter
- # Example usage:
- # imageWriter [image file [targetDevice]]
- # ... or much easier, just run without parameters from the same directory where the EspressoBIN.img is.
- # -Then insert the device and it should be detected automatically.
- image="${1:-EspressoBIN.img}"
- dev="${dev:-$2}"
- [ "$dev" ] || {
- echo "Please insert target USB-stick or SD-card now (or unplug and re-insert)..."
- n=`ls -d /dev/*`
- while [ -z "$DEVICE" ]; do
- sleep 0.1; o="$n"; n=`ls -d /dev/*`
- DEVICES=(`diff -U0 <(echo "$o") <(echo "$n") | egrep "^\+\/dev\/(mmcblk|sd)[^\/]*\$"`)
- for DEV in ${DEVICES[@]}; do
- DEV=${DEV##*/}
- BDEV=${DEV/[0-9]*}
- echo "Found device named: $DEV (block device $BDEV)"
- printf "Write image to this device ? [y/N/c] "
- key=; while [[ "$key" != [YyNnCc] ]]; do read -n 1 key; printf "\b \b"; done
- case $key in
- [Yy]) echo "Yes"; DEVICE="$DEV"; BLKDEVICE="$BDEV"; break ;;
- [Nn]) echo "No" ;;
- [Cc]) echo "Cancel"; exit 1 ;;
- esac
- done
- done
- dev="/dev/$DEVICE"
- }
- echo "dev=$dev"
- echo "image=$image"
- [ "$dev" ] && [ -f "$image" ] && echo "Writing image..." && sudo cp "$image" "$dev"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement