GAM-team / GAM

command line management for Google Workspace
https://github.com/GAM-team/GAM/wiki
Apache License 2.0
3.53k stars 473 forks source link

[Linux] Source configuration/data from standard locations #792

Open ainola opened 6 years ago

ainola commented 6 years ago

Presently, GAM uses its own directory structure; however if one wants to package this application for system installation, GAM will not (and should not) have access to alter its installation directories. GAM should be looking in standard Linux configuration directories: $XDG_CONFIG_HOME/gam/<configfile> if available, then /etc/gam/<configfile> for the system defaults. Individual user tokens should be sourced from $XDG_CONFIG_HOME/gam/<tokenfile> (and the program should refuse to work if the token is world-readable).

These changes would allow packaging into Archlinux for users to install.

ainola commented 6 years ago

Here's a hacky example that is currently applied to the Arch Linux AUR package:

--- src/var.py  2018-08-03 14:30:31.000000000 -0600
+++ src/var.py  2018-08-11 12:02:27.184546770 -0600
@@ -20,6 +20,18 @@
 GAM_LATEST_RELEASE = GAM_ALL_RELEASES+u'/latest'
 GAM_PROJECT_APIS = u'https://raw.githubusercontent.com/jay0lee/GAM/master/src/project-apis.txt'

+try:
+    XDG_CONFIG_DIR = os.environ['XDG_CONFIG_HOME']
+except KeyError:
+    XDG_CONFIG_DIR = os.path.expanduser("~") + '/.config/'
+CONFIG_DIR = unicode(XDG_CONFIG_DIR) + u'gam/'
+
+try:
+    os.makedirs(CONFIG_DIR, mode=0700)
+except OSError:
+    if not os.path.isdir(CONFIG_DIR):
+        raise
+
 TRUE = u'true'
 FALSE = u'false'
 true_values = [u'on', u'yes', u'enabled', u'true', u'1']
timwsuqld commented 5 years ago

@ainola is it worth submitting this as a patch to see if it'll be merged in?

ainola commented 5 years ago

The hack certainly is better than nothing for the AUR package but I'm afraid larger-scale changes need to happen before this gets merged in. For one, the logic for saving the token is broken IIRC and one needs to generate it with the incumbent method and move the tokens manually.

I think GAM needs to adopt the mentality of a system package rather than standalone; Now that there's an effort underway to clean up the codebase it very well may be worth our time to standardize locations (XDG directories for Linux, Library for mac, etc).

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

ainola commented 4 years ago

This is absolutely still relevant.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

jay0lee commented 1 month ago

GAM7 now supports storing config in a folder specified by the GAMCFGDIR env variable. PTAL and see if this solves this issue.