This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·175 lines (156 loc) · 5.23 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#
# This is a quick and dirty script to install the latest package.
#
# Use it like this, pick curl or wget: (sudo is optional)
# ----
# curl -sL https://raw.githubusercontent.com/this/repo/main/scripts/install.sh | sudo bash
# wget -qO- https://raw.githubusercontent.com/this/repo/main/scripts/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 FreeBSD, installs the latest txz package.
#
# This is part of application-builder.
# https://github.com/golift/application-builder
# Set the repo name correctly.
REPO=this/repo
BREW=golift/mugs/hello-world
PACKAGE=$(echo "$REPO" | cut -d/ -f 2)
# 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
ARCH=$(uname -m)
OS=$(uname -s)
P=" ==>"
echo "<-------------------------------------------------->"
if [ "$OS" = "Darwin" ]; then
echo "${P} On a mac? Use Homebrew:"
echo " brew install ${BREW}"
exit
fi
# $ARCH is passed into egrep to find the right file.
if [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "amd64" ]; then
ARCH="x86_64|amd64"
elif [[ $ARCH = *386* ]] || [[ $ARCH = *686* ]]; then
ARCH="i386"
elif [[ $ARCH = *arm64* ]] || [[ $ARCH = *armv8* ]] || [[ $ARCH = *aarch64* ]]; then
ARCH="arm64"
elif [[ $ARCH = *armv6* ]] || [[ $ARCH = *armv7* ]]; then
ARCH="armhf"
else
echo "${P} [ERROR] Unknown Architecture: ${ARCH}"
echo "${P} $(uname -a)"
echo "${P} Please report this, 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
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)"
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
CMD="curl -sL"
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)
TAG=$(echo "$PAYLOAD" | grep 'tag_name' | cut -d\" -f4 | tr -d v)
if [ "$?" != "0" ] || [ "$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 " ${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
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
vercomp () {
if [ "$1" = "" ]; then
return 3
elif [ "$1" = "$2" ]; then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# fill empty fields in ver2 with zeros
ver2[i]=0
elif ((10#${ver1[i]} > 10#${ver2[i]})); then
return 1
elif ((10#${ver1[i]} < 10#${ver2[i]})); then
return 2
fi
done
return 0
}
vercomp "$INSTALLED" "$TAG"
case $? in
0) echo "${P} The installed version of ${PACKAGE} (${INSTALLED}) is current: ${TAG}" ; exit 0 ;;
1) echo "${P} The installed version of ${PACKAGE} (${INSTALLED}) is newer than the current release (${TAG})" ; exit 0 ;;
2) echo "${P} Upgrading ${PACKAGE} to ${TAG} from ${INSTALLED}." ;;
3) echo "${P} Installing ${PACKAGE} version ${TAG}." ;;
esac
FILE=$(basename ${URL})
echo "${P} Downloading: ${URL}"
echo "${P} To Location: /tmp/${FILE}"
$CMD ${URL} > /tmp/${FILE}
# Install it.
if [ "$(id -u)" = "0" ]; then
echo "${P} Downloaded. Installing the package!"
echo "${P} Executing: ${INSTALLER} /tmp/${FILE}"
$INSTALLER /tmp/${FILE}
echo "<-------------------------------------------------->"
else
echo "${P} Downloaded. Install the package like this:"
echo " sudo $INSTALLER /tmp/${FILE}"
fi