Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mount-sd] create directory writable for all users. Fixes MER#1010 #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions scripts/mount-sd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ MNT=/media/sdcard
MOUNT_OPTS="dirsync,noatime,users"
ACTION=$1
DEVNAME=$2
# dir to store symlinks to writable location on corresponding mounted cards
LN_DIR=/run/media

if [ -z "${ACTION}" ] || [ -z "${DEVNAME}" ]; then
exit 1
fi

systemd-cat -t mount-sd /bin/echo "Called to ${ACTION} ${DEVNAME}"
log () {
systemd-cat -t mount-sd /bin/echo $@
}

get_path_fname() {
echo ${LN_DIR}/${1}
}

log "Called to ${ACTION} ${DEVNAME}"
mkdir -p $LN_DIR

if [ "$ACTION" = "add" ]; then

Expand All @@ -25,9 +36,11 @@ if [ "$ACTION" = "add" ]; then
exit 1
fi

TARGET=$MNT/${UUID}

DIR=$(grep -w ${DEVNAME} /proc/mounts | cut -d \ -f 2)
if [ -n "$DIR" ]; then
systemd-cat -t mount-sd /bin/echo "${DEVNAME} already mounted on ${DIR}, ignoring"
log "${DEVNAME} already mounted on ${DIR}, ignoring"
exit 0
fi

Expand All @@ -39,39 +52,60 @@ if [ "$ACTION" = "add" ]; then
MINER_STATUS="$(dbus-send --type=method_call --print-reply --session --dest=org.freedesktop.Tracker1.Miner.Files /org/freedesktop/Tracker1/Miner/Files org.freedesktop.Tracker1.Miner.GetStatus | grep -o 'Idle')"
STORE_STATUS="$(dbus-send --type=method_call --print-reply --session --dest=org.freedesktop.Tracker1 /org/freedesktop/Tracker1/Status org.freedesktop.Tracker1.Status.GetStatus | grep -o 'Idle')"
test "$MINER_STATUS" = "Idle" -a "$STORE_STATUS" = "Idle" && break
systemd-cat -t mount-sd /bin/echo "Waiting $count seconds for tracker"
log "Waiting $count seconds for tracker"
sleep $count ;
count=$(( count + count ))
done

test -d $MNT/${UUID} || mkdir -p $MNT/${UUID}
chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID}
touch $MNT/${UUID}
test -d ${TARGET} || mkdir -p ${TARGET}
chown $DEF_UID:$DEF_GID $MNT ${TARGET}
touch ${TARGET}

case "${TYPE}" in
vfat|exfat)
mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir $MNT/${UUID}
if mount ${DEVNAME} ${TARGET} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard; then
ln -s "${TARGET}" "$(get_path_fname ${UUID})"
else
/bin/rmdir ${TARGET}
fi
;;
# NTFS support has not been tested but it's being left to please the ego of an engineer!
ntfs)
mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8 || /bin/rmdir $MNT/${UUID}
mount ${DEVNAME} ${TARGET} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8 || /bin/rmdir ${TARGET}
;;
*)
mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID}
if mount ${DEVNAME} ${TARGET} -o $MOUNT_OPTS; then
COMMON_DIR=${TARGET}/NemoMobileData
if ! [ -d "${COMMON_DIR}" ]; then
log "Creating common directory ${COMMON_DIR}"
if mkdir ${COMMON_DIR} && chmod 1777 ${COMMON_DIR}; then
ln -s "${COMMON_DIR}" "$(get_path_fname ${UUID})"
fi
elif ! $(su nemo -c "test -w ${COMMON_DIR}"); then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This puts in the assertion that the system user is nemo, and that there's only one user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a log record to know what happened (hard to check availability for each/unknown user), I can remove it.

log "${COMMON_DIR} is not writable by nemo user"
else
ln -s "${COMMON_DIR}" "$(get_path_fname ${UUID})"
fi
else
/bin/rmdir ${TARGET}
fi
;;
esac
test -d $MNT/${UUID} && touch $MNT/${UUID}
systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} of type ${TYPE} at $MNT/${UUID}"
test -d ${TARGET} && touch ${TARGET}
log "Finished ${ACTION}ing ${DEVNAME} of type ${TYPE} at ${TARGET}"

else
DIR=$(grep -w ${DEVNAME} /proc/mounts | cut -d \ -f 2)
if [ -n "${DIR}" ] ; then
if [ "${DIR##$MNT}" = "${DIR}" ]; then
systemd-cat -t mount-sd /bin/echo "${DEVNAME} mountpoint ${DIR} is not under ${MNT}, ignoring"
log "${DEVNAME} mountpoint ${DIR} is not under ${MNT}, ignoring"
exit 0
fi
umount $DIR || umount -l $DIR
systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} at ${DIR}"
PATH_FILE=$(get_path_fname "$(basename $DIR)")
echo "Removing path file $PATH_FILE"
[ -L $PATH_FILE ] && unlink $PATH_FILE
log "Finished ${ACTION}ing ${DEVNAME} at ${DIR}"
fi
fi