Skip to content

Commit

Permalink
Merge pull request #218 from rooklift/reorganise
Browse files Browse the repository at this point in the history
2nd merge
  • Loading branch information
rooklift authored Dec 26, 2022
2 parents 728c128 + 354478c commit c33600a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 48 deletions.
Empty file modified files/scripts/builder.py
100644 → 100755
Empty file.
118 changes: 70 additions & 48 deletions files/scripts/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,62 +1,84 @@
#!/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 <<EOF | sudo tee -a /usr/local/share/applications/nibbler.desktop >/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/nibbler.png" ./
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
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}" "${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 "nibbler.png" "${ICON_PATH}"

# done
echo "Successfully installed Nibbler ${VERSION}"
echo "You will be able to find Nibbler in your lanucher shortly"

0 comments on commit c33600a

Please sign in to comment.