Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update install.sh #215

Merged
merged 4 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sudo unzip -d /opt/ on the other hand, I really do not like at all.

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}"
Comment on lines +36 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unzips into a tempdir


# 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
Comment on lines +71 to +74
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${INSTALL_DIR} ${BIN_SYMLINK_PATH} ${DESKTOP_ENTRY_PATH} and ${ICON_PATH} are all statically defined. It's just deleting several files at statically-known locations, so there's really nothing unsafe here.


# 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}"
Comment on lines +76 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and only install statically-known files into system directories.


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