This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup_nephele
executable file
·111 lines (94 loc) · 3.1 KB
/
setup_nephele
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
#!/bin/bash
PKG_NAME="nephele"
BASH_COMPLETION_FILE="nephele.sh"
DEST_PATH="/usr/local/bin"
BASH_COMPLETION_PATH="/etc/bash_completion.d"
print_status() {
echo
echo "## $1"
echo
}
bail() {
echo
echo 'Error executing command, exiting'
exit 1
}
exec_cmd_nobail() {
echo "+ $1"
bash -c "$1"
}
exec_cmd() {
exec_cmd_nobail "$1" || bail
}
setup() {
print_status "Installing ${PKG_NAME} now"
OS=$(uname)
OS_ARCH=$(uname -m)
PRE_INSTALL_PKGS=""
if [ ! -x /usr/bin/curl ]; then
PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} curl"
fi
# Install the necessary packages needed for performing the installation operation
if [ "${PRE_INSTALL_PKGS}" != "" ]; then
if [ "$OS" == "Linux" ]; then
print_status "Populating apt-get cache..."
exec_cmd 'apt-get update'
print_status "Installing packages required for setup:${PRE_INSTALL_PKGS}"
exec_cmd "apt-get install -y${PRE_INSTALL_PKGS} > /dev/null 2>&1"
else
print_status "Please install '${PRE_INSTALL_PKGS}' and try again"
exit 1
fi
fi
# Verify the operating system and its architecture compatibility before performing the installation operation
if [ "$OS" == "Linux" ]; then
if [ "$OS_ARCH" == "x86_64" ]; then
PLATFORM="linux_amd64"
elif [[ "$OS_ARCH" == "i386" || "$OS_ARCH" == "i686" ]]; then
PLATFORM="linux_386"
else
echo
echo "Your system architecture: ${OS_ARCH}, is not supported. Exiting now"
exit 1
fi
elif [ "$OS" == "Darwin" ]; then
if [ "$OS_ARCH" == "x86_64" ]; then
PLATFORM="darwin_amd64"
else
echo
echo "Your system architecture: ${OS_ARCH}, is not supported. Exiting now"
exit 1
fi
else
echo
echo "Your system OS: ${OS}, is not supported. Exiting now"
exit 1
fi
# Get the latest release from the repository
LATEST=$(curl -s https://api.github.com/repos/bharath-srinivas/nephele/tags | grep name | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2)
URL="https://github.com/bharath-srinivas/nephele/releases/download/$LATEST/nephele_$PLATFORM"
if [ -z "$LATEST" ]; then
echo
echo "Error requesting binary file. Exiting now..."
exit 1
else
print_status "Downloading ${PKG_NAME} binary onto your system. Please wait..."
exec_cmd "curl -#Lf -o ${DEST_PATH}/${PKG_NAME} ${URL}"
print_status "Setting appropriate permissions for ${PKG_NAME} to work properly..."
exec_cmd "chmod +x ${DEST_PATH}/${PKG_NAME}"
if [ "$OS" == "Darwin" ]; then
mkdir -p ${BASH_COMPLETION_PATH}
cat <<EOF >> ~/.bash_profile
if [ -x ${BASH_COMPLETION_PATH} ]; then
. ${BASH_COMPLETION_PATH}/${BASH_COMPLETION_FILE}
fi
EOF
fi
exec_cmd "curl -sLf -o ${BASH_COMPLETION_PATH}/${BASH_COMPLETION_FILE} https://raw.githubusercontent.com/bharath-srinivas/nephele/master/${BASH_COMPLETION_FILE}"
print_status "Refreshing your terminal session for the changes to take effect..."
exec_cmd "source ${BASH_COMPLETION_PATH}/${BASH_COMPLETION_FILE}"
echo
echo "Successfully installed ${PKG_NAME} on your system"
fi
}
trap setup EXIT