forked from EtherDream/jsproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·108 lines (79 loc) · 2.11 KB
/
build.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
source ./dnsconf
svc_port=443
acme_args="-d $DOMAIN -d *.$DOMAIN -d *.ext.$DOMAIN"
js_arr_items=""
ngx_vhost_rhost="\
*.ext.$DOMAIN \$_vhost_dec_ext;
"
ngx_rhost_vhost="\
default \$_rhost_enc_ext.ext.$DOMAIN;
"
while read alias host
do
[ -z "$host" ] && continue
acme_args+=" -d *.$alias.$DOMAIN"
js_arr_items+=" ['$alias', '$host'],
"
# rhost to vhost map
dot_str=${host//[^.]}
dot_num=${#dot_str}
ngx_rhost_vhost+="\
$host $alias.$DOMAIN;
www.$host www.$alias.$DOMAIN;
*.$host \$_rhost_slice_$dot_num.$alias.$DOMAIN;
"
# vhost to rhost map
dot_str=${alias//[^.]}
dot_num=${#dot_str}
ngx_vhost_rhost+="\
$alias.$DOMAIN $host;
www.$alias.$DOMAIN www.$host;
*.$alias.$DOMAIN \$_vhost_slice_$dot_num.$host;
"
done < sitelist.txt
# gen nginx conf
echo "$ngx_vhost_rhost" > ./server/include/vhost-rhost.map
echo "$ngx_rhost_vhost" > ./server/include/rhost-vhost.map
echo "\
server_name $DOMAIN;
listen $svc_port ssl;" > ./server/include/host-root.conf
echo "\
server_name *.$DOMAIN;
listen $svc_port ssl;" > ./server/include/host-wild.conf
echo "\
ssl_certificate cert/${DOMAIN}.fullchain.rsa.cer;
ssl_certificate_key cert/${DOMAIN}.rsa.key;
ssl_certificate cert/${DOMAIN}.fullchain.ecc.cer;
ssl_certificate_key cert/${DOMAIN}.ecc.key;
" > ./server/include/cert.conf
echo "\
return 200 'importScripts(\"//${DOMAIN}/x.js\")';
" > ./server/include/x-js.conf
# gen ssl cert
ACME=~/.acme.sh/acme.sh
$ACME \
--issue \
--dns $DNS_ID \
$acme_args
$ACME \
--issue \
--dns $DNS_ID \
$acme_args \
--keylength ec-256
$ACME \
--install-cert -d $DOMAIN \
--key-file ./server/cert/$DOMAIN.rsa.key \
--fullchain-file ./server/cert/$DOMAIN.fullchain.rsa.cer
$ACME \
--install-cert -d $DOMAIN --ecc \
--key-file ./server/cert/$DOMAIN.ecc.key \
--fullchain-file ./server/cert/$DOMAIN.fullchain.ecc.cer
# gen js file
cd ./browser/proxy
echo "\
// THIS FILE WAS GENERATED BY build.sh
// DO NOT MODIFY
export const MY_ROOT = '$DOMAIN'
export const HOST_LIST = [
$js_arr_items]" > ./src/hostlist.js
./release.sh