forked from inspircd/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·52 lines (42 loc) · 1.96 KB
/
bootstrap.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
#!/bin/sh
# Fail fast
set -e
# Some useful functions. See https://www.shivering-isles.com/helpful-shell-snippets-for-docker-testing-and-bootstrapping/
command_exists() { command -v "$1" >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not installed. Aborting."; exit 1; }; }
docker_installed() { command -v docker >/dev/null 2>&1 || { wget -O- http://get.docker.com | sh - ; }; command -v docker >/dev/null 2>&1 || { echo >&2 "I require docker but it's not installed and I can't install it myself. Aborting."; exit 1; }; }
command_exists wget
docker_installed
# Workaround for CentOS and maybe more OSes where docker.service is not started automatically
# See https://github.com/Adam-/inspircd-docker/issues/35
if command -v systemctl >/dev/null 2>&1; then
# Make sure docker unit exists
if [ "$(systemctl cat docker | wc -l)" -ne 0 ]; then
# Only act if the docker unit is not already active
if ! systemctl --quiet is-active docker; then
systemctl start docker
systemctl enable docker
echo "!! INFO !! !! INFO !!"
echo "!! INFO !! We started and enabled the docker service on your system !! INFO !!"
echo "!! INFO !! !! INFO !!"
fi
fi ;
fi
# Check to make sure we can talk to the docker daemon
[ -w /var/run/docker.sock ] || SUDO=sudo
# Default run parameter
RUNPARAM="-d"
# Check for available ports
if [ "$(netstat -ln | grep -c :6667)" -eq 0 ]; then
RUNPARAM="$RUNPARAM -p 6667:6667"
else
RUNPARAM="$RUNPARAM -p 6667"
echo "exposing 6667 on random port. Check \'docker ps\' for details"
fi
if [ "$(netstat -ln | grep -c :6697)" -eq 0 ]; then
RUNPARAM="$RUNPARAM -p 6697:6697"
else
RUNPARAM="$RUNPARAM -p 6697"
echo "exposing 6697 on random port. Check \'docker ps\' for details"
fi
# shellcheck disable=SC2086
$SUDO docker run $RUNPARAM inspircd/inspircd-docker