Skip to content

Commit 7ae2fed

Browse files
committed
build
1 parent 182a1b1 commit 7ae2fed

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

usr/share/usability-misc/dist-installer-cli-standalone

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,35 @@ get_su_cmd(){
406406
fi
407407
fi
408408
}
409+
410+
411+
test_run_as_target_user() {
412+
local root_output
413+
root_output="$(run_as_target_user timeout --kill-after 5 5 test -d /usr 2>&1)"
414+
if test -n "${root_output}"; then
415+
log error "'run_as_target_user' output: '${root_output}'"
416+
die 1 "${underline}run_as_target_user:${nounderline} Unexpected non-empty output for 'sudo -u ${target_user}' test."
417+
fi
418+
}
419+
420+
421+
run_as_target_user() {
422+
if [ -z "${target_user}" ]; then
423+
"${@}"
424+
else
425+
ROOT_CMD_TARGET_USER="${target_user}" root_cmd "${@}"
426+
fi
427+
}
428+
429+
430+
run_as_target_user_and_dir() {
431+
local target_dir
432+
target_dir="${1:-}"
433+
[ -z "${target_dir}" ] && die 1 "Failed to provide directory name to 'run_as_target_user_and_dir'!"
434+
[ -z "${target_user}" ] && die 1 "Cannot use 'run_as_target_user_and_dir' if 'set_target_user_account' is not used first!"
435+
shift
436+
ROOT_CMD_TARGET_USER="${target_user}" ROOT_CMD_TARGET_DIR="${target_dir}" root_cmd "${@}"
437+
}
409438
##### END pasted by build-dist-installer-cli from file /usr/libexec/helper-scripts/root_cmd.sh
410439
# shellcheck source=../../../helper-scripts/usr/libexec/helper-scripts/ip_syntax.sh
411440
##### BEGIN pasted by build-dist-installer-cli from file /usr/libexec/helper-scripts/ip_syntax.sh
@@ -4509,7 +4538,7 @@ check_hash() {
45094538
local shafile dir
45104539

45114540
shafile="${1}"
4512-
dir="$(dirname "${shafile}")"
4541+
dir="$(dirname -- "${shafile}")"
45134542
log info "Checking SHA512 checksum: '${shafile}"
45144543
## $checkhash needs to be executed on the same folder as the compared file.
45154544
log info "Changing to directory: '${dir}'"
@@ -4811,30 +4840,11 @@ set_target_user_account() {
48114840
## 'getent' may fail if the account doesn't exist, however we ignore it for now.
48124841
## The reason is because if this is run as a user account `sysmaint` on a
48134842
## system with no account 'user', this will fail, but the account may have passed
4814-
## their own --user and --directory-prefix flags which will fix it.
4843+
## their own '--user' and '--directory-prefix' flags which will fix it.
48154844
user_home_dir="$(getent passwd "${target_user}" | cut -d':' -f6)" || true
48164845
}
48174846

48184847

4819-
run_as_target_user() {
4820-
if [ -z "${target_user}" ]; then
4821-
"${@}"
4822-
else
4823-
ROOT_CMD_TARGET_USER="${target_user}" root_cmd "${@}"
4824-
fi
4825-
}
4826-
4827-
4828-
run_as_target_user_and_dir() {
4829-
local target_dir
4830-
target_dir="${1:-}"
4831-
[ -z "${target_dir}" ] && die 1 "Failed to provide directory name to 'run_as_target_user_and_dir'!"
4832-
[ -z "${target_user}" ] && die 1 "Cannot use 'run_as_target_user_and_dir' if 'set_target_user_account' is not used first!"
4833-
shift
4834-
ROOT_CMD_TARGET_USER="${target_user}" ROOT_CMD_TARGET_DIR="${target_dir}" root_cmd "${@}"
4835-
}
4836-
4837-
48384848
adjust_default_for_sysmaint_maybe() {
48394849
if getent passwd sysmaint >/dev/null; then
48404850
log info "Account 'sysmaint' exists: 'Yes'"
@@ -5089,7 +5099,7 @@ parse_opt() {
50895099
fi
50905100

50915101
## Test if parent directory exists.
5092-
directory_prefix_parent="$(dirname "${directory_prefix}")"
5102+
directory_prefix_parent="$(dirname -- "${directory_prefix}")"
50935103
if ! test_file -d "${directory_prefix_parent}"; then
50945104
die 1 "Directory doesn't exist: '${directory_prefix_parent}'"
50955105
fi
@@ -5244,12 +5254,15 @@ run_installer() {
52445254
parse_name
52455255
## If account 'sysmaint' is in use and the user hasn't configured their own directory
52465256
## prefix and target user, default to target account 'user'.
5257+
## Runs function 'set_target_user_account'.
52475258
adjust_default_for_sysmaint_maybe
52485259
## Parse command-line options.
5260+
## Uses function 'test_file' which in turn uses 'root_cmd'.
52495261
parse_opt "${@}"
52505262
## Logging mechanism.
52515263
log_term_and_file
52525264
welcome
5265+
test_run_as_target_user
52535266

52545267
get_os
52555268
get_distro

0 commit comments

Comments
 (0)