-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathget.sh
executable file
·65 lines (56 loc) · 1.88 KB
/
get.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
#!/usr/bin/env bash
PROGRAM_NAME="elc"
OWNER="ensi-platform"
REPO="elc"
BIN_LOCATION="/opt/elc"
LINK_LOCATION="/usr/local/bin"
if [ "$VERSION" == "" ]; then
version=$(curl -sI https://github.com/$OWNER/$REPO/releases/latest | grep -i "location:" | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
else
version="$VERSION"
fi
if [ ! $version ]; then
echo "Failed while attempting to install $REPO. Please manually install:"
echo ""
echo "1. Open your web browser and go to https://github.com/$OWNER/$REPO/releases"
echo "2. Download the latest release for your platform. Call it '$PROGRAM_NAME-<version>'."
echo "3. chmod +x ./$PROGRAM_NAME-<version>"
echo "4. mv ./$PROGRAM_NAME-<version> $BIN_LOCATION"
echo "5. ln -sf $BIN_LOCATION/$PROGRAM_NAME-<version> $LINK_LOCATION/$PROGRAM_NAME"
exit 1
fi
if [ -e "$BIN_LOCATION/$PROGRAM_NAME-$version" ]; then
echo "Already downloaded"
else
targetFile="/tmp/elc_linux_amd64"
if [ -e "$targetFile" ]; then
rm "$targetFile"
fi
if ! [ -e "$BIN_LOCATION" ]; then
mkdir -p "$BIN_LOCATION"
fi
echo "Downloading package $url as $targetFile"
url="https://github.com/$OWNER/$REPO/releases/download/$version/elc_linux_amd64"
curl -sSL $url --output "$targetFile"
if [ "$?" = "0" ]; then
echo "Download complete."
chmod +x "$targetFile"
$targetFile --version $> /dev/null
if [ "$?" != "0" ]; then
echo "ERROR: Downloaded file is not executable"
exit 1
fi
mv "$targetFile" "$BIN_LOCATION/$PROGRAM_NAME-$version"
if [ "$?" != "0" ]; then
echo "ERROR: Unable to move $targetFile into $BIN_LOCATION/$PROGRAM_NAME-$version"
exit 1
fi
else
echo "ERROR: Unable to download $url into $targetFile"
exit 1
fi
fi
if [ -e "$BIN_LOCATION/$PROGRAM_NAME-$version" ]; then
ln -s -f "$BIN_LOCATION/$PROGRAM_NAME-$version" "$LINK_LOCATION/$PROGRAM_NAME"
fi
echo "Successfully installed"