#!/bin/bash ######################## #### Author: Osguot #### ######################## VERSION="4.0.1" ## This file contain information about install directory and type of installation arx_downloader_conf_file="/home/$USER/.config/arx_downloader.conf" ## Export conf file if exist if [ -f "$arx_downloader_conf_file" ] then source $arx_downloader_conf_file fi ## User share directory variable USER_SHARE=/home/$USER/.local/share function scriptUpdate () { gitScriptVer=$(wget -O- https://raw.githubusercontent.com/osguot/arx-downloader/master/arx_downloader | grep 'VERSION=' | head -1 | cut -c 9- | tr -d '"') if [[ "$gitScriptVer" > "$VERSION" ]] then zenity --question --no-wrap --ok-label="$_updateLabel" --cancel-label="$_exitLabel" --title="$_funSU_title" --text="$_funSU_text" if [ $? -eq "0" ] then rm arx_downloader wget https://raw.githubusercontent.com/osguot/arx-downloader/master/arx_downloader chmod +x arx_downloader zenity --info --no-wrap --title="$_funSU_title" --text="$_funSU_textSuccess" exit 0 else exit 1 fi fi } function initialCheck () { ## Language selection local lang=$(zenity --list --width=250 --cancel-label="Exit" --ok-label="Ok" --title "Arx Downloader" --text "Please select script language" --radiolist --hide-header --column "" --column "Script language" TRUE "English" FALSE "Russian") if [ $? -eq "0" ] then case $lang in "English") lang_file="./en_US.lang" if [ -f "$lang_file" ] then source ./en_US.lang else wget https://raw.githubusercontent.com/osguot/arx-downloader/master/en_US.lang source ./en_US.lang fi;; "Russian") lang_file="./ru_RU.lang" if [ -f "$lang_file" ] then source ./ru_RU.lang else wget https://raw.githubusercontent.com/osguot/arx-downloader/master/ru_RU.lang source ./ru_RU.lang fi;; esac else exit 1 fi ## Zenity check if [[ $(hash zenity) -eq "1" ]] then echo "$_funIC_zenityNotFound" exit 1 fi ## Root check if [ "$EUID" -eq 0 ] then zenity --error --no-wrap --ok-label="$_exitLabel" --width=250 --title="$_funIC_titleError" --text="$_funIC_textError" exit 1 fi ## Check for previous installation if [ -f "$arx_downloader_conf_file" ] then ## Set main menu text based on previous installation (if exist) if [ "$TYPE" = "OnlyLibertatis" ] then declare -g MM_text="$_funIC_mainMenuConstructorAlOnly" elif [ "$TYPE" = "OnlyFatalis" ] then declare -g MM_text="$_funIC_mainMenuConstructorAfOnly" elif [ "$TYPE" = "Complex" ] then declare -g MM_text="$_funIC_mainMenuConstructorComplex" fi else declare -g MM_text="$_funIC_mainMenuConstructorDefault" fi } function libertatisDownload () { ## Set Arx Libertatis install directory directory=$(zenity --list --width=400 --cancel-label="$_exitLabel" --ok-label="$_nextLabel" --title "$_funMain_title" --text "$_funLD_text" --radiolist --hide-header --column "" --column "$_funLD_column" TRUE "$_funLD_defaultOption" FALSE "$_funLD_chooseOption") if [ $? -eq "0" ] then if [ "$directory" = "$_funLD_defaultOption" ] then declare -g install_folder="$USER_SHARE" cd $install_folder if [ -d "arx" ] then rm -r arx fi mkdir -p "$install_folder/arx" else if [ "$directory" = "$_funLD_chooseOption" ] then declare -g install_folder=`zenity --file-selection --directory --title="$_funLD_fsTitle"` if [ $? -eq "0" ] then cd $install_folder if [ -d "arx" ] then rm -r arx fi mkdir -p "$install_folder/arx" else end fi fi fi else end fi ## Save working folder for uninstaller toConfFile "TYPE=OnlyLibertatis" "INSTALL_DIR=$install_folder" ## Check latest version #getLatestLibertatisVersion | zenity --progress --width=300 --pulsate --cancel-label="$_cancelLabel" --title="$_funMain_title" --text="$_funLD_text2" --auto-close ## Choosing Libertatis version dialog, downloading, unpacking and installing ver=$(zenity --list --width=480 --cancel-label="$_exitLabel" --ok-label="$_nextLabel" --title "$_funMain_title" --text="$_funLD_text3" --radiolist --column="" --column="$_funLD_column2" TRUE "$_funLD_latestStableOption" FALSE "$_funLD_latestDevOption") if [ $? -eq "0" ] then if [ "$ver" = "$_funLD_latestStableOption" ] then cd $install_folder/arx curl -sqL $latestStableLinuxVerURL | tar xJf - | zenity --progress --width=300 --pulsate --cancel-label="$_cancelLabel" --title="$_funMain_title" --text="$_funLD_text4" --auto-close ## Move all downloaded files into arx diectory cd $latestStableVer-linux find . -maxdepth 1 -exec mv {} .. \; rmdir ../$latestStableVer-linux ## Send choosen version to conf file toConfFile "AL_VERSION=Stable" else ## Go to install directory and download archive into it cd $install_folder/arx curl -sqL $latestLinuxVerURL | tar xJf - | zenity --progress --width=300 --pulsate --cancel-label="$_cancelLabel" --title="$_funMain_title" --text="$_funLD_text4" --auto-close ## Move all downloaded files into arx diectory cd $latestVer-linux find . -maxdepth 1 -exec mv {} .. \; rmdir ../$latestVer-linux ## Send choosen version to conf file toConfFile "AL_VERSION=$latestVer" fi else end fi ## Download game data if complex parameter has been set if [ "$1" = "complex" ] then gameDownload complex else zenity --info --no-wrap --title="$_funMain_title" --ok-label="$_okLabel" --text="$_funLD_text5" fi ## Call install function zenity --question --no-wrap --ok-label="$_yesLabel" --cancel-label="$_noLabel" --title="$_funMain_title" --text="$_funLD_text6" if [ $? -eq "0" ] then libertatisInstall fi } function getLatestLibertatisVersion () { ## Detecting latest stable version of Arx Libertatis from arx-libertatis.org latestStableVer=$(wget -O- http://arx-libertatis.org/files/ | grep -Eo 'arx-libertatis-[[:digit:]]{1}.[[:digit:]]{1}.[[:digit:]]{1}' | sort -V | tail -1) ## Detecting latest dev version of Arx Libertatis from arx-libertatis.org latestVer=$(wget -O- http://arx-libertatis.org/files/snapshots/ | grep -Eo 'arx-libertatis-1.2-dev-[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}' | sort -V | tail -1) ## Set file name and url for the latest stable Arx Libertatis version latestStableLinuxVerFile=$latestStableVer"-linux.tar.xz" latestStableLinuxVerURL="http://arx-libertatis.org/files/$latestStableVer/$latestStableLinuxVerFile" ## Set file name and url for the latest Arx Libertatis version latestLinuxVerFile=$latestVer"-linux.tar.xz" latestLinuxVerURL="http://arx-libertatis.org/files/snapshots/$latestVer/$latestLinuxVerFile" ## "short-version" variables latestStableVerShort=$(echo $latestStableVer | cut -c 16-) latestVerShort=$(echo $latestVer | cut -c 16-) } function libertatisVersionChecker () { function libertatisUpdate () { ## Go to install directory and download archive into it cd $INSTALL_DIR/arx curl -sqL $latestLinuxVerURL | tar xJf - | zenity --progress --width=300 --pulsate --cancel-label="$_cancelLabel" --title="$_funLU_title" --text="$_funLU_text" --auto-close cd $latestVer-linux ## Remove old bin and data directories and copy new one rm -rf ../{bin,data} mv {bin,data} ../ rm -rf ../$latestVer-linux ## Change Arx Libertatis version in config file oldVersion=$(grep "AL_VERSION=" $arx_downloader_conf_file) sed -i -e "s/$oldVersion/AL_VERSION=$latestVer/g" $arx_downloader_conf_file zenity --info --no-wrap --title="$_funLU_title" --text="$_funLU_text2" } ## Check conf file if [ -f "$arx_downloader_conf_file" ] then ## Check current installed version if [ -z "$AL_VERSION" ] then zenity --warning --no-wrap --title="$_funLU_title" --ok-label="$_exitLabel" --text="$_funLU_text3" exit 1 elif [ "$AL_VERSION" = "Stable" ] then upgr=$(zenity --question --no-wrap --title="$_funLU_title" --ok-label="$_yesLabel" --cancel-label="$_noLabel" --text="$_funLU_text4") ## Exit if No if [ $? -eq "1" ] then exit 0 fi fi else zenity --warning --no-wrap --title="$_funLU_title" --ok-label="$_exitLabel" --text="$_funLU_text3" exit 1 fi ## Call getLatestLibertatisVersion function #getLatestLibertatisVersion | zenity --progress --width=300 --pulsate --cancel-label="$_cancelLabel" --title="$_funLU_title" --text="$_funLU_text5" --auto-close ## arx-libertatis-1.2-dev-YYYY-MM-DD --> YYYY-MM-DD latest=$(echo $latestVer | grep -Eo '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}') current=$(echo $AL_VERSION | grep -Eo '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}') ## Version comparison if [[ "$latest" > "$current" ]] then upd=$(zenity --question --no-wrap --title="$_funLU_title" --ok-label="$_yesLabel" --cancel-label="$_noLabel" --text="$_funLU_text6") if [ $? -eq "0" ] then libertatisUpdate else exit 0 fi else zenity --warning --no-wrap --title="$_funLU_title" --ok-label="$_exitLabel" --text="$_funLU_text7" exit 0 fi } function libertatisInstall () { ## Install binaries pkexec < $arx_downloader_conf_file echo "$2" >> $arx_downloader_conf_file ## Else - add line to existing file else echo "$1" >> $arx_downloader_conf_file fi } function end () { ## Delete arx_downloader.conf file when canceled rm $arx_downloader_conf_file exit 1 } function main () { ## Main menu constructor if [ -f "$arx_downloader_conf_file" ] then if [ "$TYPE" = "Complex" ] || [ "$TYPE" = "OnlyLibertatis" ] then menu=$(zenity --list --width=310 --height=250 --cancel-label="$_exitLabel" --ok-label="$_nextLabel" --title "$_funMain_title" --text="$MM_text" --radiolist --column="" --column="" TRUE "$_funMain_checkForUpdatesOption" FALSE "$_funMain_uninstallOption") elif [ "$TYPE" = "OnlyFatalis" ] then menu=$(zenity --list --width=310 --height=250 --cancel-label="$_exitLabel" --ok-label="$_nextLabel" --title "$_funMain_title" --text="$MM_text" --radiolist --column="" --column="" TRUE "$_funMain_uninstallOption") fi else menu=$(zenity --list --width=310 --height=250 --cancel-label="$_exitLabel" --ok-label="$_nextLabel" --title "$_funMain_title" --text="$MM_text" --radiolist --column="" --column="" TRUE "$_funMain_downloadAllOption" FALSE "$_funMain_downloadAlOnlyOption" FALSE "$_funMain_downloadAfOnlyOption" FALSE "$_funMain_checkForUpdatesOption" FALSE "$_funMain_uninstallOption") fi if [ $? -eq "0" ] then case $menu in "$_funMain_downloadAllOption") libertatisDownload complex;; "$_funMain_downloadAlOnlyOption") libertatisDownload;; "$_funMain_downloadAfOnlyOption") gameDownload;; "$_funMain_checkForUpdatesOption") libertatisVersionChecker;; "$_funMain_uninstallOption") libertatisUninstaller;; esac else exit 1 fi } getLatestLibertatisVersion initialCheck scriptUpdate main