xpipe-mirror/get-xpipe.sh

251 lines
5.2 KiB
Bash
Raw Permalink Normal View History

2023-04-04 08:17:31 +00:00
#!/usr/bin/env bash
release_url() {
2023-06-20 12:49:13 +00:00
local repo="$1"
local version="$2"
if [[ -z "$version" ]] ; then
echo "$repo/releases/latest/download"
2023-05-20 15:26:28 +00:00
else
2023-06-20 12:49:13 +00:00
echo "$repo/releases/download/$version"
2023-05-20 15:26:28 +00:00
fi
2023-04-04 08:17:31 +00:00
}
get_file_ending() {
local uname_str="$(uname -s)"
case "$uname_str" in
2023-05-10 00:13:49 +00:00
Linux)
if [ -f "/etc/debian_version" ]; then
echo "deb"
else
echo "rpm"
fi
;;
Darwin)
echo "pkg"
;;
*)
exit 1
;;
2023-04-04 08:17:31 +00:00
esac
}
download_release_from_repo() {
local os_info="$1"
local tmpdir="$2"
2023-06-20 12:49:13 +00:00
local repo="$3"
local version="$4"
local arch="$5"
2023-06-20 12:49:13 +00:00
2023-04-04 08:17:31 +00:00
local ending=$(get_file_ending)
2023-06-20 12:49:13 +00:00
local release_url=$(release_url "$repo" "$version")
2023-04-04 08:17:31 +00:00
local filename="xpipe-installer-$os_info-$arch.$ending"
2023-04-04 08:17:31 +00:00
local download_file="$tmpdir/$filename"
2023-05-20 15:26:28 +00:00
local archive_url="$release_url/$filename"
2023-04-04 08:17:31 +00:00
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 00:13:49 +00:00
Linux)
echo "linux"
;;
FreeBSD)
echo "linux"
;;
Darwin)
echo "macos"
;;
*)
return 1
;;
2023-04-04 08:17:31 +00:00
esac
return 0
}
install() {
local uname_str="$(uname -s)"
local file="$1"
case "$uname_str" in
2023-05-10 00:13:49 +00:00
Linux)
if [ -f "/etc/debian_version" ]; then
2024-01-01 10:03:49 +00:00
info "Installing file $file with apt"
2024-01-11 17:42:29 +00:00
sudo apt update
2024-02-13 12:10:20 +00:00
DEBIAN_FRONTEND=noninteractive sudo apt install "$file"
2024-01-11 17:42:29 +00:00
elif [ -x "$(command -v zypper)" ]; then
info "Installing file $file with zypper"
sudo zypper refresh
2024-02-13 12:10:20 +00:00
sudo zypper install --allow-unsigned-rpm "$file"
2024-01-11 17:42:29 +00:00
elif [ -x "$(command -v dnf)" ]; then
info "Installing file $file with dnf"
2024-02-13 12:10:20 +00:00
sudo dnf install --refresh "$file"
2024-01-11 17:42:29 +00:00
elif [ -x "$(command -v yum)" ]; then
info "Installing file $file with yum"
sudo yum clean expire-cache
2024-02-13 12:10:20 +00:00
sudo yum install "$file"
2023-05-10 00:13:49 +00:00
else
2024-01-01 10:03:49 +00:00
info "Installing file $file with rpm"
2024-01-11 18:19:17 +00:00
sudo rpm -U -v --force "$file"
2023-05-10 00:13:49 +00:00
fi
;;
Darwin)
sudo installer -verboseR -allowUntrusted -pkg "$file" -target /
;;
*)
exit 1
;;
2023-04-04 08:17:31 +00:00
esac
}
launch() {
2023-09-13 08:16:20 +00:00
"$kebap_product_name" open
2023-04-04 08:17:31 +00:00
}
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)"
2023-06-20 12:49:13 +00:00
local repo="$1"
local version="$2"
download_release_from_repo "$os_info" "$download_dir" "$repo" "$version" "$arch"
2023-04-04 08:17:31 +00:00
}
check_architecture() {
local arch="$(uname -m)"
2023-04-04 08:17:31 +00:00
case "$arch" in
2023-05-10 00:13:49 +00:00
x86_64)
echo x86_64
2023-05-10 00:13:49 +00:00
;;
amd64)
echo x86_64
2023-05-10 00:13:49 +00:00
;;
arm64)
echo arm64
2023-05-10 00:13:49 +00:00
;;
2023-08-17 03:08:40 +00:00
aarch64)
echo arm64
;;
*)
exit 1
2023-08-17 03:08:40 +00:00
;;
2023-04-04 08:17:31 +00:00
esac
}
# return if sourced (for testing the functions above)
return 0 2>/dev/null
arch=$(check_architecture)
exit_status="$?"
if [ "$exit_status" != 0 ]; then
2023-09-13 08:06:00 +00:00
error "Sorry! $product_name currently does not support your processor architecture."
exit "$exit_status"
fi
2023-04-04 08:17:31 +00:00
2023-06-20 12:49:13 +00:00
repo="https://github.com/xpipe-io/xpipe"
2023-09-13 08:06:00 +00:00
aur="https://aur.archlinux.org/xpipe.git"
product_name="XPipe"
kebap_product_name="xpipe"
2023-06-20 12:49:13 +00:00
version=
while getopts 'sv:' OPTION; do
case "$OPTION" in
s)
2023-09-13 06:36:02 +00:00
repo="https://github.com/xpipe-io/xpipe-ptb"
2023-09-13 08:06:00 +00:00
aur="https://aur.archlinux.org/xpipe-ptb.git"
product_name="XPipe PTB"
kebap_product_name="xpipe-ptb"
2023-06-20 12:49:13 +00:00
;;
v)
version="$OPTARG"
;;
?)
echo "Usage: $(basename $0) [-s] [-v <version>]"
exit 1
;;
esac
done
2023-08-09 05:51:57 +00:00
if ! [ -x "$(command -v apt)" ] && ! [ -x "$(command -v rpm)" ] && [ -x "$(command -v pacman)" ]; then
2023-09-13 08:06:00 +00:00
info "Installing from AUR at $aur"
2023-08-09 05:51:57 +00:00
rm -rf "/tmp/xpipe_aur" || true
if [[ -z "$version" ]] ; then
2023-09-13 08:06:00 +00:00
git clone "$aur" /tmp/xpipe_aur
2023-08-09 05:51:57 +00:00
else
2023-09-13 08:06:00 +00:00
git clone --branch "$version" "$aur" /tmp/xpipe_aur
2023-08-09 05:51:57 +00:00
fi
cd "/tmp/xpipe_aur"
makepkg -si
launch
exit 0
fi
if ! [ -x "$(command -v apt)" ] && ! [ -x "$(command -v rpm)" ] && ! [ -x "$(command -v pacman)" ]; then
2023-09-13 08:06:00 +00:00
info "Installation is not supported on this system (no apt, rpm, pacman). Can you try a portable version of $product_name?"
2023-08-09 05:51:57 +00:00
info "https://github.com/xpipe-io/xpipe#portable"
exit 1
fi
2023-05-10 00:13:49 +00:00
download_archive="$(
download_release "$repo" "$version" "$arch"
2023-05-10 00:13:49 +00:00
exit "$?"
)"
2023-04-04 08:17:31 +00:00
exit_status="$?"
2023-05-10 00:13:49 +00:00
if [ "$exit_status" != 0 ]; then
2023-09-13 08:06:00 +00:00
error "Could not download $product_name release."
2023-04-04 08:17:31 +00:00
exit "$exit_status"
fi
install "$download_archive"
2023-08-16 16:49:11 +00:00
exit_status="$?"
if [ "$exit_status" != 0 ]; then
error "Installation failed."
exit "$exit_status"
fi
2023-08-17 16:14:54 +00:00
echo ""
2023-09-13 08:06:00 +00:00
echo "$product_name was successfully installed. You should be able to find $product_name in your desktop environment now."
2023-08-16 16:49:11 +00:00
2024-01-11 17:42:29 +00:00
launch