Use XDG directories explicitly

This commit is contained in:
Anthony Rose 2022-08-18 16:37:57 +01:00
parent 40532e1bc6
commit 333a45fd7c
11 changed files with 52 additions and 34 deletions

View file

@ -1,2 +1,4 @@
#!/bin/sh #!/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

View file

@ -1,2 +1,4 @@
#!/bin/sh #!/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

View file

@ -8,6 +8,20 @@ else
export ACP="$HOME/data" export ACP="$HOME/data"
fi 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" ] if [ -n "$ZSH_VERSION" ]
then then
# These commands do not exist in zsh. # These commands do not exist in zsh.
@ -50,12 +64,11 @@ _acp_add_path () {
# Last in the list means first in the path. # Last in the list means first in the path.
for dir in "$HOME/.local/bin" \ for dir in "$HOME/.local/bin" \
"$HOME/.cargo/bin" \ "$HOME/.cargo/bin" \
"${XDG_DATA_HOME:-$HOME/.local/share}/gem/ruby/bin" \ "$XDG_DATA_HOME/gem/ruby/bin" \
"${XDG_DATA_HOME:-$HOME/.local/share}/flatpak/exports/bin" \ "$XDG_DATA_HOME/flatpak/exports/bin" \
/opt/local/bin \ /opt/local/bin \
/opt/local/sbin \ /opt/local/sbin \
/var/lib/flatpak/exports/bin \ /var/lib/flatpak/exports/bin \
$ACP/bin \
/usr/local/bin \ /usr/local/bin \
/usr/local/sbin \ /usr/local/sbin \
/usr/bin \ /usr/bin \
@ -80,9 +93,9 @@ if [ -f /etc/locale.conf ]
then then
. /etc/locale.conf . /etc/locale.conf
fi fi
if [ -f "${XDG_CONFIG_DIR:-$HOME/.config}/locale.conf" ] if [ -f "$XDG_CONFIG_DIR/locale.conf" ]
then then
. "${XDG_CONFIG_DIR:-$HOME/.config}/locale.conf" . "$XDG_CONFIG_DIR/locale.conf"
fi fi
# Other exports. # Other exports.
@ -177,7 +190,7 @@ alias en="LANG=en_GB.UTF-8"
alias fr="LANG=fr_FR.UTF-8" alias fr="LANG=fr_FR.UTF-8"
# Alias dig to drill if dig is not installed. # Alias dig to drill if dig is not installed.
if [ -x /usr/bin/drill ] && ! [ -x /usr/bin/dig ] if [ -x /usr/bin/drill ]
then then
alias dig=drill alias dig=drill
fi fi
@ -186,7 +199,7 @@ fi
if [ -x "$ACP/opt/go/bin/go" ] || [ -x /usr/bin/go ] || [ -x /usr/local/bin/go ] if [ -x "$ACP/opt/go/bin/go" ] || [ -x /usr/bin/go ] || [ -x /usr/local/bin/go ]
then then
export GOPROXY=https://proxy.golang.org export GOPROXY=https://proxy.golang.org
export GOPATH="${XDG_DATA_HOME:-$HOME/.local/share}/go" export GOPATH="$XDG_DATA_HOME/go"
if [ ! -d "$GOPATH" ] if [ ! -d "$GOPATH" ]
then then
mkdir -p "$GOPATH/bin" mkdir -p "$GOPATH/bin"

View file

@ -22,9 +22,10 @@
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.local/bin" path: "{{ ansible_env.HOME }}/.local/bin"
state: directory state: directory
mode: '0700'
- name: Create systemd user directory - name: Create systemd user directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config/systemd/user" path: "{{ ansible_env.XDG_CONFIG_HOME }}/systemd/user"
state: directory state: directory
- name: Create ~/.ssh directory - name: Create ~/.ssh directory
ansible.builtin.file: ansible.builtin.file:
@ -33,17 +34,17 @@
mode: '0700' mode: '0700'
- name: Create ~/.config directory - name: Create ~/.config directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config" path: "{{ ansible_env.XDG_CONFIG_HOME }}"
state: directory state: directory
- name: Create ~/.config/git directory - name: Create ~/.config/git directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config/git" path: "{{ ansible_env.XDG_CONFIG_HOME }}/git"
state: directory state: directory
- name: Create ~/.config/mc directory - name: Create ~/.config/mc directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config/mc" path: "{{ ansible_env.XDG_CONFIG_HOME }}/mc"
state: directory state: directory
- name: Create ~/.config/powershell directory - name: Create ~/.config/powershell directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config/powershell" path: "{{ ansible_env.XDG_CONFIG_HOME }}/powershell"
state: directory state: directory

View file

@ -28,7 +28,7 @@
- name: Copy openpgp.asc - name: Copy openpgp.asc
ansible.builtin.copy: ansible.builtin.copy:
src: openpgp.asc src: openpgp.asc
dest: "{{ ansible_env.HOME }}/.config/openpgp.asc" dest: "{{ ansible_env.XDG_CONFIG_HOME }}/openpgp.asc"
- name: Copy .dput.cf - name: Copy .dput.cf
ansible.builtin.copy: ansible.builtin.copy:
src: dput.cf src: dput.cf
@ -40,7 +40,7 @@
- name: Copy .config/git/config - name: Copy .config/git/config
ansible.builtin.copy: ansible.builtin.copy:
src: gitconfig src: gitconfig
dest: "{{ ansible_env.HOME }}/.config/git/config" dest: "{{ ansible_env.XDG_CONFIG_HOME }}/git/config"
- name: Copy .quiltrc-dpkg - name: Copy .quiltrc-dpkg
ansible.builtin.copy: ansible.builtin.copy:
src: quiltrc-dpkg src: quiltrc-dpkg
@ -61,12 +61,12 @@
- name: Copy mc ini - name: Copy mc ini
ansible.builtin.copy: ansible.builtin.copy:
src: mc.ini src: mc.ini
dest: "{{ ansible_env.HOME }}/.config/mc/ini" dest: "{{ ansible_env.XDG_CONFIG_HOME }}/mc/ini"
- name: Copy mc panels.ini - name: Copy mc panels.ini
ansible.builtin.copy: ansible.builtin.copy:
src: mc.panels.ini 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 - name: Copy Microsoft.PowerShell_profile.ps1
ansible.builtin.copy: ansible.builtin.copy:
src: Microsoft.PowerShell_profile.ps1 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"

View file

@ -15,11 +15,11 @@
- name: Create user applications directory - name: Create user applications directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.local/share/applications" path: "{{ ansible_env.XDG_DATA_HOME }}/applications"
state: directory state: directory
- name: Create user autostart directory - name: Create user autostart directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config/autostart" path: "{{ ansible_env.XDG_CONFIG_HOME }}/autostart"
state: directory state: directory
- name: Create ~/.fvwm directory - name: Create ~/.fvwm directory
ansible.builtin.file: ansible.builtin.file:
@ -27,9 +27,9 @@
state: directory state: directory
- name: Create ~/.local/share/fonts directory - name: Create ~/.local/share/fonts directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.local/share/fonts" path: "{{ ansible_env.XDG_DATA_HOME }}/fonts"
state: directory state: directory
- name: Create ~/.config/fontconfig directory - name: Create ~/.config/fontconfig directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.config/fontconfig" path: "{{ ansible_env.XDG_CONFIG_HOME }}/fontconfig"
state: directory state: directory

View file

@ -39,12 +39,12 @@
- name: Load ~/.Xresources - name: Load ~/.Xresources
ansible.builtin.copy: ansible.builtin.copy:
src: "xrdb.desktop" 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" when: ansible_distribution == "Fedora" or ansible_distribution == "Debian"
- name: Add to-do list launcher - name: Add to-do list launcher
ansible.builtin.template: ansible.builtin.template:
src: todo.desktop src: todo.desktop
dest: "{{ ansible_env.HOME }}/.local/share/applications/todo.desktop" dest: "{{ ansible_env.XDG_DATA_HOME }}/applications/todo.desktop"
- name: Copy .xbindkeysrc - name: Copy .xbindkeysrc
ansible.builtin.copy: ansible.builtin.copy:
src: "xbindkeysrc" src: "xbindkeysrc"
@ -52,4 +52,4 @@
- name: Copy fonts.conf - name: Copy fonts.conf
ansible.builtin.copy: ansible.builtin.copy:
src: "fonts.conf" src: "fonts.conf"
dest: "{{ ansible_env.HOME }}/.config/fontconfig/fonts.conf" dest: "{{ ansible_env.XDG_CONFIG_HOME }}/fontconfig/fonts.conf"

View file

@ -30,14 +30,14 @@
- name: Create Emacs user service (Linux) - name: Create Emacs user service (Linux)
ansible.builtin.template: ansible.builtin.template:
src: emacs.service src: emacs.service
dest: "{{ ansible_env.HOME }}/.config/systemd/user/emacs.service" dest: "{{ ansible_env.XDG_CONFIG_HOME }}/systemd/user/emacs.service"
vars: vars:
prefix: "{{ '/usr' if ansible_system == 'Linux' else '/usr/pkg' if ansible_system == 'NetBSD' else '/usr/local' }}" 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 when: ansible_system == 'Linux' and emacs_binary.stat.exists == True
- name: Add Emacs server to autostart (FreeBSD) - name: Add Emacs server to autostart (FreeBSD)
ansible.builtin.copy: ansible.builtin.copy:
src: '{{ ansible_env.HOME }}/.emacs.d/emacs-server.desktop' 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 remote_src: yes
when: ansible_system == 'FreeBSD' and emacs_binary.stat.exists == True when: ansible_system == 'FreeBSD' and emacs_binary.stat.exists == True
- name: Start Emacs user service - name: Start Emacs user service
@ -51,6 +51,6 @@
- name: Create Emacs client launcher - name: Create Emacs client launcher
ansible.builtin.copy: ansible.builtin.copy:
src: "{{ ansible_env.HOME }}/.emacs.d/emacs-client.desktop" 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 remote_src: yes
when: emacs_binary.stat.exists == True when: emacs_binary.stat.exists == True

View file

@ -19,7 +19,7 @@
- name: Set Linux font directory - name: Set Linux font directory
set_fact: set_fact:
font_dir: "{{ ansible_env.HOME }}/.local/share/fonts" font_dir: "{{ ansible_env.XDG_DATA_HOME }}/fonts"
- name: Set MacOSX font directory - name: Set MacOSX font directory
set_fact: set_fact:
font_dir: "{{ ansible_env.HOME }}/Library/Fonts" font_dir: "{{ ansible_env.HOME }}/Library/Fonts"

View file

@ -15,12 +15,12 @@
- name: Create MATE layouts directory - name: Create MATE layouts directory
ansible.builtin.file: ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.local/share/mate-panel/layouts" path: "{{ ansible_env.XDG_DATA_HOME }}/mate-panel/layouts"
state: directory state: directory
- name: Copy MATE panel layout - name: Copy MATE panel layout
ansible.builtin.template: ansible.builtin.template:
src: mate-acp.layout 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: vars:
prefix: "{{ '/usr' if ansible_system == 'Linux' else '/usr/pkg' if ansible_system == 'NetBSD' else '/usr/local' }}" prefix: "{{ '/usr' if ansible_system == 'Linux' else '/usr/pkg' if ansible_system == 'NetBSD' else '/usr/local' }}"
esr: "{{ '-esr' if ansible_distribution == 'Debian' else '' }}" esr: "{{ '-esr' if ansible_distribution == 'Debian' else '' }}"

View file

@ -15,10 +15,10 @@
- name: Check for Sublime Text directory - name: Check for Sublime Text directory
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ ansible_env.HOME }}/.config/sublime-text/Packages/User" path: "{{ ansible_env.XDG_CONFIG_HOME }}/sublime-text/Packages/User"
register: sublime register: sublime
- name: Copy Sublime Text preferences - name: Copy Sublime Text preferences
ansible.builtin.copy: ansible.builtin.copy:
src: Preferences.sublime-settings 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 when: sublime.stat.exists