Created
October 28, 2018 10:32
-
-
Save timofurrer/258aa59a149eb0519915c8a2ab2a4821 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
set -e | |
ENSURE_SSH=false | |
while [ -n "$1" ]; do | |
case "$1" in | |
-i|--image) | |
IMAGE="$2"; shift 2 | |
;; | |
-d|--disk) | |
DISK="$2"; shift 2 | |
;; | |
--ensure-ssh) | |
ENSURE_SSH=true; shift 2 | |
;; | |
*) | |
echo "Wrong option $1" >&2 | |
exit 1 | |
esac | |
done | |
if [ -z "$IMAGE" ]; then | |
echo "Please specify an image via -i <IMAGE>" >&2 | |
exit 1 | |
fi | |
if ${ENSURE_SSH}; then | |
echo "[*] Mounting image to write ssh file ..." | |
sudo kpartx -a "${IMAGE}" | |
sudo mkdir /tmp/raspi-disk | |
sleep 1 | |
sudo mount /dev/mapper/loop0p1 /tmp/raspi-disk | |
sudo touch /tmp/raspi-disk/ssh | |
sudo umount /tmp/raspi-disk | |
sudo rm -rf /tmp/raspi-disk | |
sudo kpartx -d "${IMAGE}" | |
echo "[*] ssh file written" | |
sleep 1 | |
fi | |
echo "[*] Writing image to SD card ..." | |
sudo dd if="${IMAGE}" of="${DISK}" bs=4M conv=fsync status=progress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment