mirror of
https://github.com/angristan/wireguard-install.git
synced 2025-04-05 03:43:30 +03:00
Update wireguard-install.sh
Сделан русский перевод. Изменен DNS-сервер по умолчанию.
This commit is contained in:
parent
4dfbc55cd9
commit
0869a48a2e
1 changed files with 60 additions and 60 deletions
|
@ -9,35 +9,35 @@ NC='\033[0m'
|
|||
|
||||
function isRoot() {
|
||||
if [ "${EUID}" -ne 0 ]; then
|
||||
echo "You need to run this script as root"
|
||||
echo "Вам нужно запустить этот скрипт от имени root-пользователя"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function checkVirt() {
|
||||
if [ "$(systemd-detect-virt)" == "openvz" ]; then
|
||||
echo "OpenVZ is not supported"
|
||||
echo "OpenVZ не поддерживается"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$(systemd-detect-virt)" == "lxc" ]; then
|
||||
echo "LXC is not supported (yet)."
|
||||
echo "WireGuard can technically run in an LXC container,"
|
||||
echo "but the kernel module has to be installed on the host,"
|
||||
echo "the container has to be run with some specific parameters"
|
||||
echo "and only the tools need to be installed in the container."
|
||||
echo "LXC не поддерживается (пока)."
|
||||
echo "Технически WireGuard может работать в контейнере LXC,"
|
||||
echo "но модуль ядра должен быть установлен на хосте,"
|
||||
echo "контейнер должен быть запущен с некоторыми определенными параметрами"
|
||||
echo "и только инструменты должны быть установлены в контейнер."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function checkOS() {
|
||||
# Check OS version
|
||||
# Проверка операционной системы
|
||||
if [[ -e /etc/debian_version ]]; then
|
||||
source /etc/os-release
|
||||
OS="${ID}" # debian or ubuntu
|
||||
if [[ ${ID} == "debian" || ${ID} == "raspbian" ]]; then
|
||||
if [[ ${VERSION_ID} -lt 10 ]]; then
|
||||
echo "Your version of Debian (${VERSION_ID}) is not supported. Please use Debian 10 Buster or later"
|
||||
echo "Ваша версия Debian (${VERSION_ID}) не поддерживается. Пожалуйста, используйте Debian 10 Buster или более позднюю версию"
|
||||
exit 1
|
||||
fi
|
||||
OS=debian # overwrite if raspbian
|
||||
|
@ -54,7 +54,7 @@ function checkOS() {
|
|||
elif [[ -e /etc/arch-release ]]; then
|
||||
OS=arch
|
||||
else
|
||||
echo "Looks like you aren't running this installer on a Debian, Ubuntu, Fedora, CentOS, Oracle or Arch Linux system"
|
||||
echo "Похоже, вы не запускаете этот установщик в системе Debian, Ubuntu, Fedora, CentOS, Oracle или Arch Linux"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -66,11 +66,11 @@ function initialCheck() {
|
|||
}
|
||||
|
||||
function installQuestions() {
|
||||
echo "Welcome to the WireGuard installer!"
|
||||
echo "The git repository is available at: https://github.com/angristan/wireguard-install"
|
||||
echo "Добро пожаловать в WireGuard installer!"
|
||||
echo "Репозиторий git доступен по адресу: https://github.com/Romanoidz/wireguard-install"
|
||||
echo ""
|
||||
echo "I need to ask you a few questions before starting the setup."
|
||||
echo "You can leave the default options and just press enter if you are ok with them."
|
||||
echo "Мне нужно задать вам несколько вопросов, прежде чем приступить к настройке."
|
||||
echo "Вы можете оставить параметры по умолчанию и просто нажать Enter, если они вас устраивают."
|
||||
echo ""
|
||||
|
||||
# Detect public IPv4 or IPv6 address and pre-fill for the user
|
||||
|
@ -79,47 +79,47 @@ function installQuestions() {
|
|||
# Detect public IPv6 address
|
||||
SERVER_PUB_IP=$(ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1)
|
||||
fi
|
||||
read -rp "IPv4 or IPv6 public address: " -e -i "${SERVER_PUB_IP}" SERVER_PUB_IP
|
||||
read -rp "Публичный адрес IPv4 или IPv6: " -e -i "${SERVER_PUB_IP}" SERVER_PUB_IP
|
||||
|
||||
# Detect public interface and pre-fill for the user
|
||||
SERVER_NIC="$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)"
|
||||
until [[ ${SERVER_PUB_NIC} =~ ^[a-zA-Z0-9_]+$ ]]; do
|
||||
read -rp "Public interface: " -e -i "${SERVER_NIC}" SERVER_PUB_NIC
|
||||
read -rp "Общедоступный интерфейс: " -e -i "${SERVER_NIC}" SERVER_PUB_NIC
|
||||
done
|
||||
|
||||
until [[ ${SERVER_WG_NIC} =~ ^[a-zA-Z0-9_]+$ && ${#SERVER_WG_NIC} -lt 16 ]]; do
|
||||
read -rp "WireGuard interface name: " -e -i wg0 SERVER_WG_NIC
|
||||
read -rp "Имя интерфейса WireGuard: " -e -i wg0 SERVER_WG_NIC
|
||||
done
|
||||
|
||||
until [[ ${SERVER_WG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do
|
||||
read -rp "Server's WireGuard IPv4: " -e -i 10.66.66.1 SERVER_WG_IPV4
|
||||
read -rp "Адрес сервера WireGuard IPv4: " -e -i 192.168.66.1 SERVER_WG_IPV4
|
||||
done
|
||||
|
||||
until [[ ${SERVER_WG_IPV6} =~ ^([a-f0-9]{1,4}:){3,4}: ]]; do
|
||||
read -rp "Server's WireGuard IPv6: " -e -i fd42:42:42::1 SERVER_WG_IPV6
|
||||
read -rp "Адрес сервера WireGuard IPv6: " -e -i fd42:42:42::1 SERVER_WG_IPV6
|
||||
done
|
||||
|
||||
# Generate random number within private ports range
|
||||
RANDOM_PORT=$(shuf -i49152-65535 -n1)
|
||||
until [[ ${SERVER_PORT} =~ ^[0-9]+$ ]] && [ "${SERVER_PORT}" -ge 1 ] && [ "${SERVER_PORT}" -le 65535 ]; do
|
||||
read -rp "Server's WireGuard port [1-65535]: " -e -i "${RANDOM_PORT}" SERVER_PORT
|
||||
read -rp "Порт сервера WireGuard [1-65535]: " -e -i "${RANDOM_PORT}" SERVER_PORT
|
||||
done
|
||||
|
||||
# Adguard DNS by default
|
||||
# Yandex DNS by default
|
||||
until [[ ${CLIENT_DNS_1} =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do
|
||||
read -rp "First DNS resolver to use for the clients: " -e -i 94.140.14.14 CLIENT_DNS_1
|
||||
read -rp "Первый DNS resolver, используемый для клиентов:(по умолчанию Яндекс DNS) " -e -i 77.88.8.8 CLIENT_DNS_1
|
||||
done
|
||||
until [[ ${CLIENT_DNS_2} =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do
|
||||
read -rp "Second DNS resolver to use for the clients (optional): " -e -i 94.140.15.15 CLIENT_DNS_2
|
||||
read -rp "Второй DNS resolver, используемый для клиентов: (по умолчанию Яндекс DNS)(опционально): " -e -i 77.88.8.1 CLIENT_DNS_2
|
||||
if [[ ${CLIENT_DNS_2} == "" ]]; then
|
||||
CLIENT_DNS_2="${CLIENT_DNS_1}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Okay, that was all I needed. We are ready to setup your WireGuard server now."
|
||||
echo "You will be able to generate a client at the end of the installation."
|
||||
read -n1 -r -p "Press any key to continue..."
|
||||
echo "Необходимые данные получены. Теперь можно настроить ваш сервер WireGuard."
|
||||
echo "Настроить и создать Клиента можно в конце установки."
|
||||
read -n1 -r -p "Нажмите любую клавишу, чтобы продолжить..."
|
||||
}
|
||||
|
||||
function installWireGuard() {
|
||||
|
@ -207,7 +207,7 @@ net.ipv6.conf.all.forwarding = 1" >/etc/sysctl.d/wg.conf
|
|||
systemctl enable "wg-quick@${SERVER_WG_NIC}"
|
||||
|
||||
newClient
|
||||
echo "If you want to add more clients, you simply need to run this script another time!"
|
||||
echo "Если вы хотите добавить больше клиентов, вам просто нужно запустить этот скрипт в еще раз!"
|
||||
|
||||
# Check if WireGuard is running
|
||||
systemctl is-active --quiet "wg-quick@${SERVER_WG_NIC}"
|
||||
|
@ -215,9 +215,9 @@ net.ipv6.conf.all.forwarding = 1" >/etc/sysctl.d/wg.conf
|
|||
|
||||
# WireGuard might not work if we updated the kernel. Tell the user to reboot
|
||||
if [[ ${WG_RUNNING} -ne 0 ]]; then
|
||||
echo -e "\n${RED}WARNING: WireGuard does not seem to be running.${NC}"
|
||||
echo -e "${ORANGE}You can check if WireGuard is running with: systemctl status wg-quick@${SERVER_WG_NIC}${NC}"
|
||||
echo -e "${ORANGE}If you get something like \"Cannot find device ${SERVER_WG_NIC}\", please reboot!${NC}"
|
||||
echo -e "\n${RED}ПРЕДУПРЕЖДЕНИЕ: WireGuard, похоже, не работает.${NC}"
|
||||
echo -e "${ORANGE}Вы можете проверить, работает ли WireGuard: systemctl status wg-quick@${SERVER_WG_NIC}${NC}"
|
||||
echo -e "${ORANGE}Если вы получите что-то вроде \"Cannot find device ${SERVER_WG_NIC}\", пожалуйста, перезагрузитесь!${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -225,16 +225,16 @@ function newClient() {
|
|||
ENDPOINT="${SERVER_PUB_IP}:${SERVER_PORT}"
|
||||
|
||||
echo ""
|
||||
echo "Tell me a name for the client."
|
||||
echo "The name must consist of alphanumeric character. It may also include an underscore or a dash and can't exceed 15 chars."
|
||||
echo "Введите имя клиента."
|
||||
echo "Имя должно состоять из буквенно-цифровых символов. Оно также может содержать подчеркивание или тире и не может превышать 15 символов."
|
||||
|
||||
until [[ ${CLIENT_NAME} =~ ^[a-zA-Z0-9_-]+$ && ${CLIENT_EXISTS} == '0' && ${#CLIENT_NAME} -lt 16 ]]; do
|
||||
read -rp "Client name: " -e CLIENT_NAME
|
||||
read -rp "Имя клиента: " -e CLIENT_NAME
|
||||
CLIENT_EXISTS=$(grep -c -E "^### Client ${CLIENT_NAME}\$" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
||||
|
||||
if [[ ${CLIENT_EXISTS} == '1' ]]; then
|
||||
echo ""
|
||||
echo "A client with the specified name was already created, please choose another name."
|
||||
echo "Клиент с указанным именем уже создан, пожалуйста, выберите другое имя."
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
|
@ -248,32 +248,32 @@ function newClient() {
|
|||
|
||||
if [[ ${DOT_EXISTS} == '1' ]]; then
|
||||
echo ""
|
||||
echo "The subnet configured supports only 253 clients."
|
||||
echo "Настроенная подсеть поддерживает только 253 клиента."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_IP=$(echo "$SERVER_WG_IPV4" | awk -F '.' '{ print $1"."$2"."$3 }')
|
||||
until [[ ${IPV4_EXISTS} == '0' ]]; do
|
||||
read -rp "Client's WireGuard IPv4: ${BASE_IP}." -e -i "${DOT_IP}" DOT_IP
|
||||
read -rp "Клиент WireGuard IPv4: ${BASE_IP}." -e -i "${DOT_IP}" DOT_IP
|
||||
CLIENT_WG_IPV4="${BASE_IP}.${DOT_IP}"
|
||||
IPV4_EXISTS=$(grep -c "$CLIENT_WG_IPV4/24" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
||||
|
||||
if [[ ${IPV4_EXISTS} == '1' ]]; then
|
||||
echo ""
|
||||
echo "A client with the specified IPv4 was already created, please choose another IPv4."
|
||||
echo "Клиент с указанным IPv4 уже создан, пожалуйста, выберите другой IPv4."
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
|
||||
BASE_IP=$(echo "$SERVER_WG_IPV6" | awk -F '::' '{ print $1 }')
|
||||
until [[ ${IPV6_EXISTS} == '0' ]]; do
|
||||
read -rp "Client's WireGuard IPv6: ${BASE_IP}::" -e -i "${DOT_IP}" DOT_IP
|
||||
read -rp "Клиент WireGuard IPv6: ${BASE_IP}::" -e -i "${DOT_IP}" DOT_IP
|
||||
CLIENT_WG_IPV6="${BASE_IP}::${DOT_IP}"
|
||||
IPV6_EXISTS=$(grep -c "${CLIENT_WG_IPV6}/64" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
||||
|
||||
if [[ ${IPV6_EXISTS} == '1' ]]; then
|
||||
echo ""
|
||||
echo "A client with the specified IPv6 was already created, please choose another IPv6."
|
||||
echo "Клиент с указанным IPv6 уже создан, пожалуйста, выберите другой IPv6."
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
|
@ -310,7 +310,7 @@ DNS = ${CLIENT_DNS_1},${CLIENT_DNS_2}
|
|||
PublicKey = ${SERVER_PUB_KEY}
|
||||
PresharedKey = ${CLIENT_PRE_SHARED_KEY}
|
||||
Endpoint = ${ENDPOINT}
|
||||
AllowedIPs = 0.0.0.0/0,::/0" >>"${HOME_DIR}/${SERVER_WG_NIC}-client-${CLIENT_NAME}.conf"
|
||||
AllowedIPs = 0.0.0.0/0,::/0" >>"${HOME_DIR}/${SERVER_WG_NIC}-${SERVER_PUB_IP}-client-${CLIENT_NAME}.conf"
|
||||
|
||||
# Add the client as a peer to the server
|
||||
echo -e "\n### Client ${CLIENT_NAME}
|
||||
|
@ -321,29 +321,29 @@ AllowedIPs = ${CLIENT_WG_IPV4}/32,${CLIENT_WG_IPV6}/128" >>"/etc/wireguard/${SER
|
|||
|
||||
wg syncconf "${SERVER_WG_NIC}" <(wg-quick strip "${SERVER_WG_NIC}")
|
||||
|
||||
echo -e "\nHere is your client config file as a QR Code:"
|
||||
echo -e "\nВот файл конфигурации вашего клиента в виде QR-кода:"
|
||||
|
||||
qrencode -t ansiutf8 -l L <"${HOME_DIR}/${SERVER_WG_NIC}-client-${CLIENT_NAME}.conf"
|
||||
qrencode -t ansiutf8 -l L <"${HOME_DIR}/${SERVER_WG_NIC}-${SERVER_PUB_IP}-client-${CLIENT_NAME}.conf"
|
||||
|
||||
echo "It is also available in ${HOME_DIR}/${SERVER_WG_NIC}-client-${CLIENT_NAME}.conf"
|
||||
echo "Он также доступен в ${HOME_DIR}/${SERVER_WG_NIC}-${SERVER_PUB_IP}-client-${CLIENT_NAME}.conf"
|
||||
}
|
||||
|
||||
function revokeClient() {
|
||||
NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
||||
if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then
|
||||
echo ""
|
||||
echo "You have no existing clients!"
|
||||
echo "У вас нет существующих клиентов!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Select the existing client you want to revoke"
|
||||
echo "Выберите существующего клиента, которого вы хотите отозвать"
|
||||
grep -E "^### Client" "/etc/wireguard/${SERVER_WG_NIC}.conf" | cut -d ' ' -f 3 | nl -s ') '
|
||||
until [[ ${CLIENT_NUMBER} -ge 1 && ${CLIENT_NUMBER} -le ${NUMBER_OF_CLIENTS} ]]; do
|
||||
if [[ ${CLIENT_NUMBER} == '1' ]]; then
|
||||
read -rp "Select one client [1]: " CLIENT_NUMBER
|
||||
read -rp "Выберите одного клиента [1]: " CLIENT_NUMBER
|
||||
else
|
||||
read -rp "Select one client [1-${NUMBER_OF_CLIENTS}]: " CLIENT_NUMBER
|
||||
read -rp "Выберите одного клиента [1-${NUMBER_OF_CLIENTS}]: " CLIENT_NUMBER
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -362,7 +362,7 @@ function revokeClient() {
|
|||
|
||||
function uninstallWg() {
|
||||
echo ""
|
||||
read -rp "Do you really want to remove WireGuard? [y/n]: " -e -i n REMOVE
|
||||
read -rp "Вы действительно хотите удалить WireGuard? [y/n]: " -e -i n REMOVE
|
||||
if [[ $REMOVE == 'y' ]]; then
|
||||
checkOS
|
||||
|
||||
|
@ -401,31 +401,31 @@ function uninstallWg() {
|
|||
WG_RUNNING=$?
|
||||
|
||||
if [[ ${WG_RUNNING} -eq 0 ]]; then
|
||||
echo "WireGuard failed to uninstall properly."
|
||||
echo "WireGuard не удалась удалить должным образом."
|
||||
exit 1
|
||||
else
|
||||
echo "WireGuard uninstalled successfully."
|
||||
echo "WireGuard успешно удален"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
echo "Removal aborted!"
|
||||
echo "Удаление прервано!"
|
||||
fi
|
||||
}
|
||||
|
||||
function manageMenu() {
|
||||
echo "Welcome to WireGuard-install!"
|
||||
echo "The git repository is available at: https://github.com/angristan/wireguard-install"
|
||||
echo "Добро пожаловать в установку WireGuard-сервера!"
|
||||
echo "Репозиторий git доступен по адресу: https://github.com/Romanoidz/wireguard-install"
|
||||
echo ""
|
||||
echo "It looks like WireGuard is already installed."
|
||||
echo "Похоже WireGuard уже установлен."
|
||||
echo ""
|
||||
echo "What do you want to do?"
|
||||
echo " 1) Add a new user"
|
||||
echo " 2) Revoke existing user"
|
||||
echo " 3) Uninstall WireGuard"
|
||||
echo " 4) Exit"
|
||||
echo "Что хотите сделать?"
|
||||
echo " 1) Добавить нового пользователя"
|
||||
echo " 2) Отозвать существующего пользователя"
|
||||
echo " 3) Удалить WireGuard"
|
||||
echo " 4) Выйти"
|
||||
until [[ ${MENU_OPTION} =~ ^[1-4]$ ]]; do
|
||||
read -rp "Select an option [1-4]: " MENU_OPTION
|
||||
read -rp "Выберите опцию [1-4]: " MENU_OPTION
|
||||
done
|
||||
case "${MENU_OPTION}" in
|
||||
1)
|
||||
|
|
Loading…
Add table
Reference in a new issue