refactor(webui): silence per-file touch/chown noise in data generators

The WebUI data snapshots (locations.json, dashboard.json, snapshots_*.json,
etc.) are regenerated on every wizard/config change. Each file emitted two
extra success lines via createTouch — "Touching <file>" and "Updating
<file> with <user> ownership" — which spammed the output around the genuinely
useful "... JSON regenerated" line.

Add an optional "silent" flag to createTouch (third arg; default keeps the
existing loud behaviour for interactive install flows) and pass it from every
WebUI data generator/task. Touch + chown still run; only the logging is
suppressed for these background regenerations.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
librelad 2026-05-23 12:40:32 +01:00
parent 4c97cbb2e2
commit 315c528306
21 changed files with 36 additions and 30 deletions

View File

@ -1,16 +1,22 @@
#!/bin/bash
createTouch()
createTouch()
{
local file="$1"
local user_name="$2"
local silent_flag="$3"
local file_name=$(basename "$file")
local file_dir=$(dirname "$file")
local clean_dir=$(echo "$file" | sed 's#//*#/#g')
local result=$(sudo touch "$clean_dir")
checkSuccess "Touching $file_name"
if [ "$silent_flag" == "silent" ]; then
sudo touch "$clean_dir"
sudo chown $user_name:$user_name "$file"
else
local result=$(sudo touch "$clean_dir")
checkSuccess "Touching $file_name"
local result=$(sudo chown $user_name:$user_name "$file")
checkSuccess "Updating $file_name with $user_name ownership"
local result=$(sudo chown $user_name:$user_name "$file")
checkSuccess "Updating $file_name with $user_name ownership"
fi
}

View File

@ -227,7 +227,7 @@ EOF
# Already root via start.sh — drop redundant sudo.
if [ $? -eq 0 ]; then
mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -71,7 +71,7 @@ webuiGenerateGluetunProviders() {
if [ -s "$tmp" ]; then
mv "$tmp" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
[[ -n "$new_etag" ]] && echo "$new_etag" | tee "$etag_file" >/dev/null
isSuccessful "Refreshed gluetun provider snapshot ($(jq '.providers | length' "$output_file") providers)."
else

View File

@ -28,7 +28,7 @@ EOF
echo " ]" >> "$temp_file"
echo "}" >> "$temp_file"
mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
fi
# Get all installed apps
@ -40,7 +40,7 @@ EOF
echo " ]" >> "$temp_file"
echo "}" >> "$temp_file"
mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
fi
# Process each app
@ -293,7 +293,7 @@ EOF
echo " ]" >> "$temp_file"
echo "}" >> "$temp_file"
mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
echo "No services found to generate"
fi
@ -304,7 +304,7 @@ EOF
if [ $? -eq 0 ]; then
mv "$temp_file" "$output_file"
# Set proper ownership for web UI access
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -423,6 +423,6 @@ JSON
fi
mv "$tmp" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
isSuccessful "Generated apps-tools.json ($(jq '[.apps[].tools | length] | add' "$output_file" 2>/dev/null || echo "?") tool(s) across $(jq '.apps | length' "$output_file" 2>/dev/null || echo "?") app(s))."
}

View File

@ -53,5 +53,5 @@ webuiGenerateBackupAppStatus()
echo "$content" | sudo tee "$temp_file" >/dev/null
sudo mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
}

View File

@ -81,6 +81,6 @@ webuiGenerateBackupDashboard()
echo "$content" | sudo tee "$temp_file" >/dev/null
sudo mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
isSuccessful "Backup dashboard JSON regenerated"
}

View File

@ -23,7 +23,7 @@ webuiGenerateBackupEngines()
local base
base=$(basename "$f")
sudo cp "$f" "$out_dir/$base"
createTouch "$out_dir/$base" "$docker_install_user"
createTouch "$out_dir/$base" "$docker_install_user" "silent"
local id="${base%.json}"
$first || index+=","
first=false
@ -33,7 +33,7 @@ webuiGenerateBackupEngines()
local idx_file="$out_dir/index.json"
echo "{\"engines\":$index,\"generated_at\":\"$(date -Iseconds)\"}" | sudo tee "$idx_file" >/dev/null
createTouch "$idx_file" "$docker_install_user"
createTouch "$idx_file" "$docker_install_user" "silent"
isSuccessful "Engines JSON regenerated"
}

View File

@ -88,6 +88,6 @@ webuiGenerateBackupLocations()
echo "$content" | sudo tee "$temp_file" >/dev/null
sudo mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
isSuccessful "Locations JSON regenerated"
}

View File

@ -37,6 +37,6 @@ webuiGenerateBackupPasswords()
chmod 0600 "$temp_file"
mv "$temp_file" "$output_file"
createTouch "$output_file" "${docker_install_user:-${sudo_user_name:-libreportal}}"
createTouch "$output_file" "${docker_install_user:-${sudo_user_name:-libreportal}}" "silent"
chmod 0600 "$output_file"
}

View File

@ -34,7 +34,7 @@ webuiGenerateBackupSnapshots()
echo "$content" | sudo tee "$temp_file" >/dev/null
sudo mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
done
isSuccessful "Snapshots JSON regenerated (${#indices[@]} location(s))"

View File

@ -97,7 +97,7 @@ EOF
if [ $? -eq 0 ]; then
sudo mv "$temp_file" "$final_file"
# Set proper ownership for web UI access using createTouch
createTouch "$final_file" "$docker_install_user"
createTouch "$final_file" "$docker_install_user" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -79,7 +79,7 @@ EOF
if [ $? -eq 0 ]; then
sudo mv "$temp_file" "$final_file"
# Set proper ownership for web UI access using createTouch
createTouch "$final_file" "$docker_install_user"
createTouch "$final_file" "$docker_install_user" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -792,7 +792,7 @@ RESTEOF
sed -i "s|__INSTALL_NAME__|${install_name_safe}|g" "$temp_file"
mv "$temp_file" "$final_file"
# Set proper ownership for web UI access using createTouch
createTouch "$final_file" "$docker_install_user"
createTouch "$final_file" "$docker_install_user" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -294,7 +294,7 @@ EOF
# Already running as root via start.sh — sudo was redundant overhead.
if [ $? -eq 0 ]; then
mv "$temp_file" "$output_file"
createTouch "$output_file" "$docker_install_user"
createTouch "$output_file" "$docker_install_user" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -57,7 +57,7 @@ EOF
if [ $? -eq 0 ]; then
mv "$temp_file" "$final_file"
# Set proper ownership for web UI access using createTouch
createTouch "$final_file" "$sudo_user_name"
createTouch "$final_file" "$sudo_user_name" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -54,7 +54,7 @@ EOF
if [ $? -eq 0 ]; then
mv "$temp_file" "$final_file"
# Set proper ownership for web UI access using createTouch
createTouch "$final_file" "$sudo_user_name"
createTouch "$final_file" "$sudo_user_name" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -51,7 +51,7 @@ EOF
if [ $? -eq 0 ]; then
mv "$temp_file" "$final_file"
# Set proper ownership for web UI access using createTouch
createTouch "$final_file" "$sudo_user_name"
createTouch "$final_file" "$sudo_user_name" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -92,7 +92,7 @@ webuiSystemUpdateCheck() {
EOF
if [ $? -eq 0 ]; then
mv "$temp_file" "$final_file"
createTouch "$final_file" "$sudo_user_name"
createTouch "$final_file" "$sudo_user_name" "silent"
else
rm -f "$temp_file" 2>/dev/null
fi

View File

@ -15,7 +15,7 @@ webuiEnsureTaskFiles() {
# Create queue.json if it doesn't exist
if [ ! -f "$task_dir/queue.json" ]; then
echo " Creating queue.json"
createTouch "$task_dir/queue.json" $docker_install_user
createTouch "$task_dir/queue.json" $docker_install_user "silent"
local result=$(echo "[]" | sudo tee "$task_dir/queue.json" > /dev/null)
checkSuccess "Created queue.json..."
else
@ -25,7 +25,7 @@ webuiEnsureTaskFiles() {
# Create current.json if it doesn't exist
if [ ! -f "$task_dir/current.json" ]; then
echo " Creating current.json"
createTouch "$task_dir/current.json" $docker_install_user
createTouch "$task_dir/current.json" $docker_install_user "silent"
local result=$(echo '{}' | sudo tee "$task_dir/current.json" > /dev/null)
checkSuccess "Created current.json..."
else

View File

@ -18,7 +18,7 @@ webuiUpdateAppLog()
if [[ "$type" == "install" ]]; then
# Create WebUI log file if it doesn't exist
if [ ! -f "${log_file}" ]; then
createTouch "$log_file" $sudo_user_name
createTouch "$log_file" $sudo_user_name "silent"
echo "=== LibrePortal Installation Started at $(date) ===" | sudo tee "${log_file}" > /dev/null
fi
elif [[ "$type" == "uninstall" ]]; then