Skip to content

Commit 80a6cb9

Browse files
authored
Merge pull request #21 from ayushjn20/dunner-script
Add installation script for dunner
2 parents f48ad62 + 3daab91 commit 80a6cb9

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

installers/dunner/install.sh

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

0 commit comments

Comments
 (0)