Preserve select environment variables with sudo.

This commit is contained in:
Brad Warren 2017-07-25 14:21:08 -07:00
parent a5cce1565f
commit e83923554a
2 changed files with 16 additions and 4 deletions

View file

@ -159,6 +159,12 @@ su_sudo() {
su root -c "$args"
}
# Run the specified command with sudo but preserve select environment
# variables.
sudo_with_env() {
sudo LE_AUTO_DIR_TEMPLATE="$LE_AUTO_DIR_TEMPLATE" LE_AUTO_JSON_URL="$LE_AUTO_JSON_URL" LE_AUTO_PUBLIC_KEY="$LE_AUTO_PUBLIC_KEY" LE_PYTHON="$LE_PYTHON" OLD_VENV_PATH="$OLD_VENV_PATH" VENV_PATH="$VENV_PATH" "$@"
}
if [ "$1" = "--cb-auto-has-root" ]; then
shift 1
elif [ "$1" != "--le-auto-phase2" ]; then
@ -170,7 +176,7 @@ elif [ "$1" != "--le-auto-phase2" ]; then
SUDO=su_sudo
;;
sudo)
SUDO=sudo
SUDO=sudo_with_env
;;
'') ;; # Nothing to do for plain root method.
*)
@ -181,7 +187,7 @@ elif [ "$1" != "--le-auto-phase2" ]; then
else
if test "`id -u`" -ne "0" ; then
if $EXISTS sudo 1>/dev/null 2>&1; then
SUDO=sudo
SUDO=sudo_with_env
else
say \"sudo\" is not available, will use \"su\" for installation steps...
SUDO=su_sudo

View file

@ -159,6 +159,12 @@ su_sudo() {
su root -c "$args"
}
# Run the specified command with sudo but preserve select environment
# variables.
sudo_with_env() {
sudo LE_AUTO_DIR_TEMPLATE="$LE_AUTO_DIR_TEMPLATE" LE_AUTO_JSON_URL="$LE_AUTO_JSON_URL" LE_AUTO_PUBLIC_KEY="$LE_AUTO_PUBLIC_KEY" LE_PYTHON="$LE_PYTHON" OLD_VENV_PATH="$OLD_VENV_PATH" VENV_PATH="$VENV_PATH" "$@"
}
if [ "$1" = "--cb-auto-has-root" ]; then
shift 1
elif [ "$1" != "--le-auto-phase2" ]; then
@ -170,7 +176,7 @@ elif [ "$1" != "--le-auto-phase2" ]; then
SUDO=su_sudo
;;
sudo)
SUDO=sudo
SUDO=sudo_with_env
;;
'') ;; # Nothing to do for plain root method.
*)
@ -181,7 +187,7 @@ elif [ "$1" != "--le-auto-phase2" ]; then
else
if test "`id -u`" -ne "0" ; then
if $EXISTS sudo 1>/dev/null 2>&1; then
SUDO=sudo
SUDO=sudo_with_env
else
say \"sudo\" is not available, will use \"su\" for installation steps...
SUDO=su_sudo