Skip to content

Commit ecae83c

Browse files
committed
Add installation script for dunner
1 parent f48ad62 commit ecae83c

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

installers/dunner/install.sh

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/bash
2+
3+
set -e
4+
if [[ -z $DUNNER_VERSION ]]; then
5+
VERSION='latest'
6+
else
7+
VERSION="v${DUNNER_VERSION}"
8+
fi
9+
10+
RELEASES_URL="https://github.com/leopardslab/dunner/releases"
11+
REPO_URL="https://github.com/leopardslab/dunner"
12+
API_URL="https://api.github.com/repos/leopardslab/dunner/releases"
13+
14+
initVersion() {
15+
# Resolve latest version
16+
if [[ $VERSION == 'latest' ]]; then
17+
VERSION=$(curl -s ${API_URL}/latest | grep -wo '"tag_name":\ .*' | sed s/'"tag_name":\ "'//g | sed s/'",'//g)
18+
fi
19+
}
20+
21+
gitClone() {
22+
# Cloning repository from GitHub
23+
git clone $REPO_URL $TARGET_DIR
24+
cd $TARGET_DIR
25+
git config --local advice.detachedHead false
26+
if [[ $VERSION == 'current' ]]; then
27+
echo "Checking out from master branch"
28+
elif [[ $VERSION == 'latest' ]]; then
29+
echo "Checking out latest version of dunner"
30+
git checkout tags/$(git describe --tags | sed s/''//g)
31+
else
32+
echo "Checking out dunner repo with version $VERSION..."
33+
git checkout tags/$VERSION
34+
fi
35+
echo
36+
}
37+
38+
installFromSource() {
39+
echo
40+
# Installing dep...
41+
if [[ -z $(which dep) ]]; then
42+
echo "Installing dep..."
43+
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
44+
fi
45+
46+
TARGET_DIR="${GOPATH}/src/github.com/leopardslab/dunner"
47+
mkdir -p $TARGET_DIR
48+
if [[ $(which git) ]]; then
49+
gitClone
50+
else
51+
echo "'git' not found. Please install git"
52+
exit 1
53+
fi
54+
55+
cd $TARGET_DIR
56+
if [[ -z $(which dep) ]]; then
57+
echo "Command 'dep' not found. Please install 'dep'"
58+
exit 1
59+
else
60+
echo "Installing dependencies using 'dep'..."
61+
dep ensure
62+
echo "Installing dunner..."
63+
go install # TODO -- Flags
64+
fi
65+
}
66+
67+
raiseVersionError() {
68+
echo "Could not find version $VERSION for dunner."
69+
exit 1
70+
}
71+
72+
promptSrcInstall() {
73+
# Prompt user to confirm to whether download the source
74+
# and install using go.
75+
read -p "Install from source code?[y/N] " -n 1 -r
76+
echo
77+
if [[ $(echo $REPLY | grep -o '^[Yy]$') ]]; then
78+
installFromSource
79+
else
80+
echo "Dunner not installed; Exited!"
81+
exit 0
82+
fi
83+
}
84+
85+
binInstall() {
86+
# Binary installation from the release page.
87+
ARCH=$(uname -m)
88+
OS=$(uname -s)
89+
90+
ver=$(echo $VERSION | sed s/v//g)
91+
release=$(curl -s ${API_URL} | grep -i "\"name\": \"dunner_${ver}_${OS}_${ARCH}.tar.gz\",")
92+
if [[ -z $release ]]; then
93+
echo "OS $OS with $ARCH architecture is not supported corresponding to version $VERSION"
94+
echo
95+
promptSrcInstall
96+
elif [[ $(which tar) ]]; then
97+
downloadUrl="${RELEASES_URL}/download/${VERSION}/dunner_${ver}_${OS}_${ARCH}.tar.gz"
98+
echo "Downloading dunner_${ver}_${OS}_${ARCH}..."
99+
wget -O "dunner.tar.gz" $downloadUrl 2>/dev/null || curl -o "dunner.tar.gz" -L $downloadUrl
100+
if [[ $OS == 'Linux' || $OS == 'Darwin' ]]; then
101+
tar -xf dunner.tar.gz
102+
cp dunner /usr/bin/
103+
fi
104+
else
105+
echo "'tar' command not found..."
106+
echo
107+
promptSrcInstall
108+
fi
109+
}
110+
111+
initInstall() {
112+
ARCH=$(uname -m)
113+
if [[ $ARCH == 'i386' ]]; then
114+
ARCH="386"
115+
elif [[ $ARCH == 'x86_64' ]]; then
116+
ARCH="amd64"
117+
fi
118+
if [[ $(which dpkg) ]]; then
119+
pkg=$(curl -s ${API_URL}/tags/${VERSION} | grep -io "\"name\": \"dunner_${ARCH}\.deb" | sed s/'"name": "'//g)
120+
if [[ -z $pkg ]]; then
121+
echo "Deb package not found for $ARCH for version $VERSION"
122+
else
123+
downloadUrl="${RELEASES_URL}/download/${VERSION}/${pkg}"
124+
echo "Downloading ${pkg} as dunner.deb..."
125+
wget -O "dunner.deb" $downloadUrl 2>/dev/null || curl -o "dunner.deb" -L $downloadUrl
126+
echo "Installing from dunner.deb"
127+
dpkg -i dunner.deb
128+
rm dunner.deb
129+
exit 0
130+
fi
131+
fi
132+
133+
if [[ $(which rpm) ]]; then
134+
pkg=$(curl -s ${API_URL}/tags/${VERSION} | grep -io "\"name\": \"dunner_${ARCH}\.rpm" | sed s/'"name": "'//g)
135+
if [[ -z $pkg ]]; then
136+
echo "RPM package not found for $OS-$ARCH for version $VERSION"
137+
else
138+
downloadUrl="${RELEASES_URL}/download/${VERSION}/${pkg}"
139+
echo "Downloading ${pkg} as dunner.rpm..."
140+
wget -O "dunner.rpm" $downloadUrl 2>/dev/null || curl -o "dunner.rpm" -L $downloadUrl
141+
echo "Installing from dunner.rpm"
142+
rpm -ivh dunner.rpm
143+
rm dunner.rpm
144+
exit 0
145+
fi
146+
fi
147+
binInstall
148+
}
149+
150+
if [[ $(which dunner) ]]; then
151+
echo "dunner already installed at $(which dunner)"
152+
exit 1
153+
fi
154+
155+
if [[ -z $(which docker) ]]; then
156+
echo "Docker not found. Please install docker to use dunner"
157+
exit 1
158+
fi
159+
160+
echoConstants() {
161+
echo $API_URL
162+
echo $RELEASES_URL
163+
echo $REPO_URL
164+
}
165+
# echoConstants
166+
initVersion
167+
initInstall

0 commit comments

Comments
 (0)