forked from cristianoliveira/ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·72 lines (58 loc) · 1.63 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
#!/usr/bin/env bash
VERSION_URL="https://raw.githubusercontent.com/cristianoliveira/ergo/master/.version"
DOWNLOAD_URL="https://github.com/cristianoliveira/ergo/releases/download"
DEST_FOLDER="/usr/local/bin"
PROGNAME=`basename "$0"`
die () {
echo "$PROGNAME: [FATAL] $1" >&2; exit ${2:-1} ;
}
getplatform(){
platform=$(uname -m)
case $platform in
x86_64)
echo "linux-amd64"
;;
*)
die "$platform is not yet supported"
;;
esac
}
install(){
echo "Using /tmp to store downloaded file"
cd /tmp
local platform=$(getplatform)
echo "Downloading version $latest_version from repo"
wget -q "$DOWNLOAD_URL/$latest_version/ergo-$latest_version-$platform.tar.gz"
[ $? -ne 0 ] && die "unable to download package"
echo "Extracting package"
tar -xf ergo-$latest_version-$platform.tar.gz
[ $? -ne 0 ] && die "unable to extract ergo from package"
echo "Copying ergo to $DEST_FOLDER. May require sudo password."
if [ -w $DEST_FOLDER ]; then
cp ergo $DEST_FOLDER
else
sudo cp ergo $DEST_FOLDER
fi
[ $? -ne 0 ] && die "unable to copy ergo to destination folder"
echo "Application was successfully installed."
echo "For uninstalling execute: rm ${DEST_FOLDER}ergo"
}
show_help(){
echo "Usage: $PROGNAME [-d destination_directory]"
}
main(){
latest_version=$(wget -q -O - "$VERSION_URL")
[ $? -ne 0 ] && die "unable to retrieve latest version information"
install
}
while getopts "h?d:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
d) DEST_FOLDER=$OPTARG
;;
esac
done
main