better script info and visibility

This commit is contained in:
Gaurav Bankar
2024-08-08 10:12:01 +05:30
parent c7d1763082
commit 049fca4d77

View File

@@ -72,10 +72,17 @@ function run_command {
local ask_confirm="${3:-yes}" # Default to asking for confirmation local ask_confirm="${3:-yes}" # Default to asking for confirmation
local use_sudo="${4:-yes}" # Default to using sudo local use_sudo="${4:-yes}" # Default to using sudo
log_message "Attempting to run: $description" local full_cmd=""
if [[ "$use_sudo" == "no" ]]; then
full_cmd="sudo -u $SUDO_USER $cmd"
else
full_cmd="$cmd"
fi
log_message "Attempting to run: $description"
print_info "\nCommand: $full_cmd"
if [[ "$ask_confirm" == "yes" ]]; then if [[ "$ask_confirm" == "yes" ]]; then
if ! ask_confirmation "\n$description"; then if ! ask_confirmation "$description"; then
# print_info "$description was skipped." # print_info "$description was skipped."
log_message "$description was skipped by user choice." log_message "$description was skipped by user choice."
return 1 return 1
@@ -84,13 +91,6 @@ function run_command {
print_info "\n$description" # Echo what it's doing without confirmation print_info "\n$description" # Echo what it's doing without confirmation
fi fi
local full_cmd=""
if [[ "$use_sudo" == "no" ]]; then
full_cmd="sudo -u $SUDO_USER $cmd"
else
full_cmd="$cmd"
fi
while ! eval "$full_cmd"; do while ! eval "$full_cmd"; do
print_error "Command failed." print_error "Command failed."
log_message "Command failed: $cmd" log_message "Command failed: $cmd"