Skip to content

Commit e7c1ca2

Browse files
authored
Merge pull request #480 from Unpackerr/dn2_installer
update install.sh script
2 parents 7068862 + 9d90e40 commit e7c1ca2

1 file changed

Lines changed: 55 additions & 46 deletions

File tree

init/install.sh

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
##########################################################################################
23
#
34
# This simple script to install the latest package.
45
#
@@ -12,29 +13,35 @@
1213
# - If you're on Debian/Ubuntu/Knoppix, installs the latest deb package.
1314
# - If you're on Arch Linux, installs the latest zst (pacman) package.
1415
# - If you're on FreeBSD, installs the latest txz package.
16+
##########################################################################################
1517

1618

1719
# Set the repo name correctly.
1820
REPO=Unpackerr/unpackerr
1921
PACKAGE=$(echo "$REPO" | cut -d/ -f 2)
2022

21-
# Nothing else needs to be changed. Unless you're fixing things!
23+
##########################################################################################
24+
############# Nothing else needs to be changed. Unless you're fixing things! #############
25+
##########################################################################################
2226

23-
LATEST=https://api.github.com/repos/${REPO}/releases/latest
24-
ISSUES=https://github.com/${REPO}/issues/new
27+
LATEST="https://api.github.com/repos/${REPO}/releases/latest"
28+
ISSUES="https://github.com/${REPO}/issues/new"
2529
ARCH=$(uname -m)
2630
OS=$(uname -s)
2731
P=" ==>"
2832

2933
echo "<-------------------------------------------------->"
3034

31-
if [ "$OS" = "Darwin" ]; then
32-
echo "${P} This script does not work on macOS. Download a DMG here: ${LATEST}"
33-
exit
35+
if [[ $OS = Darwin ]]; then
36+
echo "${P} This script does not work on macOS. Download a DMG here: https://github.com/${REPO}/releases/latest"
37+
exit 1
3438
fi
3539

40+
# This file contains ID and possibly ID_LIKE.
41+
[[ ! -f /etc/os-release ]] || . /etc/os-release
42+
3643
# $ARCH is passed into grep -E to find the right file.
37-
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
44+
if [[ $ARCH = x86_64 ]] || [[ $ARCH = amd64 ]]; then
3845
ARCH="x86_64|amd64"
3946
elif [[ $ARCH = *386* ]] || [[ $ARCH = *686* ]]; then
4047
ARCH="i386"
@@ -44,29 +51,27 @@ elif [[ $ARCH = *armv6* ]] || [[ $ARCH = *armv7* ]]; then
4451
ARCH="armhf"
4552
else
4653
echo "${P} [ERROR] Unknown Architecture: ${ARCH}"
47-
echo "${P} $(uname -a)"
54+
echo "${P} $(uname -a) | $(head -n 1 /etc/issue): ${ID}"
4855
echo "${P} Please report this error, along with the above OS details:"
4956
echo " ${ISSUES}"
5057
exit 1
5158
fi
5259

53-
if [ "$1" = "deb" ] || [ "$1" = "rpm" ] || [ "$1" = "txz" ] || [ "$1" = "zst" ]; then
54-
FILE=$1
55-
[ "$FILE" != "zst" ] || FILE=pkg.tar.zst
56-
elif pacman --version > /dev/null 2>&1 && grep -q Arch /etc/issue; then
60+
if [[ $1 = deb ]] || [[ $1 = rpm ]] || [[ $1 = txz ]] || [[ $1 = zst ]] || [[ $1 = pkg.tar.zst ]]; then
61+
[[ $1 = zst ]] && FILE=pkg.tar.zst || FILE="$1"
62+
elif pacman --version > /dev/null 2>&1 && [[ $ID = arch ]] ; then
5763
FILE=pkg.tar.zst
58-
elif rpm --version > /dev/null 2>&1; then
59-
# If you have dpkg and rpm, rpm wins.
64+
elif rpm --version > /dev/null 2>&1 && [[ $ID != debian ]] && [[ $ID_LIKE != debian ]]; then
6065
FILE=rpm
6166
elif dpkg --version > /dev/null 2>&1; then
6267
FILE=deb
6368
elif pkg --version > /dev/null 2>&1; then
6469
FILE=txz
6570
fi
6671

67-
if [ "$FILE" = "" ]; then
72+
if [[ -z ${FILE} ]]; then
6873
echo "${P} [ERROR] No pacman (arch), pkg (freebsd), dpkg (debian) or rpm (redhat) package managers found; not sure what package to download!"
69-
echo "${P} $(uname -a) $(head -n 1 /etc/issue)"
74+
echo "${P} $(uname -a) | $(head -n 1 /etc/issue): ${ID}"
7075
echo "${P} If you feel this is a mistake, please report this along with the above OS details:"
7176
echo " ${ISSUES}"
7277
exit 1
@@ -77,9 +82,7 @@ if curl --version > /dev/null 2>&1; then
7782
CMD="curl -sL"
7883
elif wget --version > /dev/null 2>&1; then
7984
CMD="wget -qO-"
80-
fi
81-
82-
if [ "$CMD" = "" ]; then
85+
else
8386
echo "${P} [ERROR] Could not locate curl nor wget - please install one to download packages!"
8487
exit 1
8588
fi
@@ -89,41 +92,47 @@ PAYLOAD=$($CMD ${LATEST})
8992
URL=$(echo "$PAYLOAD" | grep -E "browser_download_url.*(${ARCH})\.${FILE}\"" | cut -d\" -f 4)
9093
TAG=$(echo "$PAYLOAD" | grep 'tag_name' | cut -d\" -f4 | tr -d v)
9194

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

100-
if [ "$FILE" = "rpm" ]; then
101-
INSTALLER="rpm -Uvh"
102-
INSTALLED="$(rpm -q --last --info ${PACKAGE} 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')"
103-
elif [ "$FILE" = "deb" ]; then
104-
dpkg -s ${PACKAGE} 2>/dev/null | grep Status | grep -q installed
105-
[ "$?" != "0" ] || INSTALLED="$(dpkg -s ${PACKAGE} 2>/dev/null | grep ^Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')"
106-
INSTALLER="dpkg --force-confdef --force-confold --install"
107-
elif [ "$FILE" = "txz" ]; then
108-
INSTALLER="pkg install --yes"
109-
INSTALLED="$(pkg info ${PACKAGE} 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')"
110-
elif [ "$FILE" = "pkg.tar.zst" ]; then
111-
INSTALLER="pacman --noconfirm --upgrade"
112-
INSTALLED=$(pacman --query ${PACKAGE} 2>/dev/null | awk '{print $2}' | cut -d- -f1)
113-
EXTRAS="$CMD https://golift.io/gpg | pacman-key --add -
114-
pacman-key --lsign-key B93DD66EF98E54E2EAE025BA0166AD34ABC5A57C"
115-
fi
103+
case "${FILE}" in
104+
"rpm")
105+
INSTALLER="rpm -Uvh"
106+
INSTALLED=$(rpm -q --last --info "${PACKAGE}" 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')
107+
;;
108+
"deb")
109+
INSTALLED=$(dpkg -s "${PACKAGE}" 2>/dev/null | grep ^Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')
110+
dpkg -s "${PACKAGE}" 2>/dev/null | grep -qE 'Status.*installed' || INSTALLED=""
111+
INSTALLER="dpkg --force-confdef --force-confold --install"
112+
;;
113+
"txz")
114+
INSTALLER="pkg install --yes"
115+
INSTALLED=$(pkg info" ${PACKAGE}" 2>/dev/null | grep Version | cut -d: -f2 | cut -d- -f1 | awk '{print $1}')
116+
;;
117+
"pkg.tar.zst")
118+
INSTALLER="pacman --noconfirm --upgrade"
119+
INSTALLED=$(pacman --query "${PACKAGE}" 2>/dev/null | awk '{print $2}' | cut -d- -f1)
120+
EXTRAS="$CMD https://golift.io/gpg | pacman-key --add -
121+
pacman-key --lsign-key B93DD66EF98E54E2EAE025BA0166AD34ABC5A57C"
122+
;;
123+
*) echo "${P} Unknown file type: ${FILE}" ; exit 1 ;;
124+
esac
116125

117126
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
118127
vercomp () {
119-
if [ "$1" = "" ]; then
128+
if [[ -z $1 ]]; then
120129
return 3
121-
elif [ "$1" = "$2" ]; then
130+
elif [[ "$1" = "$2" ]]; then
122131
return 0
123132
fi
124133

125134
local IFS=.
126-
local i ver1=($1) ver2=($2)
135+
local i ver1=("$1") ver2=("$2")
127136
# fill empty fields in ver1 with zeros
128137
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
129138
ver1[i]=0
@@ -150,26 +159,26 @@ case $? in
150159
3) echo "${P} Installing ${PACKAGE} version ${TAG}." ;;
151160
esac
152161

153-
FILE=$(basename ${URL})
154-
TMPFILE=$(mktemp --tmpdir XXXX-${FILE})
162+
FILE=$(basename "${URL}")
163+
TMPFILE=$(mktemp --tmpdir "XXXX-${FILE}")
155164
echo "${P} Downloading: ${URL}"
156165
echo "${P} To Location: ${TMPFILE}"
157166

158-
if ! $CMD ${URL} > ${TMPFILE}; then
167+
if ! $CMD "${URL}" > "${TMPFILE}"; then
159168
echo "${P} Error writing '${TMPFILE}' file! Fix that, and run this again."
160169
exit 1
161170
fi
162171

163172
# Install it.
164-
if [ "$(id -u)" = "0" ]; then
173+
if (( $(id -u) == 0 )); then
165174
echo "${P} Downloaded. Installing the package!"
166175
echo "${P} Executing: ${EXTRAS}"
167176
eval "${EXTRAS}"
168177
echo "${P} Executing: ${INSTALLER} ${TMPFILE}"
169-
$INSTALLER ${TMPFILE}
178+
$INSTALLER "${TMPFILE}"
170179
echo "<-------------------------------------------------->"
171180
else
172181
echo "${P} Downloaded! Install the package like this:"
173-
[ "$EXTRAS" = "" ] || echo " ${EXTRAS}"
182+
[[ -z ${EXTRAS} ]] || echo " ${EXTRAS}"
174183
echo " sudo $INSTALLER ${TMPFILE}"
175184
fi

0 commit comments

Comments
 (0)