breezy-desktop/bin/breezy_gnome_setup

120 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# This setup script should do the minimum work required to download the release package, unzip it, and kick off the
# setup script contained within.
# exit when any command fails
set -e
if [ "$(id -u)" == "0" ]; then
echo "This script must not be run as root" 1>&2
exit 1
fi
check_command() {
if ! command -v "$1" &>/dev/null; then
echo "Please install \"$1\" and make sure it's available in your \$PATH, then rerun the setup."
exit 1
fi
}
check_command "curl"
check_command "gnome-shell"
check_command "jq"
ARCH=$(uname -m)
FILE_NAME="breezyGNOME-$ARCH.tar.gz"
LIBS_FILE_NAME="breezyGNOME-libs-$ARCH.tar.gz"
GNOME_VERSION=$(gnome-shell --version | cut -d' ' -f3 | cut -d'.' -f1)
VERSION_SPECIFIC_FILENAME="breezyGNOME-$GNOME_VERSION-$ARCH.tar.gz"
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/wheaney/breezy-desktop/releases/latest")
if echo "$LATEST_RELEASE" | jq -e --arg filename "$VERSION_SPECIFIC_FILENAME" '.assets[] | select(.name == $filename)' > /dev/null; then
echo "Performing setup for GNOME $GNOME_VERSION ($ARCH)"
FILE_NAME=$VERSION_SPECIFIC_FILENAME
elif [ "$GNOME_VERSION" -lt 45 ]; then
echo "Performing setup for GNOME 44 and below ($ARCH)"
FILE_NAME="breezyGNOME-44-max-$ARCH.tar.gz"
else
echo "Performing setup for GNOME 45 and up ($ARCH)"
fi
start_dir=$(pwd)
# create temp directory
tmp_dir=$(mktemp -d -t breezy-gnome-XXXXXXXXXX)
pushd $tmp_dir > /dev/null
echo "Created temp directory: ${tmp_dir}"
binary_download_url="https://github.com/wheaney/breezy-desktop/releases/latest/download/$FILE_NAME"
libs_download_url="https://github.com/wheaney/breezy-desktop/releases/latest/download/$LIBS_FILE_NAME"
if [ "$1" = "-v" ]
then
metrics_version="$2"
local_dir_arg="$3"
elif [ "$1" = "--tag" ] && [ -n "$2" ]
then
binary_download_url="https://github.com/wheaney/breezy-desktop/releases/download/$2/$FILE_NAME"
libs_download_url="https://github.com/wheaney/breezy-desktop/releases/download/$2/$LIBS_FILE_NAME"
else
local_dir_arg="$1"
fi
if [ -n "$local_dir_arg" ]
then
if [[ "$local_dir_arg" = /* ]]; then
local_dir="$local_dir_arg"
else
local_dir=$(realpath "$start_dir/$local_dir_arg")
fi
binary_path_arg="$local_dir/$FILE_NAME"
if [ ! -f "$binary_path_arg" ]; then
echo "Error: Breezy GNOME archive not found at $binary_path_arg" 1>&2
exit 1
fi
lib_path_arg="$local_dir/$LIBS_FILE_NAME"
if [ ! -f "$lib_path_arg" ]; then
echo "Error: Breezy GNOME libs archive not found at $lib_path_arg" 1>&2
exit 1
fi
fi
if [ -z "$binary_path_arg" ]
then
# download and unzip the binary
binary_path_arg="$FILE_NAME"
echo "Downloading to: ${tmp_dir}/$binary_path_arg"
curl -L "$binary_download_url" > "$binary_path_arg"
else
cp "$binary_path_arg" "$tmp_dir"
fi
echo "Extracting to: ${tmp_dir}/breezy_gnome"
tar -xf $(basename $binary_path_arg)
if [ -z "$lib_path_arg" ]
then
lib_path_arg="$LIBS_FILE_NAME"
echo "Downloading to: ${tmp_dir}/$lib_path_arg"
curl -L "$libs_download_url" > "$lib_path_arg"
else
cp "$lib_path_arg" "$tmp_dir"
fi
echo "Extracting lib to: ${tmp_dir}/breezy_gnome"
# Extract libs into the extracted directory
tar -xf $(basename $lib_path_arg)
mv breezy_desktop_lib/* breezy_gnome/
pushd breezy_gnome > /dev/null
# run the setup script that comes with this release
bin/setup $metrics_version
echo "Deleting temp directory: ${tmp_dir}"
rm -rf $tmp_dir
cd "$(dirs -l -0)" && dirs -c