194 lines
5.0 KiB
Bash
Executable File
194 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# This is an installer for Rookeries targetting Linux, OS X and FreeBSD.
|
|
# This installer is not intended for Windows!
|
|
|
|
INSTALL_PATH="/usr/local/bin/rookeries"
|
|
DOWNLOAD_PATH="/tmp/rookeries"
|
|
|
|
detect_os () {
|
|
uname -s
|
|
}
|
|
|
|
check_curl_installed () {
|
|
local curl_installed
|
|
curl_installed="$(command -v curl)"
|
|
|
|
if [[ ! ${curl_installed} ]]
|
|
then
|
|
>&2 echo "Could not find curl. Please install it before continuing."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_sudo_installed () {
|
|
local sudo_installed
|
|
sudo_installed="$(command -v sudo)"
|
|
|
|
if [ ! "${sudo_installed}" ]
|
|
then
|
|
>&2 echo "Could not find sudo. Please install it before continuing."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_shasum_installed () {
|
|
local shasum_installed
|
|
shasum_installed="$(command -v shasum)"
|
|
|
|
if [ ! "${shasum_installed}" ]
|
|
then
|
|
>&2 echo "Could not find shasum. Please install it before continuing."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
build_rookeries_path () {
|
|
echo "https://rookeries.org/${1}"
|
|
}
|
|
|
|
latest_stable_version () {
|
|
local version_release_path
|
|
version_release_path="$(build_rookeries_path downloads/latest_stable_version)"
|
|
|
|
local latest_stable_version
|
|
latest_stable_version="$(curl -X GET "${version_release_path}" -sSf)"
|
|
echo "${latest_stable_version}"
|
|
}
|
|
|
|
is_rookeries_installed () {
|
|
local rookeries_binary_path
|
|
rookeries_binary_path="$(command -v rookeries)"
|
|
|
|
if [ -n "${rookeries_binary_path}" ] && [ -f ${INSTALL_PATH} ]
|
|
then
|
|
echo "true"
|
|
elif [ -n "${rookeries_binary_path}" ] && [ ! -f ${INSTALL_PATH} ]
|
|
then
|
|
>&2 printf "Found an installed version of Rookeries at \"%s\" not controlled by this installer." "${rookeries_binary_path}"
|
|
echo "true"
|
|
elif [ -z "${rookeries_binary_path}" ] && [ -f ${INSTALL_PATH} ]
|
|
then
|
|
>&2 printf "Detected an unexpected entity at \"%s\"." "${INSTALL_PATH}"
|
|
echo "false"
|
|
else
|
|
echo "false"
|
|
fi
|
|
}
|
|
|
|
install () {
|
|
local is_installed
|
|
is_installed="$(is_rookeries_installed)";
|
|
|
|
if [ "${is_installed}" == "true" ]
|
|
then
|
|
echo "WARNING: Rookeries is already installed!"
|
|
local continue_install
|
|
read -r -p "Do you want to continue? [y/n]: " continue_install
|
|
case "${continue_install}" in
|
|
y|Y)
|
|
echo "Attempting to re-install Rookeries..."
|
|
;;
|
|
n|N|*)
|
|
echo "Exiting installer..."
|
|
exit 0
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
check_curl_installed
|
|
check_sudo_installed
|
|
check_shasum_installed
|
|
|
|
local rookeries_version
|
|
rookeries_version="$(latest_stable_version)"
|
|
|
|
local binary_to_fetch operating_system checksum_for_binary
|
|
operating_system="$(detect_os)"
|
|
case "${operating_system}" in
|
|
Linux)
|
|
binary_to_fetch="rookeries-linux-${rookeries_version}.bin"
|
|
;;
|
|
Darwin)
|
|
binary_to_fetch="rookeries-darwin-${rookeries_version}.bin"
|
|
;;
|
|
FreeBSD)
|
|
binary_to_fetch="rookeries-freebsd-${rookeries_version}.bin"
|
|
;;
|
|
*)
|
|
echo "${operating_system} is not currently supported."
|
|
echo "You can either compile the application from source, or contact us"
|
|
echo "at <contact@amber-penguin-software.ca> to see if we can support your OS."
|
|
;;
|
|
esac
|
|
checksum_for_binary="${binary_to_fetch}.sha512"
|
|
|
|
mkdir -p ${DOWNLOAD_PATH}
|
|
local bin_download_path checksum_download_path rookeries_fetch_path
|
|
bin_download_path="${DOWNLOAD_PATH}/${binary_to_fetch}"
|
|
checksum_download_path="${DOWNLOAD_PATH}/${checksum_for_binary}"
|
|
|
|
rookeries_fetch_path="$(build_rookeries_path downloads/${rookeries_version})"
|
|
|
|
if [[ ! -f "${bin_download_path}" ]] || [[ ! -f "${checksum_download_path}" ]]
|
|
then
|
|
echo "Downloading the right version of Rookeries for your OS..."
|
|
curl --silent --show-error --output "${bin_download_path}" \
|
|
"${rookeries_fetch_path}/${binary_to_fetch}"
|
|
curl --silent --show-error --output "${checksum_download_path}" \
|
|
"${rookeries_fetch_path}/${checksum_for_binary}"
|
|
else
|
|
echo "Using downloaded binary."
|
|
fi
|
|
|
|
echo "Verifying binary..."
|
|
local difference_in_files
|
|
difference_in_files="$( (cd ${DOWNLOAD_PATH} && shasum -a 512 -c ${checksum_for_binary}) )"
|
|
if [[ "${difference_in_files}" != "${bin_download_path}: OK" ]]
|
|
then
|
|
>&2 printf "Found an unexpected difference between the files: %s\n" "${difference_in_files}"
|
|
>&2 echo "Removing the downloaded files... please try re-running the installer again."
|
|
>&2 echo "If probelms persist please contact us at: <contact@amber-penguin-software.ca>"
|
|
rm -f "${bin_download_path}"
|
|
rm -f "${checksum_download_path}"
|
|
|
|
exit 1
|
|
fi
|
|
|
|
echo "Installing Rookeries..."
|
|
chmod a+x "${bin_download_path}"
|
|
sudo cp "${bin_download_path}" "${INSTALL_PATH}"
|
|
echo "Installer activated!"
|
|
}
|
|
|
|
uninstall () {
|
|
local is_installed
|
|
is_installed="$(is_rookeries_installed)";
|
|
if [ "${is_installed}" == "false" ]
|
|
then
|
|
echo "Rookeries is not installed! Exiting..."
|
|
exit 4
|
|
fi
|
|
|
|
sudo rm ${INSTALL_PATH}
|
|
echo "Rookeries uninstalled successfully."
|
|
}
|
|
|
|
if [ "${DEBUG}" == "yes" ]
|
|
then
|
|
set -x
|
|
fi
|
|
|
|
case "$1" in
|
|
install|uninstall)
|
|
echo "Running Rookeries $1..."
|
|
$1
|
|
;;
|
|
*)
|
|
echo "Running Rookeries install..."
|
|
install
|
|
;;
|
|
esac
|