From 0e6f005d0727761626ec0bdf96a37c2608edaa8c Mon Sep 17 00:00:00 2001 From: Denis Zalevskiy Date: Tue, 19 May 2015 14:40:36 +0300 Subject: [PATCH 1/2] refactoring: log() function, add var for mount target dir Signed-off-by: Denis Zalevskiy --- scripts/mount-sd.sh | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 59841ce..fd2263b 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -15,7 +15,11 @@ 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 $@ +} + +log "Called to ${ACTION} ${DEVNAME}" if [ "$ACTION" = "add" ]; then @@ -25,9 +29,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 @@ -39,39 +45,39 @@ 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} + mount ${DEVNAME} ${TARGET} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir ${TARGET} ;; # 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} + mount ${DEVNAME} ${TARGET} -o $MOUNT_OPTS || /bin/rmdir ${TARGET} ;; 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}" + log "Finished ${ACTION}ing ${DEVNAME} at ${DIR}" fi fi From 3ae68818a540e5805c74e6dc33bed7664d9da2b8 Mon Sep 17 00:00:00 2001 From: Denis Zalevskiy Date: Tue, 19 May 2015 14:50:51 +0300 Subject: [PATCH 2/2] [mount-sd] create directory writable for all users. Fixes MER#1010 If card has filesystem different from vfat or ntfs, so maybe posix attrs are applicable to it, create directory there with recognizable name and sticky bit to allow users (e.g. nemo) to create files/directories there. To git rid of the hassle of handling card with different filesystems in a different way and hard-coding sticky-marked dir name, symlink this directory for posix-compliant filesystems in the temporary runtime dir /run/media or just the filesystem root directory - for vfat and ntfs Signed-off-by: Denis Zalevskiy --- scripts/mount-sd.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index fd2263b..72dbf89 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -10,6 +10,8 @@ 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 @@ -19,7 +21,12 @@ 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 @@ -56,14 +63,32 @@ if [ "$ACTION" = "add" ]; then case "${TYPE}" in vfat|exfat) - mount ${DEVNAME} ${TARGET} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir ${TARGET} + 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} ${TARGET} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8 || /bin/rmdir ${TARGET} ;; *) - mount ${DEVNAME} ${TARGET} -o $MOUNT_OPTS || /bin/rmdir ${TARGET} + 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 + 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 ${TARGET} && touch ${TARGET} @@ -77,6 +102,9 @@ else exit 0 fi umount $DIR || umount -l $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