xpipe/get-xpipe.sh

190 lines
3.4 KiB
Bash
Raw Normal View History

2023-04-04 20:17:31 +12:00
#!/usr/bin/env bash
release_url() {
echo "https://github.com/xpipe-io/xpipe/releases/latest/download"
}
get_file_ending() {
local uname_str="$(uname -s)"
case "$uname_str" in
2023-05-10 12:13:49 +12:00
Linux)
if [ -f "/etc/debian_version" ]; then
echo "deb"
else
echo "rpm"
fi
;;
Darwin)
echo "pkg"
;;
*)
exit 1
;;
2023-04-04 20:17:31 +12:00
esac
}
download_release_from_repo() {
local os_info="$1"
local tmpdir="$2"
local ending=$(get_file_ending)
local arch="$(uname -m)"
2023-04-04 20:17:31 +12:00
local filename="xpipe-installer-$os_info-$arch.$ending"
2023-04-04 20:17:31 +12:00
local download_file="$tmpdir/$filename"
local archive_url="$(release_url)/$filename"
info "Downloading file $archive_url"
curl --progress-bar --show-error --location --fail "$archive_url" --output "$download_file" --write-out "$download_file"
}
info() {
local action="$1"
local details="$2"
command printf '\033[1;32m%12s\033[0m %s\n' "$action" "$details" 1>&2
}
error() {
command printf '\033[1;31mError\033[0m: %s\n\n' "$1" 1>&2
}
warning() {
command printf '\033[1;33mWarning\033[0m: %s\n\n' "$1" 1>&2
}
request() {
command printf '\033[1m%s\033[0m\n' "$1" 1>&2
}
eprintf() {
command printf '%s\n' "$1" 1>&2
}
bold() {
command printf '\033[1m%s\033[0m' "$1"
}
# returns the os name to be used in the packaged release
parse_os_name() {
local uname_str="$1"
local arch="$(uname -m)"
case "$uname_str" in
2023-05-10 12:13:49 +12:00
Linux)
echo "linux"
;;
FreeBSD)
echo "linux"
;;
Darwin)
echo "macos"
;;
*)
return 1
;;
2023-04-04 20:17:31 +12:00
esac
return 0
}
uninstall() {
local uname_str="$(uname -s)"
case "$uname_str" in
2023-05-10 12:13:49 +12:00
Linux)
if [ -d "/opt/xpipe" ]; then
info "Uninstalling previous version"
2023-04-04 20:17:31 +12:00
if [ -f "/etc/debian_version" ]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get remove -qy xpipe
else
sudo rpm -e xpipe
fi
2023-05-10 12:13:49 +12:00
fi
;;
Darwin)
2023-05-21 02:23:36 +12:00
if [ -d "/Applications/XPipe.app" ]; then
2023-05-10 12:13:49 +12:00
info "Uninstalling previous version"
2023-05-21 02:23:36 +12:00
sudo /Applications/XPipe.app/Contents/Resources/scripts/uninstall.sh
2023-05-10 12:13:49 +12:00
fi
;;
*)
exit 1
;;
2023-04-04 20:17:31 +12:00
esac
}
install() {
local uname_str="$(uname -s)"
local file="$1"
case "$uname_str" in
2023-05-10 12:13:49 +12:00
Linux)
if [ -f "/etc/debian_version" ]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get install -qy "$file"
else
sudo rpm -i "$file"
fi
;;
Darwin)
sudo installer -verboseR -allowUntrusted -pkg "$file" -target /
;;
*)
exit 1
;;
2023-04-04 20:17:31 +12:00
esac
}
launch() {
xpipe open
}
download_release() {
local uname_str="$(uname -s)"
local os_info
os_info="$(parse_os_name "$uname_str")"
if [ "$?" != 0 ]; then
error "The current operating system ($uname_str) does not appear to be supported."
return 1
fi
# store the downloaded archive in a temporary directory
local download_dir="$(mktemp -d)"
download_release_from_repo "$os_info" "$download_dir"
}
check_architecture() {
local arch="$1"
case "$arch" in
2023-05-10 12:13:49 +12:00
x86_64)
return 0
;;
amd64)
return 0
;;
arm64)
if [ "$(uname -s)" = "Darwin" ]; then
2023-04-04 20:17:31 +12:00
return 0
2023-05-10 12:13:49 +12:00
fi
;;
2023-04-04 20:17:31 +12:00
esac
2023-05-21 02:23:36 +12:00
error "Sorry! XPipe currently does not provide your processor architecture."
2023-04-04 20:17:31 +12:00
return 1
}
# return if sourced (for testing the functions above)
return 0 2>/dev/null
check_architecture "$(uname -m)" || exit 1
2023-05-10 12:13:49 +12:00
download_archive="$(
download_release
exit "$?"
)"
2023-04-04 20:17:31 +12:00
exit_status="$?"
2023-05-10 12:13:49 +12:00
if [ "$exit_status" != 0 ]; then
2023-05-21 02:23:36 +12:00
error "Could not download XPipe release."
2023-04-04 20:17:31 +12:00
exit "$exit_status"
fi
uninstall
install "$download_archive"
launch