Skip to content

Instantly share code, notes, and snippets.

@imneonizer
Last active November 3, 2020 13:03
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 imneonizer/f487cc57dc094c461931e8e560960667 to your computer and use it in GitHub Desktop.
Save imneonizer/f487cc57dc094c461931e8e560960667 to your computer and use it in GitHub Desktop.
#!/bin/bash
mount_safely (){
PARTITION=$1; MOUNTPOINT=$2
if [ `whoami` == root ];then
# create mount point dir if doesn't exists
[ -d $MOUNTPOINT ] || mkdir -p $MOUNTPOINT
# mount the partition to mountpoint
mount $PARTITION $MOUNTPOINT
# If mounting successful
if [ $? -eq 0 ]; then echo "Mounted: $PARTITION ==> $MOUNTPOINT";fi
else
echo "Mounting Error: $PARTITION ==> $MOUNTPOINT, Root permission required."
fi
}
# Log the errors to a log file
LOGFILE="/var/log/mount_error.log"
if [[ `whoami` == root ]];then exec 2> $LOGFILE; fi
# ----------- Modify as required ----------------
PARTITION="/dev/mmcblk1"
MOUNTPOINT="/media/sdcard"
mount_safely $PARTITION $MOUNTPOINT
# -----------------------------------------------
# Read out the errors from log file
if [[ `whoami` == root ]];then echo "Logged at `date`" >> $LOGFILE; echo `cat $LOGFILE`; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment