209 lines
8.0 KiB
Bash
209 lines
8.0 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
if [ "$InstallerUtilsVersion" ]; then return 0; fi
|
||
|
readonly InstallerUtilsVersion="1.0"
|
||
|
|
||
|
InstallerUtilsWorkspacePath="/tmp/verspace"
|
||
|
|
||
|
InstallerUtilsOutputDevice="/dev/stdout"
|
||
|
|
||
|
InstallerUtilsNoticeMark="*"
|
||
|
|
||
|
function installer_utils_run_spinner() {
|
||
|
local pid=$1
|
||
|
local delay=0.15
|
||
|
local spinstr='|/-\'
|
||
|
|
||
|
tput civis
|
||
|
while [ "`ps a | awk '{print $1}' | grep $pid`" ]; do
|
||
|
local temp=${spinstr#?}
|
||
|
printf " [%c] " "$spinstr"
|
||
|
local spinstr=$temp${spinstr%"$temp"}
|
||
|
sleep $delay
|
||
|
printf "\b\b\b\b\b\b"
|
||
|
done
|
||
|
|
||
|
printf " \b\b\b\b"
|
||
|
tput cnorm
|
||
|
}
|
||
|
|
||
|
# Pamaters: $1 - url $2 - regex
|
||
|
function installer_utils_check_version() {
|
||
|
if [ ! "$1" ]; then return 1; fi
|
||
|
|
||
|
# Attempt to retrieve versioning information from repository script.
|
||
|
local __installer_utils_check_version__online=("`timeout -s SIGTERM 20 curl "$1" 2>/dev/null | egrep "$2"`")
|
||
|
|
||
|
if [ "${__installer_utils_check_version__online[@]}" ]
|
||
|
then echo -e "${__installer_utils_check_version__online[@]}" > "$InstallerUtilsWorkspacePath/latest_version"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Pamaters: $1 - update url $2 - update regex $3 - local version $4 - local revision
|
||
|
function installer_utils_check_update() {
|
||
|
local versionDialog="Online Version"
|
||
|
local versionDialogOffset=$(($(tput cols) / 2 + ((${#versionDialog} / 2) - 4)))
|
||
|
printf "%${versionDialogOffset}s" "$versionDialog"
|
||
|
|
||
|
installer_utils_check_version "${@:1:2}" &
|
||
|
installer_utils_run_spinner "$!"
|
||
|
|
||
|
local __installer_utils_check_update__localVersion=$3
|
||
|
local __installer_utils_check_update__localRevision=$4
|
||
|
local __installer_utils_check_update__version="?"
|
||
|
local __installer_utils_check_update__revision="?"
|
||
|
|
||
|
if [ -f "$InstallerUtilsWorkspacePath/latest_version" -a \
|
||
|
-s "$InstallerUtilsWorkspacePath/latest_version" ]; then
|
||
|
mapfile __installer_utils_check_update__vInfo < "$InstallerUtilsWorkspacePath/latest_version"
|
||
|
__installer_utils_check_update__version=$(echo "${__installer_utils_check_update__vInfo[@]}" | awk -F= 'tolower($1)~/version/{print $2}')
|
||
|
__installer_utils_check_update__revision=$(echo "${__installer_utils_check_update__vInfo[@]}" | awk -F= 'tolower($1)~/revision/{print $2}')
|
||
|
fi
|
||
|
|
||
|
echo -e "$CClr [$__installer_utils_check_update__version.$__installer_utils_check_update__revision$CClr]"
|
||
|
|
||
|
echo
|
||
|
|
||
|
if [ "$__installer_utils_check_update__version" != "?" -a "$__installer_utils_check_update__revision" != "?" ]; then
|
||
|
if [ "$__installer_utils_check_update__version" -gt "$__installer_utils_check_update__localVersion" -o \
|
||
|
"$__installer_utils_check_update__version" -eq "$__installer_utils_check_update__localRevision" -a \
|
||
|
"$__installer_utils_check_update__revision" -gt "$__installer_utils_check_update__localRevision" ]; then
|
||
|
format_center_literals "${CRed}A newer version has been found!$CClr"
|
||
|
return 0
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
return 1 # Failure
|
||
|
}
|
||
|
|
||
|
# Parameters: $1 - Update source (zip) $2 - Backup file name $3 - Update output
|
||
|
function installer_utils_run_update() {
|
||
|
if [ ${#@} -ne 2 ]; then return 1; fi
|
||
|
|
||
|
local __installer_utils_run_update__source="$1"
|
||
|
local __installer_utils_run_update__backup="$2"
|
||
|
local __installer_utils_run_update__output="$3"
|
||
|
|
||
|
format_center_literals "${CYel}[ Press Y or enter to update, anything else to skip ]$CClr"
|
||
|
|
||
|
tput civis
|
||
|
local __installer_utils_run_update__option
|
||
|
read -N1 __installer_utils_run_update__option
|
||
|
tput cnorm
|
||
|
|
||
|
__installer_utils_run_update__option=${__installer_utils_run_update__option:-Y}
|
||
|
|
||
|
# If the user doesn't want to upgrade, stop this procedure.
|
||
|
if [ "$__installer_utils_run_update__option" != "Y" -a \
|
||
|
"$__installer_utils_run_update__option" != "y" ]
|
||
|
then return 1
|
||
|
fi
|
||
|
|
||
|
local __installer_utils_run_update__backupFile="$__installer_utils_run_update__backup-`date +%F_%T`"
|
||
|
local __installer_utils_run_update__backupPath="`dirname $__installer_utils_run_update__output`/$__installer_utils_run_update__backupFile.7z"
|
||
|
|
||
|
# If a file with the backup name already exists, abort.
|
||
|
if [ -f "$__installer_utils_run_update__backupPath" ]
|
||
|
then return 2
|
||
|
fi
|
||
|
|
||
|
format_center_literals "${CClr}[ ~ Creating Backup ~ ]$CClr"; echo
|
||
|
# This could use a progress indicator, but I'm a bit tired.
|
||
|
7zr a "$__installer_utils_run_update__backupPath" "$__installer_utils_run_update__output" &> $InstallerUtilsOutputDevice
|
||
|
|
||
|
|
||
|
format_center_literals "${CClr}[ ~ Downloading Update ~ ]$CClr"; echo
|
||
|
if ! curl -L "$__installer_utils_run_update__source" -o "$InstallerUtilsWorkspacePath/update.zip"; then
|
||
|
format_center_literals "${CRed}[ ~ Download Failed ~ ]$CClr"
|
||
|
sleep 3
|
||
|
return 3
|
||
|
fi
|
||
|
|
||
|
format_center_literals "${CClr}[ ~ Verifying Download ~ ]$CClr"; echo
|
||
|
if ! unzip -t "$InstallerUtilsWorkspacePath/update.zip"; then
|
||
|
format_center_literals "${CRed}[ ~ Download Appears Corrupted ~ ]$CClr"
|
||
|
sleep 3
|
||
|
return 4
|
||
|
fi
|
||
|
|
||
|
format_center_literals "${CClr}[ ~ Extracting Files ~ ]$CClr"; echo
|
||
|
mkdir "$InstallerUtilsWorkspacePath/update_contents"
|
||
|
unzip "$InstallerUtilsWorkspacePath/update.zip" -d "$InstallerUtilsWorkspacePath/update_contents"
|
||
|
|
||
|
|
||
|
if [ ! -d "$__installer_utils_run_update__output" ]; then
|
||
|
if ! mkdir -p "$__installer_utils_run_update__output"; then
|
||
|
format_center_literals "${CRed}[ ~ Failed To Create Destination Directory ~ ]$CClr"; echo
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
format_center_literals "${CClr}[ ~ Moving Files ~ ]$CClr"; echo
|
||
|
mv "$InstallerUtilsWorkspacePath"/update_contents/* "$__installer_utils_run_update__output"
|
||
|
|
||
|
format_center_literals "${CGrn}[ ~ Update Completed ~ ]$CClr"; echo
|
||
|
sleep 3
|
||
|
}
|
||
|
|
||
|
# Parameters: $1 - CLI Tools required array $2 - CLI Tools missing array (will be populated)
|
||
|
function installer_utils_check_dependencies() {
|
||
|
if [ ${#@} -ne 2 ]; then return 1; fi
|
||
|
|
||
|
local __installer_utils_run_dependencies__CLITools=("${!1}")
|
||
|
local __installer_utils_run_dependencies__CLIToolsMissing=("${!2}")
|
||
|
|
||
|
local __installer_utils_run_dependencies__CLITool
|
||
|
for __installer_utils_run_dependencies__CLITool in "${__installer_utils_run_dependencies__CLITools[@]}"; do
|
||
|
local __installer_utils_run_dependencies__identifier="`printf "%-44s" "$__installer_utils_run_dependencies__CLITool"`"
|
||
|
local __installer_utils_run_dependencies__state=".....$CGrn OK.$CClr"
|
||
|
|
||
|
if ! hash "$__installer_utils_run_dependencies__CLITool" 2>/dev/null; then
|
||
|
__installer_utils_run_dependencies__state="$CRed Missing!$CClr"
|
||
|
__installer_utils_run_dependencies__CLIToolsMissing+=("$__installer_utils_run_dependencies__CLITool")
|
||
|
fi
|
||
|
|
||
|
format_center_literals "$InstallerUtilsNoticeMark ${__installer_utils_run_dependencies__identifier// /.}$__installer_utils_run_dependencies__state"
|
||
|
echo -e "$FormatCenterLiterals"
|
||
|
done
|
||
|
|
||
|
if [ ${#__installer_utils_run_dependencies__CLIToolsMissing[@]} -gt 0 ]; then return 2; fi
|
||
|
}
|
||
|
|
||
|
# Parameters: $1 - CLI Tools missing array (will be installed) $2 - substitutes array
|
||
|
function installer_utils_run_dependencies() {
|
||
|
if [ "${#@}" -ne 2 ]; then return 1; fi
|
||
|
|
||
|
# The array below holds all the packages that will be installed.
|
||
|
local __installer_utils_run_dependencies__packages=("${!1}")
|
||
|
# The array below holds packages and their substitution.
|
||
|
local __installer_utils_run_dependencies__substitutes=("${!2}")
|
||
|
|
||
|
local __installer_utils_run_dependencies__managers=(lib/installer/managers/*)
|
||
|
|
||
|
local __installer_utils_run_dependencies__manager
|
||
|
for __installer_utils_run_dependencies__manager in "${__installer_utils_run_dependencies__managers[@]}"; do
|
||
|
source "$__installer_utils_run_dependencies__manager"
|
||
|
if [ "$PackageManagerCLT" ]; then break; fi
|
||
|
done
|
||
|
|
||
|
if [ ! "$PackageManagerCLT" ]; then
|
||
|
format_center_literals "${CRed}[ ~ No Suitable Package Manager Found ~ ]$CClr"; echo
|
||
|
sleep 3
|
||
|
return 2
|
||
|
fi
|
||
|
|
||
|
prep_package_manager
|
||
|
|
||
|
for __installer_utils_run_dependencies__package in "${__installer_utils_run_dependencies__packages[@]}"; do
|
||
|
clear
|
||
|
local __installer_utils_run_dependencies__target=$__installer_utils_run_dependencies__package
|
||
|
if [ "${__installer_utils_run_dependencies__substitutes[$__installer_utils_run_dependencies__package]}"
|
||
|
then __installer_utils_run_dependencies__target=${__installer_utils_run_dependencies__substitutes[$__installer_utils_run_dependencies__package]}
|
||
|
fi
|
||
|
$PackageManagerCLT $PackageManagerCLTInstallOptions $__installer_utils_run_dependencies__target
|
||
|
done
|
||
|
|
||
|
unprep_package_manager
|
||
|
}
|
||
|
|
||
|
# FLUXSCRIPT END
|