From d601565b96576ee2b34d71aad4bf194bf670fbc2 Mon Sep 17 00:00:00 2001 From: arisdev Date: Sat, 5 Oct 2024 21:44:26 -0600 Subject: [PATCH 1/2] . --- run-install.sh | 179 ++++++++++++++++++++++++------------------------- 1 file changed, 86 insertions(+), 93 deletions(-) diff --git a/run-install.sh b/run-install.sh index e2acf7ab..21b07f3a 100644 --- a/run-install.sh +++ b/run-install.sh @@ -1,73 +1,81 @@ -#!/bin/sh -printf "\033]0;Installer\007" -clear -rm *.bat +#!/bin/bash +set -e # Exit immediately if a command exits with a non-zero status + +# Function to log messages with timestamps +log_message() { + local msg="$1" + echo "$(date '+%Y-%m-%d %H:%M:%S') - $msg" +} + +# Function to find a suitable Python version +find_python() { + for py in python3.10 python3 python; do + if command -v "$py" > /dev/null 2>&1; then + echo "$py" + return + fi + done + log_message "No compatible Python installation found. Please install Python 3.7+." + exit 1 +} # Function to install FFmpeg based on the distribution install_ffmpeg() { - if [ -x "$(command -v apt)" ]; then - echo "Installing FFmpeg using apt..." + if command -v apt > /dev/null; then + log_message "Installing FFmpeg using apt..." sudo apt update && sudo apt install -y ffmpeg - if [ $? -ne 0 ];then - echo "Error installing FFmpeg. Check your system's package manager." - exit 1 - fi - elif [ -x "$(command -v pacman)" ]; then - echo "Installing FFmpeg using pacman..." + elif command -v pacman > /dev/null; then + log_message "Installing FFmpeg using pacman..." sudo pacman -Syu --noconfirm ffmpeg - if [ $? -ne 0 ];then - echo "Error installing FFmpeg. Check your system's package manager." - exit 1 - fi - elif [ -x "$(command -v dnf)" ]; then - echo "Installing FFmpeg using dnf..." - sudo dnf install -y ffmpeg --allowerasing - if [ $? -ne 0 ];then - echo "Error installing FFmpeg with dnf. Trying Flatpak..." - install_ffmpeg_flatpak - fi + elif command -v dnf > /dev/null; then + log_message "Installing FFmpeg using dnf..." + sudo dnf install -y ffmpeg --allowerasing || install_ffmpeg_flatpak + elif command -v brew > /dev/null; then + log_message "Installing FFmpeg using Homebrew on macOS..." + brew install ffmpeg else - echo "Unsupported distribution for FFmpeg installation. Trying Flatpak..." + log_message "Unsupported distribution for FFmpeg installation. Trying Flatpak..." install_ffmpeg_flatpak fi } # Function to install FFmpeg using Flatpak install_ffmpeg_flatpak() { - if [ -x "$(command -v flatpak)" ]; then - echo "Installing FFmpeg using Flatpak..." + if command -v flatpak > /dev/null; then + log_message "Installing FFmpeg using Flatpak..." flatpak install --user -y flathub org.freedesktop.Platform.ffmpeg - if [ $? -ne 0 ]; then - echo "Error installing FFmpeg with Flatpak. Please check your Flatpak setup." + else + log_message "Flatpak is not installed. Installing Flatpak..." + if command -v apt > /dev/null; then + sudo apt install -y flatpak + elif command -v pacman > /dev/null; then + sudo pacman -Syu --noconfirm flatpak + elif command -v dnf > /dev/null; then + sudo dnf install -y flatpak + elif command -v brew > /dev/null; then + brew install flatpak + else + log_message "Unable to install Flatpak automatically. Please install Flatpak and try again." exit 1 fi - else - echo "Flatpak is not installed. Please install Flatpak and try again." - exit 1 + flatpak install --user -y flathub org.freedesktop.Platform.ffmpeg fi } - # Function to create or activate a virtual environment prepare_install() { if [ -d ".venv" ]; then - echo "Venv found. This implies Applio has been already installed or this is a broken install." + log_message "Virtual environment found. This implies Applio has been already installed or this is a broken install." printf "Do you want to execute run-applio.sh? (Y/N): " >&2 read -r r r=$(echo "$r" | tr '[:upper:]' '[:lower:]') if [ "$r" = "y" ]; then - chmod +x run-applio.sh - ./run-applio.sh && exit 1 + chmod +x run-applio.sh + ./run-applio.sh && exit 0 else - echo "Ok! The installation will continue. Good luck!" - fi - if [ -f ".venv/bin/activate" ]; then - echo "Activating venv..." - source .venv/bin/activate - else - echo "Venv exists but activation file not found, re-creating venv..." + log_message "Continuing with the installation." rm -rf .venv - create_venv + create_venv fi else create_venv @@ -76,91 +84,76 @@ prepare_install() { # Function to create the virtual environment and install dependencies create_venv() { - echo "Creating venv..." - requirements_file="requirements.txt" - echo "Checking if python exists" - if command -v python3.10 > /dev/null 2>&1; then - py=$(which python3.10) - echo "Using python3.10" - else - if python --version | grep -qE "3\.(7|8|9|10)\."; then - py=$(which python) - echo "Using python" - else - echo "Please install Python3 or 3.10 manually." - exit 1 - fi - fi - # Try to create the env - $py -m venv .venv - if [ $? -ne 0 ]; then - echo "Error creating the virtual environment. Check Python installation or permissions." - exit 1 - fi - echo "Activating venv..." + log_message "Creating virtual environment..." + py=$(find_python) + + # Create the virtual environment + "$py" -m venv .venv + + log_message "Activating virtual environment..." source .venv/bin/activate - # Install pip using ensurepip or get-pip.py - echo "Installing pip..." - python -m ensurepip --upgrade - if [ $? -ne 0 ]; then - echo "Error with ensurepip, attempting manual pip installation..." + # Install pip if necessary and upgrade + log_message "Ensuring pip is installed..." + python -m ensurepip --upgrade || { + log_message "ensurepip failed, attempting manual pip installation..." curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py - if [ $? -ne 0 ]; then - echo "Failed to install pip manually. Check permissions and internet connection." - exit 1 - fi - fi + } python -m pip install --upgrade pip install_ffmpeg - echo "Installing Applio dependencies..." - python -m pip install -r requirements.txt - if [ $? -ne 0 ]; then - echo "Error installing Applio dependencies." + # Install dependencies + log_message "Installing Applio dependencies..." + if [ -f "requirements.txt" ]; then + python -m pip install -r requirements.txt + else + log_message "requirements.txt not found. Please ensure it exists." exit 1 fi + # Install specific PyTorch version + log_message "Installing PyTorch and related packages..." + python -m pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --upgrade --index-url https://download.pytorch.org/whl/cu121 - python -m pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --upgrade --index-url https://download.pytorch.org/whl/cu121 finish } # Function to finish installation finish() { - if [ -f "${requirements_file}" ]; then + log_message "Verifying installed packages..." + if [ -f "requirements.txt" ]; then installed_packages=$(python -m pip freeze) while IFS= read -r package; do expr "${package}" : "^#.*" > /dev/null && continue package_name=$(echo "${package}" | sed 's/[<>=!].*//') if ! echo "${installed_packages}" | grep -q "${package_name}"; then - echo "${package_name} not found. Attempting to install..." + log_message "${package_name} not found. Attempting to install..." python -m pip install --upgrade "${package}" fi - done < "${requirements_file}" + done < "requirements.txt" else - echo "${requirements_file} not found. Please ensure the requirements file with required packages exists." + log_message "requirements.txt not found. Please ensure it exists." exit 1 fi - clear - echo "Applio has been successfully downloaded. Run the file run-applio.sh to run the web interface!" + log_message "Applio has been successfully installed. Run the file run-applio.sh to start the web interface!" exit 0 } -# Main menu loop +# Main script execution if [ "$(uname)" = "Darwin" ]; then + log_message "Detected macOS..." if ! command -v brew >/dev/null 2>&1; then + log_message "Homebrew not found. Installing Homebrew..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - else - brew install python@3.10 - export PYTORCH_ENABLE_MPS_FALLBACK=1 - export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 fi + brew install python@3.10 + export PYTORCH_ENABLE_MPS_FALLBACK=1 + export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 elif [ "$(uname)" != "Linux" ]; then - echo "Unsupported operating system. Are you using Windows...?" - echo "If yes, use the batch (.bat) file instead of this one!" + log_message "Unsupported operating system. Are you using Windows?" + log_message "If yes, use the batch (.bat) file instead of this one!" exit 1 fi From 175a54efd5113bb9ce820c3bae7a8003eee30a0d Mon Sep 17 00:00:00 2001 From: arisdev Date: Sat, 5 Oct 2024 22:11:24 -0600 Subject: [PATCH 2/2] . --- run-install.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/run-install.sh b/run-install.sh index 21b07f3a..cb1c9b79 100644 --- a/run-install.sh +++ b/run-install.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e # Exit immediately if a command exits with a non-zero status +printf "\033]0;Installer\007" +clear +rm -f *.bat + # Function to log messages with timestamps log_message() { local msg="$1" @@ -87,7 +91,6 @@ create_venv() { log_message "Creating virtual environment..." py=$(find_python) - # Create the virtual environment "$py" -m venv .venv log_message "Activating virtual environment..." @@ -104,8 +107,7 @@ create_venv() { install_ffmpeg - # Install dependencies - log_message "Installing Applio dependencies..." + log_message "Installing dependencies..." if [ -f "requirements.txt" ]; then python -m pip install -r requirements.txt else @@ -113,8 +115,7 @@ create_venv() { exit 1 fi - # Install specific PyTorch version - log_message "Installing PyTorch and related packages..." + log_message "Installing PyTorch..." python -m pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --upgrade --index-url https://download.pytorch.org/whl/cu121 finish @@ -137,7 +138,9 @@ finish() { log_message "requirements.txt not found. Please ensure it exists." exit 1 fi - log_message "Applio has been successfully installed. Run the file run-applio.sh to start the web interface!" + + clear + echo "Applio has been successfully installed. Run the file run-applio.sh to start the web interface!" exit 0 }