... I don't think that mount-sd.sh is called twice (other than add/remove). If you are experiencing this I think you need to give more information. ...
mkfs.btrfs -f /dev/mmcblk1 btrfs filesystem show /dev/mmcblk1 # this is a check mkdir /mnt/microsd mount /dev/mmcblk1 /mnt/microsd/ btrfs subvolume create /mnt/microsd/.android btrfs subvolume create /mnt/microsd/.jolla btrfs subvolume create /mnt/microsd/.jolla/Desktop btrfs subvolume create /mnt/microsd/.jolla/Documents btrfs subvolume create /mnt/microsd/.jolla/Downloads btrfs subvolume create /mnt/microsd/.jolla/Music btrfs subvolume create /mnt/microsd/.jolla/Pictures btrfs subvolume create /mnt/microsd/.jolla/Public btrfs subvolume create /mnt/microsd/.jolla/Templates btrfs subvolume create /mnt/microsd/.jolla/Videos btrfs subvolume list /mnt/microsd/ # this is a check chown -R nemo:nemo /mnt/microsd/* cp -rav /home/nemo/Pictures/* /mnt/microsd/Pictures/ cp -rav /home/nemo/Videos/* /mnt/microsd/Videos/ # transfer mount-sd.sh to /home/nemo via filezilla or scp and do cp /usr/sbin/mount-sd.sh /usr/sbin/mount-sd.sh.orig cp /home/nemo/mount-sd.sh /usr/sbin/mount-sd.sh chmod +x /usr/sbin/mount-sd.sh
#!/bin/bash SDCARD=/dev/sdcard EARLYDONE="/tmp/mount-sd.early.done" LATEDONE="/tmp/mount-sd.late.done" DEF_UID=$(grep "^UID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) DEF_GID=$(grep "^GID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) DEVICEUSER=$(getent passwd ${DEF_UID} | sed 's/:.*//') LATEMNT=/run/user/${DEF_UID}/media/sdcard if [ "${ACTION}" = "add" ]; then if [ -f ${LATEDONE} ]; then echo "$0: nothing to do!" else # try only the late mount again if [ -f ${EARLYDONE} ]; then if [ -b /dev/mmcblk1p1 ]; then ID_FS_TYPE=$(file -s /dev/mmcblk1p1 | tr '[:upper:]' '[:lower:]' | cut -d " " -f2) elif [ -b /dev/mmcblk1 ]; then ID_FS_TYPE=$(file -s /dev/mmcblk1 | tr '[:upper:]' '[:lower:]' | cut -d " " -f2) else exit $? fi su ${DEVICEUSER} -c "mkdir -p ${LATEMNT}" case "${ID_FS_TYPE}" in vfat|ntfs|exfat) mount ${SDCARD} ${LATEMNT} -o uid=${DEF_UID},gid=${DEF_GID} [ $? = 0 ] && echo "$$" >> ${LATEDONE} ;; *) mount ${SDCARD} ${LATEMNT} if [ $? = 0 ]; then echo "$$" >> ${LATEDONE} chown ${DEVICEUSER}: ${LATEMNT} fi ;; esac # first call, try both: early and late mount else # create device if [ -b /dev/mmcblk1p1 ]; then ln -sf /dev/mmcblk1p1 ${SDCARD} ID_FS_TYPE=$(file -s /dev/mmcblk1p1 | tr '[:upper:]' '[:lower:]' | cut -d " " -f2) elif [ -b /dev/mmcblk1 ]; then ln -sf /dev/mmcblk1 ${SDCARD} ID_FS_TYPE=$(file -s /dev/mmcblk1 | tr '[:upper:]' '[:lower:]' | cut -d " " -f2) else exit $? fi su ${DEVICEUSER} -c "mkdir -p ${LATEMNT}" case "${ID_FS_TYPE}" in vfat|ntfs|exfat) mount ${SDCARD} ${LATEMNT} -o uid=${DEF_UID},gid=${DEF_GID} [ $? = 0 ] && echo "$$" >> ${LATEDONE} ;; btrfs) mount -o compress ${SDCARD} ${LATEMNT} if [ $? = 0 ]; then echo "$$" >> ${LATEDONE} chown ${DEVICEUSER}: ${LATEMNT} fi mount -o subvol=.jolla/Desktop,compress ${SDCARD} /home/nemo/Desktop/ mount -o subvol=.jolla/Documents ${SDCARD} /home/nemo/Documents/ mount -o subvol=.jolla/Downloads ${SDCARD} /home/nemo/Downloads/ mount -o subvol=.jolla/Music ${SDCARD} /home/nemo/Music/ mount -o subvol=.jolla/Pictures ${SDCARD} /home/nemo/Pictures/ mount -o subvol=.jolla/Public ${SDCARD} /home/nemo/Public/ mount -o subvol=.jolla/Templates ${SDCARD} /home/nemo/Templates/ mount -o subvol=.jolla/Videos ${SDCARD} /home/nemo/Videos/ [ -d /data/sdcard ] && mount -o subvol=.android ${SDCARD} /data/sdcard/ ;; *) mount ${SDCARD} ${LATEMNT} if [ $? = 0 ]; then echo "$$" >> ${LATEDONE} chown ${DEVICEUSER}: ${LATEMNT} fi ;; esac echo "$$" >> ${EARLYDONE} fi fi else # unmount all umount ${SDCARD} myret=$? while [ $myret = 0 ] do echo -n "." umount ${SDCARD} myret=$? done umount -l ${LATEMNT} rm -f ${SDCARD} # clear status flags rm -f ${LATEDONE} rm -f ${EARLYDONE} fi