From 360b9ca28dd48b61e1d5da1f79c5ca2c12ecdd2d Mon Sep 17 00:00:00 2001 From: Norman Date: Mon, 6 Apr 2026 18:34:13 -0400 Subject: [PATCH] update prompt architecture to add install sections. --- debian/configure.sh | 365 ++++++++++++++++++++++++++----------- debian/resources/config.sh | 10 +- debian/resources/git.sh | 70 ++----- 3 files changed, 277 insertions(+), 168 deletions(-) diff --git a/debian/configure.sh b/debian/configure.sh index 477fe5e..c0ec804 100644 --- a/debian/configure.sh +++ b/debian/configure.sh @@ -5,7 +5,7 @@ # It is sourced/called by install.sh BEFORE resources/config.sh is sourced. # # Usage (standalone): ./configure.sh -# Usage (from install): source ./configure.sh OR . ./configure.sh +# Usage (from install): . ./configure.sh #move to the directory this script lives in so relative paths work cd "$(dirname "$0")" 2>/dev/null || true @@ -23,10 +23,7 @@ ask() { printf "%s [%s]: " "$_prompt" "$_default" read -r _input /dev/null; then printf "%s: " "$_prompt" read -r _input # --------------------------------------------------------------------------- ask_bool() { @@ -65,14 +61,34 @@ ask_bool() { read -r _input +# --------------------------------------------------------------------------- +ask_yn() { + _prompt="$1" + _default="$2" + + while true; do + printf "%s (y/n) [%s]: " "$_prompt" "$_default" + read -r _input }" -echo " Credentials will be stored in /root/.git-credentials (mode 600)." -echo " Leave username blank to skip credential store configuration." -echo "" -ask git_username "Git username or email" "" -if [ -n "$git_username" ]; then - ask_secret git_password "Git password or personal access token" +_git_credentials_written=false + +echo "------------------------------------------------------------" +echo " Git Credentials" +echo "------------------------------------------------------------" +echo " Server detected from resources/fusionpbx.sh: ${_git_server:-}" +if ask_yn "Configure git credentials" "y"; then + echo "" + echo " Credentials will be written immediately to /root/.git-credentials (mode 600)." + echo " Leave username blank to skip." + echo "" + ask _git_username "Git username or email" "" + if [ -n "$_git_username" ]; then + ask_secret _git_password "Git password or personal access token" + + # URL-encode characters that would break the credentials file URL format + _enc_user=$(printf '%s' "$_git_username" | sed \ + -e 's/%/%25/g' -e 's/ /%20/g' \ + -e 's/:/%3A/g' -e 's/@/%40/g') + _enc_pass=$(printf '%s' "$_git_password" | sed \ + -e 's/%/%25/g' -e 's/ /%20/g' \ + -e 's/:/%3A/g' -e 's/@/%40/g') + + _CREDS_FILE="/root/.git-credentials" + + # Remove any pre-existing entry for this server to avoid duplicates + if [ -f "$_CREDS_FILE" ]; then + sed -i "/@${_git_server}/d" "$_CREDS_FILE" + fi + + printf 'https://%s:%s@%s\n' "$_enc_user" "$_enc_pass" "$_git_server" \ + >> "$_CREDS_FILE" + chmod 600 "$_CREDS_FILE" + + _git_credentials_written=true + echo " Credentials written to $_CREDS_FILE" + else + echo " No username entered — skipping credential store." + fi + + # Clear sensitive variables immediately + unset _git_password _enc_pass _git_username _enc_user + echo "" else - git_password="" + echo " Skipping git credential configuration." + echo "" fi + +# =========================================================================== +# SUMMARY — read back all settings and ask to confirm +# =========================================================================== +echo "============================================================" +echo " Configuration Summary" +echo "============================================================" +echo "" +echo " Basic Settings" +echo " domain_name = $domain_name" +echo " system_username = $system_username" +echo " system_password = $system_password" +echo " system_branch = $system_branch" +echo " php_version = $php_version" +echo " letsencrypt_folder = $letsencrypt_folder" +echo "" +echo " Advanced Settings (FreeSWITCH / Sofia-Sip / Database)" +echo " switch_branch = $switch_branch" +echo " switch_source = $switch_source" +echo " switch_package = $switch_package" +echo " switch_version = $switch_version" +echo " switch_tls = $switch_tls" +echo " switch_token = ${switch_token:-}" +echo " sofia_version = $sofia_version" +echo " database_name = $database_name" +echo " database_username = $database_username" +echo " database_password = $database_password" +echo " database_repo = $database_repo" +echo " database_version = $database_version" +echo " database_host = $database_host" +echo " database_port = $database_port" +echo " database_backup = $database_backup" +echo "" +echo " Additional Applications" +echo " transcribe = $application_transcribe" +echo " speech = $application_speech" +echo " language_model = $application_language_model" +echo " device_logs = $application_device_logs" +echo " dialplan_tools = $application_dialplan_tools" +echo " edit = $application_edit" +echo " sip_trunks = $application_sip_trunks" +echo "" +echo " Git Credentials" +echo " git_server = ${_git_server:-}" +echo " credentials = ${_git_credentials_written}" +echo "" +echo "============================================================" echo "" -# --------------------------------------------------------------------------- +if ! ask_yn "Continue with installation using these settings" "y"; then + echo "" + echo "Installation cancelled. No changes have been made." + echo "" + exit 1 +fi + +echo "" + +# =========================================================================== # Write config.sh -# --------------------------------------------------------------------------- +# =========================================================================== cat > "$CONFIG_FILE" < Profile -> Personal Auth Token +switch_branch=${switch_branch} # master, stable +switch_source=${switch_source} # true (source compile) or false (binary package) +switch_package=${switch_package} # true (binary package) or false (source compile) +switch_version=${switch_version} # which source code to download, only for source +switch_tls=${switch_tls} # true or false +switch_token=${switch_token} # Get the auth token from https://signalwire.com + # Signup or Login -> Profile -> Personal Auth Token # Sofia-Sip Settings -sofia_version=${sofia_version} # release-version for sofia-sip to use +sofia_version=${sofia_version} # release-version for sofia-sip to use # Database Settings -database_name=${database_name} # Database name (safe characters A-Z, a-z, 0-9) -database_username=${database_username} # Database username (safe characters A-Z, a-z, 0-9) -database_password=${database_password} # random or a custom value (safe characters A-Z, a-z, 0-9) -database_repo=${database_repo} # PostgreSQL official, system -database_version=${database_version} # requires repo official -database_host=${database_host} # hostname or IP address -database_port=${database_port} # port number -database_backup=${database_backup} # true or false +database_name=${database_name} # Database name (safe characters A-Z, a-z, 0-9) +database_username=${database_username} # Database username (safe characters A-Z, a-z, 0-9) +database_password=${database_password} # random or a custom value (safe characters A-Z, a-z, 0-9) +database_repo=${database_repo} # PostgreSQL official, system +database_version=${database_version} # requires repo official +database_host=${database_host} # hostname or IP address +database_port=${database_port} # port number +database_backup=${database_backup} # true or false # General Settings -php_version=${php_version} # PHP version 8.3, 8.2, 8.1 +php_version=${php_version} # PHP version 8.3, 8.2, 8.1 letsencrypt_folder=${letsencrypt_folder} # true or false # Optional Applications -application_transcribe=${application_transcribe} # Speech to Text -application_speech=${application_speech} # Text to Speech -application_language_model=${application_language_model} # Language model -application_device_logs=${application_device_logs} # Log device provision requests -application_dialplan_tools=${application_dialplan_tools} # Add additional dialplan applications -application_edit=${application_edit} # Editor for XML, Provision, Scripts, and PHP -application_sip_trunks=${application_sip_trunks} # Registration-based SIP trunks - -# Git Settings -git_server=${git_server} # Hostname parsed from resources/fusionpbx.sh clone URL -git_username=${git_username} # Git username or email for credential store -git_password=${git_password} # Git password or personal access token +application_transcribe=${application_transcribe} # Speech to Text +application_speech=${application_speech} # Text to Speech +application_language_model=${application_language_model} # Language model +application_device_logs=${application_device_logs} # Log device provision requests +application_dialplan_tools=${application_dialplan_tools} # Add additional dialplan applications +application_edit=${application_edit} # Editor for XML, Provision, Scripts, and PHP +application_sip_trunks=${application_sip_trunks} # Registration-based SIP trunks EOF -# Protect config.sh since it now contains credentials chmod 600 "$CONFIG_FILE" echo "============================================================" diff --git a/debian/resources/config.sh b/debian/resources/config.sh index 48b071e..9474ac2 100755 --- a/debian/resources/config.sh +++ b/debian/resources/config.sh @@ -39,12 +39,4 @@ application_language_model=true # Language model application_device_logs=true # Log device provision requests application_dialplan_tools=false # Add additional dialplan applications application_edit=false # Editor for XML, Provision, Scripts, and PHP -application_sip_trunks=false # Registration-based SIP trunks - -# Git Settings -# git_server is auto-detected from the clone URL in resources/fusionpbx.sh -# by configure.sh at install time. Set manually here only if running git.sh -# standalone without configure.sh. -git_server= # Hostname for the git credential store entry -git_username= # Git username or email for credential store -git_password= # Git password or personal access token \ No newline at end of file +application_sip_trunks=false # Registration-based SIP trunks \ No newline at end of file diff --git a/debian/resources/git.sh b/debian/resources/git.sh index fe22bfa..c3b4005 100644 --- a/debian/resources/git.sh +++ b/debian/resources/git.sh @@ -1,15 +1,12 @@ #!/bin/sh -# git.sh - Configure global git settings for the installer -# - Credential helper pointing to the file-based store -# - ~/.git-credentials entry for the internal git server -# (server hostname is read from git_server in config.sh, which is -# auto-parsed from the clone URL in resources/fusionpbx.sh) -# - safe.directory for /var/www/fusionpbx (needed when git runs -# as root but the directory is owned by www-data) +# git.sh - Apply global git configuration required by the installer +# - credential.helper pointing to /root/.git-credentials +# (the file itself is written by configure.sh before install begins) +# - safe.directory for /var/www/fusionpbx (needed when git runs as root +# but the directory is owned by www-data, git >= 2.35.2 requirement) # -# This script must be called AFTER resources/config.sh has been sourced -# so that git_* variables are available. +# This script must be called after git is installed (handled by install.sh). #move to script directory so all relative paths work cd "$(dirname "$0")" @@ -23,58 +20,17 @@ verbose "Configuring global git settings" CREDENTIALS_FILE="/root/.git-credentials" # --------------------------------------------------------------------------- -# 1. Credential store +# 1. Credential helper +# Wire git to the file-based store that configure.sh already populated. # --------------------------------------------------------------------------- -if [ -n "$git_username" ] && [ -n "$git_password" ] && [ -n "$git_server" ]; then - - # Point git at the file-based credential store - git config --global credential.helper "store --file $CREDENTIALS_FILE" - verbose " credential.helper = store --file $CREDENTIALS_FILE" - - # Build the credential URL: https://user:pass@server - # URL-encode only the characters that would break the URL inside the - # credentials file (@, :, /, space). For most tokens/passwords this - # is sufficient; complex passwords with other special chars should use - # a personal access token instead. - _encoded_user=$(printf '%s' "$git_username" | sed \ - -e 's/%/%25/g' \ - -e 's/ /%20/g' \ - -e 's/:/%3A/g' \ - -e 's/@/%40/g') - _encoded_pass=$(printf '%s' "$git_password" | sed \ - -e 's/%/%25/g' \ - -e 's/ /%20/g' \ - -e 's/:/%3A/g' \ - -e 's/@/%40/g') - - _cred_entry="https://${_encoded_user}:${_encoded_pass}@${git_server}" - - # Write (or replace) the entry for this server in the credentials file. - # Remove any pre-existing line for the same server first to avoid duplicates. - if [ -f "$CREDENTIALS_FILE" ]; then - # Strip existing entries for this server - sed -i "/@${git_server}/d" "$CREDENTIALS_FILE" - fi - - printf '%s\n' "$_cred_entry" >> "$CREDENTIALS_FILE" - chmod 600 "$CREDENTIALS_FILE" - - verbose " credentials written to $CREDENTIALS_FILE" - - # Clear sensitive variables from the environment as soon as they are - # no longer needed. - unset _encoded_pass _cred_entry - -else - verbose " git credentials not configured (git_username or git_password not set)" -fi +git config --global credential.helper "store --file $CREDENTIALS_FILE" +verbose " credential.helper = store --file $CREDENTIALS_FILE" # --------------------------------------------------------------------------- # 2. Safe directory for /var/www/fusionpbx -# Git ≥ 2.35.2 refuses to operate on directories owned by a different -# user. The installer runs as root but chowns the checkout to www-data, -# so subsequent git operations (updates, pulls) fail unless the directory -# is explicitly marked safe. +# Git >= 2.35.2 refuses to operate on directories owned by a different +# user. The installer runs as root but chowns the checkout to www-data, +# so subsequent git operations (updates, pulls) fail without this. # --------------------------------------------------------------------------- git config --global --add safe.directory /var/www/fusionpbx verbose " safe.directory += /var/www/fusionpbx"