#!/bin/bash set -eu trap 'echo "Script failed with exit code $?."' EXIT function link_to_path(){ IFS=":"; for path in $PATH; do [[ -w "$path" ]] && ln -nfs ${1}Loader/Loader ${path}/Loader && break; done IFS='\n' } function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } macos_install() { echo -e "\nDetecting macOS version..." macos_version=$(sw_vers -productVersion) echo "Running on macOS $macos_version" if [ "$(version "$macos_version")" -lt "$(version "10.13")" ]; then echo "Your macOS version is too old. QLoader requires macOS 10.13 or higher." exit 1 fi echo -e "\nDetecting processor architecture..." arch_name=$(uname -m) if [ "${arch_name}" = "x86_64" ]; then if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then echo "Running on Rosetta 2" #ARCH="arm64" ARCH="x64" else echo "Running on Intel" ARCH="x64" fi elif [ "${arch_name}" = "arm64" ]; then echo "Running on M1/M2" echo "Loader will need Rosetta 2 to run" #ARCH="arm64" ARCH="x64" else echo "Unknown architecture: ${arch_name}" exit 1 fi #if [ "$ARCH" = "arm64" ]; then #while true; do # read -p "Do you want to install the native M1 version of the Loader? (y/n) " yn # case $yn in # [Yy]* ) break;; # [Nn]* ) ARCH="x64"; break;; # * ) echo "Please answer yes or no.";; # esac #done #fi #echo "Using $ARCH architecture" echo -e "\nSelect installation directory:" # open folder picking dialog, set path to Desktop if fails TARGETPATH="$(osascript -l JavaScript -e 'a=Application.currentApplication();a.includeStandardAdditions=true;a.chooseFolder({withPrompt:"Select installation directory:"}).toString()')" || { echo "Failed to select directory, setting to Desktop"; TARGETPATH="/Users/$(whoami)/Desktop"; } # Don't allow installation to /Applications* if [[ "$TARGETPATH" == /Applications* ]]; then echo "Installation to /Applications may cause issues. Please select another directory." exit 1 fi # Add trailing slash if not present if [ "${TARGETPATH: -1}" != "/" ]; then TARGETPATH="$TARGETPATH/" fi echo "Selected installation path: ${TARGETPATH}Loader/" while true; do read -p "Do you want to install the QLoader to the selected directory? (y/n) " yn case $yn in [Yy]* ) break;; [Nn]* ) echo "Installation cancelled."; exit;; * ) echo "Please answer yes or no.";; esac done while true; do read -p "Do you want to install optional trailers add-on (~6GB)? (y/n) " yn case $yn in [Yy]* ) TRAILERS=1;break;; [Nn]* ) TRAILERS=0;break;; * ) echo "Please answer yes or no.";; esac done echo -e "\nDownloading latest release for macOS ${ARCH}..." curl --fail -L "https://cloud.dipvr.ru/onlineinstall/files/osx-$ARCH.zip" -o "/tmp/osx-$ARCH.zip" echo "Installing" if [ -d /tmp/osx-$ARCH ]; then rm -rf /tmp/osx-$ARCH fi unzip -q "/tmp/osx-$ARCH.zip" -d /tmp/ rm "/tmp/osx-$ARCH.zip" cp -rf "/tmp/osx-$ARCH/." "${TARGETPATH}Loader/" rm -r "/tmp/osx-$ARCH" if [ "$TRAILERS" = "1" ]; then echo "Downloading trailers add-on..." curl --fail -L "https://cloud.dipvr.ru/onlineinstall/files/TrailersAddon.zip" -o "/tmp/TrailersAddon.zip" echo "Download complete" echo "Copying trailers add-on to installation directory. QLoader will install it on first start." mv -f "/tmp/TrailersAddon.zip" "${TARGETPATH}Loader/TrailersAddon.zip" fi # Just in case echo "Removing quarantine attrs" chmod ugo+x "${TARGETPATH}Loader/Loader" chmod -R ugo+x "${TARGETPATH}Loader/rclone" /usr/bin/xattr -rd com.apple.quarantine "${TARGETPATH}Loader/" link_to_path $TARGETPATH echo -e "\nInstallation completed\QLoader has been installed to ${TARGETPATH}Loader/" echo -e "You can start it by double-clicking the Loader executable in Finder.\n" } linux_install() { echo -e "\nDetecting processor architecture..." arch_name=$(uname -m) if [ "${arch_name}" = "x86_64" ]; then if [ "$(getconf LONG_BIT)" == "32" ]; then echo "You are running x86 Linux" echo "Loader only supports x64 and arm64 Linux" exit 1 fi echo "Running on x64" ARCH="x64" elif [ "${arch_name}" = "arm64" ]; then echo "Running on arm64" ARCH="arm64" elif [ "${arch_name}" = "aarch64" ]; then echo "Running on aarch64" ARCH="arm64" else echo "Unknown architecture: ${arch_name}" exit 1 fi echo -e "\nEnter installation directory path or leave empty to install to current directory:" read TARGETPATH if [ -z "$TARGETPATH" ]; then TARGETPATH=$(pwd) fi # Check if directory exists if [ ! -d "$TARGETPATH" ]; then echo "Directory $TARGETPATH does not exist" exit 1 fi # Add trailing slash if not present if [ "${TARGETPATH: -1}" != "/" ]; then TARGETPATH="$TARGETPATH/" fi echo "Selected installation path: ${TARGETPATH}Loader/" while true; do read -p "Do you want to install the QLoader to the selected directory? (y/n) " yn case $yn in [Yy]* ) break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done while true; do read -p "Do you want to install optional trailers add-on (~6GB)? (y/n) " yn case $yn in [Yy]* ) TRAILERS=1;break;; [Nn]* ) TRAILERS=0;break;; * ) echo "Please answer yes or no.";; esac done echo -e "\nDownloading latest release for Linux ${ARCH}..." IFS=":"; for path in $PATH; do [[ -w "$path" ]] && ln -s ${TARGETPATH}/Loader ${path}/Loader && break; done IFS='\n' curl --fail -L "https://cloud.dipvr.ru/onlineinstall/files/linux-$ARCH.tar" -o /tmp/linux-$ARCH.tar echo "Download complete" echo "Installing" if [ -d /tmp/linux-$ARCH ]; then rm -rf /tmp/linux-$ARCH fi tar xf "/tmp/linux-$ARCH.tar" -C /tmp rm "/tmp/linux-$ARCH.tar" cp -rf "/tmp/linux-$ARCH/." "${TARGETPATH}Loader/" rm -r "/tmp/linux-$ARCH" if [ "$TRAILERS" = "1" ]; then echo "Downloading trailers add-on..." curl --fail -L "https://cloud.dipvr.ru/onlineinstall/files/TrailersAddon.zip" -o /tmp/TrailersAddon.zip echo "Download complete" echo "Copying trailers add-on to installation directory. QLoader will install it on first start." mv -f "/tmp/TrailersAddon.zip" "${TARGETPATH}Loader/TrailersAddon.zip" echo "NOTE: You need to have VLC player installed to use trailers add-on." # If we are running on Arch, show message with it's package names if [ -f /etc/pacman.conf ]; then echo "You may also need to install libx11 (from extra repository) and libvlc (from AUR)" # Else show message with debian package names else echo "You may also need to install libx11-dev and libvlc-dev packages." fi fi while true; do read -p "Do you want to create a desktop entry? (y/n) " yn case $yn in [Yy]* ) CREATESHORTCUT=1;break;; [Nn]* ) CREATESHORTCUT=0;break;; * ) echo "Please answer yes or no.";; esac done DESKTOPHINT="" if [ "$CREATESHORTCUT" = "1" ]; then echo "Creating desktop entry..." if [ ! -d ~/.local/share/applications ]; then mkdir -p ~/.local/share/applications fi cat > ~/.local/share/applications/com.ffa.qloader.desktop <