Refactor VPN configuration input, handle special cases

This commit is contained in:
Roger Gonzalez 2024-12-30 18:21:03 -03:00
parent f755a2ce20
commit c820e50871
Signed by: rogs
GPG Key ID: C7ECE9C6C36EC2E6
2 changed files with 72 additions and 50 deletions

View File

@ -269,15 +269,25 @@ configure_vpn() {
log_info "Please check $vpn_service's documentation for specific configuration:" log_info "Please check $vpn_service's documentation for specific configuration:"
log_info "https://github.com/qdm12/gluetun-wiki/blob/main/setup/providers/${vpn_service// /-}.md" log_info "https://github.com/qdm12/gluetun-wiki/blob/main/setup/providers/${vpn_service// /-}.md"
log_warning "If you are using ProtonVPN, remember to suffix '+pmp' to your username"
echo echo
read -p "VPN username (without spaces): " vpn_user read -p "VPN username (without spaces): " vpn_user
[ -z "$vpn_user" ] && log_error "VPN username cannot be empty" [ -z "$vpn_user" ] && log_error "VPN username cannot be empty"
# Handle special cases for VPN providers
if [ "$vpn_service" = "protonvpn" ] && [[ ! "$vpn_user" =~ \+pmp$ ]]; then
vpn_user="${vpn_user}+pmp"
log_info "Added +pmp suffix to username for ProtonVPN port forwarding"
fi
# Handle password input based on VPN service
if [ "$vpn_service" = "mullvad" ]; then
vpn_password="$vpn_user"
log_info "Using Mullvad username as password"
else
# Use hidden input for password # Use hidden input for password
unset vpn_password unset vpn_password
charcount=0 charcount=0
prompt="VPN password (if using mullvad, enter username again): " prompt="VPN password: "
while IFS= read -p "$prompt" -r -s -n 1 char; do while IFS= read -p "$prompt" -r -s -n 1 char; do
if [[ $char == $'\0' ]]; then if [[ $char == $'\0' ]]; then
break break
@ -299,6 +309,7 @@ configure_vpn() {
echo echo
[ -z "$vpn_password" ] && log_error "VPN password cannot be empty" [ -z "$vpn_password" ] && log_error "VPN password cannot be empty"
fi
# Export for use in other functions # Export for use in other functions
export vpn_service vpn_user vpn_password setup_vpn export vpn_service vpn_user vpn_password setup_vpn

View File

@ -202,15 +202,25 @@ configure_vpn() {
log_info "Please check $vpn_service's documentation for specific configuration:" log_info "Please check $vpn_service's documentation for specific configuration:"
log_info "https://github.com/qdm12/gluetun-wiki/blob/main/setup/providers/${vpn_service// /-}.md" log_info "https://github.com/qdm12/gluetun-wiki/blob/main/setup/providers/${vpn_service// /-}.md"
log_warning "If you are using ProtonVPN, remember to suffix '+pmp' to your username"
echo echo
read -p "VPN username (without spaces): " vpn_user read -p "VPN username (without spaces): " vpn_user
[ -z "$vpn_user" ] && log_error "VPN username cannot be empty" [ -z "$vpn_user" ] && log_error "VPN username cannot be empty"
# Handle special cases for VPN providers
if [ "$vpn_service" = "protonvpn" ] && [[ ! "$vpn_user" =~ \+pmp$ ]]; then
vpn_user="${vpn_user}+pmp"
log_info "Added +pmp suffix to username for ProtonVPN port forwarding"
fi
# Handle password input based on VPN service
if [ "$vpn_service" = "mullvad" ]; then
vpn_password="$vpn_user"
log_info "Using Mullvad username as password"
else
# Use hidden input for password # Use hidden input for password
unset vpn_password unset vpn_password
charcount=0 charcount=0
prompt="VPN password (if using mullvad, enter username again): " prompt="VPN password: "
while IFS= read -p "$prompt" -r -s -n 1 char; do while IFS= read -p "$prompt" -r -s -n 1 char; do
if [[ $char == $'\0' ]]; then if [[ $char == $'\0' ]]; then
break break
@ -232,6 +242,7 @@ configure_vpn() {
echo echo
[ -z "$vpn_password" ] && log_error "VPN password cannot be empty" [ -z "$vpn_password" ] && log_error "VPN password cannot be empty"
fi
# Export for use in other functions # Export for use in other functions
export vpn_service vpn_user vpn_password setup_vpn export vpn_service vpn_user vpn_password setup_vpn