Skip to content

Commit

Permalink
update install script to support arch
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Aug 2, 2024
1 parent 138d72f commit 032b9e3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
.DS_Store
*~
/package_build_*
/release
/release*
MANUAL
MANUAL.html
README
Expand Down
155 changes: 82 additions & 73 deletions userscripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
#!/bin/bash
##########################################################################################
#
# This is a quick and dirty script to install the latest package.
# This simple script to install the latest package.
#
# Use it like this, pick curl or wget: (sudo is optional)
# ----
# curl -sL https://raw.githubusercontent.com/Notifiarr/notifiarr/main/userscripts/install.sh | sudo bash
# wget -qO- https://raw.githubusercontent.com/Notifiarr/notifiarr/main/userscripts/install.sh | sudo bash
# curl -sL https://raw.githubusercontent.com/Notifiarr/notifiarr/main/init/install.sh | sudo bash
# wget -qO- https://raw.githubusercontent.com/Notifiarr/notifiarr/main/init/install.sh | sudo bash
# ----
#
# - If you're on RedHat/CentOS/Fedora, installs the latest rpm package.
# - If you're on Debian/Ubuntu/Knoppix, installs the latest deb package.
# - If you're on Arch Linux, installs the latest zst (pacman) package.
# - If you're on FreeBSD, installs the latest txz package.
#
# This is part of application-builder.
# https://github.com/golift/application-builder
##########################################################################################


# Set the repo name correctly.
REPO=Notifiarr/notifiarr
BREW=golift/mugs/notifiarr
PACKAGE=$(echo "$REPO" | cut -d/ -f 2)

# Nothing else needs to be changed. Unless you're fixing things!
##########################################################################################
############# Nothing else needs to be changed. Unless you're fixing things! #############
##########################################################################################

LATEST=https://api.github.com/repos/${REPO}/releases/latest
ISSUES=https://github.com/${REPO}/issues/new
LATEST="https://api.github.com/repos/${REPO}/releases/latest"
ISSUES="https://github.com/${REPO}/issues/new"
ARCH=$(uname -m)
OS=$(uname -s)
P=" ==>"

echo "<-------------------------------------------------->"

if [ "$OS" = "Darwin" ]; then
echo "${P} On a mac? Use Homebrew:"
echo " brew install ${BREW}"
exit
if [[ $OS = Darwin ]]; then
echo "${P} This script does not work on macOS. Download a DMG here: https://github.com/${REPO}/releases/latest"
exit 1
fi

# $ARCH is passed into egrep to find the right file.
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
# This file contains ID and possibly ID_LIKE.
[[ ! -f /etc/os-release ]] || . /etc/os-release

# $ARCH is passed into grep -E to find the right file.
if [[ $ARCH = x86_64 ]] || [[ $ARCH = amd64 ]]; then
ARCH="x86_64|amd64"
elif [[ $ARCH = *386* ]] || [[ $ARCH = *686* ]]; then
ARCH="i386"
Expand All @@ -47,91 +51,88 @@ elif [[ $ARCH = *armv6* ]] || [[ $ARCH = *armv7* ]]; then
ARCH="armhf"
else
echo "${P} [ERROR] Unknown Architecture: ${ARCH}"
echo "${P} $(uname -a)"
echo "${P} $(uname -a) | $(head -n 1 /etc/issue): ${ID}"
echo "${P} Please report this error, along with the above OS details:"
echo " ${ISSUES}"
exit 1
fi

if [ "$1" = "deb" ] || [ "$1" = "rpm" ] || [ "$1" = "txz" ]; then
FILE=$1
else
# If you have both, rpm wins.
rpm --version > /dev/null 2>&1
if [ "$?" = "0" ]; then
FILE=rpm
else
dpkg --version > /dev/null 2>&1
if [ "$?" = "0" ]; then
FILE=deb
else
pkg --version > /dev/null 2>&1
if [ "$?" = "0" ]; then
FILE=txz
fi
fi
fi
if [[ $1 = deb ]] || [[ $1 = rpm ]] || [[ $1 = txz ]] || [[ $1 = zst ]] || [[ $1 = pkg.tar.zst ]]; then
[[ $1 = zst ]] && FILE=pkg.tar.zst || FILE="$1"
elif pacman --version > /dev/null 2>&1 && [[ $ID = arch ]] ; then
FILE=pkg.tar.zst
elif rpm --version > /dev/null 2>&1 && [[ $ID != debian ]] && [[ $ID_LIKE != debian ]]; then
FILE=rpm
elif dpkg --version > /dev/null 2>&1; then
FILE=deb
elif pkg --version > /dev/null 2>&1; then
FILE=txz
fi

if [ "$FILE" = "" ]; then
echo "${P} [ERROR] No pkg (freebsd), dpkg (debian) or rpm (redhat) package managers found; not sure what package to download!"
echo "${P} $(uname -a)"
if [[ -z ${FILE} ]]; then
echo "${P} [ERROR] No pacman (arch), pkg (freebsd), dpkg (debian) or rpm (redhat) package managers found; not sure what package to download!"
echo "${P} $(uname -a) | $(head -n 1 /etc/issue): ${ID}"
echo "${P} If you feel this is a mistake, please report this along with the above OS details:"
echo " ${ISSUES}"
exit 1
fi

# curl or wget?
curl --version > /dev/null 2>&1
if [ "$?" = "0" ]; then
if curl --version > /dev/null 2>&1; then
CMD="curl -sL"
elif wget --version > /dev/null 2>&1; then
CMD="wget -qO-"
else
wget --version > /dev/null 2>&1
if [ "$?" = "0" ]; then
CMD="wget -qO-"
fi
fi

if [ "$CMD" = "" ]; then
echo "${P} [ERROR] Could not locate curl nor wget - please install one to download packages!"
exit 1
fi

# Grab latest release file from github.
PAYLOAD=$($CMD ${LATEST})
URL=$(echo "$PAYLOAD" | egrep "browser_download_url.*(${ARCH})\.${FILE}\"" | cut -d\" -f 4)
URL=$(echo "$PAYLOAD" | grep -E "browser_download_url.*(${ARCH})\.${FILE}\"" | cut -d\" -f 4)
TAG=$(echo "$PAYLOAD" | grep 'tag_name' | cut -d\" -f4 | tr -d v)

if [ "$?" != "0" ] || [ "$URL" = "" ]; then
if [[ -z ${TAG} ]] || [[ -z ${URL} ]]; then
echo "${P} [ERROR] Missing latest release for '${FILE}' file ($OS/${ARCH}) at ${LATEST}"
echo "${P} $(uname -a)"
echo "${P} Please report error this, along with the above OS details:"
echo "${P} $(uname -a) | $(head -n 1 /etc/issue): ${ID}"
echo "${P} Please report this error, along with the above OS details:"
echo " ${ISSUES}"
exit 1
fi

if [ "$FILE" = "rpm" ]; then
INSTALLER="rpm -Uvh"
INSTALLED="$(rpm -q --last --info ${PACKAGE} 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')"
elif [ "$FILE" = "deb" ]; then
dpkg -s ${PACKAGE} 2>/dev/null | grep Status | grep -q installed
[ "$?" != "0" ] || INSTALLED="$(dpkg -s ${PACKAGE} 2>/dev/null | grep ^Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')"
INSTALLER="dpkg --force-confdef --force-confold --install"
elif [ "$FILE" = "txz" ]; then
INSTALLER="pkg install --yes"
INSTALLED="$(pkg info ${PACKAGE} 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')"
fi
case "${FILE}" in
"rpm")
INSTALLER="rpm -Uvh"
INSTALLED=$(rpm -q --last --info "${PACKAGE}" 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')
;;
"deb")
INSTALLED=$(dpkg -s "${PACKAGE}" 2>/dev/null | grep ^Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')
dpkg -s "${PACKAGE}" 2>/dev/null | grep -qE 'Status.*installed' || INSTALLED=""
INSTALLER="dpkg --force-confdef --force-confold --install"
;;
"txz")
INSTALLER="pkg install --yes"
INSTALLED=$(pkg info" ${PACKAGE}" 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')
;;
"pkg.tar.zst")
INSTALLER="pacman --noconfirm --upgrade"
INSTALLED=$(pacman --query "${PACKAGE}" 2>/dev/null | awk '{print $2}' | cut -d- -f1)
EXTRAS="$CMD https://golift.io/gpg | pacman-key --add -
pacman-key --lsign-key B93DD66EF98E54E2EAE025BA0166AD34ABC5A57C"
;;
*) echo "${P} Unknown file type: ${FILE}" ; exit 1 ;;
esac

# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
vercomp () {
if [ "$1" = "" ]; then
if [[ -z $1 ]]; then
return 3
elif [ "$1" = "$2" ]; then
elif [[ "$1" = "$2" ]]; then
return 0
fi

local IFS=.
local i ver1=($1) ver2=($2)
local i ver1=("$1") ver2=("$2")
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
Expand All @@ -158,18 +159,26 @@ case $? in
3) echo "${P} Installing ${PACKAGE} version ${TAG}." ;;
esac

FILE=$(basename ${URL})
FILE=$(basename "${URL}")
TMPFILE=$(mktemp --tmpdir "XXXX-${FILE}")
echo "${P} Downloading: ${URL}"
echo "${P} To Location: /tmp/${FILE}"
$CMD ${URL} > /tmp/${FILE}
echo "${P} To Location: ${TMPFILE}"

if ! $CMD "${URL}" > "${TMPFILE}"; then
echo "${P} Error writing '${TMPFILE}' file! Fix that, and run this again."
exit 1
fi

# Install it.
if [ "$(id -u)" = "0" ]; then
if (( $(id -u) == 0 )); then
echo "${P} Downloaded. Installing the package!"
echo "${P} Executing: ${INSTALLER} /tmp/${FILE}"
$INSTALLER /tmp/${FILE}
echo "${P} Executing: ${EXTRAS}"
eval "${EXTRAS}"
echo "${P} Executing: ${INSTALLER} ${TMPFILE}"
$INSTALLER "${TMPFILE}"
echo "<-------------------------------------------------->"
else
echo "${P} Downloaded. Install the package like this:"
echo " sudo $INSTALLER /tmp/${FILE}"
echo "${P} Downloaded! Install the package like this:"
[[ -z ${EXTRAS} ]] || echo " ${EXTRAS}"
echo " sudo $INSTALLER ${TMPFILE}"
fi

0 comments on commit 032b9e3

Please sign in to comment.