From a53adb2df147fdda32dae4b5a60aa602ab2d85d3 Mon Sep 17 00:00:00 2001 From: Slava-Shchipunov Date: Sun, 3 Nov 2024 22:16:34 +0700 Subject: [PATCH] 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