aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-09-25 20:39:41 -0400
committerB Stack <bgstack15@gmail.com>2020-09-25 20:39:41 -0400
commitcee836f71e191e51dd48d34633bfd8c977ba3b8a (patch)
tree5cf0cbf47cea50276f2dc853500400554d04bd04
parentprovide working trayicon now (diff)
downloadmyautomount-cee836f71e191e51dd48d34633bfd8c977ba3b8a.tar.gz
myautomount-cee836f71e191e51dd48d34633bfd8c977ba3b8a.tar.bz2
myautomount-cee836f71e191e51dd48d34633bfd8c977ba3b8a.zip
rename to myautomount
Add annotations to conf file, separate out initialization so daemon can be per-user. Use a sane name.
-rw-r--r--README14
-rw-r--r--src/etc/myautomount.conf21
-rwxr-xr-xsrc/usr/bin/myautomount-trayicon4
-rwxr-xr-xsrc/usr/bin/myautomountd (renamed from stackrpms-automount.sh)34
-rw-r--r--src/usr/libexec/myautomount/myautomount-initialize.sh24
-rwxr-xr-xsrc/usr/libexec/myautomount/myautomount-trayicon.py (renamed from automount-trayicon.py)36
-rw-r--r--stackrpms-automount.conf6
7 files changed, 96 insertions, 43 deletions
diff --git a/README b/README
index 701eb89..d3f808e 100644
--- a/README
+++ b/README
@@ -1,4 +1,12 @@
-Translated to shell almost line-for-line from Go source at https://github.com/project-trident/trident-utilities/blame/master/src-go/automount/main.go
+asdf
+Myautomount was translated to shell almost line-for-line from Go source at https://github.com/project-trident/trident-utilities/blame/master/src-go/automount/main.go but then it diverged.
-Future goals:
-make system tray icon version, probably that reads xdg desktop entries and displays icons for them
+TODO:
+write makefile
+write full dependencies (including gtk3)
+
+# TESTING AND BUILDING
+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
diff --git a/src/etc/myautomount.conf b/src/etc/myautomount.conf
new file mode 100644
index 0000000..eef2ca8
--- /dev/null
+++ b/src/etc/myautomount.conf
@@ -0,0 +1,21 @@
+# This config file is dot-sourced by a shell script, for both the daemon
+# and myautomount-trayicon.
+
+# TMPFILE is only needed for trayicon
+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.
+export AUTOMOUNT_DIR=/etc/auto.master.d
+export AUTOMOUNT_DIR_FILE=/etc/auto.master.d/myautomount.autofs
+export AUTOMOUNT_FILE=/etc/autofs.myautomount
+
+# BASEDIR is where the pseudo-xdg desktop files will go. This directory
+# should not be controlled by anything else.
+# The daemon places desktop files here that the trayicon uses.
+export AUTOMOUNT_BASEDIR=/run/user/${UID}/automedia
+
+# This needs to match what you put in /etc/autofs.myautomount, and is
+# where the filesystems get mounted to. This location should not be
+# controlled by anything else.
+export AUTOMOUNT_BROWSEDIR=/browse
diff --git a/src/usr/bin/myautomount-trayicon b/src/usr/bin/myautomount-trayicon
new file mode 100755
index 0000000..08be25d
--- /dev/null
+++ b/src/usr/bin/myautomount-trayicon
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Part of myautomount project
+. ${MYA_PREFIX}/etc/myautomount.conf
+${MYA_PREFIX}/usr/libexec/myautomount/myautomount-trayicon.py
diff --git a/stackrpms-automount.sh b/src/usr/bin/myautomountd
index a3f7c09..d23940a 100755
--- a/stackrpms-automount.sh
+++ b/src/usr/bin/myautomountd
@@ -1,5 +1,5 @@
#!/bin/sh
-# File: stackrpms-automount.sh
+# File: /usr/bin/myautomountd
# Location: gitlab
# Authors: beanpole135, bgstack15
# Startdate: 2020-09-23
@@ -10,11 +10,14 @@
# Several translation notes: configuration split out into separate file
# and given a Fedora flavor.
# Usage:
-# Run as root.
+# Invoke this at X startup. This can be from the xdg autostart mechanism, or "exec myautomountd &" in ~/fluxbox.startup
+# This is the backend to myautomount-trayicon
# Reference:
-# 1: https://github.com/project-trident/trident-utilities/blob/master/src-go/automount/main.go
+# https://github.com/project-trident/trident-utilities/blob/master/src-go/automount/main.go
# Improve:
-# Dependencies: udevadm (from systemd-udev or eudev)
+# Dependencies:
+# udevadm (from systemd-udev or eudev)
+# dep-devuan: eudev
# FUNCTIONS
clean_automount() {
@@ -111,29 +114,10 @@ createEntry() {
} > "${_filepath}"
}
-setupSystem() {
- _needrestart=0
- mkdir -m0755 -p "${AUTOMOUNT_DIR}" || fail "Could not setup autofs rules! Check if this is being run as root?"
- ! test -f "${AUTOMOUNT_FILE}" && {
- { touch "${AUTOMOUNT_FILE}" && echo "* -fstype=auto,rw,nosuid,uid=${USER},gid=users :/dev/& " > "${AUTOMOUNT_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
- _needrestart=1
- }
- ! test -f "${AUTOMOUNT_DIR_FILE}" && {
- { touch "${AUTOMOUNT_DIR_FILE}" && echo "${AUTOMOUNT_BROWSEDIR} ${AUTOMOUNT_FILE} --timeout=5 " > "${AUTOMOUNT_DIR_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
- _needrestart=1
- }
- test ${_needrestart} -eq 1 && eval "service autofs restart"
-}
-
-fail() {
- echo "${@}" 1>&2
- exit 1
-}
-
# INITIALIZE
-. ${0%%.sh}.conf
+. ${MYA_PREFIX}/etc/myautomount.conf
trap '__ec=$? ; clean_automount ; trap "" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 ; exit ${__ec} ;' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20
-setupSystem
+mkdir -p "${AUTOMOUNT_BASEDIR}"
# MAIN
# start udevadm
diff --git a/src/usr/libexec/myautomount/myautomount-initialize.sh b/src/usr/libexec/myautomount/myautomount-initialize.sh
new file mode 100644
index 0000000..fc75d36
--- /dev/null
+++ b/src/usr/libexec/myautomount/myautomount-initialize.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Only needs to be run once. This is more for reference than for using. The package should handle these tasks.
+
+fail() {
+ echo "${@}" 1>&2
+ exit 1
+}
+
+setupSystem() {
+ _needrestart=0
+ mkdir -m0755 -p "${AUTOMOUNT_DIR}" || fail "Could not setup autofs rules! Check if this is being run as root?"
+ ! test -f "${AUTOMOUNT_FILE}" && {
+ { touch "${AUTOMOUNT_FILE}" && echo "* -fstype=auto,rw,nosuid,uid=${USER},gid=users :/dev/& " > "${AUTOMOUNT_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
+ _needrestart=1
+ }
+ ! test -f "${AUTOMOUNT_DIR_FILE}" && {
+ { touch "${AUTOMOUNT_DIR_FILE}" && echo "${AUTOMOUNT_BROWSEDIR} ${AUTOMOUNT_FILE} --timeout=5 " > "${AUTOMOUNT_DIR_FILE}" ; } || fail "Could not setup autofs rules! Check if this is being run as root?"
+ _needrestart=1
+ }
+ test ${_needrestart} -eq 1 && eval "service autofs restart"
+}
+
+. ${MYA_PREFIX}/etc/myautomount.conf
+setupSystem
diff --git a/automount-trayicon.py b/src/usr/libexec/myautomount/myautomount-trayicon.py
index 84312e7..257c54f 100755
--- a/automount-trayicon.py
+++ b/src/usr/libexec/myautomount/myautomount-trayicon.py
@@ -1,19 +1,30 @@
#!/usr/bin/python3
-# File: automount-trayicon.py
-# startdate: 2020-09-24 13:17
-# References:
+# File: /usr/libexec/myautomount/automount-trayicon.py
+# License: CC-BY-SA 4.0
+# Author: bgstack15
+# Startdate: 2020-09-24 13:17
+# Title: Tray icon for automount daemon
+# Purpose: Easy access to autofs-mounted removable media
+# History:
+# Usage:
+# to be called from /usr/bin/myautomount-trayicon only, because it loads the environment variables
+# Reference:
# https://gitlab.com/bgstack15/logout-manager/-/blob/master/src/usr/bin/logout-manager-trayicon
# https://github.com/gapan/xdgmenumaker/blob/master/src/xdgmenumaker
# https://github.com/seb-m/pyinotify/blob/master/python2/examples/stats_threaded.py
# https://stackoverflow.com/questions/28279363/python-way-to-get-mounted-filesystems/28279434#28279434
# timer https://python-gtk-3-tutorial.readthedocs.io/en/latest/spinner.html?highlight=timer#id1
-# vim: ts=3 sw=3 sts=3
# Improve:
-# move out config to separate file (read main .conf, but in shell format)
+# move out user configs to separate file in ~/.config/myautomount, but using the xdg spec.
# add all headers
# document
+# add option to HIDE WHEN NO MEDIA
# Dependencies:
-# autofs, root running the included stackrpms-automount
+# dep-devuan: autofs, python3-pyinotify
+# dep-fedora:
+# dep-pip: inotify
+# python-inotify, the seb-m one.
+# And whatever provides Gtk 3.0 for python3.
import gi, os, fnmatch, sys, pyinotify, time, subprocess
gi.require_version("Gtk","3.0")
@@ -24,8 +35,15 @@ import xdg.Exceptions as exc
showmount = 1 # show the "MOUNTED" value for each drive
skip_sd_without_partitions = 1 # skip sdb sdc, etc. # NOT IMPLEMENTED YET.
only_update_on_menuitem = 0 # if 1, then disables the mouseover poll. Prevents showmount=1 from working.
-AUTOMOUNT_BASEDIR="/media"
-AUTOMOUNT_BROWSEDIR="/browse"
+
+# load environment variables
+AUTOMOUNT_BASEDIR = os.getenv("AUTOMOUNT_BASEDIR") # probably /run/user/${UID}/automedia
+if not AUTOMOUNT_BASEDIR:
+ print("Need env var AUTOMOUNT_BASEDIR. Aborted.",file=sys.stderr)
+ sys.exit(1)
+AUTOMOUNT_BROWSEDIR = os.getenv("AUTOMOUNT_BROWSEDIR") # probably /browse
+if showmount and not AUTOMOUNT_BROWSEDIR:
+ print("Without AUTOMOUNT_BROWSEDIR, showmount option cannot be used. Continuing...",file=sys.stderr)
# FUNCTIONS
@@ -246,7 +264,7 @@ class MainIcon(Gtk.StatusIcon):
mounted_str=""
# collection = [line.split()[1] for line in open("/etc/mtab") if line.split()[1].startswith('/browse') and line.split()[2] != "autofs"]
if label_paren_str is not None and label_paren_str != "":
- if showmount:
+ if showmount and AUTOMOUNT_BROWSEDIR:
if label_paren_str in [line.split()[1] for line in open("/etc/mtab") if line.split()[1].startswith(AUTOMOUNT_BROWSEDIR) and line.split()[2] != "autofs"]:
label_paren_str = "MOUNTED " + label_paren_str
full_label_str += " (" + label_paren_str + ")"
diff --git a/stackrpms-automount.conf b/stackrpms-automount.conf
deleted file mode 100644
index a191a57..0000000
--- a/stackrpms-automount.conf
+++ /dev/null
@@ -1,6 +0,0 @@
-export AUTOMOUNT_TMPFILE="$( TMPDIR=/tmp mktemp -t ${USER}.automount.XXXXXXXXX )"
-export AUTOMOUNT_DIR=/etc/auto.master.d
-export AUTOMOUNT_FILE=/etc/autofs.stackrpms
-export AUTOMOUNT_DIR_FILE=/etc/auto.master.d/stackrpms.autofs
-export AUTOMOUNT_BASEDIR=/media
-export AUTOMOUNT_BROWSEDIR=/browse
bgstack15