-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·152 lines (127 loc) · 3.92 KB
/
run
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
#!/bin/bash
ARCH=`uname -m`
OS=`uname -s`
export SERVER_PATH="$(pwd)/.server"
export ROOT_PATH="$(pwd)"
function info() {
echo -e "\033[32mINFO: \033[0m $@" >/dev/stdout
}
function error() {
echo -e "\033[31mERROR: \033[0m $*" >/dev/stderr
}
function env_status() {
if [ ! -e .env ]; then
error "Please set up your .env file before starting your enviornment."
cp .env.sample .env
exit 1
fi
}
function run_docker(){
docker info 2>&1 >/dev/null
if [ $? -ne 0 ];then
clear
echo "=========================="
echo "=== Please Run Docker ===="
echo "=========================="
exit 1
fi
}
function prompt_yn () {
while true; do
read -p "$1 " answer
case ${answer:0:1} in
y|Y ) return 0;;
n|N ) return 1;;
* ) echo "Please answer yes or no.";;
esac
done
}
function NOT_SUPPORT() {
print_error "Not Support ${OS} ${ARCH}\n"; exit 1
}
function password_admin() {
# 2.1 Check if a password was set up in the .env file
if [ -z "$ADMIN_PASSWORD" ]; then
error "You must set up a password in your '.env' file."
exit 1
fi
# 2.2 Check if passowrd was the same as sample file
if [ $ADMIN_PASSWORD = "your_admin_password" ]; then
if prompt_yn "Do you want to change your current password (y/n)?"; then
read -s -p "Enter your Password: " ADMIN_PASSWORD
if [ ${OS} = "Darwin" ];then
sed -i "" "s/^ADMIN_PASSWORD.*/ADMIN_PASSWORD=${ADMIN_PASSWORD}/g" .env
else
sed -i "s/^ADMIN_PASSWORD.*/ADMIN_PASSWORD=${ADMIN_PASSWORD}/g" .env
fi
# 2.3 Generate the encrypted password
ENCRYPTED_PASSWORD=$(docker run --rm httpd:2.4-alpine htpasswd -nbB admin $ADMIN_PASSWORD | cut -d ":" -f 2)
# 2.4 Delete old ENCRYPTED_PASSWORD
sed -Ei '/ENCRYPTED_PASSWORD/d' .env
# 2.5 Send passowrd to .env file
echo "ENCRYPTED_PASSWORD=$ENCRYPTED_PASSWORD" >> .env
# 2.6 Start Portainer container
docker-compose -f docker-compose-with-passowrd.yml up -d --remove-orphans
else
echo
echo "#-----------------------------------------------------------"
echo "#"
echo "# CAREFUL!"
echo "#"
echo "# You are using the same passowrd of our sample."
echo "# Please change it AS SOON AS POSSIBLE!"
echo "#"
echo "#-----------------------------------------------------------"
echo
# 2.6 Start Portainer container
docker-compose -f docker-compose.yml up -d --remove-orphans
fi
else
# 2.6 Start Portainer container
docker-compose -f docker-compose-with-passowrd.yml up -d --remove-orphans
fi
}
function setup_web_proxy() {
# Domains message
echo
echo "#-----------------------------------------------------------"
echo "#"
echo "# The WebProxy take a few moments to get the SSL Certificates"
echo "#"
echo "# Please check your browser to see if it is running, use your"
echo "# domain(s): "
echo "# $DOMAINS"
echo "#"
echo "#-----------------------------------------------------------"
echo
# 3. Create docker network
if [[ "$(docker network ls | grep $NETWORK 2> /dev/null)" == "" ]]; then
docker network create $NETWORK -d bridge
fi
# 4. Download the latest version of nginx.tmpl
if [ ! -f ./.server/templates/nginx.tmpl ]; then
if [ ! -d ./.server/templates ]; then
mkdir -p ./.server/templates
fi
curl https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl > ./.server/templates/nginx.tmpl
fi
docker-compose -f docker-compose.yml up -d --remove-orphans
# 4. Start proxy
for d in `ls -d docker/*`;
do
docker-compose -f $d/docker-compose.yml up -d --build --remove-orphans
done
}
function main() {
run_docker
info "ARCH is ${OS} ${ARCH}\n"
# 1. Check if .env file exists
env_status
source .env
# 2. Passowrd for Admin User
#password_admin
# 3. Configure proxy env
setup_web_proxy
exit 0
}
main