|
5 | 5 | # Based on the work of Nyr and contributors at:
|
6 | 6 | # https://github.com/Nyr/wireguard-install
|
7 | 7 | #
|
8 |
| -# Copyright (c) 2022-2023 Lin Song <[email protected]> |
| 8 | +# Copyright (c) 2022-2024 Lin Song <[email protected]> |
9 | 9 | # Copyright (c) 2020-2023 Nyr
|
10 | 10 | #
|
11 | 11 | # Released under the MIT License, see the accompanying file LICENSE.txt
|
|
519 | 519 | show_header2() {
|
520 | 520 | cat <<'EOF'
|
521 | 521 |
|
522 |
| -Copyright (c) 2022-2023 Lin Song |
| 522 | +Copyright (c) 2022-2024 Lin Song |
523 | 523 | Copyright (c) 2020-2023 Nyr
|
524 | 524 | EOF
|
525 | 525 | }
|
@@ -798,10 +798,11 @@ else
|
798 | 798 | echo " 1) Add a new client"
|
799 | 799 | echo " 2) List existing clients"
|
800 | 800 | echo " 3) Remove an existing client"
|
801 |
| - echo " 4) Remove WireGuard" |
802 |
| - echo " 5) Exit" |
| 801 | + echo " 4) Show QR code for a client" |
| 802 | + echo " 5) Remove WireGuard" |
| 803 | + echo " 6) Exit" |
803 | 804 | read -rp "Option: " option
|
804 |
| - until [[ "$option" =~ ^[1-5]$ ]]; do |
| 805 | + until [[ "$option" =~ ^[1-6]$ ]]; do |
805 | 806 | echo "$option: invalid selection."
|
806 | 807 | read -rp "Option: " option
|
807 | 808 | done
|
|
845 | 846 | elif [ -n "$num_of_clients" ]; then
|
846 | 847 | printf '\n%s\n' "Total: $num_of_clients clients"
|
847 | 848 | fi
|
| 849 | + exit |
848 | 850 | ;;
|
849 | 851 | 3)
|
850 | 852 | num_of_clients=$(grep -c '^# BEGIN_PEER' /etc/wireguard/wg0.conf)
|
@@ -893,6 +895,38 @@ else
|
893 | 895 | exit
|
894 | 896 | ;;
|
895 | 897 | 4)
|
| 898 | + num_of_clients=$(grep -c '^# BEGIN_PEER' /etc/wireguard/wg0.conf) |
| 899 | + if [[ "$num_of_clients" = 0 ]]; then |
| 900 | + echo |
| 901 | + echo "There are no existing clients!" |
| 902 | + exit |
| 903 | + fi |
| 904 | + echo |
| 905 | + echo "Select the client to show QR code for:" |
| 906 | + grep '^# BEGIN_PEER' /etc/wireguard/wg0.conf | cut -d ' ' -f 3 | nl -s ') ' |
| 907 | + read -rp "Client: " client_num |
| 908 | + [ -z "$client_num" ] && abort_and_exit |
| 909 | + until [[ "$client_num" =~ ^[0-9]+$ && "$client_num" -le "$num_of_clients" ]]; do |
| 910 | + echo "$client_num: invalid selection." |
| 911 | + read -rp "Client: " client_num |
| 912 | + [ -z "$client_num" ] && abort_and_exit |
| 913 | + done |
| 914 | + client=$(grep '^# BEGIN_PEER' /etc/wireguard/wg0.conf | cut -d ' ' -f 3 | sed -n "$client_num"p) |
| 915 | + echo |
| 916 | + get_export_dir |
| 917 | + wg_file="$export_dir$client.conf" |
| 918 | + if [ ! -f "$wg_file" ]; then |
| 919 | + echo "Error: Cannot show QR code. Missing client config file $wg_file" >&2 |
| 920 | + echo " You may instead re-run this script and add a new client." >&2 |
| 921 | + exit 1 |
| 922 | + fi |
| 923 | + qrencode -t UTF8 < "$wg_file" |
| 924 | + echo -e '\xE2\x86\x91 That is a QR code containing the client configuration.' |
| 925 | + echo |
| 926 | + echo "Configuration for '$client' is available in: $wg_file" |
| 927 | + exit |
| 928 | + ;; |
| 929 | + 5) |
896 | 930 | echo
|
897 | 931 | read -rp "Confirm WireGuard removal? [y/N]: " remove
|
898 | 932 | until [[ "$remove" =~ ^[yYnN]*$ ]]; do
|
@@ -985,7 +1019,7 @@ else
|
985 | 1019 | fi
|
986 | 1020 | exit
|
987 | 1021 | ;;
|
988 |
| - 5) |
| 1022 | + 6) |
989 | 1023 | exit
|
990 | 1024 | ;;
|
991 | 1025 | esac
|
|
0 commit comments