#! /usr/bin/env bash # abort on nonzero exitstatus set -o errexit # abort on unbound variable set -o nounset # don't hide errors within pipes set -o pipefail if [ $# -eq 0 ] then echo "No argument supplied. Please specify the unziped Raspberry Pi OS file." exit 1 fi mkdir -p /mnt/sdcard_1 # extract the start offset sector_offset=$(fdisk --list ${1} | awk '/W95 FAT32/{print $2}') # multiply it with the sector size byte_offset=$((${sector_offset} * 512)) # mount the first partition mount --options loop,offset=${byte_offset} ${1} /mnt/sdcard_1 if [ $? -eq 0 ] then # create the file touch /mnt/sdcard_1/ssh if [ $? -eq 0 ] then echo "File created." else echo "Unable to create the file." fi # unmount umount /mnt/sdcard_1 else echo "Can't mount the file." fi