-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·89 lines (74 loc) · 2.39 KB
/
deploy.sh
File metadata and controls
executable file
·89 lines (74 loc) · 2.39 KB
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
#!/usr/bin/env bash
# Description: Ensures that a dependency (package) is present
# Arguments:
# - Argument 1: Dependency to ensure.
ensure_dependency()
{
# If $1 dependency is not present
if ! command -v "$1" &>/dev/null; then
if isRoot; then
${PACKAGE_MANAGER_INSTALL} "$1"
else
# We are not root and dependency is not available, install using root
echo
echo "Introduce password to install $1 if asked"
sudo ${PACKAGE_MANAGER_INSTALL} "$1"
fi
fi
}
# Description: Returns true (0) if the user executing the code is root and false (1) otherwise.
# Arguments:
# - Argument 1: Dependency to ensure.
isRoot()
{
if [ "${EUID}" == 0 ]; then
return 0
else
return 1
fi
}
# Description: Ensure all depenendcies for Chemotion software, deploys the Chemotion instance, runs it and shows it using the browser.
main()
{
dependencies=("wget" "docker" "docker-compose")
for dependency in ${dependencies[@]}; do
ensure_dependency "${dependency}"
done
# Download the docker-compose file
echo
echo "Downloading docker compose file"
rm -f "${PROJECT_FOLDER}/docker-compose.yml*"
wget -q --show-progress "https://raw.githubusercontent.com/ptrxyz/chemotion/cb906ce8d37e0a173ae66b3696a9f039f540eace/docker-compose.yml" -O "${PROJECT_FOLDER}/docker-compose.yml"
# Run it using docker-compose, depending on our privileges
if isRoot; then
docker-compose up -d
else
echo
echo "Introduce password to deploy container if asked"
sudo docker-compose up -d
fi
# Shows it in the browser, after active waiting
echo
echo "Chemotion will be opened in the browser"
# Use xdg if available, if not use firefox, which is usually present in Linux systems
if command -v "xdg-open" &>/dev/null; then
xdg-open "http://localhost:4000/"
elif command -v "firefox" &>/dev/null; then
firefox "http://localhost:4000/"
elif command -v "wget" &>/dev/null; then
echo "No browser installed, do a wget"
wget "http://localhost:4000"
elif command -v "curl" &>/dev/null; then
echo "No browser installed, do a curl"
curl "http://localhost:4000"
else
echo "There is not an available command to test the deployment"
fi
}
CURRENT_DIR="$(pwd)"
PROJECT_FOLDER="$(cd "$(dirname "$(realpath "$0")")" &>/dev/null && pwd)"
PACKAGE_MANAGER_INSTALL="apt-get install -y"
cd "${PROJECT_FOLDER}"
main "$@"
cd "${CURRENT_DIR}"
exit 0