From 64ebbbd2e3f5787ca4245f165507a882872b97c3 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 26 Aug 2014 21:52:07 +0200 Subject: [PATCH] gsu: Don't fail if HOME is unset. As pointed out by Joffrey Fitz, gsu-based scripts do not work when run as a user without home directory. This happens for example if the script is executed through a web application as the www-data user. This patch replaces all references to HOME by ${HOME:-}, i.e. we just default to the empty string but don't fail immediately. --- misc/gsu/config | 4 ++-- misc/gsu/gui | 2 +- misc/gsu/subcommand | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/misc/gsu/config b/misc/gsu/config index 6edd502..09330f3 100644 --- a/misc/gsu/config +++ b/misc/gsu/config @@ -4,7 +4,7 @@ # file. gsu_check_options() { - local i conf="${gsu_config_file:=$HOME/.$gsu_name.rc}" val + local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val for ((i=0; i < ${#gsu_options[@]}; i++)); do eval "${gsu_options[$i]}" @@ -79,7 +79,7 @@ gsu_check_options_or_die() } if [[ "$(type -t _gsu_setup)" != "function" ]]; then - gsu_dir=${gsu_dir:=$HOME/.gsu} + gsu_dir=${gsu_dir:=${HOME:-}/.gsu} . $gsu_dir/common || exit 1 _gsu_setup fi diff --git a/misc/gsu/gui b/misc/gsu/gui index 99da51a..eb9f29f 100644 --- a/misc/gsu/gui +++ b/misc/gsu/gui @@ -1,7 +1,7 @@ #!/bin/bash if [[ $(type -t gsu_is_a_number) != "function" ]]; then - GSU_DIR=${GSU_DIR:=$HOME/.gsu} + GSU_DIR=${GSU_DIR:=${HOME:-}/.gsu} . $GSU_DIR/common || exit 1 fi diff --git a/misc/gsu/subcommand b/misc/gsu/subcommand index 3a1bc6d..f1685aa 100644 --- a/misc/gsu/subcommand +++ b/misc/gsu/subcommand @@ -2,7 +2,7 @@ # (C) 2006-2011 Andre Noll if [[ $(type -t gsu_is_a_number) != "function" ]]; then - GSU_DIR=${GSU_DIR:=$HOME/.gsu} + GSU_DIR=${GSU_DIR:=${HOME-}/.gsu} . $GSU_DIR/common || exit 1 fi @@ -90,7 +90,7 @@ options, the command prints out a list of all cmt config variables, together with their current value and the default value." _com_prefs() { - local i conf="${gsu_config_file:=$HOME/.$gsu_name.rc}" + local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" gsu_getopts "e" eval "$result" -- 2.39.2