Last active
September 12, 2023 15:45
-
-
Save Razuuu/39fb8bf1f89f186d5c45a2731f27cb7d to your computer and use it in GitHub Desktop.
Mounts stock rom (system,vendor) to /mnt/stock/. Can also unmount
This file contains 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 | |
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