aboutsummaryrefslogtreecommitdiff
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
parentadd sudo rule (diff)
downloadmyautomount-0d5f8b7657527eab8380f5aa81ecd072714cf13c.tar.gz
myautomount-0d5f8b7657527eab8380f5aa81ecd072714cf13c.tar.bz2
myautomount-0d5f8b7657527eab8380f5aa81ecd072714cf13c.zip
add sudo, fix initialization
-rw-r--r--README.md17
-rw-r--r--myautomount.spec3
-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
8 files changed, 22 insertions, 13 deletions
diff --git a/README.md b/README.md
index cf8f9c7..b744b14 100644
--- a/README.md
+++ b/README.md
@@ -1,25 +1,28 @@
# README for myautomount
## Overview
-Myautomount is a solution for desktop users who want to have easy access to removable media, without dbus. Dependencies include autofs, python3, and gtk3. This package provides a system tray icon that displays the available removable media that can be mounted with autofs.
+Myautomount is a solution for desktop users who want to have easy access to removable media, without dbus. Dependencies include autofs, sudo, python3, and gtk3. This package provides a system tray icon that displays the available removable media that can be mounted with autofs.
Myautomount is my response to the Go tool by Project Trident, [trident-automount][1]. I translated the Go tool almost line-for-line into shell, and then modified it slightly.
## Design and architecture
-A shell script, myautomountd, wraps around `udevadm monitor` to watch for block devices that are added and removed. Upon finding a new block device, the daemon will generate pseudo-xdg [desktop files][2] in a particular directory which defaults to `/run/user/${UID}/media`.
-The tray icon uses a python implementation of [inotify][3] to watch that directory, and generate menus for the left- and right-click actions.
+A shell script, myautomountd, wraps around `udevadm monitor` to watch for block devices that are added and removed. Upon finding a new block device, the daemon will generate pseudo-xdg [desktop files][2] in a particular directory which defaults to `/run/user/${UID}/media`. At startup, the daemon will insert the current user into the autofs rule so that the files on mounted filesystems will be owned by this user, if applicable.
+
+The tray icon uses a python implementation of [inotify][3] to watch that directory, and generate menus for the left- and right-click actions. The icon supports using the [XApp library][4] for StatusIcon instead of just the [deprecated][5] Gtk.StatusIcon, but it is a setting in the [python script](src/usr/libexec/myautomount/myautomount-trayicon.py) itself and not yet in the Makefile.
## Testing and building myautomount
-Build dependencies include txt2man, and my txtman-wrapper from [bgscripts-core][4].
+Build dependencies include txt2man, and my txtman-wrapper from [bgscripts-core][5].
Use environment variable `MYA_PREFIX` for testing.
export MYA_PREFIX=~/dev/myautomount/src
sudo DEBUG=1 MYA_PREFIX=~/dev/myautomount/src sh -x usr/libexec/myautomount/myautomount-initialize.sh
-## TODO
-A number of steps are still required before this package is production-worthy.
+## Improvements
+* Add notifications, perhaps with [xnotify](https://github.com/phillbush/xnotify)?
# References
[1]: https://github.com/project-trident/trident-utilities/blame/master/src-go/automount/main.go
[2]: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
[3]: https://github.com/seb-m/pyinotify
-[4]: https://gitlab.com/bgstack15/bgscripts/-/blob/master/src/usr/bin/txt2man-wrapper
+[4]: https://github.com/linuxmint/xapp
+[5]: https://developer.gnome.org/gtk3/stable/GtkStatusIcon.html
+[6]: https://gitlab.com/bgstack15/bgscripts/-/blob/master/src/usr/bin/txt2man-wrapper
diff --git a/myautomount.spec b/myautomount.spec
index 2079034..cc821f0 100644
--- a/myautomount.spec
+++ b/myautomount.spec
@@ -48,8 +48,10 @@ Group: Applications/System
URL: https://bgstack15.wordpress.com/
Packager: B Stack <bgstack15@gmail.com>
Requires: autofs
+Requires: sudo
Requires: python3-inotify
BuildRequires: txt2man
+BuildRequires: bgscripts-core
Buildarch: noarch
%description
@@ -83,6 +85,7 @@ exit 0
%config %attr(0644, -, -) %{_sysconfdir}/autofs.%{name}
%config %attr(0644, -, -) %{_sysconfdir}/auto.master.d/*
%{_bindir}/*
+%{_sysconfdir}/sudoers.d/*
%{_datadir}/applications/*
%{_libexecdir}/%{name}/*
%doc %{_mandir}/man1/*
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