add config file to hanamgr, cleaned up hanamgr prompts

This commit is contained in:
2026-06-24 12:15:31 +02:00
parent bcc6427eea
commit a171fdd1e2
2 changed files with 61 additions and 9 deletions
+60 -8
View File
@@ -1,5 +1,5 @@
#!/bin/bash
# Version: 1.6.0
# Version: 1.7.0
# Author: Tomi Eckert
# ==============================================================================
# HANA Database Manager Menu (hanamgr.sh)
@@ -111,8 +111,12 @@ do_export() {
echo -e "\n\033[1m=== Export Schema ===\033[0m"
select_schema "$GLOBAL_USER_KEY"
local schema_name="$SELECTED_SCHEMA"
read -p "Enter Target Directory or File Path (.tar.gz): " target_path
local default_export_path="/hana/shared/backup/schema"
echo " Without compression: provide a parent directory — the script will create a new subdirectory inside it."
echo " With compression: provide a parent directory (script auto-names the .tar.gz), or a full path ending in .tar.gz (script creates that file)."
read -p "Target path [${default_export_path}]: " target_path
target_path="${target_path:-${default_export_path}}"
local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2))
[[ $half_threads -lt 1 ]] && half_threads=1
@@ -297,7 +301,10 @@ do_copy() {
fi
read -p "Enter Target Schema Name: " target_schema
read -p "Enter Temporary Export Directory Path: " export_path
local default_copy_path="/hana/shared/backup/schema"
echo " Provide a parent directory — the script will create a temporary subdirectory inside it for the intermediate export, then delete it when done."
read -p "Temporary export directory [${default_copy_path}]: " export_path
export_path="${export_path:-${default_copy_path}}"
local max_threads=$(nproc --all 2>/dev/null || echo 1)
local half_threads=$((max_threads / 2))
@@ -448,14 +455,59 @@ do_rename_db() {
check_hdbsql
# --- Config ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="${SCRIPT_DIR}/.hanamgr.conf"
load_config() {
if [[ -f "$CONFIG_FILE" ]]; then
local saved_key
saved_key=$(grep -m1 '^HDBUSERSTORE_KEY=' "$CONFIG_FILE" | cut -d'=' -f2-)
if [[ -n "$saved_key" ]]; then
echo "$saved_key"
fi
fi
}
save_config() {
local key="$1"
if [[ -f "$CONFIG_FILE" ]]; then
# Update existing key entry
sed -i "s|^HDBUSERSTORE_KEY=.*|HDBUSERSTORE_KEY=${key}|" "$CONFIG_FILE"
if ! grep -q '^HDBUSERSTORE_KEY=' "$CONFIG_FILE"; then
echo "HDBUSERSTORE_KEY=${key}" >> "$CONFIG_FILE"
fi
else
echo "HDBUSERSTORE_KEY=${key}" > "$CONFIG_FILE"
fi
}
echo
echo "========================================================"
echo " HANA Database Manager Init "
echo "========================================================"
read -p "Enter HDBUSERSTORE Key: " GLOBAL_USER_KEY
if [[ -z "$GLOBAL_USER_KEY" ]]; then
echo -e "\033[31m[ERROR] Key is required.\033[0m"
exit 1
SAVED_KEY="$(load_config)"
if [[ -n "$SAVED_KEY" ]]; then
read -p "Use saved HDBUSERSTORE key '${SAVED_KEY}'? [Y/n]: " use_saved
use_saved="${use_saved:-Y}"
if [[ "$use_saved" =~ ^[Yy]$ ]]; then
GLOBAL_USER_KEY="$SAVED_KEY"
else
read -p "Enter HDBUSERSTORE Key: " GLOBAL_USER_KEY
if [[ -z "$GLOBAL_USER_KEY" ]]; then
echo -e "\033[31m[ERROR] Key is required.\033[0m"
exit 1
fi
save_config "$GLOBAL_USER_KEY"
fi
else
read -p "Enter HDBUSERSTORE Key: " GLOBAL_USER_KEY
if [[ -z "$GLOBAL_USER_KEY" ]]; then
echo -e "\033[31m[ERROR] Key is required.\033[0m"
exit 1
fi
save_config "$GLOBAL_USER_KEY"
fi
while true; do