generated from Start9Labs/hello-world-startos
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker_entrypoint.sh
More file actions
executable file
·136 lines (121 loc) · 4.03 KB
/
docker_entrypoint.sh
File metadata and controls
executable file
·136 lines (121 loc) · 4.03 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
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
#!/bin/bash
echo "Starting up..."
export HOST_IP=$(ip -4 route list match 0/0 | awk '{print $3}')
home_type=$(yq e '.homepage.type' start9/config.yaml)
subdomains=($(yq e '.subdomains.[].name' start9/config.yaml))
tor_address=($(yq e '.tor-address' start9/config.yaml))
bucket_size=64
for subdomain in "${subdomains[@]}"; do
suffix=".${tor_address}"
len=$(( ${#suffix} + ${#subdomain} ))
if [[ $len -ge $bucket_size ]]; then
bucket_size=$(( $bucket_size * 2 ))
fi
done
if [[ $home_type = "index" ]]; then
if [ ${#subdomains} -ne 0 ]; then
cp /var/www/index/index-prefix.html /var/www/index/index.html
for subdomain in "${subdomains[@]}"; do
echo " <li><a target=\"_blank\" href=\"http://${subdomain}.${tor_address}\">${subdomain}</a></li>" >> /var/www/index/index.html
done
cat /var/www/index/index-suffix.html >> /var/www/index/index.html
else
cp /var/www/index/empty.html /var/www/index/index.html
fi
fi
echo "server_names_hash_bucket_size ${bucket_size};" > /etc/nginx/http.d/default.conf
if [[ $home_type = "redirect" ]]; then
target=$(yq e '.homepage.target' start9/config.yaml)
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
listen 80;
listen [::]:80;
server_name ${tor_address};
return 301 http://${target}.${tor_address}$request_uri;
}
EOT
elif [[ $home_type = "web-page" ]]; then
directory=$(yq e '.homepage.source.folder' start9/config.yaml)
source=$(yq e '.homepage.source.type' start9/config.yaml)
path=""
if ! test -d "/mnt/${source}"
then
echo "${source} mountpoint does not exist"
exit 0
fi
if [[ $source = "nextcloud" ]]; then
user=$(yq e '.homepage.source.user' start9/config.yaml)
path="/mnt/${source}/data/${user}/files/${directory}"
else
path="/mnt/${source}/${directory}"
fi
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
autoindex on;
listen 80;
listen [::]:80;
server_name ${tor_address};
root ${path};
}
EOT
else
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
listen 80;
listen [::]:80;
server_name ${tor_address};
root "/var/www/${home_type}";
}
EOT
fi
for subdomain in "${subdomains[@]}"; do
subdomain_type=$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings |.type" start9/config.yaml)
path=""
if [[ $subdomain_type = "web-page" ]]; then
directory="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source | .folder" start9/config.yaml)"
source="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source | .type" start9/config.yaml)"\
if ! test -d "/mnt/${source}"
then
echo "${source} mountpoint does not exist"
exit 0
fi
if [[ $source = "nextcloud" ]]; then
user="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .source | .user" start9/config.yaml)"
path="/mnt/${source}/data/${user}/files/${directory}"
else
path="/mnt/${source}/${directory}"
fi
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
autoindex on;
listen 80;
listen [::]:80;
server_name ${subdomain}.${tor_address};
root ${path};
}
EOT
elif [ $subdomain_type = "redirect" ]; then
if [ "$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .target == ~" start9/config.yaml)" = "true"]; then
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
listen 80;
listen [::]:80;
server_name ${subdomain}.${tor_address};
return 301 http://${tor_address}$request_uri;
}
EOT
else
target="$(yq e ".subdomains.[] | select(.name == \"$subdomain\") | .settings | .target" start9/config.yaml)"
cat >> /etc/nginx/http.d/default.conf <<EOT
server {
listen 80;
listen [::]:80;
server_name ${subdomain}.${tor_address};
return 301 http://${target}.${tor_address}$request_uri;
}
EOT
fi
fi
done
echo "Start9 Pages initalized"
exec tini -- nginx -g "daemon off;"