diff --git a/containers/authelia/authelia.sh b/containers/authelia/authelia.sh index 5d11e99..8c3ca5c 100755 --- a/containers/authelia/authelia.sh +++ b/containers/authelia/authelia.sh @@ -60,10 +60,10 @@ installAuthelia() dockerComposeSetupFile $app_name; - local result=$(copyResource "$app_name" "configuration.yml" "config" | sudo tee -a "$logs_dir/$docker_log_file" 2>&1) + local result=$(copyResource "$app_name" "configuration.yml" "config" | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1) checkSuccess "Copying configuration.yml to $containers_dir$app_name/config" - local result=$(copyResource "$app_name" "users_database.yml" "config" | sudo tee -a "$logs_dir/$docker_log_file" 2>&1) + local result=$(copyResource "$app_name" "users_database.yml" "config" | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1) checkSuccess "Copying users_database.yml to $containers_dir$app_name/config" local authelia_config_file="$containers_dir$app_name/config/configuration.yml" diff --git a/containers/headscale/headscale.sh b/containers/headscale/headscale.sh index b837c3f..fbcdd79 100755 --- a/containers/headscale/headscale.sh +++ b/containers/headscale/headscale.sh @@ -54,7 +54,7 @@ installHeadscale() local result=$(createFolders "loud" $docker_install_user $containers_dir$app_name/config) checkSuccess "Create config folder" - local result=$(copyResource "$app_name" "config.yaml" "config" | sudo tee -a "$logs_dir/$docker_log_file" 2>&1) + local result=$(copyResource "$app_name" "config.yaml" "config" | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1) checkSuccess "Copying config.yaml to config folder." configSetupFileWithData $app_name "config.yaml" "config"; diff --git a/containers/prometheus/prometheus.sh b/containers/prometheus/prometheus.sh index e0ba04a..8e4c4f7 100755 --- a/containers/prometheus/prometheus.sh +++ b/containers/prometheus/prometheus.sh @@ -57,7 +57,7 @@ installPrometheus() local result=$(createTouch "$containers_dir$app_name/$app_name/$app_name.yml" $docker_install_user) checkSuccess "Created $app_name.yml file for $app_name" - local result=$(copyResource "$app_name" "$app_name.yml" "$app_name" | sudo tee -a "$logs_dir/$docker_log_file" 2>&1) + local result=$(copyResource "$app_name" "$app_name.yml" "$app_name" | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1) checkSuccess "Copying $app_name.yml to containers folder." ((menu_number++)) diff --git a/containers/unbound/unbound.sh b/containers/unbound/unbound.sh index 570337d..4cfef9a 100755 --- a/containers/unbound/unbound.sh +++ b/containers/unbound/unbound.sh @@ -53,7 +53,7 @@ installUnbound() monitoringToggleAppConfig "$app_name" "docker-compose.yml"; - local result=$(copyResource "$app_name" "unbound.conf" "etc" | sudo tee -a "$logs_dir/$docker_log_file" 2>&1) + local result=$(copyResource "$app_name" "unbound.conf" "etc" | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1) checkSuccess "Copying unbound.conf to containers folder." monitoringToggleAppConfig "$app_name" "etc/unbound.conf"; diff --git a/scripts/docker/compose/setup_compose_yml.sh b/scripts/docker/compose/setup_compose_yml.sh index f40d721..9b082b1 100755 --- a/scripts/docker/compose/setup_compose_yml.sh +++ b/scripts/docker/compose/setup_compose_yml.sh @@ -40,7 +40,7 @@ dockerComposeSetupFile() isError "The source file '$source_file' does not exist." fi - copyFile "loud" "$source_file" "$target_file" $docker_install_user | sudo tee -a "$logs_dir/$docker_log_file" 2>&1 + copyFile "loud" "$source_file" "$target_file" $docker_install_user | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1 if [ $? -ne 0 ]; then isError "Failed to copy the source file to '$target_path'. Check '$docker_log_file' for more details." diff --git a/scripts/function/checks/check_success.sh b/scripts/function/checks/check_success.sh index 12181b2..5810aec 100755 --- a/scripts/function/checks/check_success.sh +++ b/scripts/function/checks/check_success.sh @@ -5,7 +5,7 @@ function checkSuccess() if [ $? -eq 0 ]; then isSuccessful "$1" if [ -f "$logs_dir/$docker_log_file" ]; then - echo "✓ Success $1" | sudo tee -a "$logs_dir/$docker_log_file" >/dev/null + echo "✓ Success $1" | runFileWrite -a "$logs_dir/$docker_log_file" >/dev/null fi else isError "$1" @@ -14,8 +14,8 @@ function checkSuccess() # blocking on read. if [[ "$LIBREPORTAL_NONINTERACTIVE" == "1" ]] || [ ! -t 0 ]; then if [ -f "$logs_dir/$docker_log_file" ]; then - isError " $1" | sudo tee -a "$logs_dir/$docker_log_file" >/dev/null - echo "===================================" | sudo tee -a "$logs_dir/$docker_log_file" >/dev/null + isError " $1" | runFileWrite -a "$logs_dir/$docker_log_file" >/dev/null + echo "===================================" | runFileWrite -a "$logs_dir/$docker_log_file" >/dev/null fi isNotice "Non-interactive mode: aborting on error." exit 1 @@ -36,15 +36,15 @@ function checkSuccess() if [[ "$error_occurred" == [xX] ]]; then # Log the error output to the log file - isError " $1" | sudo tee -a "$logs_dir/$docker_log_file" - echo "===================================" | sudo tee -a "$logs_dir/$docker_log_file" + isError " $1" | runFileWrite -a "$logs_dir/$docker_log_file" + echo "===================================" | runFileWrite -a "$logs_dir/$docker_log_file" exit 1 # Exit the script with a non-zero status to stop the current action fi if [[ "$error_occurred" == [mM] ]]; then # Log the error output to the log file - isError " $1" | sudo tee -a "$logs_dir/$docker_log_file" - echo "===================================" | sudo tee -a "$logs_dir/$docker_log_file" + isError " $1" | runFileWrite -a "$logs_dir/$docker_log_file" + echo "===================================" | runFileWrite -a "$logs_dir/$docker_log_file" if [[ "$initial_command2" == "terminal" ]]; then resetToMenu; fi diff --git a/scripts/headscale/tailscale/tailscale_install.sh b/scripts/headscale/tailscale/tailscale_install.sh index 432c643..02bb6aa 100755 --- a/scripts/headscale/tailscale/tailscale_install.sh +++ b/scripts/headscale/tailscale/tailscale_install.sh @@ -8,7 +8,7 @@ tailscaleInstallToContainer() local result=$(createFolders "loud" $docker_install_user $containers_dir$app_name/tailscale) checkSuccess "Creating Tailscale folder" - copyFile "loud" "${install_scripts_dir}tailscale.sh" "$containers_dir$app_name/tailscale/tailscale.sh" $docker_install_user | sudo tee -a "$logs_dir/$docker_log_file" 2>&1 + copyFile "loud" "${install_scripts_dir}tailscale.sh" "$containers_dir$app_name/tailscale/tailscale.sh" $docker_install_user | runFileWrite -a "$logs_dir/$docker_log_file" 2>&1 if [[ "$type" != "install" ]]; then dockerComposeRestart $app_name; diff --git a/scripts/network/monitoring/monitoring.sh b/scripts/network/monitoring/monitoring.sh index c1f9539..7a5d8f0 100644 --- a/scripts/network/monitoring/monitoring.sh +++ b/scripts/network/monitoring/monitoring.sh @@ -17,7 +17,7 @@ monitoringInstalledApps() { [[ -f "$docker_dir/$db_file" ]] || return 0 - sudo sqlite3 "$docker_dir/$db_file" \ + runFileOp sqlite3 "$docker_dir/$db_file" \ "SELECT name FROM apps WHERE status = 1 ORDER BY name;" 2>/dev/null } @@ -26,7 +26,7 @@ monitoringIsInstalled() { [[ -f "$docker_dir/$db_file" ]] || return 1 local n - n="$(sudo sqlite3 "$docker_dir/$db_file" \ + n="$(runFileOp sqlite3 "$docker_dir/$db_file" \ "SELECT COUNT(*) FROM apps WHERE name = '$1' AND status = 1;" 2>/dev/null)" [[ -n "$n" && "$n" -gt 0 ]] } @@ -62,13 +62,13 @@ monitoringToggleAppConfig() if monitoringAppEnabled "$app_name"; then # Uncomment: strip the leading # from every non-marker line in range. - sudo sed -i '/# >>> libreportal-monitoring >>>/,/# <<< libreportal-monitoring <<>> libreportal-monitoring >>>/,/# <<< libreportal-monitoring <<>> libreportal-monitoring >>>/,/# <<< libreportal-monitoring <<>> libreportal-monitoring >>>/,/# <<< libreportal-monitoring <</dev/null + runFileOp chmod -R a+rX "$scrape_dir" 2>/dev/null - if sudo docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^prometheus-service$'; then - local result=$(sudo docker kill --signal=HUP prometheus-service 2>&1) + if dockerCommandRun "docker ps --format '{{.Names}}'" "sudo" 2>/dev/null | grep -q '^prometheus-service$'; then + local result=$(dockerCommandRun "docker kill --signal=HUP prometheus-service" "sudo" 2>&1) checkSuccess "Reloaded Prometheus ($count monitored app(s))" else isNotice "Prometheus container not running — scrape.d updated, applied on next start ($count app(s))." @@ -160,11 +160,11 @@ monitoringRefreshGrafana() local ds_dir="$prov/datasources" local dash_provider_dir="$prov/dashboards" local dash_dir="$prov/dashboards/libreportal" - sudo mkdir -p "$ds_dir" "$dash_dir" + runFileOp mkdir -p "$ds_dir" "$dash_dir" # Prometheus datasource — reachable from the grafana container by the # prometheus service name on the shared libreportal docker network. - sudo tee "$ds_dir/libreportal-prometheus.yml" >/dev/null <<'EOF' + runFileWrite "$ds_dir/libreportal-prometheus.yml" <<'EOF' apiVersion: 1 datasources: - name: Prometheus @@ -176,7 +176,7 @@ datasources: EOF # Dashboard provider — points Grafana at the gathered dashboards dir. - sudo tee "$dash_provider_dir/libreportal.yml" >/dev/null <<'EOF' + runFileWrite "$dash_provider_dir/libreportal.yml" <<'EOF' apiVersion: 1 providers: - name: LibrePortal @@ -192,23 +192,23 @@ EOF # Gather each monitoring-enabled app's dashboard JSONs (prefixed with the # app name to avoid filename clashes). Clear stale ones first. - sudo find "$dash_dir" -type f -name '*.json' -delete 2>/dev/null + runFileOp find "$dash_dir" -type f -name '*.json' -delete 2>/dev/null local count=0 app_name app_dash f for app_name in $(monitoringInstalledApps); do app_dash="${containers_dir}${app_name}/resources/monitoring/grafana-dashboards" if monitoringAppEnabled "$app_name" && [[ -d "$app_dash" ]]; then for f in "$app_dash"/*.json; do [[ -f "$f" ]] || continue - sudo cp "$f" "$dash_dir/${app_name}-$(basename "$f")" + runFileOp cp "$f" "$dash_dir/${app_name}-$(basename "$f")" count=$((count + 1)) done fi done - sudo chmod -R a+rX "$prov" 2>/dev/null + runFileOp chmod -R a+rX "$prov" 2>/dev/null - if sudo docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^grafana-service$'; then - local result=$(sudo docker restart grafana-service 2>&1) + if dockerCommandRun "docker ps --format '{{.Names}}'" "sudo" 2>/dev/null | grep -q '^grafana-service$'; then + local result=$(dockerCommandRun "docker restart grafana-service" "sudo" 2>&1) checkSuccess "Restarted Grafana ($count dashboard(s) provisioned)" else isNotice "Grafana container not running — provisioning updated, applied on next start ($count dashboard(s))."