3
This commit is contained in:
13
lib/log.sh
13
lib/log.sh
@@ -1,6 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
log_init() {
|
||||
local fallback_dir=""
|
||||
local fallback_file=""
|
||||
|
||||
mkdir -p "$RUNTIME_LOG_DIR" 2>/dev/null || true
|
||||
if : > "$RUNTIME_LOG_FILE" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
fallback_dir="${TMPDIR:-/tmp}/postinstall-debian-$(id -u)"
|
||||
fallback_file="$fallback_dir/install.log"
|
||||
mkdir -p "$fallback_dir"
|
||||
RUNTIME_LOG_DIR="$fallback_dir"
|
||||
RUNTIME_LOG_FILE="$fallback_file"
|
||||
: > "$RUNTIME_LOG_FILE"
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@ package_is_installed() {
|
||||
dpkg -s "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
package_is_available() {
|
||||
apt-cache show "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
package_refresh_indexes() {
|
||||
apt-get update
|
||||
}
|
||||
|
||||
@@ -30,6 +30,47 @@ system_require_root() {
|
||||
ui_success "Privileges root valides"
|
||||
}
|
||||
|
||||
system_can_prompt_password() {
|
||||
[[ -t 0 && -t 1 ]]
|
||||
}
|
||||
|
||||
system_reexec_as_root() {
|
||||
local entrypoint="${POSTINSTALL_ENTRYPOINT:-}"
|
||||
local quoted_args=""
|
||||
local arg=""
|
||||
|
||||
if [[ "${EUID:-$(id -u)}" -eq 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -z "$entrypoint" || ! -f "$entrypoint" ]]; then
|
||||
ui_error "Impossible de relancer automatiquement en root depuis cette execution"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! system_can_prompt_password; then
|
||||
ui_error "Privileges root requis et aucun terminal interactif disponible"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for arg in "$@"; do
|
||||
quoted_args="${quoted_args} $(printf '%q' "$arg")"
|
||||
done
|
||||
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
ui_info "Privileges root requis, tentative avec sudo"
|
||||
exec sudo --preserve-env=TMPDIR bash "$entrypoint" "$@"
|
||||
fi
|
||||
|
||||
if command -v su >/dev/null 2>&1; then
|
||||
ui_info "Privileges root requis, bascule vers root avec su"
|
||||
exec su -c "bash $(printf '%q' "$entrypoint")$quoted_args"
|
||||
fi
|
||||
|
||||
ui_error "Ni sudo ni su ne sont disponibles pour obtenir les privileges root"
|
||||
return 1
|
||||
}
|
||||
|
||||
system_user_exists() {
|
||||
local user_name="$1"
|
||||
id "$user_name" >/dev/null 2>&1
|
||||
@@ -57,3 +98,27 @@ system_primary_interface() {
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
||||
system_origin_user() {
|
||||
if [[ -n "${SUDO_USER:-}" ]]; then
|
||||
printf '%s\n' "$SUDO_USER"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "${PKEXEC_UID:-}" ]]; then
|
||||
getent passwd "$PKEXEC_UID" | cut -d: -f1
|
||||
return 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "$(id -un)"
|
||||
}
|
||||
|
||||
system_privilege_mode() {
|
||||
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
|
||||
printf 'utilisateur\n'
|
||||
elif [[ -n "${SUDO_USER:-}" ]]; then
|
||||
printf 'sudo\n'
|
||||
else
|
||||
printf 'root direct\n'
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user