#!/bin/bash

# Author: Tomi Eckert
# This script helps to configure backup.conf

# Source the backup.conf to get current values
source backup.conf

HDBSQL_PATH_INPUT=$(which hdbsql)

# Default values if not found
HDBSQL_PATH_INPUT=${HDBSQL_PATH_INPUT:-"/usr/sap/hdbclient/hdbsql"}

# Calculate default threads (half of available)
TOTAL_THREADS=$(nproc --all)
THREADS_DEFAULT=$((TOTAL_THREADS / 2))

# Update backup.conf
sed -i "s#^HDBSQL_PATH=\".*\"#HDBSQL_PATH=\"$HDBSQL_PATH_INPUT\"#" backup.conf
sed -i "s#^THREADS=.\"*\"#THREADS=\"$THREADS_DEFAULT\"#" backup.conf

echo "backup.conf updated successfully!"