mirror of
https://github.com/hwdsl2/wireguard-install.git
synced 2024-09-22 00:00:55 +02:00
Improve user input
- On servers with multiple IPv4, use the IP address on the default route, instead of asking the user to select.
This commit is contained in:
parent
4de37a141b
commit
10d45a7040
|
@ -287,33 +287,37 @@ if [[ ! -e /etc/wireguard/wg0.conf ]]; then
|
||||||
echo
|
echo
|
||||||
echo 'I need to ask you a few questions before starting setup.'
|
echo 'I need to ask you a few questions before starting setup.'
|
||||||
echo 'You can use the default options and just press enter if you are OK with them.'
|
echo 'You can use the default options and just press enter if you are OK with them.'
|
||||||
# If system has a single IPv4, it is selected automatically. Else, ask the user
|
# If system has a single IPv4, it is selected automatically.
|
||||||
if [[ $(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}') -eq 1 ]]; then
|
if [[ $(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}') -eq 1 ]]; then
|
||||||
ip=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}')
|
ip=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}')
|
||||||
else
|
else
|
||||||
find_public_ip
|
# Use the IP address on the default route
|
||||||
ip_match=0
|
ip=$(ip -4 route get 1 | sed 's/ uid .*//' | awk '{print $NF;exit}' 2>/dev/null)
|
||||||
if [ -n "$get_public_ip" ]; then
|
if ! check_ip "$ip"; then
|
||||||
ip_list=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}')
|
find_public_ip
|
||||||
while IFS= read -r line; do
|
ip_match=0
|
||||||
if [ "$line" = "$get_public_ip" ]; then
|
if [ -n "$get_public_ip" ]; then
|
||||||
ip_match=1
|
ip_list=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}')
|
||||||
ip="$line"
|
while IFS= read -r line; do
|
||||||
fi
|
if [ "$line" = "$get_public_ip" ]; then
|
||||||
done <<< "$ip_list"
|
ip_match=1
|
||||||
fi
|
ip="$line"
|
||||||
if [ "$ip_match" = 0 ]; then
|
fi
|
||||||
number_of_ip=$(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}')
|
done <<< "$ip_list"
|
||||||
echo
|
fi
|
||||||
echo "Which IPv4 address should be used?"
|
if [ "$ip_match" = 0 ]; then
|
||||||
ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | nl -s ') '
|
number_of_ip=$(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}')
|
||||||
read -rp "IPv4 address [1]: " ip_number
|
echo
|
||||||
until [[ -z "$ip_number" || "$ip_number" =~ ^[0-9]+$ && "$ip_number" -le "$number_of_ip" ]]; do
|
echo "Which IPv4 address should be used?"
|
||||||
echo "$ip_number: invalid selection."
|
ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | nl -s ') '
|
||||||
read -rp "IPv4 address [1]: " ip_number
|
read -rp "IPv4 address [1]: " ip_number
|
||||||
done
|
until [[ -z "$ip_number" || "$ip_number" =~ ^[0-9]+$ && "$ip_number" -le "$number_of_ip" ]]; do
|
||||||
[[ -z "$ip_number" ]] && ip_number="1"
|
echo "$ip_number: invalid selection."
|
||||||
ip=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | sed -n "$ip_number"p)
|
read -rp "IPv4 address [1]: " ip_number
|
||||||
|
done
|
||||||
|
[[ -z "$ip_number" ]] && ip_number="1"
|
||||||
|
ip=$(ip -4 addr | grep inet | grep -vE '127(\.[0-9]{1,3}){3}' | cut -d '/' -f 1 | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | sed -n "$ip_number"p)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# If $ip is a private IP address, the server must be behind NAT
|
# If $ip is a private IP address, the server must be behind NAT
|
||||||
|
|
Loading…
Reference in New Issue
Block a user