Update unix_install.sh, conversione da bash a sh, supporto bsd

This commit is contained in:
BluTiger 2024-09-24 11:38:07 +02:00 committed by GitHub
parent 43c37a88b2
commit 05455e303a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,49 +1,50 @@
#!/bin/bash #!/bin/sh
# Function to check if a command exists # Function to check if a command exists
command_exists() { command_exists() {
command -v "$1" &> /dev/null command -v "$1" > /dev/null 2>&1
} }
# Install on Debian/Ubuntu-based systems # Install on Debian/Ubuntu-based systems
install_on_debian() { install_on_debian() {
echo "Installing $1..." echo "Installing $1..."
sudo apt update sudo apt update
sudo apt install -y $1 sudo apt install -y "$1"
} }
# Install on Red Hat/CentOS/Fedora-based systems # Install on Red Hat/CentOS/Fedora-based systems
install_on_redhat() { install_on_redhat() {
echo "Installing $1..." echo "Installing $1..."
sudo yum install -y $1 sudo yum install -y "$1"
} }
# Install on Arch-based systems # Install on Arch-based systems
install_on_arch() { install_on_arch() {
echo "Installing $1..." echo "Installing $1..."
sudo pacman -Sy --noconfirm $1 sudo pacman -Sy --noconfirm "$1"
} }
# Install on BSD-based systems # Install on BSD-based systems
install_on_bsd() { install_on_bsd() {
echo "Installing $1..." echo "Installing $1..."
env ASSUME_ALWAYS_YES=yes pkg install -y $1 env ASSUME_ALWAYS_YES=yes sudo pkg install -y "$1"
} }
# Install on macOS # Install on macOS
install_on_macos() { install_on_macos() {
echo "Installing $1..." echo "Installing $1..."
if command_exists brew; then if command_exists brew; then
brew install $1 brew install "$1"
else else
echo "Homebrew is not installed. Installing Homebrew first..." echo "Homebrew is not installed. Installing Homebrew first..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install $1 brew install "$1"
fi fi
} }
set -e set -e
# Check and install Python3 # Check and install Python3
# if command_exists python3 > /dev/null 2>&1; then # if command_exists python3 > /dev/null 2>&1; then
# echo "Checking Python..." # echo "Checking Python..."
@ -78,7 +79,7 @@ PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_inf
# Compare the Python version with 3.8 # Compare the Python version with 3.8
REQUIRED_VERSION="3.8" REQUIRED_VERSION="3.8"
if [[ $(echo -e "$PYTHON_VERSION\n$REQUIRED_VERSION" | sort -V | head -n1) == "$REQUIRED_VERSION" ]]; then if [ "$(echo -e "$PYTHON_VERSION\n$REQUIRED_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
echo "Python version $PYTHON_VERSION is >= $REQUIRED_VERSION. Continuing..." echo "Python version $PYTHON_VERSION is >= $REQUIRED_VERSION. Continuing..."
else else
echo "ERROR: Python version $PYTHON_VERSION is < $REQUIRED_VERSION. Exiting..." echo "ERROR: Python version $PYTHON_VERSION is < $REQUIRED_VERSION. Exiting..."
@ -86,12 +87,13 @@ else
fi fi
if [ -d ".venv/" ]; then if [ -d ".venv/" ]; then
echo ".venv exists. Installing requirements.txt. ..." echo ".venv exists. Installing requirements.txt..."
.venv/bin/pip install -r requirements.txt .venv/bin/pip install -r requirements.txt
else else
echo "Making .venv and installing requirements.txt. ..." echo "Making .venv and installing requirements.txt..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Detect the package manager if [ "$(uname)" = "Linux" ]; then
# Detect the package manager for venv installation check.
if command_exists apt; then if command_exists apt; then
echo "Detected Debian-based system. Checking python3-venv." echo "Detected Debian-based system. Checking python3-venv."
if dpkg -l | grep -q "python3-venv"; then if dpkg -l | grep -q "python3-venv"; then
@ -102,33 +104,29 @@ else
fi fi
fi fi
fi fi
python3 -m venv .venv python3 -m venv .venv
.venv/bin/pip install -r requirements.txt .venv/bin/pip install -r requirements.txt
fi fi
if command_exists ffmpeg > /dev/null 2>&1; then if command_exists ffmpeg; then
echo "ffmpeg exists." echo "ffmpeg exists."
else else
echo "ffmpeg does no exists." echo "ffmpeg does not exist."
# Detect the platform and install ffmpeg accordingly
if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Detect the platform and install ffmpeg accordingly.
# Detect the package manager case "$(uname)" in
Linux)
if command_exists apt; then if command_exists apt; then
echo "Detected Debian-based system." echo "Detected Debian-based system."
install_on_debian "ffmpeg" install_on_debian "ffmpeg"
elif command_exists yum; then elif command_exists yum; then
echo "Detected Red Hat-based system." echo "Detected Red Hat-based system."
echo "Installing needed repos for ffmpeg..." echo "Installing needed repos for ffmpeg..."
echo "Enabling crb..." sudo yum config-manager --set-enabled crb > /dev/null 2>&1 || true
sudo yum config-manager --set-enabled crb > /dev/null 2>&1 sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-$(rpm -E %rhel).noarch.rpm > /dev/null 2>&1 || true
echo "crb enabled." sudo yum install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm > /dev/null 2>&1 || true
echo "Installig epel..."
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-$(rpm -E %rhel).noarch.rpm > /dev/null 2>&1
echo "epel installed."
echo "Adding ffmpeg repos..."
sudo yum install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm > /dev/null 2>&1
echo "ffmpeg repos added."
install_on_redhat "ffmpeg" install_on_redhat "ffmpeg"
elif command_exists pacman; then elif command_exists pacman; then
echo "Detected Arch-based system." echo "Detected Arch-based system."
@ -137,62 +135,66 @@ else
echo "Unsupported Linux distribution." echo "Unsupported Linux distribution."
exit 1 exit 1
fi fi
elif [[ "$OSTYPE" == "bsd"* ]]; then ;;
FreeBSD|NetBSD|OpenBSD)
echo "Detected BSD-based system." echo "Detected BSD-based system."
install_on_bsd "ffmpeg" install_on_bsd "ffmpeg"
elif [[ "$OSTYPE" == "darwin"* ]]; then ;;
Darwin)
echo "Detected macOS." echo "Detected macOS."
install_on_macos "ffmpeg" install_on_macos "ffmpeg"
else ;;
*)
echo "Unsupported operating system." echo "Unsupported operating system."
exit 1 exit 1
fi ;;
esac
fi fi
if command_exists openssl > /dev/null 2>&1 || .venv/bin/pip list | grep -q "pycryptodome"; then if command_exists openssl || .venv/bin/pip list | grep -q pycryptodome; then
echo "openssl or pycryptodome exists." echo "openssl or pycryptodome exists."
else else
echo "Please choose an option:" echo "Please choose an option:"
echo "1) openssl" echo "1) openssl"
echo "2) pycryptodome" echo "2) pycryptodome"
read -p "Enter your choice (1): " choice read -p "Enter your choice (1): " choice
case $choice in
case "$choice" in
2) 2)
echo "Installing pycryptodome." echo "Installing pycryptodome."
.venv/bin/pip install pycryptodome .venv/bin/pip install pycryptodome
;; ;;
*) *)
# Detect the platform and install OpenSSL accordingly # Detect the platform and install OpenSSL accordingly.
if [[ "$OSTYPE" == "linux-gnu"* ]]; then case "$(uname)" in
# Detect the package manager Linux)
if command_exists apt; then if command_exists apt; then
echo "Detected Debian-based system." install_on_debian openssl
install_on_debian "openssl"
elif command_exists yum; then elif command_exists yum; then
echo "Detected Red Hat-based system." install_on_redhat openssl
install_on_redhat "openssl"
elif command_exists pacman; then elif command_exists pacman; then
echo "Detected Arch-based system." install_on_arch openssl
install_on_arch "openssl"
else else
echo "Unsupported Linux distribution." echo "Unsupported Linux distribution."
exit 1 exit 1
fi fi
elif [[ "$OSTYPE" == "bsd"* ]]; then ;;
echo "Detected BSD-based system." FreeBSD|NetBSD|OpenBSD)
install_on_bsd "openssl" install_on_bsd openssl
elif [[ "$OSTYPE" == "darwin"* ]]; then ;;
echo "Detected macOS." Darwin)
install_on_macos "openssl" install_on_macos openssl
else ;;
*)
echo "Unsupported operating system." echo "Unsupported operating system."
exit 1 exit 1
fi ;;
esac
;; ;;
esac esac
fi fi
sed -i.bak "1s|.*|#!.venv/bin/python3|" run.py sed -i.bak '1s|.*|#!.venv/bin/python3|' run.py
sudo chmod +x run.py sudo chmod +x run.py
echo "Everything is installed!" echo 'Everything is installed!'
echo "Run StreamingCommunity with './run.py'" echo 'Run StreamingCommunity with "./run.py"'