aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-09-29 22:47:28 -0400
committerB Stack <bgstack15@gmail.com>2020-09-29 22:47:28 -0400
commit0d5f8b7657527eab8380f5aa81ecd072714cf13c (patch)
tree80de0f0ea39fd4690d07f85856ab6511175bff8f /src
parentadd sudo rule (diff)
downloadmyautomount-0d5f8b7657527eab8380f5aa81ecd072714cf13c.tar.gz
myautomount-0d5f8b7657527eab8380f5aa81ecd072714cf13c.tar.bz2
myautomount-0d5f8b7657527eab8380f5aa81ecd072714cf13c.zip
add sudo, fix initialization
Diffstat (limited to 'src')
-rw-r--r--src/etc/myautomount.conf2
-rw-r--r--src/etc/sudoers.d/40_myautomount_sudo2
-rwxr-xr-xsrc/usr/bin/myautomountd2
-rw-r--r--src/usr/libexec/myautomount/myautomount-initialize.sh7
-rw-r--r--src/usr/share/applications/myautomount-trayicon.desktop1
-rw-r--r--src/usr/share/applications/myautomountd.desktop1
6 files changed, 9 insertions, 6 deletions
diff --git a/src/etc/myautomount.conf b/src/etc/myautomount.conf
index a64dace..543649a 100644
--- a/src/etc/myautomount.conf
+++ b/src/etc/myautomount.conf
@@ -2,7 +2,7 @@
# and myautomount-trayicon.
# TMPFILE is only needed for trayicon
-export AUTOMOUNT_TMPFILE="$( TMPDIR="/run/user/${UID}" mktemp -t ${USER}.automount.XXXXXXXXX )"
+test -z "${AUTOMOUNT_DAEMON}" && export AUTOMOUNT_TMPFILE="$( TMPDIR="/run/user/${UID}" mktemp -t ${USER}.automount.XXXXXXXXX )"
# DIR and FILE are for the initialization only. These are the most
# likely to change per distro.
diff --git a/src/etc/sudoers.d/40_myautomount_sudo b/src/etc/sudoers.d/40_myautomount_sudo
index 7f31d15..5c45984 100644
--- a/src/etc/sudoers.d/40_myautomount_sudo
+++ b/src/etc/sudoers.d/40_myautomount_sudo
@@ -1,3 +1,3 @@
# File: /etc/sudoers.d/30_myautomount_sudo
-Defaults env_keep += "DRYRUN VERBOSE MYA_PREFIX DEBUG"
+Defaults env_keep += "DRYRUN VERBOSE MYA_PREFIX DEBUG AUTOMOUNT_USER"
ALL ALL = (root) NOPASSWD: /usr/libexec/myautomount/myautomount-initialize.sh
diff --git a/src/usr/bin/myautomountd b/src/usr/bin/myautomountd
index 340ce04..06bb2da 100755
--- a/src/usr/bin/myautomountd
+++ b/src/usr/bin/myautomountd
@@ -120,7 +120,7 @@ trap '__ec=$? ; clean_automount ; trap "" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
mkdir -p "${AUTOMOUNT_BASEDIR}"
# run initialization script as root
-$( which sudo 2>/dev/null ) /usr/libexec/myautomount/myautomount-initialize.sh
+$( which sudo 2>/dev/null ) AUTOMOUNT_USER="${USER}" /usr/libexec/myautomount/myautomount-initialize.sh
_response="${?}" ; test ${_response} -ne 0 && exit ${_response}
# MAIN
diff --git a/src/usr/libexec/myautomount/myautomount-initialize.sh b/src/usr/libexec/myautomount/myautomount-initialize.sh
index 67fe2f3..1f7a42b 100644
--- a/src/usr/libexec/myautomount/myautomount-initialize.sh
+++ b/src/usr/libexec/myautomount/myautomount-initialize.sh
@@ -11,17 +11,18 @@ fail() {
setupSystem() {
_needrestart=0
mkdir -m0755 -p "${MYA_PREFIX}${AUTOMOUNT_DIR}" || fail "Could not setup autofs rules! Check if this is being run as root?"
- ! test -f "${MYA_PREFIX}${AUTOMOUNT_FILE}" && {
- { touch "${MYA_PREFIX}${AUTOMOUNT_FILE}" && echo "* -fstype=auto,rw,nosuid,uid=${USER},gid=users :/dev/& " > "${MYA_PREFIX}${AUTOMOUNT_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
+ ! grep -q -e "uid=${AUTOMOUNT_USER}," "${MYA_PREFIX}${AUTOMOUNT_FILE}" 2>/dev/null && {
+ { touch "${MYA_PREFIX}${AUTOMOUNT_FILE}" && echo "* -fstype=auto,rw,nosuid,uid=${AUTOMOUNT_USER},gid=users :/dev/& " > "${MYA_PREFIX}${AUTOMOUNT_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
_needrestart=1
}
- ! test -f "${MYA_PREFIX}${AUTOMOUNT_DIR_FILE}" && {
+ ! grep -q -e "${AUTOMOUNT_BROWSEDIR}" "${MYA_PREFIX}${AUTOMOUNT_DIR_FILE}" 2>/dev/null && {
{ touch "${MYA_PREFIX}${AUTOMOUNT_DIR_FILE}" && echo "${AUTOMOUNT_BROWSEDIR} ${AUTOMOUNT_FILE} --timeout=5 " > "${MYA_PREFIX}${AUTOMOUNT_DIR_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
_needrestart=1
}
test ${_needrestart} -eq 1 && test -z "${MYA_SKIP_RESTART}" && eval "service autofs restart"
}
+export AUTOMOUNT_DAEMON=1 # to suppress the useless error about mktemp: failed to create file
. ${MYA_PREFIX}/etc/myautomount.conf
setupSystem
# must enforce exit 0 because otherwise an already-initialized system will end with test ${_needrestart} -eq 1 as false which will break `make`.
diff --git a/src/usr/share/applications/myautomount-trayicon.desktop b/src/usr/share/applications/myautomount-trayicon.desktop
index 061454d..5a1dfbb 100644
--- a/src/usr/share/applications/myautomount-trayicon.desktop
+++ b/src/usr/share/applications/myautomount-trayicon.desktop
@@ -1,6 +1,7 @@
[Desktop Entry]
Comment=Tray icon for managing removable media
Exec=/usr/bin/myautomount-trayicon
+Categories=Utility;TrayIcon;
GenericName=Automount helper tray icon
Icon=media-removable
Keywords=automount;
diff --git a/src/usr/share/applications/myautomountd.desktop b/src/usr/share/applications/myautomountd.desktop
index 57a147a..037dbe9 100644
--- a/src/usr/share/applications/myautomountd.desktop
+++ b/src/usr/share/applications/myautomountd.desktop
@@ -1,6 +1,7 @@
[Desktop Entry]
Comment=Monitor udevadm for removable media
Exec=/usr/bin/myautomountd
+Categories=Utility;
GenericName=Automount helper daemon
Icon=media-removable
Keywords=automount;
bgstack15