LibrePortal/scripts/database/tables/db_display_tables.sh
librelad 21afae2eff refactor(desudo): drop runtime root from docker_run, sqlite guards, restores
- docker_run: in rooted mode run docker AS the manager via the docker
  group (no sudo); the type=='sudo' branch was unreachable dead code
- 8 db helpers: fix 'command -v sudo sqlite3' guard to 'command -v
  sqlite3' (bodies already query via runInstallOp)
- restic/kopia single-file dump: write target_file via runBackupOp tee
  (as the backup user, matching the snapshot-restore path) instead of
  root tee
- adguard auth: root-owned scratch via runSystem mktemp

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 18:03:36 +01:00

61 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
databaseDisplayTables()
{
if [[ "$toollistalltables" == [yY] ]]; then
local table_number=0
local selected_table=""
local sorted_tables=()
isHeader "View Database Table Data"
while true; do
# Check if sqlite3 is available
if ! command -v sqlite3 &> /dev/null; then
isNotice "sqlite3 command not found. Make sure it's installed."
fi
# Ensure the database file exists
if [ ! -f "$docker_dir/$db_file" ]; then
isNotice "Database file not found: $docker_dir/$db_file"
fi
# Get a list of existing tables in the database
local tables_list=($(runInstallOp sqlite3 "$docker_dir/$db_file" ".tables"))
# Sort the tables alphabetically
sorted_tables=($(printf "%s\n" "${tables_list[@]}" | sort))
# Check if there are any tables in the database
if [ "${#sorted_tables[@]}" -eq 0 ]; then
isError "No tables found in the database."
fi
table_number=0
for table_name in "${sorted_tables[@]}"; do
table_number=$((table_number+1))
echo "$table_number. $table_name"
done
echo ""
isQuestion "Enter the number of the table to view data (x to exit): "
read -p "" selected_table
if [[ "$selected_table" == "x" ]]; then
echo ""
echo "Exiting."
elif [[ "$selected_table" =~ ^[0-9]+$ ]] && ((selected_table >= 1)) && ((selected_table <= "${#sorted_tables[@]}")); then
selected_table="${sorted_tables[$((selected_table-1))]}"
# Display all data for the selected table with formatted output
isHeader "Displaying $selected_table Table Data"
runInstallOp sqlite3 -column -header "$docker_dir/$db_file" "SELECT * FROM $selected_table;"
echo ""
isQuestion "Press Enter to continue..."
read -p "" input
else
isNotice "Invalid table number. Please try again."
fi
done
fi
}