refactor(de-sudo): apps DB access via runInstallOp, not sudo
The apps SQLite DB ($docker_dir/$db_file) is owned by the manager user, so read/write it AS the manager via runInstallOp instead of sudo (root). 48 call sites across 28 scripts. In rooted this drops root->manager (correct owner); in rootless it's the manager too (using runFileOp/dockerinstall here was the 'unable to open database' bug). The broken 'command -v sudo sqlite3' check lines are left untouched (separate pre-existing issue). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
parent
d755cad8b9
commit
c6dd2659be
@ -24,7 +24,7 @@ appGluetunRecreateRouted()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local installed_apps
|
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)
|
"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
|
if ! sudo docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^gluetun-service$'; then
|
||||||
|
|||||||
@ -12,7 +12,7 @@ backupAllApps()
|
|||||||
local app_names=()
|
local app_names=()
|
||||||
while IFS= read -r name; do
|
while IFS= read -r name; do
|
||||||
app_names+=("$name")
|
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
|
if [[ ${#app_names[@]} -eq 0 ]]; then
|
||||||
isNotice "No installed applications found — nothing to back up"
|
isNotice "No installed applications found — nothing to back up"
|
||||||
|
|||||||
@ -17,7 +17,7 @@ backupScheduleEnabledApps()
|
|||||||
while IFS= read -r name; do
|
while IFS= read -r name; do
|
||||||
[[ -z "$name" ]] && continue
|
[[ -z "$name" ]] && continue
|
||||||
app_names+=("$name")
|
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
|
local queued=0
|
||||||
for name in "${app_names[@]}"; do
|
for name in "${app_names[@]}"; do
|
||||||
|
|||||||
@ -20,7 +20,7 @@ viewAppCategoryConfigs()
|
|||||||
local category_info=$(grep -Po '(?<=# Category : ).*' "$app_config_file")
|
local category_info=$(grep -Po '(?<=# Category : ).*' "$app_config_file")
|
||||||
if [ "$category_info" == "$category" ]; then
|
if [ "$category_info" == "$category" ]; then
|
||||||
# Check if the app_name is installed based on the database query
|
# 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
|
if [[ -n "$results" ]]; then
|
||||||
local app_description="\e[32m*INSTALLED*\e[0m - $app_name"
|
local app_description="\e[32m*INSTALLED*\e[0m - $app_name"
|
||||||
installed_apps+=("$app_description")
|
installed_apps+=("$app_description")
|
||||||
|
|||||||
@ -10,7 +10,7 @@ tagsProcessorAppUrl()
|
|||||||
|
|
||||||
local traefik_installed=""
|
local traefik_installed=""
|
||||||
if [[ -f "$docker_dir/$db_file" ]] && command -v sqlite3 >/dev/null 2>&1; then
|
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
|
fi
|
||||||
|
|
||||||
local app_url=""
|
local app_url=""
|
||||||
@ -19,7 +19,7 @@ tagsProcessorAppUrl()
|
|||||||
else
|
else
|
||||||
local external_port=""
|
local external_port=""
|
||||||
if [[ -f "$docker_dir/$db_file" ]] && command -v sqlite3 >/dev/null 2>&1; then
|
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
|
fi
|
||||||
local host="${public_ip_v4:-localhost}"
|
local host="${public_ip_v4:-localhost}"
|
||||||
if [[ -n "$external_port" ]]; then
|
if [[ -n "$external_port" ]]; then
|
||||||
|
|||||||
@ -12,7 +12,7 @@ databaseCycleThroughListApps()
|
|||||||
local app_names=()
|
local app_names=()
|
||||||
while IFS= read -r name; do
|
while IFS= read -r name; do
|
||||||
app_names+=("$name")
|
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
|
for name in "${app_names[@]}"; do
|
||||||
isQuestion "Do you want to backup $name? (y/n) "
|
isQuestion "Do you want to backup $name? (y/n) "
|
||||||
|
|||||||
@ -20,15 +20,15 @@ databaseInstallApp()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the app exists in the database
|
# 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
|
if [ "$app_exists" -eq 0 ]; then
|
||||||
isNotice "App does not exist in the database, setting up now."
|
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."
|
checkSuccess "Adding $app_name to the apps database."
|
||||||
else
|
else
|
||||||
isNotice "App already exists in the database, updating now."
|
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."
|
checkSuccess "Updating apps database for $app_name to installed status."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ databaseListInstalledApps()
|
|||||||
isHeader "Listing installed apps"
|
isHeader "Listing installed apps"
|
||||||
|
|
||||||
# Get apps and display them
|
# 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
|
if [ -n "$apps" ]; then
|
||||||
echo "$apps" | while IFS="|" read -r app_name; do
|
echo "$apps" | while IFS="|" read -r app_name; do
|
||||||
|
|||||||
@ -19,7 +19,7 @@ databaseUninstallApp()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the app exists in the database
|
# 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
|
if [ -z "$results" ]; then
|
||||||
# App not found in the database
|
# App not found in the database
|
||||||
@ -27,7 +27,7 @@ databaseUninstallApp()
|
|||||||
else
|
else
|
||||||
# App found in the database, update status to 0 and set uninstall_date
|
# App found in the database, update status to 0 and set uninstall_date
|
||||||
isNotice "Uninstalling $app_name..."
|
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."
|
isError "Failed to update the database for $app_name."
|
||||||
fi
|
fi
|
||||||
isSuccessful "$app_name successfully uninstalled."
|
isSuccessful "$app_name successfully uninstalled."
|
||||||
|
|||||||
@ -9,7 +9,7 @@ checkIfOSUpdateShouldRun()
|
|||||||
isNotice "Database file not found: $docker_dir/$db_file"
|
isNotice "Database file not found: $docker_dir/$db_file"
|
||||||
else
|
else
|
||||||
local table_name="sysupdate"
|
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
|
if [[ -n "$latest_timestamp" ]]; then
|
||||||
local latest_timestamp_unix=$(date -d "$latest_timestamp" +%s)
|
local latest_timestamp_unix=$(date -d "$latest_timestamp" +%s)
|
||||||
@ -18,10 +18,10 @@ checkIfOSUpdateShouldRun()
|
|||||||
local threshold=$(($CFG_UPDATER_CHECK * 60))
|
local threshold=$(($CFG_UPDATER_CHECK * 60))
|
||||||
|
|
||||||
if ((time_difference >= threshold)); then
|
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
|
fi
|
||||||
else
|
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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,6 @@ databaseBackupInsert()
|
|||||||
{
|
{
|
||||||
local app_name="$1"
|
local app_name="$1"
|
||||||
local table_name=backups
|
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."
|
checkSuccess "Adding $app_name to the $table_name table."
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,13 @@ databaseOptionInsert()
|
|||||||
local option="$1"
|
local option="$1"
|
||||||
local content="$2"
|
local content="$2"
|
||||||
local table_name=options
|
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
|
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."
|
checkSuccess "Adding $option to the $table_name table."
|
||||||
else
|
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."
|
checkSuccess "$option already added to the $table_name table. Updating content to $content."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,9 @@ databasePortOpenInsert()
|
|||||||
# Split the portdata into port and type
|
# Split the portdata into port and type
|
||||||
IFS='/' read -r port type <<< "$portdata"
|
IFS='/' read -r port type <<< "$portdata"
|
||||||
# Check if already exists in the database
|
# 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
|
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."
|
checkSuccess "Adding port $port and type $type for $app_name to the $table_name table."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -8,9 +8,9 @@ databasePortUsedInsert()
|
|||||||
if [ -f "$docker_dir/$db_file" ] && [ -n "$app_name" ]; then
|
if [ -f "$docker_dir/$db_file" ] && [ -n "$app_name" ]; then
|
||||||
local table_name=ports
|
local table_name=ports
|
||||||
# Check if already exists in the database
|
# 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
|
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."
|
checkSuccess "Adding port $port for $app_name to the $table_name table."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -4,6 +4,6 @@ databaseRestoreInsert()
|
|||||||
{
|
{
|
||||||
local app_name="$1"
|
local app_name="$1"
|
||||||
local table_name=restores
|
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."
|
checkSuccess "Adding $app_name to the $table_name table."
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ databaseDisplayTables()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Get a list of existing tables in the database
|
# 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
|
# Sort the tables alphabetically
|
||||||
sorted_tables=($(printf "%s\n" "${tables_list[@]}" | sort))
|
sorted_tables=($(printf "%s\n" "${tables_list[@]}" | sort))
|
||||||
@ -48,7 +48,7 @@ databaseDisplayTables()
|
|||||||
selected_table="${sorted_tables[$((selected_table-1))]}"
|
selected_table="${sorted_tables[$((selected_table-1))]}"
|
||||||
# Display all data for the selected table with formatted output
|
# Display all data for the selected table with formatted output
|
||||||
isHeader "Displaying $selected_table Table Data"
|
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 ""
|
echo ""
|
||||||
isQuestion "Press Enter to continue..."
|
isQuestion "Press Enter to continue..."
|
||||||
read -p "" input
|
read -p "" input
|
||||||
|
|||||||
@ -16,7 +16,7 @@ databaseEmptyTable()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Get a list of existing tables in the database
|
# 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
|
# Check if there are any tables in the database
|
||||||
if [ -z "$tables_list" ]; then
|
if [ -z "$tables_list" ]; then
|
||||||
@ -35,9 +35,9 @@ databaseEmptyTable()
|
|||||||
echo ""
|
echo ""
|
||||||
if [[ "$table_name" == "x" ]]; then
|
if [[ "$table_name" == "x" ]]; then
|
||||||
isNotice "Exiting."
|
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
|
# 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."
|
isSuccessful "Table '$table_name' has been emptied."
|
||||||
else
|
else
|
||||||
isNotice "Invalid table name. Please try again."
|
isNotice "Invalid table name. Please try again."
|
||||||
|
|||||||
@ -24,7 +24,7 @@ dockerCheckAppInstalled()
|
|||||||
elif [ ! -f "$docker_dir/$db_file" ]; then
|
elif [ ! -f "$docker_dir/$db_file" ]; then
|
||||||
package_status="not_installed"
|
package_status="not_installed"
|
||||||
else
|
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
|
if [ -n "$results" ]; then
|
||||||
package_status="installed"
|
package_status="installed"
|
||||||
else
|
else
|
||||||
|
|||||||
@ -9,11 +9,11 @@ dockerSwitcherSwap()
|
|||||||
|
|
||||||
# Select preexisting docker_type
|
# Select preexisting docker_type
|
||||||
if [ -f "$docker_dir/$db_file" ]; then
|
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
|
# Insert into DB if something doesnt exist
|
||||||
if [[ $docker_type == "" ]]; then
|
if [[ $docker_type == "" ]]; then
|
||||||
databaseOptionInsert "docker_type" $CFG_DOCKER_INSTALL_TYPE;
|
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
|
fi
|
||||||
else
|
else
|
||||||
:
|
:
|
||||||
|
|||||||
@ -19,7 +19,7 @@ gluetunRouteExistingAppsPrompt()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local installed
|
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)
|
"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
|
if [[ -z "$installed" ]]; then
|
||||||
|
|||||||
@ -8,7 +8,7 @@ ipFindAvailable()
|
|||||||
local start_last=2 # Hardcoded sensible default: .2
|
local start_last=2 # Hardcoded sensible default: .2
|
||||||
local end_last=254 # Hardcoded sensible default: .254
|
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
|
if [[ $? -ne 0 ]]; then
|
||||||
isError "Database query failed while checking existing IPs"
|
isError "Database query failed while checking existing IPs"
|
||||||
available_ip=""
|
available_ip=""
|
||||||
|
|||||||
@ -5,7 +5,7 @@ portLookupExisting()
|
|||||||
local app_name="$1"
|
local app_name="$1"
|
||||||
local service_name="$2"
|
local service_name="$2"
|
||||||
local row
|
local row
|
||||||
row=$(sudo sqlite3 "$docker_dir/$db_file" \
|
row=$(runInstallOp sqlite3 "$docker_dir/$db_file" \
|
||||||
"SELECT resource_value FROM network_resources \
|
"SELECT resource_value FROM network_resources \
|
||||||
WHERE app_name='$app_name' AND resource_type='port' \
|
WHERE app_name='$app_name' AND resource_type='port' \
|
||||||
AND service_name='$service_name' AND status='active' LIMIT 1;" 2>/dev/null)
|
AND service_name='$service_name' AND status='active' LIMIT 1;" 2>/dev/null)
|
||||||
@ -18,7 +18,7 @@ portAllocate()
|
|||||||
local app_name="$1"
|
local app_name="$1"
|
||||||
|
|
||||||
if [[ ${#port_config_data[@]} -eq 0 ]]; then
|
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
|
local service_num=1
|
||||||
if [[ -n "$existing_services" ]]; then
|
if [[ -n "$existing_services" ]]; then
|
||||||
|
|||||||
@ -44,7 +44,7 @@ portFindNextAvailablePort()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if port is available
|
# 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
|
if [[ -z "$check_result" ]]; then
|
||||||
available_port="$random_port"
|
available_port="$random_port"
|
||||||
fi
|
fi
|
||||||
@ -59,7 +59,7 @@ portFindNextAvailablePort()
|
|||||||
if portIsReservedHostPort "$port"; then
|
if portIsReservedHostPort "$port"; then
|
||||||
continue
|
continue
|
||||||
fi
|
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
|
if [[ -z "$check_result" ]]; then
|
||||||
available_port="$port"
|
available_port="$port"
|
||||||
break
|
break
|
||||||
|
|||||||
@ -74,7 +74,7 @@ installRecommendedApps()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# SSHdownload
|
# 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 [[ "$sshdownload_status" != "installed" ]]; then
|
||||||
if [[ "$ssh_new_key" == "true" ]]; then
|
if [[ "$ssh_new_key" == "true" ]]; then
|
||||||
isHeader "SSH Key Downloader"
|
isHeader "SSH Key Downloader"
|
||||||
|
|||||||
@ -49,7 +49,7 @@ webuiPatchAppConfigJson() {
|
|||||||
local installed="false"
|
local installed="false"
|
||||||
if [[ -f "$docker_dir/$db_file" ]]; then
|
if [[ -f "$docker_dir/$db_file" ]]; then
|
||||||
local row
|
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"
|
[[ "$row" == "1" ]] && installed="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ webuiGenerateBackupAppStatus()
|
|||||||
if [[ -f "$docker_dir/$db_file" ]]; then
|
if [[ -f "$docker_dir/$db_file" ]]; then
|
||||||
while IFS= read -r a; do
|
while IFS= read -r a; do
|
||||||
[[ -n "$a" ]] && webuiGenerateBackupAppStatus "$a"
|
[[ -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
|
fi
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -65,7 +65,7 @@ webuiGenerateBackupDashboard()
|
|||||||
$first || apps_json+=","
|
$first || apps_json+=","
|
||||||
first=false
|
first=false
|
||||||
apps_json+="{\"app\":\"$app\",\"latest_snapshot\":\"$latest_id\",\"latest_time\":\"$latest_time\"}"
|
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
|
fi
|
||||||
apps_json+="]"
|
apps_json+="]"
|
||||||
|
|
||||||
|
|||||||
@ -12,18 +12,18 @@ getLibrePortalWebUIUrls()
|
|||||||
# Check if sqlite3 is available and database exists
|
# Check if sqlite3 is available and database exists
|
||||||
if command -v sudo sqlite3 &> /dev/null && [ -f "$docker_dir/$db_file" ]; then
|
if command -v sudo sqlite3 &> /dev/null && [ -f "$docker_dir/$db_file" ]; then
|
||||||
# Check if LibrePortal app is installed
|
# 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
|
if [[ -n "$libreportal_check" ]]; then
|
||||||
# Get the main service IP for LibrePortal
|
# 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
|
if [[ -n "$docker_service" ]]; then
|
||||||
local service_name=$(echo "$docker_service" | cut -d'|' -f1)
|
local service_name=$(echo "$docker_service" | cut -d'|' -f1)
|
||||||
local service_ip=$(echo "$docker_service" | cut -d'|' -f2)
|
local service_ip=$(echo "$docker_service" | cut -d'|' -f2)
|
||||||
|
|
||||||
# Get the webui port mapping for this service
|
# 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
|
if [[ -n "$port_mapping" ]]; then
|
||||||
local port_service_name=$(echo "$port_mapping" | cut -d'|' -f1)
|
local port_service_name=$(echo "$port_mapping" | cut -d'|' -f1)
|
||||||
@ -35,11 +35,11 @@ getLibrePortalWebUIUrls()
|
|||||||
local access_type=$(echo "$port_data" | cut -d':' -f3)
|
local access_type=$(echo "$port_data" | cut -d':' -f3)
|
||||||
|
|
||||||
# Check if Traefik is installed for domain access
|
# 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
|
if [[ -n "$traefik_installed" ]]; then
|
||||||
# Get domain from general config
|
# 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
|
if [[ -n "$domain" ]]; then
|
||||||
libreportal_external_url="https://libreportal.$domain"
|
libreportal_external_url="https://libreportal.$domain"
|
||||||
else
|
else
|
||||||
@ -64,7 +64,7 @@ getLibrePortalWebUIUrls()
|
|||||||
# Better fallback: try to find any available port for LibrePortal
|
# Better fallback: try to find any available port for LibrePortal
|
||||||
if [[ -z "$libreportal_external_url" ]]; then
|
if [[ -z "$libreportal_external_url" ]]; then
|
||||||
# Try to get any port mapping for LibrePortal
|
# 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
|
if [[ -n "$any_port" ]]; then
|
||||||
local external_port=$(echo "$any_port" | cut -d':' -f1)
|
local external_port=$(echo "$any_port" | cut -d':' -f1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user