Last active
September 16, 2020 14:53
-
-
Save highercomve/92775e5ca166c3a1901cdff0a2375b34 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 | |
| [ "$UID" -eq 0 ] || exec sudo "$0" "$@" | |
| imagefile=$1 | |
| mountpoint=$2 | |
| if [ -z "$1" ] || [ -z "$2" ]; then | |
| echo "Usage: " | |
| echo "mount_image IMAGE_FILE_PATH MOUNT_POINT" | |
| exit 0 | |
| fi | |
| sector_size=$(fdisk -l $imagefile | grep Units: | sed 's/.*= //' | sed 's/ [a-zA-Z]*//') | |
| echo "" | |
| echo "Select what image you what to mount" | |
| echo "" | |
| i=0 | |
| echo "0) All at once" | |
| fdisk -l $imagefile | grep "$imagefile[0-9]" | while read line | |
| do | |
| i=$((i + 1)) | |
| echo "$i) $line" | |
| done | |
| echo "" | |
| read -p "Enter the number option to mount: " input | |
| echo "" | |
| if [[ ! "$input" == ?(-)+([0-9]) ]]; then | |
| echo "Your selection is not a number" | |
| exit 0 | |
| fi | |
| if [ "$input" -lt 1 ] || [ "$input" -gt "$i" ]; then | |
| echo "Your selection is invalid, maximun selection is: $i" | |
| exit 0 | |
| fi | |
| if [ "$input" -gt 0 ]; then | |
| startat=$(fdisk -l $imagefile | grep "$imagefile[0-9]" | sed "${input}q;d" | awk '{print $2}') | |
| if ! [ -d "$mountpoint" ]; then | |
| mkdir -p $mountpoint | |
| fi | |
| offset=$((startat * $sector_size)) | |
| mount -o loop,rw,sync,offset=$offset $imagefile $mountpoint | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment