From 466c913298c723c643685add8690c75cdc1a38ed Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 14 Dec 2022 07:53:22 +0800 Subject: [PATCH 1/4] Update `install.sh` --- files/scripts/install.sh | 113 ++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/files/scripts/install.sh b/files/scripts/install.sh index 033da18c..b8569116 100644 --- a/files/scripts/install.sh +++ b/files/scripts/install.sh @@ -1,62 +1,79 @@ -#!/bin/bash +#!/usr/bin/env bash set -e -BASE_URL="https://github.com/rooklift/nibbler/" -if [ ! -x /usr/bin/curl ] ; then - # some extra check if curl is not installed at the usual place - command -v curl >/dev/null 2>&1 || { echo >&2 "Please install curl or set it in your path. Aborting."; exit 1; } +BASE_URL="https://github.com/rooklift/nibbler" + +# check curl +if ! which curl 1>/dev/null 2>&1 ; then + echo "Please install curl and make sure it's added to \$PATH" + echo "Aborting" + exit 1 fi -# calculate the latest release number dynamically -VERSION_NR=$(basename $(curl -fs -o/dev/null -w %{redirect_url} ${BASE_URL}/releases/latest)) +# start +echo "You are installing Nibbler" -VERSION_NR_ONLY_DIGIT="${VERSION_NR:1}" -URL="${BASE_URL}releases/download/${VERSION_NR}/nibbler-${VERSION_NR_ONLY_DIGIT}-linux.zip" +# get the latest release version +VERSION=$(curl -fs -o /dev/null -w "%{redirect_url}" "${BASE_URL}/releases/latest" | xargs basename) +echo "Latest release is ${VERSION}" +ZIP_NAME="nibbler-${VERSION#v}-linux.zip" +ZIP_URL="${BASE_URL}/releases/download/${VERSION}/${ZIP_NAME}" -cd /tmp -echo "Downloading the latest release from the github release page ..." -echo ${URL} -wget -q -c "${URL}" -if [ $? -eq 0 ]; then - echo "Successfully Downloaded Nibbler ${VERSION_NR_ONLY_DIGIT} " +# create and enter temp dir +TEMP_DIR=$(mktemp -d) +cd "${TEMP_DIR}" + +# download +echo "Downloading release from ${ZIP_URL}" +if curl -fOL "${ZIP_URL}"; then + echo "Successfully downloaded ${ZIP_NAME}" else - echo "Failed to Download Nibbler ${VERSION_NR_ONLY_DIGIT}. Exiting ..." + echo "Failed to download ${ZIP_NAME}" + echo "Exiting" exit 1 fi -ZIP_NAME="nibbler-${VERSION_NR_ONLY_DIGIT}-linux.zip" -FILE_NAME="nibbler-${VERSION_NR_ONLY_DIGIT}-linux" -LOCATION="/opt/${FILE_NAME}" -echo "Unzipping to $LOCATION, sudo needed" -echo sudo unzip -qq ${ZIP_NAME} -d /opt/ -sudo unzip -qq ${ZIP_NAME} -d /opt/ -sudo chmod +x /opt/${FILE_NAME}/nibbler -echo "Successfully extracted Nibbler." - -read -p "Would you like to create a Desktop shortcut? (y/n)" -n 1 -r -if [[ $REPLY =~ ^[Yy]$ ]] -then -printf "\n" -echo sudo mkdir -p /usr/local/share/applications -sudo mkdir -p /usr/local/share/applications -cat </dev/null -[Desktop Entry] -Type=Application -Version=1.0 -Name=Nibbler -Icon=/opt/${FILE_NAME}/resources/app/pieces/K.png -Exec=/opt/${FILE_NAME}/nibbler -Terminal=false -StartupNotify=false -Categories=Game;BoardGame; -EOF -printf "Desktop shortcut created:/usr/local/share/applications/nibbler.desktop" -printf "\nThe Desktop shortcut will appear shortly in the applications menu." -else - printf "\nNo Desktop shortcut" +# extract +echo "Extracting..." +unzip -q "${ZIP_NAME}" +echo "Successfully extracted Nibbler" +UNZIPPED_NAME="${ZIP_NAME%.zip}" + +# prepare +chmod +x "${UNZIPPED_NAME}/nibbler" +mv "${UNZIPPED_NAME}/resources/linux" ./ + +# check if already installed +INSTALL_DIR="/opt/nibbler" +if [[ -d "${INSTALL_DIR}" ]]; then + echo "${INSTALL_DIR} already exists!" + echo "It looks like there is an existing installation of Nibbler on your system" + read -p "Would you like to overwrite it? [y/n]" -n 1 CONFIRM_INSTALL + echo + if ! [[ "$CONFIRM_INSTALL" =~ ^[Yy]$ ]]; then + echo "Aborting" + exit 1 + fi fi -printf "\n" -echo "Successfully installed Nibbler ${VERSION_NR_ONLY_DIGIT}" +# start install +DESKTOP_ENTRY_PATH="/usr/local/share/applications/nibbler.desktop" +ICON_PATH="/usr/local/share/icons/hicolor/512x512/apps/nibbler.png" +echo "Installing Nibbler to ${INSTALL_DIR}" +echo "Installing desktop entry to ${DESKTOP_ENTRY_PATH}" +echo "Installing icon to ${ICON_PATH}" +echo "This will require sudo privilege." + +# remove old and make sure directories are created +for FILE in "${INSTALL_DIR}" "${DESKTOP_ENTRY_PATH}" "${ICON_PATH}"; do + sudo rm -rf "$FILE" + sudo mkdir -p $(dirname "$FILE") +done +# install new +sudo mv "${UNZIPPED_NAME}" "${INSTALL_DIR}" +sudo mv "linux/nibbler.desktop" "${DESKTOP_ENTRY_PATH}" +sudo mv "linux/nibbler.png" "${ICON_PATH}" +# done +echo "Successfully installed Nibbler ${VERSION}" From 51bc1f735bafba5d87862fa29e3519c3505c1303 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 14 Dec 2022 07:55:37 +0800 Subject: [PATCH 2/4] `chmod +x` on all scripts --- files/scripts/builder.py | 0 files/scripts/install.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 files/scripts/builder.py mode change 100644 => 100755 files/scripts/install.sh diff --git a/files/scripts/builder.py b/files/scripts/builder.py old mode 100644 new mode 100755 diff --git a/files/scripts/install.sh b/files/scripts/install.sh old mode 100644 new mode 100755 From 1fc502abe2fa3de54dd595ff6f076d61df5d3802 Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 14 Dec 2022 08:11:32 +0800 Subject: [PATCH 3/4] Add binary symlink & fix icon path --- files/scripts/install.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/files/scripts/install.sh b/files/scripts/install.sh index b8569116..f5016e2c 100755 --- a/files/scripts/install.sh +++ b/files/scripts/install.sh @@ -41,6 +41,7 @@ UNZIPPED_NAME="${ZIP_NAME%.zip}" # prepare chmod +x "${UNZIPPED_NAME}/nibbler" +mv "${UNZIPPED_NAME}/resources/nibbler.png" ./ mv "${UNZIPPED_NAME}/resources/linux" ./ # check if already installed @@ -57,23 +58,26 @@ if [[ -d "${INSTALL_DIR}" ]]; then fi # start install +BIN_SYMLINK_PATH="/usr/local/bin/nibbler" DESKTOP_ENTRY_PATH="/usr/local/share/applications/nibbler.desktop" ICON_PATH="/usr/local/share/icons/hicolor/512x512/apps/nibbler.png" echo "Installing Nibbler to ${INSTALL_DIR}" +echo "Creating binary symlink at ${BIN_SYMLINK_PATH}" echo "Installing desktop entry to ${DESKTOP_ENTRY_PATH}" echo "Installing icon to ${ICON_PATH}" echo "This will require sudo privilege." # remove old and make sure directories are created -for FILE in "${INSTALL_DIR}" "${DESKTOP_ENTRY_PATH}" "${ICON_PATH}"; do +for FILE in "${INSTALL_DIR}" "${BIN_SYMLINK_PATH}" "${DESKTOP_ENTRY_PATH}" "${ICON_PATH}"; do sudo rm -rf "$FILE" sudo mkdir -p $(dirname "$FILE") done # install new sudo mv "${UNZIPPED_NAME}" "${INSTALL_DIR}" +sudo ln -s "${INSTALL_DIR}/nibbler" "${BIN_SYMLINK_PATH}" sudo mv "linux/nibbler.desktop" "${DESKTOP_ENTRY_PATH}" -sudo mv "linux/nibbler.png" "${ICON_PATH}" +sudo mv "nibbler.png" "${ICON_PATH}" # done echo "Successfully installed Nibbler ${VERSION}" From 3bd27ae1e2329a72aa97c8edfe14b439c79cf98b Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Wed, 14 Dec 2022 08:14:07 +0800 Subject: [PATCH 4/4] Inform user about Nibbler in launcher --- files/scripts/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/files/scripts/install.sh b/files/scripts/install.sh index f5016e2c..79aaabdd 100755 --- a/files/scripts/install.sh +++ b/files/scripts/install.sh @@ -81,3 +81,4 @@ sudo mv "nibbler.png" "${ICON_PATH}" # done echo "Successfully installed Nibbler ${VERSION}" +echo "You will be able to find Nibbler in your lanucher shortly"