Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ "$(id -u)" != "0" ]; then
- exec sudo "$0" "$@"
- fi
- imgfile="$1"
- if [ ! -e $2 ]; then whereToMount="$2"; else whereToMount="mountPoint"; fi
- partition=`parted -s "$imgfile" unit B print | awk '{print $2}' | sed -n '/Start/,$p' | sed '1d' | sed '/^$/d' | sed 's/B//'`
- offset=($partition)
- numPartitions=${#offset[@]}
- echo -e "\n$imgfile contains $numPartitions partitions\n"
- for partNum in 0 $(($numPartitions-1)); do
- offset="${offset[$partNum]}"
- nextoffset="${offset[$partNum+1]}"
- if [ ! -z $nextoffset ]; then
- sizelimit=$(($nextoffset-$offset))
- else
- sizelimit=""
- fi
- mkdir -p "$whereToMount/part$partNum"
- mount -o loop,offset=$offset,sizelimit=$sizelimit $imgfile $whereToMount/part$partNum
- done
- xdg-open $whereToMount 2>/dev/null 1>/dev/null
- echo "Image should now be mounted and browsable"
- echo "Leave this terminal open while you browse the image"
- echo 'then come back and dismount the image by entering "Y"'
- while [ "$response" != "y" ]; do
- read -p "Dismount the image now? [Y/n]: " response
- response=${response:-Y}
- response="${response:0:1}"
- response="${response,,}"
- done
- umount $whereToMount/*
- rmdir $whereToMount/*
- rmdir $whereToMount
- exit
Advertisement
Add Comment
Please, Sign In to add comment