From 72cac43c0f8c9d87c5302ec4c1e777a9c4fe1a1f Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 13 Oct 2023 08:46:39 +0200 Subject: [PATCH] Added _install_provider() --- installers/common.sh | 91 +++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 194477a9..814b4088 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -411,55 +411,60 @@ function _prompt_install_vpn_providers() { if [ "$answer" != "${answer#[Nn]}" ]; then _install_status 0 "(Skipped)" else - echo -e "Select an option from the list:" - while true; do - json="$webroot_dir/config/"vpn-providers.json - while IFS='|' read -r key value; do - options["$key"]="$value" - done< <(jq -r '.providers[] | "\(.id)|\(.name)|\(.bin_path)"' "$json") - - # display provider options - for key in "${!options[@]}"; do - echo " $key) ${options[$key]%%|*}" - done - echo " 0) None" - echo -n "Choose an option: " - read answer < /dev/tty - - if [ "$answer" != "${answer#[0]}" ]; then - _install_status 0 "(Skipped)" - break - elif [[ "$answer" =~ ^[0-9]+$ ]] && [[ -n ${options[$answer]+abc} ]]; then - selected="${options[$answer]}" - echo "Configuring support for ${selected%%|*}" - bin_path=${selected#*|} - if ! grep -q "$bin_path" "$webroot_dir/installers/raspap.sudoers"; then - echo "Adding $bin_path to raspap.sudoers" - echo "www-data ALL=(ALL) NOPASSWD:$bin_path" | sudo tee -a "$webroot_dir/installers/raspap.sudoers" > /dev/null || _install_status 1 "Unable to modify raspap.sudoers" - fi - echo "Enabling administration option for ${selected%%|*}" - sudo sed -i "s/\('RASPI_VPN_PROVIDER_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php" - - echo "Adding VPN provider to $raspap_dir/provider.ini" - if [ ! -f "$raspap_dir/provider.ini" ]; then - sudo touch "$raspap_dir/provider.ini" - echo "providerID = $answer" | sudo tee "$raspap_dir/provider.ini" > /dev/null || _install_status 1 "Unable to create $raspap_dir/provider.ini" - elif ! grep -q "providerID = $answer" "$raspap_dir/provider.ini"; then - echo "providerID = $answer" | sudo tee "$raspap_dir/provider.ini" > /dev/null || _install_status 1 "Unable to write to $raspap_dir/provider.ini" - fi - - _install_status 0 - break - else - echo "Invalid choice. Select a valid option:" - fi - done + _install_provider fi else echo "(Skipped)" fi } +# Install VPN provider client configuration +function _install_provider() { + echo -e "Select an option from the list:" + while true; do + json="$webroot_dir/config/"vpn-providers.json + while IFS='|' read -r key value; do + options["$key"]="$value" + done< <(jq -r '.providers[] | "\(.id)|\(.name)|\(.bin_path)"' "$json") + + # display provider options + for key in "${!options[@]}"; do + echo " $key) ${options[$key]%%|*}" + done + echo " 0) None" + echo -n "Choose an option: " + read answer < /dev/tty + + if [ "$answer" != "${answer#[0]}" ]; then + _install_status 0 "(Skipped)" + break + elif [[ "$answer" =~ ^[0-9]+$ ]] && [[ -n ${options[$answer]+abc} ]]; then + selected="${options[$answer]}" + echo "Configuring support for ${selected%%|*}" + bin_path=${selected#*|} + if ! grep -q "$bin_path" "$webroot_dir/installers/raspap.sudoers"; then + echo "Adding $bin_path to raspap.sudoers" + echo "www-data ALL=(ALL) NOPASSWD:$bin_path" | sudo tee -a "$webroot_dir/installers/raspap.sudoers" > /dev/null || _install_status 1 "Unable to modify raspap.sudoers" + fi + echo "Enabling administration option for ${selected%%|*}" + sudo sed -i "s/\('RASPI_VPN_PROVIDER_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php" + + echo "Adding VPN provider to $raspap_dir/provider.ini" + if [ ! -f "$raspap_dir/provider.ini" ]; then + sudo touch "$raspap_dir/provider.ini" + echo "providerID = $answer" | sudo tee "$raspap_dir/provider.ini" > /dev/null || _install_status 1 "Unable to create $raspap_dir/provider.ini" + elif ! grep -q "providerID = $answer" "$raspap_dir/provider.ini"; then + echo "providerID = $answer" | sudo tee "$raspap_dir/provider.ini" > /dev/null || _install_status 1 "Unable to write to $raspap_dir/provider.ini" + fi + + _install_status 0 + break + else + echo "Invalid choice. Select a valid option:" + fi + done +} + # Prompt to install openvpn function _prompt_install_openvpn() { _install_log "Configure OpenVPN support"