-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgirouette.sh
executable file
·161 lines (128 loc) · 4.89 KB
/
girouette.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
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
153
154
155
156
157
158
159
160
161
#!/bin/bash
echo ''
echo ' _______ __ __ '
echo ' / ____(_)________ __ _____ / /_/ /____ '
echo ' / / __/ / ___/ __ \/ / / / _ \/ __/ __/ _ \'
echo ' / /_/ / / / / /_/ / /_/ / __/ /_/ /_/ __/'
echo ' \____/_/_/ \____/\__,_/\___/\__/\__/\___/ '
echo ' ____________________________________________'
echo ''
echo ' - https://www.girouette.dev - '
echo ''
curl -X GET https://raw.githubusercontent.com/apoutchika/girouette/master/license
echo ''
echo ''
ACCEPT='null'
while [[ ${ACCEPT} != 'Y' && ${ACCEPT} != 'n' ]]
do
echo -e "\e[1m"
read -p "? Accept the license ? [Y/n] : " ACCEPT
echo -e "\e[0m"
[[ ${ACCEPT} != 'Y' && ${ACCEPT} != 'n' ]] && echo -e "\e[31mPlease set Y or n...\e[0m"
done
[[ ${ACCEPT} != 'Y' ]] && echo ";-(" && exit
echo ""
echo -e "\e[34m> Test if has docker\e[39m\n"
! docker -v &> /dev/null && echo -e "\n\e[31mDocker not found\e[39m" && exit
docker volume create girouette_install
function run_node () {
docker run --rm -ti --network="host" -v "girouette_install:/app" node:20 bash -c "${1}"
}
echo ""
echo -e "\e[34m> Clean old Girouette install...\e[39m"
[[ $(docker network ls --format "{{.Name}}" | grep '^girouette$' | wc -l) == "0" ]] && docker network create girouette
[[ $(docker volume ls --format "{{.Name}}" | grep '^girouette$' | wc -l) == "0" ]] && docker volume create girouette
[[ $(docker ps --format "{{.Names}}" | grep '^girouette$' | wc -l) == "1" ]] && docker stop girouette
[[ $(docker ps -a --format "{{.Names}}" | grep '^girouette$' | wc -l) == "1" ]] && docker rm girouette
[[ $(docker images --format "{{.Repository}}" | grep "girouette/girouette" | wc -l ) == "1" ]] && docker rmi girouette/girouette
echo ""
echo -e "\e[34m> Test port configuration\e[39m\n"
PACKAGE='{"type": "module", "dependencies": {"chalk": "5.3.0", "inquirer": "9.2.12", "is-port-reachable": "4.0.0"}}'
run_node "cd /app && echo '${PACKAGE}' > package.json && npm config set update-notifier false && npm i -s"
TEST_CONFIG=$(cat <<EOF
import isPortReachable from 'is-port-reachable';
import fs from 'fs';
import chalk from 'chalk';
const test = async port => {
if(await isPortReachable(port, {host: 'localhost'})) {
console.log(chalk.red('> Girouette use port ' + port + ', and it not free'));
fs.writeFileSync('/app/fail', 'FAIL');
}
}
test(80);
test(443);
test(53);
EOF
)
run_node "cd /app && node --input-type=module -e \"${TEST_CONFIG}\""
FAIL=$(run_node "cat /app/fail")
if [[ ${FAIL} == 'FAIL' ]];
then
docker volume rm girouette_install
exit
fi
echo -e "\e[34m> Prepare new install...\e[39m"
echo ""
CONFIGURE=$(cat <<EOF
import fs from 'fs';
import inquirer from 'inquirer';
inquirer.prompt([
{
type: 'input',
name: 'tlds',
message: 'Domain extensions for redirect to Girouette (commat separed) : ',
default: () => '.devel'
},
{
type: 'input',
name: 'dns',
message: 'Choose your preferred dns server (commat separed) : ',
default: () => '1.1.1.1'
}
]).then(answers => {
console.log(''); // space
answers.tlds = answers.tlds.split(',').map(tld => tld.replace(/^\\\\./, '')).join(',');
fs.writeFileSync('/app/tld', answers.tlds.split(',')[0]);
fs.writeFileSync('/app/tlds', answers.tlds.split(',').join('\\\\n'));
fs.writeFileSync('/app/dnsmasq', answers.tlds.split(',').map(tld => 'address=/.' + tld + '/127.0.0.1').join('\\\\n'));
fs.writeFileSync('/app/dns', answers.dns);
})
EOF
)
run_node "cd /app && node --input-type=module -e \"${CONFIGURE}\""
DNSMASQ=$(run_node "cat /app/dnsmasq")
TLDS=$(run_node "cat /app/tlds")
TLD=$(run_node "cat /app/tld")
DNS=$(run_node "cat /app/dns")
docker volume rm girouette_install
docker run \
--restart="always" \
--name girouette \
--dns=${DNS} \
-d \
-p 80:80 \
-p 443:443 \
-p 127.0.0.1:53:5353 \
-p 127.0.0.1:53:5353/udp \
--network girouette \
-e DNS=${DNS} \
-e TLD=${TLD} \
-e TLDS=${TLDS} \
-e DNSMASQ=${DNSMASQ} \
-v "girouette:/data" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
--label girouette.domains="girouette.${TLD}:8080" \
--label girouette.group="Girouette" \
girouette/girouette
echo "####################################################################"
echo "## ##"
echo "## 1) Download certificate : http://girouette.${TLD}/certificate ##"
echo "## ##"
echo "## And add certificate Autority to navigator : ##"
echo "## - Chrome : chrome://settings/certificates ##"
echo "## - Firefox: about:preferences#privacy ##"
echo "## ##"
echo "## 2) Go to dashboard: https://girouette.${TLD} ##"
echo "## ##"
echo "####################################################################"
echo ""