forked from WithSecureLabs/awspx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSTALL
executable file
·193 lines (151 loc) · 5.61 KB
/
INSTALL
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
#####################################################################################################
# #
# This script serves a couple of purposes, its behaviour will vary based on how it is named: #
# #
# - INSTALL - will create the awspx container and copy this script to awspx #
# - awspx - will pass arguments to cli.py in the awpx container #
# - docker-entrypoint.sh - will start the webserver and neo4j (sourced by /docker-entrypoint.sh) #
# #
#####################################################################################################
_OS_="UNKNOWN"
function host_checks(){
#MacOS
if [ "$(uname)" == "Darwin" ]; then
_OS_="MACOS"
# Linux
elif [[ "$(uname)" =~ "Linux" ]]; then
_OS_="LINUX"
if [[ "$(whoami)" != "root" ]]; then
echo "[-] awspx must be run with root privileges."
exit 1
fi
# Unsupported
else
echo "[-] Platform: '$(uname)' is not supported"
exit 1
fi
DOCKER_RUNNING="$(docker info >/dev/null 2>&1)"
if [ "${?}" -ne 0 ]; then
echo "[-] \"docker\" must first be started."
exit 1
fi
}
function install(){
BIN_PATH="/usr/local/bin"
[[ $_OS_ == "MACOS" ]] \
&& MOUNT="${HOME}/bin/awspx" \
|| MOUNT="/opt/awspx"
# Use default path for awspx installation
if [[ ":${PATH}:" != *":${BIN_PATH}:"* ]] || [ ! -w "${BIN_PATH}" ]; then
read -p "[*] '${BIN_PATH}' isn't in your \$PATH. Choose another location to save \"awspx\" [y/n]? " response
if [[ "${response}" == "Y" || "${response}" == "y" ]]; then
select p in $(for p in $(echo "${PATH}" | tr ':' '\n' | sort); do [[ -w $p ]] && echo $p; done); do
case $p in
/*)
BIN_PATH="$p"
break
;;
*) ;;
esac
done
fi
fi
cp -f $0 ${BIN_PATH}/awspx
# Assert awspx exists in $PATH
if (which awspx >/dev/null 2>&1) ; then
echo "awspx successfully written to ${BIN_PATH}/awspx"
else
>&2 echo "Failed to identify a writable \$PATH directory"
exit 2
fi
# Delete all containers named awspx (prompt for confirmation)
if [ -n "$(docker ps -a -f name=awspx -q)" ]; then
echo -e "[!] An existing container named \"awspx\" was detected\n"
echo -e " In order to continue, it must be deleted. All data will be lost."
read -p " Continue [y/n]? " response
[[ "${response}" == "Y" || "${response}" == "y" ]] \
|| exit
docker stop awspx >/dev/null 2>&1
docker rm awspx >/dev/null 2>&1
fi
echo ""
# Build or pull awspx
case $1 in
build|BUILD)
echo -e "[*] Creating \"awspx\" image...\n"
docker build $(dirname $0) -t beatro0t/awspx:latest
;;
*)
echo -e "[*] Pulling \"awspx\" image... \n"
docker pull beatro0t/awspx:latest
;;
esac
if [ $? -ne 0 ]; then
echo -e "\n[-] Installation failed"
exit 1
fi
echo ""
# Create container
echo -en "[*] Creating \"awspx\" container... "
if docker run -itd \
--name awspx \
--hostname=awspx \
--env NEO4J_AUTH=neo4j/password \
-p 0.0.0.0:80:80 \
-p 0.0.0.0:7687:7687 \
-p 0.0.0.0:7373:7373 \
-p 0.0.0.0:7474:7474 \
-v ${MOUNT}/data:/opt/awspx/data:z \
-e NEO4J_dbms_security_procedures_unrestricted=apoc.jar \
--restart=always beatro0t/awspx:latest >/dev/null; then
cp $(dirname $0)/data/sample.zip -f ${MOUNT}/data/. >/dev/null 2>&1
echo -e "and you're all set!\n"
echo -e " The web interface (http://localhost) will be available shortly..."
echo -e " Run: \`awspx -h\` for a list of options."
fi
echo ""
}
function hook(){
if [[ "${@}" == "neo4j" ]]; then
# Start web interface
[[ -z "$(pgrep npm)" ]] \
&& cd /opt/awspx/www \
&& nohup npm run serve>/dev/null 2>&1 &
# Start neo4j
nohup bash /docker-entrypoint.sh neo4j console 2>&1 &
# Start bash so /docker-entrypoint.sh doesn't terminate
exec bash
fi
}
function awspx(){
if [[ -z "$(docker ps -a -f name=^/awspx$ -q)" ]]; then
echo -e "[-] Couldn't find \"awspx\" container, you will need to create it first"
exit 1
fi
if [[ -z "$(docker ps -a -f name=^/awspx$ -f status=running -q)" ]]; then
docker start awspx > /dev/null
fi
docker exec -it \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \
-e AWS_SECURITY_TOKEN=$AWS_SECURITY_TOKEN \
awspx /opt/awspx/cli.py $@
}
function main(){
case "$(basename $0)" in
INSTALL)
host_checks
install $@
;;
docker-entrypoint.sh)
hook $@
;;
awspx)
host_checks
awspx $@
;;
esac
}
main $@