Skip to content

Commit

Permalink
Per XDG Base Directory Specification, create XDG_RUNTIME_DIR in /tmp …
Browse files Browse the repository at this point in the history
…if not set. Issue graysky2#343
  • Loading branch information
morgant committed Jan 1, 2023
1 parent 09eb57a commit 6fba69a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions common/profile-sync-daemon.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ VERS="@VERSION@"

user=$(id -un)
HOME="$(getent passwd "$user" | cut -d: -f6)"
TMPDIR="${TMPDIR:-/tmp}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
PSDCONFDIR="$XDG_CONFIG_HOME/psd"
PSDCONF="$PSDCONFDIR/psd.conf"
SHAREDIR="/usr/share/psd"
VOLATILE="$XDG_RUNTIME_DIR/psd"
PID_FILE="$XDG_RUNTIME_DIR/psd.pid"

if [[ ! -d "$SHAREDIR" ]]; then
echo -e " ${RED}ERROR:${NRM}${BLD} Missing ${BLU}$SHAREDIR${NRM}${BLD} - reinstall the package to use profile-sync-daemon.${NRM}"
Expand All @@ -53,11 +52,31 @@ if [[ $EUID -eq 0 ]]; then
exit 1
fi

if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
# Create an XDG_RUNTIME_DIR if not given one (i.e. running without DE)
# See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if [[ -z "$XDG_RUNTIME_DIR" ]]; then
XDG_RUNTIME_DIR="${TMPDIR}/runtime-${user}"
echo -e " ${RED}WARNING:${NRM}${BLD} XDG_RUNTIME_DIR not set, defaulting to '${XDG_RUNTIME_DIR}'.${NRM}"
if [[ ! -d "$XDG_RUNTIME_DIR" ]] && ! mkdir "$XDG_RUNTIME_DIR"; then
echo -e " ${RED}ERROR:${NRM}${BLD} Unable to create runtime directory '${XDG_RUNTIME_DIR}'.${NRM}"
exit 1
fi
if ! chown "${user}" "${XDG_RUNTIME_DIR}"; then
echo -e " ${RED}ERROR:${NRM}${BLD} Unable to make user '${user}' owner of runtime directory '${XDG_RUNTIME_DIR}'.${NRM}"
exit 1
fi
if ! chmod 0700 "${XDG_RUNTIME_DIR}"; then
echo -e " ${RED}ERROR:${NRM}${BLD} Uname to make runtime directory '${XDG_RUNTIME_DIR}' only accessible to user '$user'.${NRM}"
exit 1
fi
elif [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
echo -e " ${RED}ERROR:${NRM}${BLD} Cannot find XDG_RUNTIME_DIR which should be set by systemd.${NRM}"
exit 1
fi

VOLATILE="$XDG_RUNTIME_DIR/psd"
PID_FILE="$XDG_RUNTIME_DIR/psd.pid"

# Setup check for config file
if [[ -f "$PSDCONF" ]]; then
if [[ ! -f "$PID_FILE" ]]; then
Expand Down

0 comments on commit 6fba69a

Please sign in to comment.