Add --provider non-interactive option to installer

This commit is contained in:
billz 2024-02-01 08:51:55 +00:00
parent ccbdf8dccf
commit 38a84fc258
2 changed files with 57 additions and 39 deletions

View file

@ -419,6 +419,8 @@ function _prompt_install_vpn_providers() {
else else
_install_provider _install_provider
fi fi
elif [[ "$pv_option" =~ ^[0-9]+$ ]]; then
_install_provider
else else
echo "(Skipped)" echo "(Skipped)"
fi fi
@ -426,49 +428,60 @@ function _prompt_install_vpn_providers() {
# Install VPN provider client configuration # Install VPN provider client configuration
function _install_provider() { 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 json="$webroot_dir/config/"vpn-providers.json
for key in "${!options[@]}"; do while IFS='|' read -r key value; do
echo " $key) ${options[$key]%%|*}" options["$key"]="$value"
done done< <(jq -r '.providers[] | "\(.id)|\(.name)|\(.bin_path)"' "$json")
echo " 0) None"
echo -n "Choose an option: "
read answer < /dev/tty
if [ "$answer" != "${answer#[0]}" ]; then if [ -n "$pv_option" ]; then
_install_status 0 "(Skipped)" if [[ -n ${options[$pv_option]+abc} ]]; then
break answer="$pv_option"
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 else
echo "Invalid choice. Select a valid option:" echo "Invalid choice. The specified option does not exist."
return 1
fi 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 # Prompt to install openvpn

View file

@ -42,6 +42,7 @@ OPTIONS:
-o, --openvpn <flag> Used with -y, --yes, sets OpenVPN install option (0=no install) -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) -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) -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) -r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
-b, --branch <name> Overrides the default git branch (latest release) -b, --branch <name> Overrides the default git branch (latest release)
-t, --token <accesstoken> Specify a GitHub token to access a private repository -t, --token <accesstoken> Specify a GitHub token to access a private repository
@ -118,6 +119,10 @@ function _parse_params() {
wg_option="$2" wg_option="$2"
shift shift
;; ;;
-e|--provider)
pv_option="$2"
shift
;;
-c|--cert|--certificate) -c|--cert|--certificate)
install_cert=1 install_cert=1
;; ;;