Skip to content

Instantly share code, notes, and snippets.

@Razuuu
Last active September 12, 2023 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Razuuu/39fb8bf1f89f186d5c45a2731f27cb7d to your computer and use it in GitHub Desktop.
Save Razuuu/39fb8bf1f89f186d5c45a2731f27cb7d to your computer and use it in GitHub Desktop.
Mounts stock rom (system,vendor) to /mnt/stock/. Can also unmount
#!/bin/bash
DEVICE="$1"
UMOUNT="$2"
if [ -z "$DEVICE" ]; then
echo "Usage: $0 <DEVICE> [optional: --unmount]"
exit 1
fi
for IMG in system vendor; do
IMGFOLDER="/mnt/stock/${DEVICE}/${IMG}"
IMGPATH="$(dirname "$(readlink -f "$0")")/${IMG}.img"
# Check if img exists
if [ ! -f "$IMGPATH" ]; then
echo "Imagefile $IMGPATH does not exist, exiting."
continue
fi
# Check if unmount option is specified
if [ "$UMOUNT" == "--unmount" ]; then
if [ -n "$(mount | grep "$IMGFOLDER")" ]; then
echo "Unmounting $IMGFOLDER."
sudo umount "$IMGFOLDER"
else
echo "$IMGFOLDER is not currently mounted, skipping unmount."
fi
continue
fi
# Check if mount folder exists
if [ ! -d "$IMGFOLDER" ]; then
sudo mkdir -p "$IMGFOLDER"
echo "Successfully created folder $IMGFOLDER!"
fi
# Check if already mounted
if [ "$(mount | grep "$IMGFOLDER")" ]; then
echo "$IMGFOLDER is already mounted, skipping mount."
else
# Mount img
echo "Mounting $IMGPATH to $IMGFOLDER."
sudo mount "$IMGPATH" "$IMGFOLDER"
# Set permission to folder
chown -R $USER:$USER "${IMGFOLDER}/.."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment