diff --git a/scripts/app/containers/gluetun/gluetun_recreate_routed.sh b/scripts/app/containers/gluetun/gluetun_recreate_routed.sh index 3d8ae23..a2493c1 100644 --- a/scripts/app/containers/gluetun/gluetun_recreate_routed.sh +++ b/scripts/app/containers/gluetun/gluetun_recreate_routed.sh @@ -24,7 +24,7 @@ appGluetunRecreateRouted() fi local installed_apps - installed_apps=$(sudo sqlite3 "$docker_dir/$db_file" \ + installed_apps=$(runInstallOp sqlite3 "$docker_dir/$db_file" \ "SELECT name FROM apps WHERE status = 1 ORDER BY name;" 2>/dev/null) if ! sudo docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^gluetun-service$'; then diff --git a/scripts/backup/app/backup_app_all.sh b/scripts/backup/app/backup_app_all.sh index 54eb6d5..cc62c73 100644 --- a/scripts/backup/app/backup_app_all.sh +++ b/scripts/backup/app/backup_app_all.sh @@ -12,7 +12,7 @@ backupAllApps() local app_names=() while IFS= read -r name; do app_names+=("$name") - done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") + done < <(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") if [[ ${#app_names[@]} -eq 0 ]]; then isNotice "No installed applications found — nothing to back up" diff --git a/scripts/backup/app/backup_schedule_all.sh b/scripts/backup/app/backup_schedule_all.sh index bdccb1e..98e051e 100644 --- a/scripts/backup/app/backup_schedule_all.sh +++ b/scripts/backup/app/backup_schedule_all.sh @@ -17,7 +17,7 @@ backupScheduleEnabledApps() while IFS= read -r name; do [[ -z "$name" ]] && continue app_names+=("$name") - done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") + done < <(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") local queued=0 for name in "${app_names[@]}"; do diff --git a/scripts/config/application/application_menu_category.sh b/scripts/config/application/application_menu_category.sh index d7f10e7..ca2446f 100755 --- a/scripts/config/application/application_menu_category.sh +++ b/scripts/config/application/application_menu_category.sh @@ -20,7 +20,7 @@ viewAppCategoryConfigs() local category_info=$(grep -Po '(?<=# Category : ).*' "$app_config_file") if [ "$category_info" == "$category" ]; then # Check if the app_name is installed based on the database query - results=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1 AND name = '$app_name';") + results=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1 AND name = '$app_name';") if [[ -n "$results" ]]; then local app_description="\e[32m*INSTALLED*\e[0m - $app_name" installed_apps+=("$app_description") diff --git a/scripts/config/tags/processors/tags_processor_app_url.sh b/scripts/config/tags/processors/tags_processor_app_url.sh index a490c8b..e73d21f 100644 --- a/scripts/config/tags/processors/tags_processor_app_url.sh +++ b/scripts/config/tags/processors/tags_processor_app_url.sh @@ -10,7 +10,7 @@ tagsProcessorAppUrl() local traefik_installed="" if [[ -f "$docker_dir/$db_file" ]] && command -v sqlite3 >/dev/null 2>&1; then - traefik_installed=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = 'traefik' AND status = 1;" 2>/dev/null) + traefik_installed=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = 'traefik' AND status = 1;" 2>/dev/null) fi local app_url="" @@ -19,7 +19,7 @@ tagsProcessorAppUrl() else local external_port="" if [[ -f "$docker_dir/$db_file" ]] && command -v sqlite3 >/dev/null 2>&1; then - external_port=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE app_name = '$app_name' AND resource_type = 'port' AND service_name LIKE '%webui%' AND status = 'active' ORDER BY service_name LIMIT 1;" 2>/dev/null | cut -d':' -f1) + external_port=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE app_name = '$app_name' AND resource_type = 'port' AND service_name LIKE '%webui%' AND status = 'active' ORDER BY service_name LIMIT 1;" 2>/dev/null | cut -d':' -f1) fi local host="${public_ip_v4:-localhost}" if [[ -n "$external_port" ]]; then diff --git a/scripts/database/app/db_cycle_apps.sh b/scripts/database/app/db_cycle_apps.sh index ea85e0e..9d528b0 100755 --- a/scripts/database/app/db_cycle_apps.sh +++ b/scripts/database/app/db_cycle_apps.sh @@ -12,7 +12,7 @@ databaseCycleThroughListApps() local app_names=() while IFS= read -r name; do app_names+=("$name") - done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") + done < <(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") for name in "${app_names[@]}"; do isQuestion "Do you want to backup $name? (y/n) " diff --git a/scripts/database/app/db_install_app.sh b/scripts/database/app/db_install_app.sh index 810eb72..4294187 100755 --- a/scripts/database/app/db_install_app.sh +++ b/scripts/database/app/db_install_app.sh @@ -20,15 +20,15 @@ databaseInstallApp() fi # Check if the app exists in the database - app_exists=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT COUNT(*) FROM apps WHERE name = '$app_name';") + app_exists=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT COUNT(*) FROM apps WHERE name = '$app_name';") if [ "$app_exists" -eq 0 ]; then isNotice "App does not exist in the database, setting up now." - local result=$(sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO apps (name, status, install_date, install_time) VALUES ('$app_name', '1', '$current_date', '$current_time');") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO apps (name, status, install_date, install_time) VALUES ('$app_name', '1', '$current_date', '$current_time');") checkSuccess "Adding $app_name to the apps database." else isNotice "App already exists in the database, updating now." - local result=$(sudo sqlite3 "$docker_dir/$db_file" "UPDATE apps SET status = '1', install_date = '$current_date', install_time = '$current_time', uninstall_date = NULL WHERE name = '$app_name';") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "UPDATE apps SET status = '1', install_date = '$current_date', install_time = '$current_time', uninstall_date = NULL WHERE name = '$app_name';") checkSuccess "Updating apps database for $app_name to installed status." fi } diff --git a/scripts/database/app/db_list_installed_apps.sh b/scripts/database/app/db_list_installed_apps.sh index 5d9f69d..803b84a 100755 --- a/scripts/database/app/db_list_installed_apps.sh +++ b/scripts/database/app/db_list_installed_apps.sh @@ -15,7 +15,7 @@ databaseListInstalledApps() isHeader "Listing installed apps" # Get apps and display them - local apps=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") + local apps=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;") if [ -n "$apps" ]; then echo "$apps" | while IFS="|" read -r app_name; do diff --git a/scripts/database/app/db_uninstall_app.sh b/scripts/database/app/db_uninstall_app.sh index 524762f..f95e40a 100755 --- a/scripts/database/app/db_uninstall_app.sh +++ b/scripts/database/app/db_uninstall_app.sh @@ -19,7 +19,7 @@ databaseUninstallApp() fi # Check if the app exists in the database - results=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = '$app_name'") + results=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = '$app_name'") if [ -z "$results" ]; then # App not found in the database @@ -27,7 +27,7 @@ databaseUninstallApp() else # App found in the database, update status to 0 and set uninstall_date isNotice "Uninstalling $app_name..." - if ! sudo sqlite3 "$docker_dir/$db_file" "UPDATE apps SET status = 0, uninstall_date = '$current_date', uninstall_time = '$current_time' WHERE name = '$app_name';"; then + if ! runInstallOp sqlite3 "$docker_dir/$db_file" "UPDATE apps SET status = 0, uninstall_date = '$current_date', uninstall_time = '$current_time' WHERE name = '$app_name';"; then isError "Failed to update the database for $app_name." fi isSuccessful "$app_name successfully uninstalled." diff --git a/scripts/database/check_os_update.sh b/scripts/database/check_os_update.sh index 4f17734..df20f23 100755 --- a/scripts/database/check_os_update.sh +++ b/scripts/database/check_os_update.sh @@ -9,7 +9,7 @@ checkIfOSUpdateShouldRun() isNotice "Database file not found: $docker_dir/$db_file" else local table_name="sysupdate" - local latest_timestamp=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT datetime(date || ' ' || time) FROM \"$table_name\" ORDER BY date DESC, time DESC LIMIT 1;") + local latest_timestamp=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT datetime(date || ' ' || time) FROM \"$table_name\" ORDER BY date DESC, time DESC LIMIT 1;") if [[ -n "$latest_timestamp" ]]; then local latest_timestamp_unix=$(date -d "$latest_timestamp" +%s) @@ -18,10 +18,10 @@ checkIfOSUpdateShouldRun() local threshold=$(($CFG_UPDATER_CHECK * 60)) if ((time_difference >= threshold)); then - sudo sqlite3 "$docker_dir/$db_file" "UPDATE \"$table_name\" SET date='$current_date', time='$current_time' WHERE ROWID=1;" + runInstallOp sqlite3 "$docker_dir/$db_file" "UPDATE \"$table_name\" SET date='$current_date', time='$current_time' WHERE ROWID=1;" fi else - sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO \"$table_name\" (date, time) VALUES ('$current_date', '$current_time');" + runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO \"$table_name\" (date, time) VALUES ('$current_date', '$current_time');" fi fi } diff --git a/scripts/database/insert/db_insert_backups.sh b/scripts/database/insert/db_insert_backups.sh index fb20b50..59a356b 100755 --- a/scripts/database/insert/db_insert_backups.sh +++ b/scripts/database/insert/db_insert_backups.sh @@ -4,6 +4,6 @@ databaseBackupInsert() { local app_name="$1" local table_name=backups - local result=$(sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, date, time) VALUES ('$app_name', '$current_date', '$current_time');") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, date, time) VALUES ('$app_name', '$current_date', '$current_time');") checkSuccess "Adding $app_name to the $table_name table." } diff --git a/scripts/database/insert/db_insert_option.sh b/scripts/database/insert/db_insert_option.sh index 8b52525..7064320 100755 --- a/scripts/database/insert/db_insert_option.sh +++ b/scripts/database/insert/db_insert_option.sh @@ -5,13 +5,13 @@ databaseOptionInsert() local option="$1" local content="$2" local table_name=options - local option_in_db=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT COUNT(*) FROM $table_name WHERE option = '$option';") + local option_in_db=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT COUNT(*) FROM $table_name WHERE option = '$option';") if [ "$option_in_db" -eq 0 ]; then - local result=$(sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (option, content) VALUES ('$option', '$content');") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (option, content) VALUES ('$option', '$content');") checkSuccess "Adding $option to the $table_name table." else - local result=$(sudo sqlite3 "$docker_dir/$db_file" "UPDATE $table_name SET option = '$option', content = '$content';") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "UPDATE $table_name SET option = '$option', content = '$content';") checkSuccess "$option already added to the $table_name table. Updating content to $content." fi } diff --git a/scripts/database/insert/db_insert_port_open.sh b/scripts/database/insert/db_insert_port_open.sh index 7fe26e8..3353a1b 100755 --- a/scripts/database/insert/db_insert_port_open.sh +++ b/scripts/database/insert/db_insert_port_open.sh @@ -10,9 +10,9 @@ databasePortOpenInsert() # Split the portdata into port and type IFS='/' read -r port type <<< "$portdata" # Check if already exists in the database - local existing_portdata=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT port FROM $table_name WHERE name = '$app_name' AND port = '$port' AND type = '$type';") + local existing_portdata=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT port FROM $table_name WHERE name = '$app_name' AND port = '$port' AND type = '$type';") if [ -z "$existing_portdata" ]; then - local result=$(sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, port, type) VALUES ('$app_name', '$port', '$type');") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, port, type) VALUES ('$app_name', '$port', '$type');") checkSuccess "Adding port $port and type $type for $app_name to the $table_name table." fi fi diff --git a/scripts/database/insert/db_insert_port_used.sh b/scripts/database/insert/db_insert_port_used.sh index c511bd7..fd3bd67 100755 --- a/scripts/database/insert/db_insert_port_used.sh +++ b/scripts/database/insert/db_insert_port_used.sh @@ -8,9 +8,9 @@ databasePortUsedInsert() if [ -f "$docker_dir/$db_file" ] && [ -n "$app_name" ]; then local table_name=ports # Check if already exists in the database - local existing_portdata=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT port FROM $table_name WHERE name = '$app_name' AND port = '$port';") + local existing_portdata=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT port FROM $table_name WHERE name = '$app_name' AND port = '$port';") if [ -z "$existing_portdata" ]; then - local result=$(sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, port) VALUES ('$app_name', '$port');") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, port) VALUES ('$app_name', '$port');") checkSuccess "Adding port $port for $app_name to the $table_name table." fi fi diff --git a/scripts/database/insert/db_insert_restore.sh b/scripts/database/insert/db_insert_restore.sh index f4f3e03..8bd0a65 100755 --- a/scripts/database/insert/db_insert_restore.sh +++ b/scripts/database/insert/db_insert_restore.sh @@ -4,6 +4,6 @@ databaseRestoreInsert() { local app_name="$1" local table_name=restores - local result=$(sudo sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, date, time) VALUES ('$app_name', '$current_date', '$current_time');") + local result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "INSERT INTO $table_name (name, date, time) VALUES ('$app_name', '$current_date', '$current_time');") checkSuccess "Adding $app_name to the $table_name table." } diff --git a/scripts/database/tables/db_display_tables.sh b/scripts/database/tables/db_display_tables.sh index 908c8c7..a6e6f4c 100755 --- a/scripts/database/tables/db_display_tables.sh +++ b/scripts/database/tables/db_display_tables.sh @@ -21,7 +21,7 @@ databaseDisplayTables() fi # Get a list of existing tables in the database - local tables_list=($(sudo sqlite3 "$docker_dir/$db_file" ".tables")) + local tables_list=($(runInstallOp sqlite3 "$docker_dir/$db_file" ".tables")) # Sort the tables alphabetically sorted_tables=($(printf "%s\n" "${tables_list[@]}" | sort)) @@ -48,7 +48,7 @@ databaseDisplayTables() selected_table="${sorted_tables[$((selected_table-1))]}" # Display all data for the selected table with formatted output isHeader "Displaying $selected_table Table Data" - sudo sqlite3 -column -header "$docker_dir/$db_file" "SELECT * FROM $selected_table;" + runInstallOp sqlite3 -column -header "$docker_dir/$db_file" "SELECT * FROM $selected_table;" echo "" isQuestion "Press Enter to continue..." read -p "" input diff --git a/scripts/database/tables/db_empty_table.sh b/scripts/database/tables/db_empty_table.sh index edcea72..d7b26b0 100755 --- a/scripts/database/tables/db_empty_table.sh +++ b/scripts/database/tables/db_empty_table.sh @@ -16,7 +16,7 @@ databaseEmptyTable() fi # Get a list of existing tables in the database - local tables_list=$(sudo sqlite3 "$docker_dir/$db_file" ".tables") + local tables_list=$(runInstallOp sqlite3 "$docker_dir/$db_file" ".tables") # Check if there are any tables in the database if [ -z "$tables_list" ]; then @@ -35,9 +35,9 @@ databaseEmptyTable() echo "" if [[ "$table_name" == "x" ]]; then isNotice "Exiting." - elif sudo sqlite3 "$docker_dir/$db_file" ".tables" | grep -q "\b$table_name\b"; then + elif runInstallOp sqlite3 "$docker_dir/$db_file" ".tables" | grep -q "\b$table_name\b"; then # Empty the selected table - sudo sqlite3 "$docker_dir/$db_file" "DELETE FROM \"$table_name\";" + runInstallOp sqlite3 "$docker_dir/$db_file" "DELETE FROM \"$table_name\";" isSuccessful "Table '$table_name' has been emptied." else isNotice "Invalid table name. Please try again." diff --git a/scripts/docker/app/checks/app_installed.sh b/scripts/docker/app/checks/app_installed.sh index c286b6b..564afc0 100755 --- a/scripts/docker/app/checks/app_installed.sh +++ b/scripts/docker/app/checks/app_installed.sh @@ -24,7 +24,7 @@ dockerCheckAppInstalled() elif [ ! -f "$docker_dir/$db_file" ]; then package_status="not_installed" else - results=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1 AND name = '$app_name';" 2>/dev/null) + results=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1 AND name = '$app_name';" 2>/dev/null) if [ -n "$results" ]; then package_status="installed" else diff --git a/scripts/docker/type_switcher/swap_docker_type.sh b/scripts/docker/type_switcher/swap_docker_type.sh index b0ff5c3..d225da1 100755 --- a/scripts/docker/type_switcher/swap_docker_type.sh +++ b/scripts/docker/type_switcher/swap_docker_type.sh @@ -9,11 +9,11 @@ dockerSwitcherSwap() # Select preexisting docker_type if [ -f "$docker_dir/$db_file" ]; then - local docker_type=$(sudo sqlite3 "$docker_dir/$db_file" 'SELECT content FROM options WHERE option = "docker_type";') + local docker_type=$(runInstallOp sqlite3 "$docker_dir/$db_file" 'SELECT content FROM options WHERE option = "docker_type";') # Insert into DB if something doesnt exist if [[ $docker_type == "" ]]; then databaseOptionInsert "docker_type" $CFG_DOCKER_INSTALL_TYPE; - local docker_type=$(sudo sqlite3 "$docker_dir/$db_file" 'SELECT content FROM options WHERE option = "docker_type";') + local docker_type=$(runInstallOp sqlite3 "$docker_dir/$db_file" 'SELECT content FROM options WHERE option = "docker_type";') fi else : diff --git a/scripts/gluetun/gluetun_route_apps.sh b/scripts/gluetun/gluetun_route_apps.sh index 34060c0..baa571a 100644 --- a/scripts/gluetun/gluetun_route_apps.sh +++ b/scripts/gluetun/gluetun_route_apps.sh @@ -19,7 +19,7 @@ gluetunRouteExistingAppsPrompt() fi local installed - installed=$(sudo sqlite3 "$docker_dir/$db_file" \ + installed=$(runInstallOp sqlite3 "$docker_dir/$db_file" \ "SELECT name FROM apps WHERE status = 1 AND name NOT IN ('gluetun','libreportal','traefik','fail2ban') ORDER BY name;" 2>/dev/null) if [[ -z "$installed" ]]; then diff --git a/scripts/network/ip/ip_find_available.sh b/scripts/network/ip/ip_find_available.sh index 3e950fd..f1fcfd4 100755 --- a/scripts/network/ip/ip_find_available.sh +++ b/scripts/network/ip/ip_find_available.sh @@ -8,7 +8,7 @@ ipFindAvailable() local start_last=2 # Hardcoded sensible default: .2 local end_last=254 # Hardcoded sensible default: .254 - local existing_ips=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE resource_type = 'ip' AND status = 'active';" 2>/dev/null) + local existing_ips=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE resource_type = 'ip' AND status = 'active';" 2>/dev/null) if [[ $? -ne 0 ]]; then isError "Database query failed while checking existing IPs" available_ip="" diff --git a/scripts/network/ports/allocation/port_allocate.sh b/scripts/network/ports/allocation/port_allocate.sh index dd1399b..ccd417d 100755 --- a/scripts/network/ports/allocation/port_allocate.sh +++ b/scripts/network/ports/allocation/port_allocate.sh @@ -5,7 +5,7 @@ portLookupExisting() local app_name="$1" local service_name="$2" local row - row=$(sudo sqlite3 "$docker_dir/$db_file" \ + row=$(runInstallOp sqlite3 "$docker_dir/$db_file" \ "SELECT resource_value FROM network_resources \ WHERE app_name='$app_name' AND resource_type='port' \ AND service_name='$service_name' AND status='active' LIMIT 1;" 2>/dev/null) @@ -18,7 +18,7 @@ portAllocate() local app_name="$1" if [[ ${#port_config_data[@]} -eq 0 ]]; then - local existing_services=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT service_name FROM network_resources WHERE app_name='$app_name' AND resource_type='port' AND service_name LIKE '${app_name}_service_%' AND status='active';" 2>/dev/null) + local existing_services=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT service_name FROM network_resources WHERE app_name='$app_name' AND resource_type='port' AND service_name LIKE '${app_name}_service_%' AND status='active';" 2>/dev/null) local service_num=1 if [[ -n "$existing_services" ]]; then diff --git a/scripts/network/ports/core/port_find_next_available.sh b/scripts/network/ports/core/port_find_next_available.sh index 7ccea1f..74bc865 100755 --- a/scripts/network/ports/core/port_find_next_available.sh +++ b/scripts/network/ports/core/port_find_next_available.sh @@ -44,7 +44,7 @@ portFindNextAvailablePort() fi # Check if port is available - local check_result=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT 1 FROM network_resources WHERE resource_value LIKE '$random_port:%' AND resource_type='port' AND status='active' LIMIT 1" 2>/dev/null) + local check_result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT 1 FROM network_resources WHERE resource_value LIKE '$random_port:%' AND resource_type='port' AND status='active' LIMIT 1" 2>/dev/null) if [[ -z "$check_result" ]]; then available_port="$random_port" fi @@ -59,7 +59,7 @@ portFindNextAvailablePort() if portIsReservedHostPort "$port"; then continue fi - local check_result=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT 1 FROM network_resources WHERE resource_value LIKE '$port:%' AND resource_type='port' AND status='active' LIMIT 1" 2>/dev/null) + local check_result=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT 1 FROM network_resources WHERE resource_value LIKE '$port:%' AND resource_type='port' AND status='active' LIMIT 1" 2>/dev/null) if [[ -z "$check_result" ]]; then available_port="$port" break diff --git a/scripts/start/start_recommended.sh b/scripts/start/start_recommended.sh index 7ef119c..9909989 100755 --- a/scripts/start/start_recommended.sh +++ b/scripts/start/start_recommended.sh @@ -74,7 +74,7 @@ installRecommendedApps() fi # SSHdownload - local ssh_new_key=$(sudo sqlite3 "$docker_dir/$db_file" 'SELECT content FROM options WHERE option = "ssh_new_key";') + local ssh_new_key=$(runInstallOp sqlite3 "$docker_dir/$db_file" 'SELECT content FROM options WHERE option = "ssh_new_key";') if [[ "$sshdownload_status" != "installed" ]]; then if [[ "$ssh_new_key" == "true" ]]; then isHeader "SSH Key Downloader" diff --git a/scripts/webui/data/generators/apps/webui_config_patch.sh b/scripts/webui/data/generators/apps/webui_config_patch.sh index b411472..2323f76 100644 --- a/scripts/webui/data/generators/apps/webui_config_patch.sh +++ b/scripts/webui/data/generators/apps/webui_config_patch.sh @@ -49,7 +49,7 @@ webuiPatchAppConfigJson() { local installed="false" if [[ -f "$docker_dir/$db_file" ]]; then local row - row=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT status FROM apps WHERE name = '${app_name//\'/\'\'}';" 2>/dev/null) + row=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT status FROM apps WHERE name = '${app_name//\'/\'\'}';" 2>/dev/null) [[ "$row" == "1" ]] && installed="true" fi diff --git a/scripts/webui/data/generators/backup/webui_backup_app_status.sh b/scripts/webui/data/generators/backup/webui_backup_app_status.sh index 8a4aec2..8e9fcc5 100644 --- a/scripts/webui/data/generators/backup/webui_backup_app_status.sh +++ b/scripts/webui/data/generators/backup/webui_backup_app_status.sh @@ -10,7 +10,7 @@ webuiGenerateBackupAppStatus() if [[ -f "$docker_dir/$db_file" ]]; then while IFS= read -r a; do [[ -n "$a" ]] && webuiGenerateBackupAppStatus "$a" - done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;" 2>/dev/null) + done < <(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;" 2>/dev/null) fi return 0 fi diff --git a/scripts/webui/data/generators/backup/webui_backup_dashboard.sh b/scripts/webui/data/generators/backup/webui_backup_dashboard.sh index 53bd2ea..65d532b 100644 --- a/scripts/webui/data/generators/backup/webui_backup_dashboard.sh +++ b/scripts/webui/data/generators/backup/webui_backup_dashboard.sh @@ -65,7 +65,7 @@ webuiGenerateBackupDashboard() $first || apps_json+="," first=false apps_json+="{\"app\":\"$app\",\"latest_snapshot\":\"$latest_id\",\"latest_time\":\"$latest_time\"}" - done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;" 2>/dev/null) + done < <(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;" 2>/dev/null) fi apps_json+="]" diff --git a/scripts/webui/webui_display_logins.sh b/scripts/webui/webui_display_logins.sh index bd0767e..afae0f4 100755 --- a/scripts/webui/webui_display_logins.sh +++ b/scripts/webui/webui_display_logins.sh @@ -12,18 +12,18 @@ getLibrePortalWebUIUrls() # Check if sqlite3 is available and database exists if command -v sudo sqlite3 &> /dev/null && [ -f "$docker_dir/$db_file" ]; then # Check if LibrePortal app is installed - local libreportal_check=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = 'libreportal' AND status = 1;" 2>/dev/null) + local libreportal_check=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = 'libreportal' AND status = 1;" 2>/dev/null) if [[ -n "$libreportal_check" ]]; then # Get the main service IP for LibrePortal - local docker_service=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT DISTINCT service_name, resource_value FROM network_resources WHERE app_name = 'libreportal' AND resource_type = 'ip' AND status = 'active' ORDER BY service_name LIMIT 1;" 2>/dev/null) + local docker_service=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT DISTINCT service_name, resource_value FROM network_resources WHERE app_name = 'libreportal' AND resource_type = 'ip' AND status = 'active' ORDER BY service_name LIMIT 1;" 2>/dev/null) if [[ -n "$docker_service" ]]; then local service_name=$(echo "$docker_service" | cut -d'|' -f1) local service_ip=$(echo "$docker_service" | cut -d'|' -f2) # Get the webui port mapping for this service - local port_mapping=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT service_name, resource_value FROM network_resources WHERE app_name = 'libreportal' AND resource_type = 'port' AND parent_service = '$service_name' AND service_name LIKE '%webui%' AND status = 'active' ORDER BY service_name LIMIT 1;" 2>/dev/null) + local port_mapping=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT service_name, resource_value FROM network_resources WHERE app_name = 'libreportal' AND resource_type = 'port' AND parent_service = '$service_name' AND service_name LIKE '%webui%' AND status = 'active' ORDER BY service_name LIMIT 1;" 2>/dev/null) if [[ -n "$port_mapping" ]]; then local port_service_name=$(echo "$port_mapping" | cut -d'|' -f1) @@ -35,11 +35,11 @@ getLibrePortalWebUIUrls() local access_type=$(echo "$port_data" | cut -d':' -f3) # Check if Traefik is installed for domain access - local traefik_installed=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = 'traefik' AND status = 1;" 2>/dev/null) + local traefik_installed=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE name = 'traefik' AND status = 1;" 2>/dev/null) if [[ -n "$traefik_installed" ]]; then # Get domain from general config - local domain=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM options WHERE option = 'domain_LIBREPORTAL_DOMAIN';" 2>/dev/null) + local domain=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM options WHERE option = 'domain_LIBREPORTAL_DOMAIN';" 2>/dev/null) if [[ -n "$domain" ]]; then libreportal_external_url="https://libreportal.$domain" else @@ -64,7 +64,7 @@ getLibrePortalWebUIUrls() # Better fallback: try to find any available port for LibrePortal if [[ -z "$libreportal_external_url" ]]; then # Try to get any port mapping for LibrePortal - local any_port=$(sudo sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE app_name = 'libreportal' AND resource_type = 'port' AND status = 'active' LIMIT 1;" 2>/dev/null) + local any_port=$(runInstallOp sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE app_name = 'libreportal' AND resource_type = 'port' AND status = 'active' LIMIT 1;" 2>/dev/null) if [[ -n "$any_port" ]]; then local external_port=$(echo "$any_port" | cut -d':' -f1)