From 333a45fd7c3d76abe5894e91dbdba365559bf0ca Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Thu, 18 Aug 2022 16:37:57 +0100 Subject: [PATCH] Use XDG directories explicitly --- console.sh | 4 +++- desktop.sh | 4 +++- roles/home-cli/files/bashrc | 27 ++++++++++++++++++++------- roles/home-cli/tasks/dirs.yml | 11 ++++++----- roles/home-cli/tasks/dotfiles.yml | 10 +++++----- roles/home-gui/tasks/dirs.yml | 8 ++++---- roles/home-gui/tasks/dotfiles.yml | 6 +++--- roles/home-gui/tasks/emacs.yml | 6 +++--- roles/home-gui/tasks/fonts.yml | 2 +- roles/home-gui/tasks/mate.yml | 4 ++-- roles/home-gui/tasks/sublimetext.yml | 4 ++-- 11 files changed, 52 insertions(+), 34 deletions(-) diff --git a/console.sh b/console.sh index 11ed8ce..cadb72f 100755 --- a/console.sh +++ b/console.sh @@ -1,2 +1,4 @@ #!/bin/sh -./admin-cli.yml -K -i ./local.ini && ./user-cli.yml -i ./local.ini +. ./roles/home-cli/files/bashrc +./admin-cli.yml -K -i ./local.ini +./user-cli.yml -i ./local.ini diff --git a/desktop.sh b/desktop.sh index 43f0eeb..2e00148 100755 --- a/desktop.sh +++ b/desktop.sh @@ -1,2 +1,4 @@ #!/bin/sh -./admin-gui.yml -K -i ./local.ini && ./user-gui.yml -i ./local.ini +. ./roles/home-cli/files/bashrc +./admin-gui.yml -K -i ./local.ini +./user-gui.yml -i ./local.ini diff --git a/roles/home-cli/files/bashrc b/roles/home-cli/files/bashrc index 6985312..b50b4f3 100644 --- a/roles/home-cli/files/bashrc +++ b/roles/home-cli/files/bashrc @@ -8,6 +8,20 @@ else export ACP="$HOME/data" fi +# Set up XDG variables. See: +# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html +export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/local/share:/usr/share} +export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg} +export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" +export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" +export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" +export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}" +if [ ! -d $XDG_DATA_HOME ] ; then install -d -m 0700 "$XDG_DATA_HOME" ; fi +if [ ! -d $XDG_CACHE_HOME ] ; then install -d -m 0700 "$XDG_CACHE_HOME" ; fi +if [ ! -d $XDG_CONFIG_HOME ] ; then install -d -m 0700 "$XDG_CONFIG_HOME" ; fi +if [ ! -d $XDG_STATE_HOME ] ; then install -d -m 0700 "$XDG_STATE_HOME" ; fi +if [ ! -d "$HOME/.local/bin" ] ; then install -d -m 0700 "$HOME/.local/bin" ; fi + if [ -n "$ZSH_VERSION" ] then # These commands do not exist in zsh. @@ -50,12 +64,11 @@ _acp_add_path () { # Last in the list means first in the path. for dir in "$HOME/.local/bin" \ "$HOME/.cargo/bin" \ - "${XDG_DATA_HOME:-$HOME/.local/share}/gem/ruby/bin" \ - "${XDG_DATA_HOME:-$HOME/.local/share}/flatpak/exports/bin" \ + "$XDG_DATA_HOME/gem/ruby/bin" \ + "$XDG_DATA_HOME/flatpak/exports/bin" \ /opt/local/bin \ /opt/local/sbin \ /var/lib/flatpak/exports/bin \ - $ACP/bin \ /usr/local/bin \ /usr/local/sbin \ /usr/bin \ @@ -80,9 +93,9 @@ if [ -f /etc/locale.conf ] then . /etc/locale.conf fi -if [ -f "${XDG_CONFIG_DIR:-$HOME/.config}/locale.conf" ] +if [ -f "$XDG_CONFIG_DIR/locale.conf" ] then - . "${XDG_CONFIG_DIR:-$HOME/.config}/locale.conf" + . "$XDG_CONFIG_DIR/locale.conf" fi # Other exports. @@ -177,7 +190,7 @@ alias en="LANG=en_GB.UTF-8" alias fr="LANG=fr_FR.UTF-8" # Alias dig to drill if dig is not installed. -if [ -x /usr/bin/drill ] && ! [ -x /usr/bin/dig ] +if [ -x /usr/bin/drill ] then alias dig=drill fi @@ -186,7 +199,7 @@ fi if [ -x "$ACP/opt/go/bin/go" ] || [ -x /usr/bin/go ] || [ -x /usr/local/bin/go ] then export GOPROXY=https://proxy.golang.org - export GOPATH="${XDG_DATA_HOME:-$HOME/.local/share}/go" + export GOPATH="$XDG_DATA_HOME/go" if [ ! -d "$GOPATH" ] then mkdir -p "$GOPATH/bin" diff --git a/roles/home-cli/tasks/dirs.yml b/roles/home-cli/tasks/dirs.yml index 399fd3f..7722cdd 100644 --- a/roles/home-cli/tasks/dirs.yml +++ b/roles/home-cli/tasks/dirs.yml @@ -22,9 +22,10 @@ ansible.builtin.file: path: "{{ ansible_env.HOME }}/.local/bin" state: directory + mode: '0700' - name: Create systemd user directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/systemd/user" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/systemd/user" state: directory - name: Create ~/.ssh directory ansible.builtin.file: @@ -33,17 +34,17 @@ mode: '0700' - name: Create ~/.config directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config" + path: "{{ ansible_env.XDG_CONFIG_HOME }}" state: directory - name: Create ~/.config/git directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/git" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/git" state: directory - name: Create ~/.config/mc directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/mc" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/mc" state: directory - name: Create ~/.config/powershell directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/powershell" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/powershell" state: directory diff --git a/roles/home-cli/tasks/dotfiles.yml b/roles/home-cli/tasks/dotfiles.yml index b1577e2..585acd9 100644 --- a/roles/home-cli/tasks/dotfiles.yml +++ b/roles/home-cli/tasks/dotfiles.yml @@ -28,7 +28,7 @@ - name: Copy openpgp.asc ansible.builtin.copy: src: openpgp.asc - dest: "{{ ansible_env.HOME }}/.config/openpgp.asc" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/openpgp.asc" - name: Copy .dput.cf ansible.builtin.copy: src: dput.cf @@ -40,7 +40,7 @@ - name: Copy .config/git/config ansible.builtin.copy: src: gitconfig - dest: "{{ ansible_env.HOME }}/.config/git/config" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/git/config" - name: Copy .quiltrc-dpkg ansible.builtin.copy: src: quiltrc-dpkg @@ -61,12 +61,12 @@ - name: Copy mc ini ansible.builtin.copy: src: mc.ini - dest: "{{ ansible_env.HOME }}/.config/mc/ini" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/mc/ini" - name: Copy mc panels.ini ansible.builtin.copy: src: mc.panels.ini - dest: "{{ ansible_env.HOME }}/.config/mc/panels.ini" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/mc/panels.ini" - name: Copy Microsoft.PowerShell_profile.ps1 ansible.builtin.copy: src: Microsoft.PowerShell_profile.ps1 - dest: "{{ ansible_env.HOME }}/.config/powershell/Microsoft.PowerShell_profile.ps1" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/powershell/Microsoft.PowerShell_profile.ps1" diff --git a/roles/home-gui/tasks/dirs.yml b/roles/home-gui/tasks/dirs.yml index 98eecec..6390cff 100644 --- a/roles/home-gui/tasks/dirs.yml +++ b/roles/home-gui/tasks/dirs.yml @@ -15,11 +15,11 @@ - name: Create user applications directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.local/share/applications" + path: "{{ ansible_env.XDG_DATA_HOME }}/applications" state: directory - name: Create user autostart directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/autostart" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/autostart" state: directory - name: Create ~/.fvwm directory ansible.builtin.file: @@ -27,9 +27,9 @@ state: directory - name: Create ~/.local/share/fonts directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.local/share/fonts" + path: "{{ ansible_env.XDG_DATA_HOME }}/fonts" state: directory - name: Create ~/.config/fontconfig directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.config/fontconfig" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/fontconfig" state: directory diff --git a/roles/home-gui/tasks/dotfiles.yml b/roles/home-gui/tasks/dotfiles.yml index 7184ecf..7884b46 100644 --- a/roles/home-gui/tasks/dotfiles.yml +++ b/roles/home-gui/tasks/dotfiles.yml @@ -39,12 +39,12 @@ - name: Load ~/.Xresources ansible.builtin.copy: src: "xrdb.desktop" - dest: "{{ ansible_env.HOME }}/.config/autostart/xrdb.desktop" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/autostart/xrdb.desktop" when: ansible_distribution == "Fedora" or ansible_distribution == "Debian" - name: Add to-do list launcher ansible.builtin.template: src: todo.desktop - dest: "{{ ansible_env.HOME }}/.local/share/applications/todo.desktop" + dest: "{{ ansible_env.XDG_DATA_HOME }}/applications/todo.desktop" - name: Copy .xbindkeysrc ansible.builtin.copy: src: "xbindkeysrc" @@ -52,4 +52,4 @@ - name: Copy fonts.conf ansible.builtin.copy: src: "fonts.conf" - dest: "{{ ansible_env.HOME }}/.config/fontconfig/fonts.conf" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/fontconfig/fonts.conf" diff --git a/roles/home-gui/tasks/emacs.yml b/roles/home-gui/tasks/emacs.yml index 9189c37..f0a71f1 100644 --- a/roles/home-gui/tasks/emacs.yml +++ b/roles/home-gui/tasks/emacs.yml @@ -30,14 +30,14 @@ - name: Create Emacs user service (Linux) ansible.builtin.template: src: emacs.service - dest: "{{ ansible_env.HOME }}/.config/systemd/user/emacs.service" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/systemd/user/emacs.service" vars: prefix: "{{ '/usr' if ansible_system == 'Linux' else '/usr/pkg' if ansible_system == 'NetBSD' else '/usr/local' }}" when: ansible_system == 'Linux' and emacs_binary.stat.exists == True - name: Add Emacs server to autostart (FreeBSD) ansible.builtin.copy: src: '{{ ansible_env.HOME }}/.emacs.d/emacs-server.desktop' - dest: '{{ ansible_env.HOME }}/.config/autostart' + dest: '{{ ansible_env.XDG_CONFIG_HOME }}/autostart' remote_src: yes when: ansible_system == 'FreeBSD' and emacs_binary.stat.exists == True - name: Start Emacs user service @@ -51,6 +51,6 @@ - name: Create Emacs client launcher ansible.builtin.copy: src: "{{ ansible_env.HOME }}/.emacs.d/emacs-client.desktop" - dest: "{{ ansible_env.HOME }}/.local/share/applications/emacs.desktop" + dest: "{{ ansible_env.XDG_DATA_HOME }}/applications/emacs.desktop" remote_src: yes when: emacs_binary.stat.exists == True diff --git a/roles/home-gui/tasks/fonts.yml b/roles/home-gui/tasks/fonts.yml index ab76654..35e5f4e 100644 --- a/roles/home-gui/tasks/fonts.yml +++ b/roles/home-gui/tasks/fonts.yml @@ -19,7 +19,7 @@ - name: Set Linux font directory set_fact: - font_dir: "{{ ansible_env.HOME }}/.local/share/fonts" + font_dir: "{{ ansible_env.XDG_DATA_HOME }}/fonts" - name: Set MacOSX font directory set_fact: font_dir: "{{ ansible_env.HOME }}/Library/Fonts" diff --git a/roles/home-gui/tasks/mate.yml b/roles/home-gui/tasks/mate.yml index 5da1e56..d3ed899 100644 --- a/roles/home-gui/tasks/mate.yml +++ b/roles/home-gui/tasks/mate.yml @@ -15,12 +15,12 @@ - name: Create MATE layouts directory ansible.builtin.file: - path: "{{ ansible_env.HOME }}/.local/share/mate-panel/layouts" + path: "{{ ansible_env.XDG_DATA_HOME }}/mate-panel/layouts" state: directory - name: Copy MATE panel layout ansible.builtin.template: src: mate-acp.layout - dest: "{{ ansible_env.HOME }}/.local/share/mate-panel/layouts/acp.layout" + dest: "{{ ansible_env.XDG_DATA_HOME }}/mate-panel/layouts/acp.layout" vars: prefix: "{{ '/usr' if ansible_system == 'Linux' else '/usr/pkg' if ansible_system == 'NetBSD' else '/usr/local' }}" esr: "{{ '-esr' if ansible_distribution == 'Debian' else '' }}" diff --git a/roles/home-gui/tasks/sublimetext.yml b/roles/home-gui/tasks/sublimetext.yml index 76304e8..a2e9255 100644 --- a/roles/home-gui/tasks/sublimetext.yml +++ b/roles/home-gui/tasks/sublimetext.yml @@ -15,10 +15,10 @@ - name: Check for Sublime Text directory ansible.builtin.stat: - path: "{{ ansible_env.HOME }}/.config/sublime-text/Packages/User" + path: "{{ ansible_env.XDG_CONFIG_HOME }}/sublime-text/Packages/User" register: sublime - name: Copy Sublime Text preferences ansible.builtin.copy: src: Preferences.sublime-settings - dest: "{{ ansible_env.HOME }}/.config/sublime-text/Packages/User/Preferences.sublime-settings" + dest: "{{ ansible_env.XDG_CONFIG_HOME }}/sublime-text/Packages/User/Preferences.sublime-settings" when: sublime.stat.exists