Skip to content

Commit

Permalink
Check OS and Update packages
Browse files Browse the repository at this point in the history
- Detect OS and version
- Update necessary packages
  • Loading branch information
ReturnFI authored Sep 2, 2024
2 parents 4b3b79f + 3c08117 commit 0c42ba1
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,60 @@
# Ensure necessary packages are installed
# Check if the script is being run by the root user
#!/bin/bash

check_os_version() {
local os_name os_version

if [ -f /etc/os-release ]; then
os_name=$(grep '^ID=' /etc/os-release | cut -d= -f2)
os_version=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | tr -d '"')
else
echo "Unsupported OS or unable to determine OS version."
exit 1
fi

if ! command -v bc &> /dev/null; then
apt update && apt install -y bc
fi

if [[ "$os_name" == "ubuntu" && $(echo "$os_version >= 22" | bc) -eq 1 ]] ||
[[ "$os_name" == "debian" && $(echo "$os_version >= 11" | bc) -eq 1 ]]; then
return 0
else
echo "This script is only supported on Ubuntu 22+ or Debian 11+."
exit 1
fi
}

if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root."
exit 1
fi

clear
if ! command -v jq &> /dev/null || ! command -v git &> /dev/null || ! command -v qrencode &> /dev/null || ! command -v curl &> /dev/null; then
echo "${yellow}Necessary packages are not installed. Please wait while they are being installed..."
sleep 3
echo
apt update && apt upgrade -y && apt install jq qrencode curl pwgen uuid-runtime python3 python3-pip python3-venv git bc zip -y
check_os_version

REQUIRED_PACKAGES=("jq" "qrencode" "curl" "pwgen" "uuid-runtime" "python3" "python3-pip" "python3-venv" "git" "bc" "zip")
MISSING_PACKAGES=()

for package in "${REQUIRED_PACKAGES[@]}"; do
if ! command -v "$package" &> /dev/null; then
MISSING_PACKAGES+=("$package")
fi
done

if [ ${#MISSING_PACKAGES[@]} -ne 0 ]; then
echo "The following packages are missing and will be installed: ${MISSING_PACKAGES[@]}"
apt update && apt upgrade -y
apt install -y "${MISSING_PACKAGES[@]}"
else
echo "All required packages are already installed."
fi

git clone https://github.com/ReturnFI/Hysteria2 /etc/hysteria

# Create and activate Python virtual environment
cd /etc/hysteria
python3 -m venv hysteria2_venv
source /etc/hysteria/hysteria2_venv/bin/activate
pip install -r requirements.txt

# Add alias 'hys2' for Hysteria2
if ! grep -q "alias hys2='source /etc/hysteria/hysteria2_venv/bin/activate && /etc/hysteria/menu.sh'" ~/.bashrc; then
echo "alias hys2='source /etc/hysteria/hysteria2_venv/bin/activate && /etc/hysteria/menu.sh'" >> ~/.bashrc
source ~/.bashrc
Expand Down

0 comments on commit 0c42ba1

Please sign in to comment.