Improve download script

This commit is contained in:
crschnick 2023-05-10 00:13:49 +00:00
parent 90bc07981f
commit 2c9d26f65f

View file

@ -7,18 +7,19 @@ release_url() {
get_file_ending() { get_file_ending() {
local uname_str="$(uname -s)" local uname_str="$(uname -s)"
case "$uname_str" in case "$uname_str" in
Linux) Linux)
if [ -f "/etc/debian_version" ]; then if [ -f "/etc/debian_version" ]; then
echo "deb" echo "deb"
else else
echo "rpm" echo "rpm"
fi fi
;; ;;
Darwin) Darwin)
echo "pkg" echo "pkg"
;; ;;
*) *)
exit 1 exit 1
;;
esac esac
} }
@ -68,17 +69,18 @@ parse_os_name() {
local arch="$(uname -m)" local arch="$(uname -m)"
case "$uname_str" in case "$uname_str" in
Linux) Linux)
echo "linux" echo "linux"
;; ;;
FreeBSD) FreeBSD)
echo "linux" echo "linux"
;; ;;
Darwin) Darwin)
echo "macos" echo "macos"
;; ;;
*) *)
return 1 return 1
;;
esac esac
return 0 return 0
} }
@ -86,18 +88,25 @@ parse_os_name() {
uninstall() { uninstall() {
local uname_str="$(uname -s)" local uname_str="$(uname -s)"
case "$uname_str" in case "$uname_str" in
Linux) Linux)
if [ -d "/opt/xpipe" ]; then
info "Uninstalling previous version"
if [ -f "/etc/debian_version" ]; then if [ -f "/etc/debian_version" ]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get remove -qy xpipe DEBIAN_FRONTEND=noninteractive sudo apt-get remove -qy xpipe
else else
sudo rpm -e xpipe sudo rpm -e xpipe
fi fi
;; fi
Darwin) ;;
Darwin)
if [ -d "/Applications/X-Pipe.app" ]; then
info "Uninstalling previous version"
sudo /Applications/X-Pipe.app/Contents/Resources/scripts/uninstall.sh sudo /Applications/X-Pipe.app/Contents/Resources/scripts/uninstall.sh
;; fi
*) ;;
exit 1 *)
exit 1
;;
esac esac
} }
@ -106,18 +115,19 @@ install() {
local file="$1" local file="$1"
case "$uname_str" in case "$uname_str" in
Linux) Linux)
if [ -f "/etc/debian_version" ]; then if [ -f "/etc/debian_version" ]; then
DEBIAN_FRONTEND=noninteractive sudo apt-get install -qy "$file" DEBIAN_FRONTEND=noninteractive sudo apt-get install -qy "$file"
else else
sudo rpm -i "$file" sudo rpm -i "$file"
fi fi
;; ;;
Darwin) Darwin)
sudo installer -verboseR -allowUntrusted -pkg "$file" -target / sudo installer -verboseR -allowUntrusted -pkg "$file" -target /
;; ;;
*) *)
exit 1 exit 1
;;
esac esac
} }
@ -142,33 +152,34 @@ download_release() {
check_architecture() { check_architecture() {
local arch="$1" local arch="$1"
case "$arch" in case "$arch" in
x86_64) x86_64)
return 0
;;
amd64)
return 0
;;
arm64)
if [ "$(uname -s)" = "Darwin" ]; then
return 0 return 0
;; fi
amd64) ;;
return 0
;;
arm64)
if [ "$(uname -s)" = "Darwin" ]; then
return 0
fi
;;
esac esac
error "Sorry! X-Pipe currently does not provide your processor architecture." error "Sorry! X-Pipe currently does not provide your processor architecture."
return 1 return 1
} }
# return if sourced (for testing the functions above) # return if sourced (for testing the functions above)
return 0 2>/dev/null return 0 2>/dev/null
check_architecture "$(uname -m)" || exit 1 check_architecture "$(uname -m)" || exit 1
download_archive="$(download_release; exit "$?")" download_archive="$(
download_release
exit "$?"
)"
exit_status="$?" exit_status="$?"
if [ "$exit_status" != 0 ] if [ "$exit_status" != 0 ]; then
then
error "Could not download X-Pipe release." error "Could not download X-Pipe release."
exit "$exit_status" exit "$exit_status"
fi fi