From d9a1ff3e782688d83073279dbf75fa7332147d18 Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Sat, 7 Sep 2019 01:52:47 -0700 Subject: [PATCH] dist/freedoom: support ~/.local installs, make it easier to read paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bunch of logic to use XDG_DATA_HOME or fallback according to the actual XDG recommendations. Use an array to build up paths (can be edited easily in the future or for whatever custom purpose), which shellcheck warned is a bash-ism, so change the script interpreter to bash as well. Let’s hope that doesn’t break anyone (does anyone lack bash even if they don’t use it as their shell?) --- dist/freedoom | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dist/freedoom b/dist/freedoom index 1ce68276..074b5a13 100755 --- a/dist/freedoom +++ b/dist/freedoom @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/bin/bash - # These ports should really be ordered by ease-of-use. Most likely # advanced users with many ports installed will invoke their preferred @@ -32,7 +32,25 @@ case "$(basename "$0")" in esac if [ -z "$DOOMWADPATH" ]; then - export DOOMWADPATH="/usr/share/doom:/usr/share/games/doom:/usr/local/share/doom:/usr/local/share/games/doom" + # Support installations of Freedoom to the home directory using + # the XDG spec. Makes this complicated, but let’s do it right. + if [ -z "$XDG_DATA_HOME" ]; then + if [ -z "$HOME" ]; then + HOME=/ + fi + XDG_PATH="$HOME"/.local/share/games/doom + else + XDG_PATH="$XDG_DATA_HOME"/games/doom + fi + + PATHS=( + "$XDG_PATH" + /usr/local/share/games/doom + /usr/local/share/doom + /usr/share/games/doom + /usr/share/doom + ) + export DOOMWADPATH="$(echo "${PATHS[@]}" | tr ' ' :)" fi if [ -z "$DOOMPORT" ] && [ -h "$HOME"/.doomport ]; then