From 31d4f479937535567e74fa1f824f0ce2a7fbc48e Mon Sep 17 00:00:00 2001 From: YISH Date: Mon, 25 Apr 2022 17:06:41 +0800 Subject: [PATCH 1/4] Fix scirpt err with `su -c`, add env auto loading. --- contrib/upgrade.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/upgrade.sh b/contrib/upgrade.sh index 9a5e903b6b68d..7bb2632c93a29 100755 --- a/contrib/upgrade.sh +++ b/contrib/upgrade.sh @@ -10,6 +10,9 @@ # upgrade.sh 1.15.10 # giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh +# load environment variables from `giteaenv` when `giteaenv` exists. +[[ -f "$(dirname $0)/giteaenv" ]] && source "$(dirname $0)/giteaenv" + # apply variables from environment : "${giteabin:="/usr/local/bin/gitea"}" : "${giteahome:="/var/lib/gitea"}" @@ -24,7 +27,8 @@ function giteacmd { if [[ $sudocmd = "su" ]]; then - "$sudocmd" - "$giteauser" -c "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@" + # `-c` accept one string as argument. + "$sudocmd" - "$giteauser" -c "$giteabin --config $giteaconf --work-path $giteahome $@" else "$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@" fi From d220607016f9a7653295669b48c907920e066037 Mon Sep 17 00:00:00 2001 From: YISH Date: Mon, 25 Apr 2022 18:45:40 +0800 Subject: [PATCH 2/4] Update upgrade.sh --- contrib/upgrade.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contrib/upgrade.sh b/contrib/upgrade.sh index 7bb2632c93a29..0afe0b9e3e34e 100755 --- a/contrib/upgrade.sh +++ b/contrib/upgrade.sh @@ -10,9 +10,6 @@ # upgrade.sh 1.15.10 # giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh -# load environment variables from `giteaenv` when `giteaenv` exists. -[[ -f "$(dirname $0)/giteaenv" ]] && source "$(dirname $0)/giteaenv" - # apply variables from environment : "${giteabin:="/usr/local/bin/gitea"}" : "${giteahome:="/var/lib/gitea"}" @@ -27,7 +24,7 @@ function giteacmd { if [[ $sudocmd = "su" ]]; then - # `-c` accept one string as argument. + # `-c` only accept one string as argument. "$sudocmd" - "$giteauser" -c "$giteabin --config $giteaconf --work-path $giteahome $@" else "$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@" From 1174c614fb0be7a82ac6733f00d8c4d5598d90b5 Mon Sep 17 00:00:00 2001 From: YISH Date: Mon, 25 Apr 2022 18:54:09 +0800 Subject: [PATCH 3/4] Update upgrade.sh --- contrib/upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/upgrade.sh b/contrib/upgrade.sh index 0afe0b9e3e34e..5d46a2f4adba5 100755 --- a/contrib/upgrade.sh +++ b/contrib/upgrade.sh @@ -25,7 +25,7 @@ function giteacmd { if [[ $sudocmd = "su" ]]; then # `-c` only accept one string as argument. - "$sudocmd" - "$giteauser" -c "$giteabin --config $giteaconf --work-path $giteahome $@" + "$sudocmd" - "$giteauser" -c "\"$giteabin\" --config \"$giteaconf\" --work-path \"$giteahome\" \"$@\"" else "$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@" fi From 2258705154b1705c82d075bae115737d27eab5d4 Mon Sep 17 00:00:00 2001 From: YISH Date: Tue, 26 Apr 2022 11:09:27 +0800 Subject: [PATCH 4/4] Update contrib/upgrade.sh Co-authored-by: wxiaoguang --- contrib/upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/upgrade.sh b/contrib/upgrade.sh index 5d46a2f4adba5..3a98c277d6b33 100755 --- a/contrib/upgrade.sh +++ b/contrib/upgrade.sh @@ -25,7 +25,7 @@ function giteacmd { if [[ $sudocmd = "su" ]]; then # `-c` only accept one string as argument. - "$sudocmd" - "$giteauser" -c "\"$giteabin\" --config \"$giteaconf\" --work-path \"$giteahome\" \"$@\"" + "$sudocmd" - "$giteauser" -c "$(printf "%q " "$giteabin" "--config" "$giteaconf" "--work-path" "$giteahome" "$@")" else "$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@" fi