Launcher to enfoce XDG Base Directory compliance for any application
This script is designed to enforce compliance with the XDG Base Directory Specification for applications that do not natively respect the user's XDG settings. By redefining the HOME environment variable and temporarily linking necessary files, this script forces applications store their configuration, cache, and data files in the appropriate XDG-defined locations.
xdg-launch [-cd <directory>] [--fuzz] [--quiet] <application> [-- <options>]
-d,--dir,--cd <directory>: Specify a working directory for the application. The script will change to this directory before launching the application.-f,--fuzz: Fuzz the/etc/passwdfile for applications that ignore environment variables.--help,-h: Display usage information.--quiet,-q: Quiet mode to supress launcher messages. The launched application's output is not affected.<application>: The application to be launched.[<options>]: Additional options or arguments passed to the application.
-
Environment Setup:
- The script checks for user's
XDG_CONFIG_HOME,XDG_CACHE_HOME,XDG_DATA_HOME, andXDG_STATE_HOME. - If they are not already defined, the default values are used.
- Missing directories are created, if needed, just in case.
- The script checks for user's
-
Resource Useage Registratoin:
- The launcher aquires a mutex lock on the file
$XDG_STATE_HOME/xdg/launcher.lock. - The quantity of applications using links within the specified
XDG_DATA_HOMEis incremented. - This data is saved within the
$XDG_STATE_HOME/xdg/launcher.datafile.
- The launcher aquires a mutex lock on the file
-
Temporary Links: Temporary links to the following items are created within
XDG_DATA_HOME..cache.config.Xauthority
-
/etc/passwd Fuzzing (if enabled):
- A copy of the
/etc/passwdfile is created as/tmp/$USER/passwd.pid - Within the file, the root user's home directory is set to the real user's
XDG_DATA_HOME.
- A copy of the
-
Application Launch:
- The working directory is changed to the specified target directory.
- The script temporarily redefines the
HOMEenvironment variable to point toXDG_DATA_HOME. - If enabled, a new private namespace is created which overrides
/etc/passwdwith the fuzzed version. - The specified application is launched with its arguments.
-
Cleanup After the Application Exits:
- The number of registerd applications is decremented within the
$XDG_STATE_HOME/xdg/launcher.datafile. - Temporary links are removed unless registered as still in use by another application.
- Fuzzed passwd files are not removed from the
/tmp/$USER/directory.
- The number of registerd applications is decremented within the
If you have an $XAUTHORITY setting, the .Xauthority link will not be made. It is hoped that the setting works without it. I have not yet been successful in enabling this setting. So if you do have it set, please let me know if this works for you or not.