mirror of
				https://github.com/billz/raspap-webgui.git
				synced 2025-03-01 10:31:47 +00:00 
			
		
		
		
	Add --provider non-interactive option to installer
This commit is contained in:
		| @@ -419,6 +419,8 @@ function _prompt_install_vpn_providers() { | ||||
|         else | ||||
|             _install_provider | ||||
|         fi | ||||
|     elif [[ "$pv_option" =~ ^[0-9]+$ ]]; then | ||||
|         _install_provider | ||||
|     else | ||||
|         echo "(Skipped)" | ||||
|     fi | ||||
| @@ -426,49 +428,60 @@ function _prompt_install_vpn_providers() { | ||||
|  | ||||
| # 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 | ||||
|     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") | ||||
|  | ||||
|         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 | ||||
|     if [ -n "$pv_option" ]; then | ||||
|         if [[ -n ${options[$pv_option]+abc} ]]; then | ||||
|             answer="$pv_option" | ||||
|         else | ||||
|             echo "Invalid choice. Select a valid option:" | ||||
|             echo "Invalid choice. The specified option does not exist." | ||||
|             return 1 | ||||
|         fi | ||||
|     done | ||||
|     else | ||||
|         echo -e "Select an option from the list:" | ||||
|         while true; do | ||||
|             # 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 | ||||
|                 break | ||||
|             else | ||||
|                 echo "Invalid choice. Select a valid option:" | ||||
|             fi | ||||
|         done | ||||
|     fi | ||||
|  | ||||
|     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 | ||||
| } | ||||
|  | ||||
| # Prompt to install openvpn | ||||
|   | ||||
| @@ -42,6 +42,7 @@ OPTIONS: | ||||
| -o, --openvpn <flag>                Used with -y, --yes, sets OpenVPN install option (0=no install) | ||||
| -a, --adblock <flag>                Used with -y, --yes, sets Adblock install option (0=no install) | ||||
| -w, --wireguard <flag>              Used with -y, --yes, sets WireGuard install option (0=no install) | ||||
| -e, --provider <value>              Used with -y, --yes, sets the VPN provider install option | ||||
| -r, --repo, --repository <name>     Overrides the default GitHub repo (RaspAP/raspap-webgui) | ||||
| -b, --branch <name>                 Overrides the default git branch (latest release) | ||||
| -t, --token <accesstoken>           Specify a GitHub token to access a private repository | ||||
| @@ -118,6 +119,10 @@ function _parse_params() { | ||||
|             wg_option="$2" | ||||
|             shift | ||||
|             ;; | ||||
|             -e|--provider) | ||||
|             pv_option="$2" | ||||
|             shift | ||||
|             ;; | ||||
|             -c|--cert|--certificate) | ||||
|             install_cert=1 | ||||
|             ;; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user