From 862274c941d11ff7cd7803a47ca2ff8a23fca565 Mon Sep 17 00:00:00 2001 From: Snowy-Fluffy Date: Wed, 26 Mar 2025 15:29:34 +0300 Subject: [PATCH] bug fix --- installer.sh | 56 ++++++++++++++++++-------------------- installer.sh.old | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 30 deletions(-) create mode 100755 installer.sh.old diff --git a/installer.sh b/installer.sh index 72901c0..ac78ade 100755 --- a/installer.sh +++ b/installer.sh @@ -7,22 +7,24 @@ install_dependencies() { if [ "$kernel" = "Linux" ]; then . /etc/os-release - declare -A command_by_ID=( - ["arch"]="pacman -S --noconfirm git" - ["debian"]="DEBIAN_FRONTEND=noninteractive apt install -y git" - ["fedora"]="dnf install -y git" - ["ubuntu"]="DEBIAN_FRONTEND=noninteractive apt install -y git" - ["mint"]="DEBIAN_FRONTEND=noninteractive apt install -y git" - ["void"]="xpbs-install -y git " - ["gentoo"]="emerge --ask=n dev-vcs/git" - ["opensuse"]="zypper install -y git " - ) - - if [[ -v command_by_ID[$ID] ]]; then - eval "${command_by_ID[$ID]}" - elif [[ -v command_by_ID[$ID_LIKE] ]]; then - eval "${command_by_ID[$ID_LIKE]}" - fi + case "$ID" in + arch) $SUDO pacman -S --noconfirm git ;; + debian|ubuntu|mint) $SUDO DEBIAN_FRONTEND=noninteractive apt install -y git ;; + fedora) $SUDO dnf install -y git ;; + void) $SUDO xbps-install -y git ;; + gentoo) $SUDO emerge --ask=n dev-vcs/git ;; + opensuse) $SUDO zypper install -y git ;; + *) + if [ -n "$ID_LIKE" ]; then + case "$ID_LIKE" in + debian) $SUDO DEBIAN_FRONTEND=noninteractive apt install -y git ;; + *) echo "Неизвестная ОС: ${ID} ${ID_LIKE}"; exit 1 ;; + esac + else + echo "Неизвестная ОС: ${ID}"; exit 1 + fi + ;; + esac elif [ "$kernel" = "Darwin" ]; then echo "macOS не поддерживается на данный момент." exit 1 @@ -32,13 +34,12 @@ install_dependencies() { fi } - if [ "$(id -u)" -eq 0 ]; then SUDO="" else - if command -v sudo &> /dev/null; then + if command -v sudo > /dev/null 2>&1; then SUDO="sudo" - elif command -v doas &> /dev/null; then + elif command -v doas > /dev/null 2>&1; then SUDO="doas" else echo "Скрипт не может быть выполнен не от имени суперпользователя." @@ -46,23 +47,18 @@ else fi fi -if command -v git > /dev/null 2>&1; then - echo "" -else - $SUDO install_dependencies +if ! command -v git > /dev/null 2>&1; then + install_dependencies fi if [ ! -d "/opt/zapret.installer" ]; then - cd /opt || exit - $SUDO git clone https://github.com/Snowy-Fluffy/zapret.installer.git + $SUDO git clone https://github.com/Snowy-Fluffy/zapret.installer.git /opt/zapret.installer else - cd "/opt/zapret.installer" || exit + cd /opt/zapret.installer || exit if ! $SUDO git pull; then echo "Ошибка при обновлении. Удаляю репозиторий и клонирую заново..." - cd /opt || exit - $SUDO rm -rf "/opt/zapret.installer" - $SUDO git clone https://github.com/Snowy-Fluffy/zapret.installer.git - cd "/opt/zapret.installer" || exit + $SUDO rm -rf /opt/zapret.installer + $SUDO git clone https://github.com/Snowy-Fluffy/zapret.installer.git /opt/zapret.installer fi fi diff --git a/installer.sh.old b/installer.sh.old new file mode 100755 index 0000000..72901c0 --- /dev/null +++ b/installer.sh.old @@ -0,0 +1,71 @@ +#!/bin/sh + +set -e + +install_dependencies() { + kernel="$(uname -s)" + if [ "$kernel" = "Linux" ]; then + . /etc/os-release + + declare -A command_by_ID=( + ["arch"]="pacman -S --noconfirm git" + ["debian"]="DEBIAN_FRONTEND=noninteractive apt install -y git" + ["fedora"]="dnf install -y git" + ["ubuntu"]="DEBIAN_FRONTEND=noninteractive apt install -y git" + ["mint"]="DEBIAN_FRONTEND=noninteractive apt install -y git" + ["void"]="xpbs-install -y git " + ["gentoo"]="emerge --ask=n dev-vcs/git" + ["opensuse"]="zypper install -y git " + ) + + if [[ -v command_by_ID[$ID] ]]; then + eval "${command_by_ID[$ID]}" + elif [[ -v command_by_ID[$ID_LIKE] ]]; then + eval "${command_by_ID[$ID_LIKE]}" + fi + elif [ "$kernel" = "Darwin" ]; then + echo "macOS не поддерживается на данный момент." + exit 1 + else + echo "Неизвестная ОС: ${kernel}" + exit 1 + fi +} + + +if [ "$(id -u)" -eq 0 ]; then + SUDO="" +else + if command -v sudo &> /dev/null; then + SUDO="sudo" + elif command -v doas &> /dev/null; then + SUDO="doas" + else + echo "Скрипт не может быть выполнен не от имени суперпользователя." + exit 1 + fi +fi + +if command -v git > /dev/null 2>&1; then + echo "" +else + $SUDO install_dependencies +fi + +if [ ! -d "/opt/zapret.installer" ]; then + cd /opt || exit + $SUDO git clone https://github.com/Snowy-Fluffy/zapret.installer.git +else + cd "/opt/zapret.installer" || exit + if ! $SUDO git pull; then + echo "Ошибка при обновлении. Удаляю репозиторий и клонирую заново..." + cd /opt || exit + $SUDO rm -rf "/opt/zapret.installer" + $SUDO git clone https://github.com/Snowy-Fluffy/zapret.installer.git + cd "/opt/zapret.installer" || exit + fi +fi + +$SUDO chmod +x /opt/zapret.installer/zapret-control.sh +bash /opt/zapret.installer/zapret-control.sh +