-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·102 lines (82 loc) · 3.27 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
#!/usr/bin/env bash
cd "$(dirname "$0")"
if [[ ! -f traefik/dynamic.toml ]]; then
cp traefik/dynamic-sample.toml traefik/dynamic.toml
echo "Created traefik/dynamic.toml file."
cert_filename="traefik"
if [[ "$1" = "--cert-filename" ]]; then
if [[ -n "$2" ]]; then
cert_filename="$2"
else
echo "Error: SSL certificate file name is required."
exit 1
fi
fi
if [[ -f "traefik/cert/${cert_filename}.key" ]]; then
echo "SSL certificate already exists."
else
traefik/create-cert --cert-filename "${cert_filename}"
if [[ "${cert_filename}" != "traefik" ]]; then
sed -i.bak "s/traefik.crt/${cert_filename}.crt/g" "traefik/dynamic.toml"
sed -i.bak "s/traefik.key/${cert_filename}.key/g" "traefik/dynamic.toml"
rm "traefik/dynamic.toml.bak"
fi
echo "Created SSL certificate."
fi
else
echo "Traefik dynamic configuration file already exists."
fi
if [[ ! -f services ]]; then
cp services-sample services
echo "Created services file."
else
echo "Services file already exists."
fi
if [[ ! -f .build.env ]]; then
if [[ -z "${TZ}" ]]; then
echo "Finding time zone."
dir="$(pwd)"
cd /usr/share/zoneinfo
#https://superuser.com/a/639096
TIME_ZONE=($(find * -type f -exec sh -c "diff -q /etc/localtime '{}' > /dev/null && echo {}" \;))
TZ="${TIME_ZONE[0]}"
echo "Time zone is: ${TZ}"
cd "${dir}"
fi
if [[ -z "${LANG}" ]]; then
echo "Warning: the environment variable LANG is not set!";
read -p "Enter a locale: [en_US.UTF-8] " LANG
[[ -z "${LANG}" ]] && LANG="en_US.UTF-8"
fi
read -sp "Enter the database root user password: [secret] " password
echo ""
[[ -z "${password}" ]] && password="secret"
composer_dir="${HOME}/.composer"
[[ -n "${COMPOSER_HOME}" ]] && composer_dir="${COMPOSER_HOME}"
if [[ ! -d "${composer_dir}" ]]; then
echo "Creating Composer directory: ${composer_dir}"
mkdir -p "${composer_dir}"
fi
[[ "${composer_dir}" = "${HOME}/.composer" ]] && composer_dir="~/.composer"
ssh_dir="${HOME}/.ssh"
if [[ ! -d "${ssh_dir}" ]]; then
echo "Error. SSH directory not found: ${ssh_dir}"
read -p "Do you want to create the SSH directory now? [no|yes*] " create
if [[ -z "${create}" ]] || [[ "${create}" = "yes" ]] || [[ "${create}" = "y" ]]; then
echo "Creating SSH directory: ${ssh_dir}"
mkdir -p "${ssh_dir}"
chmod 700 "${ssh_dir}"
fi
fi
cp ".build-sample.env" ".build.env"
sed -i.bak "s@export USER_ID=1000@export USER_ID=$(id -u)@" ".build.env"
sed -i.bak "s@export GROUP_ID=1000@export GROUP_ID=$(id -g)@" ".build.env"
sed -i.bak "s@export TIME_ZONE=UTC@export TIME_ZONE=${TZ}@" ".build.env"
sed -i.bak "s@export LOCALE=en_US\.UTF-8@export LOCALE=${LANG}@" ".build.env"
sed -i.bak "s@export DATABASE_ROOT_PASSWORD=secret@export DATABASE_ROOT_PASSWORD=${password}@" ".build.env"
sed -i.bak "s@export COMPOSER_DIR=.*@export COMPOSER_DIR=${composer_dir}@" ".build.env"
rm ".build.env.bak"
echo "Created .build.env file."
else
echo "Build environment file (.build.env) already exists."
fi