From d070ba5c4e93b6fd92f3eba66511fdfc28f98dc5 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Tue, 29 Oct 2024 20:40:57 +0700 Subject: [PATCH 01/16] feat: add awg install to install.sh --- install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 22fce74..90e20f7 100755 --- a/install.sh +++ b/install.sh @@ -48,8 +48,7 @@ while true; do ;; 3) - echo "As long as it's not automated" - printf "\e[1;32mUse script from here https://github.com/Slava-Shchipunov/awg-openwrt\e[0m\n" + sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/awg-openwrt/refs/heads/master/amneziawg-install.sh) break ;; From bdcbba137679bc4665d14b4f88b836f6e23a738d Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 30 Oct 2024 09:29:11 +0700 Subject: [PATCH 02/16] feat: add awg install script --- install.sh | 2 +- utils/amneziawg-install.sh | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 utils/amneziawg-install.sh diff --git a/install.sh b/install.sh index 90e20f7..953ee5b 100755 --- a/install.sh +++ b/install.sh @@ -48,7 +48,7 @@ while true; do ;; 3) - sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/awg-openwrt/refs/heads/master/amneziawg-install.sh) + sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/amneziawg-install.sh) break ;; diff --git a/utils/amneziawg-install.sh b/utils/amneziawg-install.sh new file mode 100644 index 0000000..424666f --- /dev/null +++ b/utils/amneziawg-install.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +install_awg_packages() { + # Получение pkgarch с наибольшим приоритетом + PKGARCH=$(opkg print-architecture | awk 'BEGIN {max=0} {if ($3 > max) {max = $3; arch = $2}} END {print arch}') + + TARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 1) + SUBTARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 2) + VERSION=$(ubus call system board | jsonfilter -e '@.release.version') + PKGPOSTFIX="_v${VERSION}_${PKGARCH}_${TARGET}_${SUBTARGET}.ipk" + BASE_URL="https://github.com/Slava-Shchipunov/awg-openwrt/releases/download/" + + AWG_DIR="/tmp/amneziawg" + mkdir -p "$AWG_DIR" + + if opkg list-installed | grep -q kmod-amneziawg; then + echo "kmod-amneziawg already installed" + else + KMOD_AMNEZIAWG_FILENAME="kmod-amneziawg${PKGPOSTFIX}" + DOWNLOAD_URL="${BASE_URL}v${VERSION}/${KMOD_AMNEZIAWG_FILENAME}" + wget -O "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL" + + if [ $? -eq 0 ]; then + echo "kmod-amneziawg file downloaded successfully" + else + echo "Error downloading kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again" + exit 1 + fi + + opkg install "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" + + if [ $? -eq 0 ]; then + echo "kmod-amneziawg file downloaded successfully" + else + echo "Error installing kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again" + exit 1 + fi + fi + + if opkg list-installed | grep -q amneziawg-tools; then + echo "amneziawg-tools already installed" + else + AMNEZIAWG_TOOLS_FILENAME="amneziawg-tools${PKGPOSTFIX}" + DOWNLOAD_URL="${BASE_URL}v${VERSION}/${AMNEZIAWG_TOOLS_FILENAME}" + wget -O "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" "$DOWNLOAD_URL" + + if [ $? -eq 0 ]; then + echo "amneziawg-tools file downloaded successfully" + else + echo "Error downloading amneziawg-tools. Please, install amneziawg-tools manually and run the script again" + exit 1 + fi + + opkg install "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" + + if [ $? -eq 0 ]; then + echo "amneziawg-tools file downloaded successfully" + else + echo "Error installing amneziawg-tools. Please, install amneziawg-tools manually and run the script again" + exit 1 + fi + fi + + if opkg list-installed | grep -q luci-app-amneziawg; then + echo "luci-app-amneziawg already installed" + else + LUCI_APP_AMNEZIAWG_FILENAME="luci-app-amneziawg${PKGPOSTFIX}" + DOWNLOAD_URL="${BASE_URL}v${VERSION}/${LUCI_APP_AMNEZIAWG_FILENAME}" + wget -O "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL" + + if [ $? -eq 0 ]; then + echo "luci-app-amneziawg file downloaded successfully" + else + echo "Error downloading luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again" + exit 1 + fi + + opkg install "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" + + if [ $? -eq 0 ]; then + echo "luci-app-amneziawg file downloaded successfully" + else + echo "Error installing luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again" + exit 1 + fi + fi + + rm -rf "$AWG_DIR" +} + +install_awg_packages From 0c8896bb6fda3db5071b64b7dbd711ccf6146f17 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 30 Oct 2024 10:00:38 +0700 Subject: [PATCH 03/16] feat: add wg_awg_setup script --- install.sh | 1 + utils/wg-awg-setup.sh | 110 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 utils/wg-awg-setup.sh diff --git a/install.sh b/install.sh index 953ee5b..fd6e2d1 100755 --- a/install.sh +++ b/install.sh @@ -49,6 +49,7 @@ while true; do 3) sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/amneziawg-install.sh) + sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg_awg_setup.sh) AmneziaWG break ;; diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh new file mode 100644 index 0000000..f2f33de --- /dev/null +++ b/utils/wg-awg-setup.sh @@ -0,0 +1,110 @@ +wg_awg_setup() { + PROTOCOL_NAME=$1 + printf "\033[32;1mConfigure ${PROTOCOL_NAME}\033[0m\n" + if [ "$PROTOCOL_NAME" = 'Wireguard' ]; then + INTERFACE_NAME="wg0" + CONFIG_NAME="wireguard_wg0" + PROTO="wireguard" + ZONE_NAME="wg" + fi + + if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then + INTERFACE_NAME="awg0" + CONFIG_NAME="amneziawg_awg0" + PROTO="amneziawg" + ZONE_NAME="awg" + fi + + read -r -p "Enter the private key (from [Interface]):"$'\n' WG_PRIVATE_KEY_INT + + while true; do + read -r -p "Enter internal IP address with subnet, example 192.168.100.5/24 (from [Interface]):"$'\n' WG_IP + if echo "$WG_IP" | egrep -oq '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]+$'; then + break + else + echo "This IP is not valid. Please repeat" + fi + done + + read -r -p "Enter the public key (from [Peer]):"$'\n' WG_PUBLIC_KEY_INT + read -r -p "If use PresharedKey, Enter this (from [Peer]). If your don't use leave blank:"$'\n' WG_PRESHARED_KEY_INT + read -r -p "Enter Endpoint host without port (Domain or IP) (from [Peer]):"$'\n' WG_ENDPOINT_INT + + read -r -p "Enter Endpoint host port (from [Peer]) [51820]:"$'\n' WG_ENDPOINT_PORT_INT + WG_ENDPOINT_PORT_INT=${WG_ENDPOINT_PORT_INT:-51820} + if [ "$WG_ENDPOINT_PORT_INT" = '51820' ]; then + echo $WG_ENDPOINT_PORT_INT + fi + + if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then + read -r -p "Enter Jc value (from [Interface]):"$'\n' AWG_JC + read -r -p "Enter Jmin value (from [Interface]):"$'\n' AWG_JMIN + read -r -p "Enter Jmax value (from [Interface]):"$'\n' AWG_JMAX + read -r -p "Enter S1 value (from [Interface]):"$'\n' AWG_S1 + read -r -p "Enter S2 value (from [Interface]):"$'\n' AWG_S2 + read -r -p "Enter H1 value (from [Interface]):"$'\n' AWG_H1 + read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2 + read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3 + read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 + fi + + uci set network.${INTERFACE_NAME}=interface + uci set network.${INTERFACE_NAME}.proto=$PROTO + uci set network.${INTERFACE_NAME}.private_key=$WG_PRIVATE_KEY_INT + uci set network.${INTERFACE_NAME}.listen_port='51821' + uci set network.${INTERFACE_NAME}.addresses=$WG_IP + + if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then + uci set network.${INTERFACE_NAME}.awg_jc=$AWG_JC + uci set network.${INTERFACE_NAME}.awg_jmin=$AWG_JMIN + uci set network.${INTERFACE_NAME}.awg_jmax=$AWG_JMAX + uci set network.${INTERFACE_NAME}.awg_s1=$AWG_S1 + uci set network.${INTERFACE_NAME}.awg_s2=$AWG_S2 + uci set network.${INTERFACE_NAME}.awg_h1=$AWG_H1 + uci set network.${INTERFACE_NAME}.awg_h2=$AWG_H2 + uci set network.${INTERFACE_NAME}.awg_h3=$AWG_H3 + uci set network.${INTERFACE_NAME}.awg_h4=$AWG_H4 + fi + + if ! uci show network | grep -q ${CONFIG_NAME}; then + uci add network ${CONFIG_NAME} + fi + + uci set network.@${CONFIG_NAME}[0]=$CONFIG_NAME + uci set network.@${CONFIG_NAME}[0].name="${INTERFACE_NAME}_client" + uci set network.@${CONFIG_NAME}[0].public_key=$WG_PUBLIC_KEY_INT + uci set network.@${CONFIG_NAME}[0].preshared_key=$WG_PRESHARED_KEY_INT + uci set network.@${CONFIG_NAME}[0].route_allowed_ips='0' + uci set network.@${CONFIG_NAME}[0].persistent_keepalive='25' + uci set network.@${CONFIG_NAME}[0].endpoint_host=$WG_ENDPOINT_INT + uci set network.@${CONFIG_NAME}[0].allowed_ips='0.0.0.0/0' + uci set network.@${CONFIG_NAME}[0].endpoint_port=$WG_ENDPOINT_PORT_INT + uci commit network + + if ! uci show firewall | grep -q "@zone.*name='${ZONE_NAME}'"; then + printf "\033[32;1mZone Create\033[0m\n" + uci add firewall zone + uci set firewall.@zone[-1].name=$ZONE_NAME + uci set firewall.@zone[-1].network=$INTERFACE_NAME + uci set firewall.@zone[-1].forward='REJECT' + uci set firewall.@zone[-1].output='ACCEPT' + uci set firewall.@zone[-1].input='REJECT' + uci set firewall.@zone[-1].masq='1' + uci set firewall.@zone[-1].mtu_fix='1' + uci set firewall.@zone[-1].family='ipv4' + uci commit firewall + fi + + if ! uci show firewall | grep -q "@forwarding.*name='${ZONE_NAME}'"; then + printf "\033[32;1mConfigured forwarding\033[0m\n" + uci add firewall forwarding + uci set firewall.@forwarding[-1]=forwarding + uci set firewall.@forwarding[-1].name="${ZONE_NAME}-lan" + uci set firewall.@forwarding[-1].dest=${ZONE_NAME} + uci set firewall.@forwarding[-1].src='lan' + uci set firewall.@forwarding[-1].family='ipv4' + uci commit firewall + fi + + service network restart +} From 415b5df621d10057fcb08119d7decbcde08937f0 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 30 Oct 2024 10:13:57 +0700 Subject: [PATCH 04/16] fix: fix run wg-awg-setup --- install.sh | 2 +- utils/wg-awg-setup.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index fd6e2d1..54cc62b 100755 --- a/install.sh +++ b/install.sh @@ -49,7 +49,7 @@ while true; do 3) sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/amneziawg-install.sh) - sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg_awg_setup.sh) AmneziaWG + sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg-awg-setup.sh) AmneziaWG break ;; diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh index f2f33de..3cdc70d 100644 --- a/utils/wg-awg-setup.sh +++ b/utils/wg-awg-setup.sh @@ -108,3 +108,5 @@ wg_awg_setup() { service network restart } + +wg_awg_setup "$1" From 7b9f7ba6051622e2f21b3526396cc1833669b4aa Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Wed, 30 Oct 2024 10:23:52 +0700 Subject: [PATCH 05/16] fix: move network restart run --- install.sh | 5 ++++- utils/wg-awg-setup.sh | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 54cc62b..8217421 100755 --- a/install.sh +++ b/install.sh @@ -80,4 +80,7 @@ echo "Installed podkop..." opkg install $DOWNLOAD_DIR/podkop*.ipk opkg install $DOWNLOAD_DIR/luci-app-podkop*.ipk -rm -f $DOWNLOAD_DIR/podkop*.ipk $DOWNLOAD_DIR/luci-app-podkop*.ipk \ No newline at end of file +rm -f $DOWNLOAD_DIR/podkop*.ipk $DOWNLOAD_DIR/luci-app-podkop*.ipk + +printf "\033[32;1mRestart network\033[0m\n" +service network restart diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh index 3cdc70d..bb79cb2 100644 --- a/utils/wg-awg-setup.sh +++ b/utils/wg-awg-setup.sh @@ -105,8 +105,6 @@ wg_awg_setup() { uci set firewall.@forwarding[-1].family='ipv4' uci commit firewall fi - - service network restart } wg_awg_setup "$1" From 65efe20fd275a0f69c4e093aefbd5e7e3c17d2fd Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Fri, 1 Nov 2024 17:26:31 +0700 Subject: [PATCH 06/16] feat: add wg auto setup --- install.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 8217421..6c412ec 100755 --- a/install.sh +++ b/install.sh @@ -43,13 +43,30 @@ while true; do 2) opkg install wireguard-tools luci-proto-wireguard luci-app-wireguard - printf "\e[1;32mUse these instructions to configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" + + printf "\033[32;1mDo you want to configure the wireguard interface? (y/n): \033[0m\n" + read IS_SHOULD_CONFIGURE_WG_INTERFACE + + if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then + sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg-awg-setup.sh) Wireguard + else + printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" + fi + break ;; 3) sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/amneziawg-install.sh) - sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg-awg-setup.sh) AmneziaWG + + + printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n" + read IS_SHOULD_CONFIGURE_WG_INTERFACE + + if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then + sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg-awg-setup.sh) AmneziaWG + fi + break ;; From 708cbe5a972aa83691b0cef0bffc941261d57ba6 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Fri, 1 Nov 2024 17:54:33 +0700 Subject: [PATCH 07/16] feat: add wg obfuscation --- utils/wg-awg-setup.sh | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh index bb79cb2..942cac4 100644 --- a/utils/wg-awg-setup.sh +++ b/utils/wg-awg-setup.sh @@ -6,6 +6,7 @@ wg_awg_setup() { CONFIG_NAME="wireguard_wg0" PROTO="wireguard" ZONE_NAME="wg" + CONFIG_TYPE="wg" fi if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then @@ -13,6 +14,11 @@ wg_awg_setup() { CONFIG_NAME="amneziawg_awg0" PROTO="amneziawg" ZONE_NAME="awg" + + echo "Do you want to use AmneziaWG config or basic Wireguard config + automatic obfuscation?" + echo "1) AmneziaWG" + echo "2) Wireguard + automatic obfuscation" + read CONFIG_TYPE fi read -r -p "Enter the private key (from [Interface]):"$'\n' WG_PRIVATE_KEY_INT @@ -37,15 +43,28 @@ wg_awg_setup() { fi if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then - read -r -p "Enter Jc value (from [Interface]):"$'\n' AWG_JC - read -r -p "Enter Jmin value (from [Interface]):"$'\n' AWG_JMIN - read -r -p "Enter Jmax value (from [Interface]):"$'\n' AWG_JMAX - read -r -p "Enter S1 value (from [Interface]):"$'\n' AWG_S1 - read -r -p "Enter S2 value (from [Interface]):"$'\n' AWG_S2 - read -r -p "Enter H1 value (from [Interface]):"$'\n' AWG_H1 - read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2 - read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3 - read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 + if [ "$CONFIG_TYPE" = '1' ]; then + read -r -p "Enter Jc value (from [Interface]):"$'\n' AWG_JC + read -r -p "Enter Jmin value (from [Interface]):"$'\n' AWG_JMIN + read -r -p "Enter Jmax value (from [Interface]):"$'\n' AWG_JMAX + read -r -p "Enter S1 value (from [Interface]):"$'\n' AWG_S1 + read -r -p "Enter S2 value (from [Interface]):"$'\n' AWG_S2 + read -r -p "Enter H1 value (from [Interface]):"$'\n' AWG_H1 + read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2 + read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3 + read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 + else if [ "$CONFIG_TYPE" = '2' ]; then + #Default values to wg automatic obfuscation + AWG_JC=3 + AWG_JMIN=40 + AWG_JMAX=70 + AWG_S1=0 + AWG_S2=0 + AWG_H1=1 + AWG_H2=2 + AWG_H3=3 + AWG_H4=4 + fi fi uci set network.${INTERFACE_NAME}=interface From afe96ff29504ecf82705673354cd4abb66a6d1ec Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Fri, 1 Nov 2024 18:07:56 +0700 Subject: [PATCH 08/16] fix: fix syntax error --- utils/wg-awg-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh index 942cac4..938761a 100644 --- a/utils/wg-awg-setup.sh +++ b/utils/wg-awg-setup.sh @@ -53,7 +53,7 @@ wg_awg_setup() { read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2 read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3 read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 - else if [ "$CONFIG_TYPE" = '2' ]; then + elif [ "$CONFIG_TYPE" = '2' ]; then #Default values to wg automatic obfuscation AWG_JC=3 AWG_JMIN=40 From 9754708fc16337a0e448835076d10f1a8187f8c7 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Fri, 1 Nov 2024 20:25:37 +0700 Subject: [PATCH 09/16] refactor: add raw base url --- install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 6c412ec..73e6cad 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,7 @@ #!/bin/sh REPO="https://api.github.com/repos/itdoginfo/podkop/releases/latest" +BASE_RAW_URL="https://raw.githubusercontent.com/itdoginfo/domain-routing-openwrt/refs/heads/main" DOWNLOAD_DIR="/tmp/podkop" mkdir -p "$DOWNLOAD_DIR" @@ -48,7 +49,7 @@ while true; do read IS_SHOULD_CONFIGURE_WG_INTERFACE if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg-awg-setup.sh) Wireguard + sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh) Wireguard else printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" fi @@ -57,14 +58,14 @@ while true; do ;; 3) - sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/amneziawg-install.sh) + sh <(wget -O - "$BASE_RAW_URL/utils/amneziawg-install.sh) printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n" read IS_SHOULD_CONFIGURE_WG_INTERFACE if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - https://raw.githubusercontent.com/Slava-Shchipunov/podkop/refs/heads/feat/add-amneziawg-auto-install/utils/wg-awg-setup.sh) AmneziaWG + sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh) AmneziaWG fi break From 2524e08096a7b1acb7abedd657ec171f45401d46 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Fri, 1 Nov 2024 20:33:27 +0700 Subject: [PATCH 10/16] feat: update obfuscation Jc --- utils/wg-awg-setup.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh index 938761a..c4ebbc1 100644 --- a/utils/wg-awg-setup.sh +++ b/utils/wg-awg-setup.sh @@ -6,7 +6,6 @@ wg_awg_setup() { CONFIG_NAME="wireguard_wg0" PROTO="wireguard" ZONE_NAME="wg" - CONFIG_TYPE="wg" fi if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then @@ -55,7 +54,7 @@ wg_awg_setup() { read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 elif [ "$CONFIG_TYPE" = '2' ]; then #Default values to wg automatic obfuscation - AWG_JC=3 + AWG_JC=4 AWG_JMIN=40 AWG_JMAX=70 AWG_S1=0 From 8cf9f4b61b881a45a9adf60089e44c8c7238c693 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Fri, 1 Nov 2024 21:22:40 +0700 Subject: [PATCH 11/16] fix: add lost quotation mark --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 73e6cad..619e622 100755 --- a/install.sh +++ b/install.sh @@ -49,7 +49,7 @@ while true; do read IS_SHOULD_CONFIGURE_WG_INTERFACE if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh) Wireguard + sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") Wireguard else printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" fi @@ -58,14 +58,14 @@ while true; do ;; 3) - sh <(wget -O - "$BASE_RAW_URL/utils/amneziawg-install.sh) + sh <(wget -O - "$BASE_RAW_URL/utils/amneziawg-install.sh") printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n" read IS_SHOULD_CONFIGURE_WG_INTERFACE if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh) AmneziaWG + sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") AmneziaWG fi break From fe245c31c37b34030d5d7fd711f99e98647b12f4 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Sun, 3 Nov 2024 22:13:16 +0700 Subject: [PATCH 12/16] refactor: move add tunnel to function --- install.sh | 114 +++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/install.sh b/install.sh index 619e622..8036d50 100755 --- a/install.sh +++ b/install.sh @@ -25,74 +25,78 @@ else [ -f /etc/config/dhcp-opkg ] && cp /etc/config/dhcp /etc/config/dhcp-old && mv /etc/config/dhcp-opkg /etc/config/dhcp fi -echo "What type of VPN or proxy will be used?" -echo "1) VLESS, Shadowsocks (A sing-box will be installed)" -echo "2) Wireguard" -echo "3) AmneziaWG" -echo "4) OpenVPN" -echo "5) OpenConnect" -echo "6) Skip this step" +add_tunnel() { + echo "What type of VPN or proxy will be used?" + echo "1) VLESS, Shadowsocks (A sing-box will be installed)" + echo "2) Wireguard" + echo "3) AmneziaWG" + echo "4) OpenVPN" + echo "5) OpenConnect" + echo "6) Skip this step" -while true; do - read -r -p '' TUNNEL - case $TUNNEL in + while true; do + read -r -p '' TUNNEL + case $TUNNEL in - 1) - opkg install sing-box - break - ;; + 1) + opkg install sing-box + break + ;; - 2) - opkg install wireguard-tools luci-proto-wireguard luci-app-wireguard + 2) + opkg install wireguard-tools luci-proto-wireguard luci-app-wireguard - printf "\033[32;1mDo you want to configure the wireguard interface? (y/n): \033[0m\n" - read IS_SHOULD_CONFIGURE_WG_INTERFACE + printf "\033[32;1mDo you want to configure the wireguard interface? (y/n): \033[0m\n" + read IS_SHOULD_CONFIGURE_WG_INTERFACE - if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") Wireguard - else - printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" - fi + if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then + sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") Wireguard + else + printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" + fi - break - ;; + break + ;; - 3) - sh <(wget -O - "$BASE_RAW_URL/utils/amneziawg-install.sh") - - - printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n" - read IS_SHOULD_CONFIGURE_WG_INTERFACE + 3) + sh <(wget -O - "$BASE_RAW_URL/utils/amneziawg-install.sh") + + + printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n" + read IS_SHOULD_CONFIGURE_WG_INTERFACE - if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") AmneziaWG - fi + if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then + sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") AmneziaWG + fi - break - ;; + break + ;; - 4) - opkg install opkg install openvpn-openssl luci-app-openvpn - printf "\e[1;32mUse these instructions to configure https://itdog.info/nastrojka-klienta-openvpn-na-openwrt/\e[0m\n" - break - ;; + 4) + opkg install opkg install openvpn-openssl luci-app-openvpn + printf "\e[1;32mUse these instructions to configure https://itdog.info/nastrojka-klienta-openvpn-na-openwrt/\e[0m\n" + break + ;; - 5) - opkg install opkg install openconnect luci-proto-openconnect - printf "\e[1;32mUse these instructions to configure https://itdog.info/nastrojka-klienta-openconnect-na-openwrt/\e[0m\n" - break - ;; + 5) + opkg install opkg install openconnect luci-proto-openconnect + printf "\e[1;32mUse these instructions to configure https://itdog.info/nastrojka-klienta-openconnect-na-openwrt/\e[0m\n" + break + ;; - 6) - echo "Skip. Use this if you're installing an upgrade." - break - ;; + 6) + echo "Skip. Use this if you're installing an upgrade." + break + ;; - *) - echo "Choose from the following options" - ;; - esac -done + *) + echo "Choose from the following options" + ;; + esac + done +} + +add_tunnel echo "Installed podkop..." opkg install $DOWNLOAD_DIR/podkop*.ipk From a53adb2df147fdda32dae4b5a60aa602ab2d85d3 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Sun, 3 Nov 2024 22:16:34 +0700 Subject: [PATCH 13/16] refactor: move install awg packages to install.sh --- install.sh | 93 ++++++++++++++++++++++++++++++++++++-- utils/amneziawg-install.sh | 91 ------------------------------------- 2 files changed, 90 insertions(+), 94 deletions(-) delete mode 100644 utils/amneziawg-install.sh diff --git a/install.sh b/install.sh index 8036d50..bcdffae 100755 --- a/install.sh +++ b/install.sh @@ -25,6 +25,94 @@ else [ -f /etc/config/dhcp-opkg ] && cp /etc/config/dhcp /etc/config/dhcp-old && mv /etc/config/dhcp-opkg /etc/config/dhcp fi +install_awg_packages() { + # Получение pkgarch с наибольшим приоритетом + PKGARCH=$(opkg print-architecture | awk 'BEGIN {max=0} {if ($3 > max) {max = $3; arch = $2}} END {print arch}') + + TARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 1) + SUBTARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 2) + VERSION=$(ubus call system board | jsonfilter -e '@.release.version') + PKGPOSTFIX="_v${VERSION}_${PKGARCH}_${TARGET}_${SUBTARGET}.ipk" + BASE_URL="https://github.com/Slava-Shchipunov/awg-openwrt/releases/download/" + + AWG_DIR="/tmp/amneziawg" + mkdir -p "$AWG_DIR" + + if opkg list-installed | grep -q kmod-amneziawg; then + echo "kmod-amneziawg already installed" + else + KMOD_AMNEZIAWG_FILENAME="kmod-amneziawg${PKGPOSTFIX}" + DOWNLOAD_URL="${BASE_URL}v${VERSION}/${KMOD_AMNEZIAWG_FILENAME}" + wget -O "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL" + + if [ $? -eq 0 ]; then + echo "kmod-amneziawg file downloaded successfully" + else + echo "Error downloading kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again" + exit 1 + fi + + opkg install "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" + + if [ $? -eq 0 ]; then + echo "kmod-amneziawg file downloaded successfully" + else + echo "Error installing kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again" + exit 1 + fi + fi + + if opkg list-installed | grep -q amneziawg-tools; then + echo "amneziawg-tools already installed" + else + AMNEZIAWG_TOOLS_FILENAME="amneziawg-tools${PKGPOSTFIX}" + DOWNLOAD_URL="${BASE_URL}v${VERSION}/${AMNEZIAWG_TOOLS_FILENAME}" + wget -O "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" "$DOWNLOAD_URL" + + if [ $? -eq 0 ]; then + echo "amneziawg-tools file downloaded successfully" + else + echo "Error downloading amneziawg-tools. Please, install amneziawg-tools manually and run the script again" + exit 1 + fi + + opkg install "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" + + if [ $? -eq 0 ]; then + echo "amneziawg-tools file downloaded successfully" + else + echo "Error installing amneziawg-tools. Please, install amneziawg-tools manually and run the script again" + exit 1 + fi + fi + + if opkg list-installed | grep -q luci-app-amneziawg; then + echo "luci-app-amneziawg already installed" + else + LUCI_APP_AMNEZIAWG_FILENAME="luci-app-amneziawg${PKGPOSTFIX}" + DOWNLOAD_URL="${BASE_URL}v${VERSION}/${LUCI_APP_AMNEZIAWG_FILENAME}" + wget -O "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL" + + if [ $? -eq 0 ]; then + echo "luci-app-amneziawg file downloaded successfully" + else + echo "Error downloading luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again" + exit 1 + fi + + opkg install "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" + + if [ $? -eq 0 ]; then + echo "luci-app-amneziawg file downloaded successfully" + else + echo "Error installing luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again" + exit 1 + fi + fi + + rm -rf "$AWG_DIR" +} + add_tunnel() { echo "What type of VPN or proxy will be used?" echo "1) VLESS, Shadowsocks (A sing-box will be installed)" @@ -59,9 +147,8 @@ add_tunnel() { ;; 3) - sh <(wget -O - "$BASE_RAW_URL/utils/amneziawg-install.sh") - - + install_awg_packages + printf "\033[32;1mThere are no instructions for manual configure yet. Do you want to configure the amneziawg interface? (y/n): \033[0m\n" read IS_SHOULD_CONFIGURE_WG_INTERFACE diff --git a/utils/amneziawg-install.sh b/utils/amneziawg-install.sh deleted file mode 100644 index 424666f..0000000 --- a/utils/amneziawg-install.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh - -install_awg_packages() { - # Получение pkgarch с наибольшим приоритетом - PKGARCH=$(opkg print-architecture | awk 'BEGIN {max=0} {if ($3 > max) {max = $3; arch = $2}} END {print arch}') - - TARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 1) - SUBTARGET=$(ubus call system board | jsonfilter -e '@.release.target' | cut -d '/' -f 2) - VERSION=$(ubus call system board | jsonfilter -e '@.release.version') - PKGPOSTFIX="_v${VERSION}_${PKGARCH}_${TARGET}_${SUBTARGET}.ipk" - BASE_URL="https://github.com/Slava-Shchipunov/awg-openwrt/releases/download/" - - AWG_DIR="/tmp/amneziawg" - mkdir -p "$AWG_DIR" - - if opkg list-installed | grep -q kmod-amneziawg; then - echo "kmod-amneziawg already installed" - else - KMOD_AMNEZIAWG_FILENAME="kmod-amneziawg${PKGPOSTFIX}" - DOWNLOAD_URL="${BASE_URL}v${VERSION}/${KMOD_AMNEZIAWG_FILENAME}" - wget -O "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL" - - if [ $? -eq 0 ]; then - echo "kmod-amneziawg file downloaded successfully" - else - echo "Error downloading kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again" - exit 1 - fi - - opkg install "$AWG_DIR/$KMOD_AMNEZIAWG_FILENAME" - - if [ $? -eq 0 ]; then - echo "kmod-amneziawg file downloaded successfully" - else - echo "Error installing kmod-amneziawg. Please, install kmod-amneziawg manually and run the script again" - exit 1 - fi - fi - - if opkg list-installed | grep -q amneziawg-tools; then - echo "amneziawg-tools already installed" - else - AMNEZIAWG_TOOLS_FILENAME="amneziawg-tools${PKGPOSTFIX}" - DOWNLOAD_URL="${BASE_URL}v${VERSION}/${AMNEZIAWG_TOOLS_FILENAME}" - wget -O "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" "$DOWNLOAD_URL" - - if [ $? -eq 0 ]; then - echo "amneziawg-tools file downloaded successfully" - else - echo "Error downloading amneziawg-tools. Please, install amneziawg-tools manually and run the script again" - exit 1 - fi - - opkg install "$AWG_DIR/$AMNEZIAWG_TOOLS_FILENAME" - - if [ $? -eq 0 ]; then - echo "amneziawg-tools file downloaded successfully" - else - echo "Error installing amneziawg-tools. Please, install amneziawg-tools manually and run the script again" - exit 1 - fi - fi - - if opkg list-installed | grep -q luci-app-amneziawg; then - echo "luci-app-amneziawg already installed" - else - LUCI_APP_AMNEZIAWG_FILENAME="luci-app-amneziawg${PKGPOSTFIX}" - DOWNLOAD_URL="${BASE_URL}v${VERSION}/${LUCI_APP_AMNEZIAWG_FILENAME}" - wget -O "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" "$DOWNLOAD_URL" - - if [ $? -eq 0 ]; then - echo "luci-app-amneziawg file downloaded successfully" - else - echo "Error downloading luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again" - exit 1 - fi - - opkg install "$AWG_DIR/$LUCI_APP_AMNEZIAWG_FILENAME" - - if [ $? -eq 0 ]; then - echo "luci-app-amneziawg file downloaded successfully" - else - echo "Error installing luci-app-amneziawg. Please, install luci-app-amneziawg manually and run the script again" - exit 1 - fi - fi - - rm -rf "$AWG_DIR" -} - -install_awg_packages From e154718e90e4fce56c2353d805ab119a6a76d563 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Sun, 3 Nov 2024 22:19:36 +0700 Subject: [PATCH 14/16] refactor: move wg-awg setup to install.sh --- install.sh | 132 +++++++++++++++++++++++++++++++++++++++++- utils/wg-awg-setup.sh | 128 ---------------------------------------- 2 files changed, 129 insertions(+), 131 deletions(-) delete mode 100644 utils/wg-awg-setup.sh diff --git a/install.sh b/install.sh index bcdffae..3694f0a 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,6 @@ #!/bin/sh REPO="https://api.github.com/repos/itdoginfo/podkop/releases/latest" -BASE_RAW_URL="https://raw.githubusercontent.com/itdoginfo/domain-routing-openwrt/refs/heads/main" DOWNLOAD_DIR="/tmp/podkop" mkdir -p "$DOWNLOAD_DIR" @@ -113,6 +112,133 @@ install_awg_packages() { rm -rf "$AWG_DIR" } +wg_awg_setup() { + PROTOCOL_NAME=$1 + printf "\033[32;1mConfigure ${PROTOCOL_NAME}\033[0m\n" + if [ "$PROTOCOL_NAME" = 'Wireguard' ]; then + INTERFACE_NAME="wg0" + CONFIG_NAME="wireguard_wg0" + PROTO="wireguard" + ZONE_NAME="wg" + fi + + if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then + INTERFACE_NAME="awg0" + CONFIG_NAME="amneziawg_awg0" + PROTO="amneziawg" + ZONE_NAME="awg" + + echo "Do you want to use AmneziaWG config or basic Wireguard config + automatic obfuscation?" + echo "1) AmneziaWG" + echo "2) Wireguard + automatic obfuscation" + read CONFIG_TYPE + fi + + read -r -p "Enter the private key (from [Interface]):"$'\n' WG_PRIVATE_KEY_INT + + while true; do + read -r -p "Enter internal IP address with subnet, example 192.168.100.5/24 (from [Interface]):"$'\n' WG_IP + if echo "$WG_IP" | egrep -oq '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]+$'; then + break + else + echo "This IP is not valid. Please repeat" + fi + done + + read -r -p "Enter the public key (from [Peer]):"$'\n' WG_PUBLIC_KEY_INT + read -r -p "If use PresharedKey, Enter this (from [Peer]). If your don't use leave blank:"$'\n' WG_PRESHARED_KEY_INT + read -r -p "Enter Endpoint host without port (Domain or IP) (from [Peer]):"$'\n' WG_ENDPOINT_INT + + read -r -p "Enter Endpoint host port (from [Peer]) [51820]:"$'\n' WG_ENDPOINT_PORT_INT + WG_ENDPOINT_PORT_INT=${WG_ENDPOINT_PORT_INT:-51820} + if [ "$WG_ENDPOINT_PORT_INT" = '51820' ]; then + echo $WG_ENDPOINT_PORT_INT + fi + + if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then + if [ "$CONFIG_TYPE" = '1' ]; then + read -r -p "Enter Jc value (from [Interface]):"$'\n' AWG_JC + read -r -p "Enter Jmin value (from [Interface]):"$'\n' AWG_JMIN + read -r -p "Enter Jmax value (from [Interface]):"$'\n' AWG_JMAX + read -r -p "Enter S1 value (from [Interface]):"$'\n' AWG_S1 + read -r -p "Enter S2 value (from [Interface]):"$'\n' AWG_S2 + read -r -p "Enter H1 value (from [Interface]):"$'\n' AWG_H1 + read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2 + read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3 + read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 + elif [ "$CONFIG_TYPE" = '2' ]; then + #Default values to wg automatic obfuscation + AWG_JC=4 + AWG_JMIN=40 + AWG_JMAX=70 + AWG_S1=0 + AWG_S2=0 + AWG_H1=1 + AWG_H2=2 + AWG_H3=3 + AWG_H4=4 + fi + fi + + uci set network.${INTERFACE_NAME}=interface + uci set network.${INTERFACE_NAME}.proto=$PROTO + uci set network.${INTERFACE_NAME}.private_key=$WG_PRIVATE_KEY_INT + uci set network.${INTERFACE_NAME}.listen_port='51821' + uci set network.${INTERFACE_NAME}.addresses=$WG_IP + + if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then + uci set network.${INTERFACE_NAME}.awg_jc=$AWG_JC + uci set network.${INTERFACE_NAME}.awg_jmin=$AWG_JMIN + uci set network.${INTERFACE_NAME}.awg_jmax=$AWG_JMAX + uci set network.${INTERFACE_NAME}.awg_s1=$AWG_S1 + uci set network.${INTERFACE_NAME}.awg_s2=$AWG_S2 + uci set network.${INTERFACE_NAME}.awg_h1=$AWG_H1 + uci set network.${INTERFACE_NAME}.awg_h2=$AWG_H2 + uci set network.${INTERFACE_NAME}.awg_h3=$AWG_H3 + uci set network.${INTERFACE_NAME}.awg_h4=$AWG_H4 + fi + + if ! uci show network | grep -q ${CONFIG_NAME}; then + uci add network ${CONFIG_NAME} + fi + + uci set network.@${CONFIG_NAME}[0]=$CONFIG_NAME + uci set network.@${CONFIG_NAME}[0].name="${INTERFACE_NAME}_client" + uci set network.@${CONFIG_NAME}[0].public_key=$WG_PUBLIC_KEY_INT + uci set network.@${CONFIG_NAME}[0].preshared_key=$WG_PRESHARED_KEY_INT + uci set network.@${CONFIG_NAME}[0].route_allowed_ips='0' + uci set network.@${CONFIG_NAME}[0].persistent_keepalive='25' + uci set network.@${CONFIG_NAME}[0].endpoint_host=$WG_ENDPOINT_INT + uci set network.@${CONFIG_NAME}[0].allowed_ips='0.0.0.0/0' + uci set network.@${CONFIG_NAME}[0].endpoint_port=$WG_ENDPOINT_PORT_INT + uci commit network + + if ! uci show firewall | grep -q "@zone.*name='${ZONE_NAME}'"; then + printf "\033[32;1mZone Create\033[0m\n" + uci add firewall zone + uci set firewall.@zone[-1].name=$ZONE_NAME + uci set firewall.@zone[-1].network=$INTERFACE_NAME + uci set firewall.@zone[-1].forward='REJECT' + uci set firewall.@zone[-1].output='ACCEPT' + uci set firewall.@zone[-1].input='REJECT' + uci set firewall.@zone[-1].masq='1' + uci set firewall.@zone[-1].mtu_fix='1' + uci set firewall.@zone[-1].family='ipv4' + uci commit firewall + fi + + if ! uci show firewall | grep -q "@forwarding.*name='${ZONE_NAME}'"; then + printf "\033[32;1mConfigured forwarding\033[0m\n" + uci add firewall forwarding + uci set firewall.@forwarding[-1]=forwarding + uci set firewall.@forwarding[-1].name="${ZONE_NAME}-lan" + uci set firewall.@forwarding[-1].dest=${ZONE_NAME} + uci set firewall.@forwarding[-1].src='lan' + uci set firewall.@forwarding[-1].family='ipv4' + uci commit firewall + fi +} + add_tunnel() { echo "What type of VPN or proxy will be used?" echo "1) VLESS, Shadowsocks (A sing-box will be installed)" @@ -138,7 +264,7 @@ add_tunnel() { read IS_SHOULD_CONFIGURE_WG_INTERFACE if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") Wireguard + wg_awg_setup Wireguard else printf "\e[1;32mUse these instructions to manual configure https://itdog.info/nastrojka-klienta-wireguard-na-openwrt/\e[0m\n" fi @@ -153,7 +279,7 @@ add_tunnel() { read IS_SHOULD_CONFIGURE_WG_INTERFACE if [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "y" ] || [ "$IS_SHOULD_CONFIGURE_WG_INTERFACE" = "Y" ]; then - sh <(wget -O - "$BASE_RAW_URL/utils/wg-awg-setup.sh") AmneziaWG + wg_awg_setup AmneziaWG fi break diff --git a/utils/wg-awg-setup.sh b/utils/wg-awg-setup.sh deleted file mode 100644 index c4ebbc1..0000000 --- a/utils/wg-awg-setup.sh +++ /dev/null @@ -1,128 +0,0 @@ -wg_awg_setup() { - PROTOCOL_NAME=$1 - printf "\033[32;1mConfigure ${PROTOCOL_NAME}\033[0m\n" - if [ "$PROTOCOL_NAME" = 'Wireguard' ]; then - INTERFACE_NAME="wg0" - CONFIG_NAME="wireguard_wg0" - PROTO="wireguard" - ZONE_NAME="wg" - fi - - if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then - INTERFACE_NAME="awg0" - CONFIG_NAME="amneziawg_awg0" - PROTO="amneziawg" - ZONE_NAME="awg" - - echo "Do you want to use AmneziaWG config or basic Wireguard config + automatic obfuscation?" - echo "1) AmneziaWG" - echo "2) Wireguard + automatic obfuscation" - read CONFIG_TYPE - fi - - read -r -p "Enter the private key (from [Interface]):"$'\n' WG_PRIVATE_KEY_INT - - while true; do - read -r -p "Enter internal IP address with subnet, example 192.168.100.5/24 (from [Interface]):"$'\n' WG_IP - if echo "$WG_IP" | egrep -oq '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]+$'; then - break - else - echo "This IP is not valid. Please repeat" - fi - done - - read -r -p "Enter the public key (from [Peer]):"$'\n' WG_PUBLIC_KEY_INT - read -r -p "If use PresharedKey, Enter this (from [Peer]). If your don't use leave blank:"$'\n' WG_PRESHARED_KEY_INT - read -r -p "Enter Endpoint host without port (Domain or IP) (from [Peer]):"$'\n' WG_ENDPOINT_INT - - read -r -p "Enter Endpoint host port (from [Peer]) [51820]:"$'\n' WG_ENDPOINT_PORT_INT - WG_ENDPOINT_PORT_INT=${WG_ENDPOINT_PORT_INT:-51820} - if [ "$WG_ENDPOINT_PORT_INT" = '51820' ]; then - echo $WG_ENDPOINT_PORT_INT - fi - - if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then - if [ "$CONFIG_TYPE" = '1' ]; then - read -r -p "Enter Jc value (from [Interface]):"$'\n' AWG_JC - read -r -p "Enter Jmin value (from [Interface]):"$'\n' AWG_JMIN - read -r -p "Enter Jmax value (from [Interface]):"$'\n' AWG_JMAX - read -r -p "Enter S1 value (from [Interface]):"$'\n' AWG_S1 - read -r -p "Enter S2 value (from [Interface]):"$'\n' AWG_S2 - read -r -p "Enter H1 value (from [Interface]):"$'\n' AWG_H1 - read -r -p "Enter H2 value (from [Interface]):"$'\n' AWG_H2 - read -r -p "Enter H3 value (from [Interface]):"$'\n' AWG_H3 - read -r -p "Enter H4 value (from [Interface]):"$'\n' AWG_H4 - elif [ "$CONFIG_TYPE" = '2' ]; then - #Default values to wg automatic obfuscation - AWG_JC=4 - AWG_JMIN=40 - AWG_JMAX=70 - AWG_S1=0 - AWG_S2=0 - AWG_H1=1 - AWG_H2=2 - AWG_H3=3 - AWG_H4=4 - fi - fi - - uci set network.${INTERFACE_NAME}=interface - uci set network.${INTERFACE_NAME}.proto=$PROTO - uci set network.${INTERFACE_NAME}.private_key=$WG_PRIVATE_KEY_INT - uci set network.${INTERFACE_NAME}.listen_port='51821' - uci set network.${INTERFACE_NAME}.addresses=$WG_IP - - if [ "$PROTOCOL_NAME" = 'AmneziaWG' ]; then - uci set network.${INTERFACE_NAME}.awg_jc=$AWG_JC - uci set network.${INTERFACE_NAME}.awg_jmin=$AWG_JMIN - uci set network.${INTERFACE_NAME}.awg_jmax=$AWG_JMAX - uci set network.${INTERFACE_NAME}.awg_s1=$AWG_S1 - uci set network.${INTERFACE_NAME}.awg_s2=$AWG_S2 - uci set network.${INTERFACE_NAME}.awg_h1=$AWG_H1 - uci set network.${INTERFACE_NAME}.awg_h2=$AWG_H2 - uci set network.${INTERFACE_NAME}.awg_h3=$AWG_H3 - uci set network.${INTERFACE_NAME}.awg_h4=$AWG_H4 - fi - - if ! uci show network | grep -q ${CONFIG_NAME}; then - uci add network ${CONFIG_NAME} - fi - - uci set network.@${CONFIG_NAME}[0]=$CONFIG_NAME - uci set network.@${CONFIG_NAME}[0].name="${INTERFACE_NAME}_client" - uci set network.@${CONFIG_NAME}[0].public_key=$WG_PUBLIC_KEY_INT - uci set network.@${CONFIG_NAME}[0].preshared_key=$WG_PRESHARED_KEY_INT - uci set network.@${CONFIG_NAME}[0].route_allowed_ips='0' - uci set network.@${CONFIG_NAME}[0].persistent_keepalive='25' - uci set network.@${CONFIG_NAME}[0].endpoint_host=$WG_ENDPOINT_INT - uci set network.@${CONFIG_NAME}[0].allowed_ips='0.0.0.0/0' - uci set network.@${CONFIG_NAME}[0].endpoint_port=$WG_ENDPOINT_PORT_INT - uci commit network - - if ! uci show firewall | grep -q "@zone.*name='${ZONE_NAME}'"; then - printf "\033[32;1mZone Create\033[0m\n" - uci add firewall zone - uci set firewall.@zone[-1].name=$ZONE_NAME - uci set firewall.@zone[-1].network=$INTERFACE_NAME - uci set firewall.@zone[-1].forward='REJECT' - uci set firewall.@zone[-1].output='ACCEPT' - uci set firewall.@zone[-1].input='REJECT' - uci set firewall.@zone[-1].masq='1' - uci set firewall.@zone[-1].mtu_fix='1' - uci set firewall.@zone[-1].family='ipv4' - uci commit firewall - fi - - if ! uci show firewall | grep -q "@forwarding.*name='${ZONE_NAME}'"; then - printf "\033[32;1mConfigured forwarding\033[0m\n" - uci add firewall forwarding - uci set firewall.@forwarding[-1]=forwarding - uci set firewall.@forwarding[-1].name="${ZONE_NAME}-lan" - uci set firewall.@forwarding[-1].dest=${ZONE_NAME} - uci set firewall.@forwarding[-1].src='lan' - uci set firewall.@forwarding[-1].family='ipv4' - uci commit firewall - fi -} - -wg_awg_setup "$1" From dcc0733b89c3a54adf4e95d6d309ce6a36c5a1d6 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Sun, 3 Nov 2024 22:38:55 +0700 Subject: [PATCH 15/16] docs: update readme --- README.md | 8 ++++++-- install.sh | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e2366e..221a4fa 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ sh <(wget -O - https://raw.githubusercontent.com/itdoginfo/domain-routing-openwr sh <(wget -O - https://raw.githubusercontent.com/itdoginfo/podkop/refs/heads/main/install.sh) ``` +Скрипт также предложит выбрать, какой туннель будет использоваться. Для выбранного туннеля будут установлены нужные пакеты, а для Wireguard и AmneziaWG также будет предложена автоматическая настройка - прямо в консоли скрипт запросит данные конфига. Для AmneziaWG можно также выбрать вариант с использованием конфига обычного Wireguard и автоматической обфускацией до AmneziaWG. + +Для AmneziaWG скрипт проверяет наличие пакетов под вашу платформу в [стороннем репозитории](https://github.com/Slava-Shchipunov/awg-openwrt/releases), так как в официальном репозитории OpenWRT они отсутствуют, и автоматически их устанавливает. + ## Вручную Сделать `opkg update`, чтоб установились зависимости. Скачать пакеты `podkop_*.ipk` и `luci-app-podkop_*.ipk` из релиза. `opkg install` сначала первый, потом второй. @@ -94,8 +98,8 @@ opkg update && opkg install sing-box - [ ] IPv6 - [ ] Придумать автонастройку DNS через stubby итд. Как лучше это реализовать. - [ ] Удаление подсетей CF из domain sets раз в N часов -- [ ] Автонастройка wireguard по примеру getdomains -- [ ] Автонастройка awg по примеру getdomains +- [x] Автонастройка wireguard по примеру getdomains +- [x] Автонастройка awg по примеру getdomains Wiki - [ ] Тема diff --git a/install.sh b/install.sh index 3694f0a..e81f6b4 100755 --- a/install.sh +++ b/install.sh @@ -240,7 +240,7 @@ wg_awg_setup() { } add_tunnel() { - echo "What type of VPN or proxy will be used?" + echo "What type of VPN or proxy will be used? We also can automatically configure Wireguard and Amnezia WireGuard." echo "1) VLESS, Shadowsocks (A sing-box will be installed)" echo "2) Wireguard" echo "3) AmneziaWG" From ee8bef67eeeec970d1875ea4fe61f57e1b65deeb Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Tue, 5 Nov 2024 10:27:57 +0700 Subject: [PATCH 16/16] refactor: add handler_network_restart --- install.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index e81f6b4..adc93d8 100755 --- a/install.sh +++ b/install.sh @@ -24,6 +24,12 @@ else [ -f /etc/config/dhcp-opkg ] && cp /etc/config/dhcp /etc/config/dhcp-old && mv /etc/config/dhcp-opkg /etc/config/dhcp fi +IS_SHOULD_RESTART_NETWORK=false + +handler_network_restart() { + IS_SHOULD_RESTART_NETWORK=true +} + install_awg_packages() { # Получение pkgarch с наибольшим приоритетом PKGARCH=$(opkg print-architecture | awk 'BEGIN {max=0} {if ($3 > max) {max = $3; arch = $2}} END {print arch}') @@ -237,6 +243,8 @@ wg_awg_setup() { uci set firewall.@forwarding[-1].family='ipv4' uci commit firewall fi + + handler_network_restart } add_tunnel() { @@ -317,5 +325,7 @@ opkg install $DOWNLOAD_DIR/luci-app-podkop*.ipk rm -f $DOWNLOAD_DIR/podkop*.ipk $DOWNLOAD_DIR/luci-app-podkop*.ipk -printf "\033[32;1mRestart network\033[0m\n" -service network restart +if [ "$IS_SHOULD_RESTART_NETWORK" ]; then + printf "\033[32;1mRestart network\033[0m\n" + /etc/init.d/network restart +fi