Last active
November 3, 2020 13:03
-
-
Save imneonizer/f487cc57dc094c461931e8e560960667 to your computer and use it in GitHub Desktop.
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 | |
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