瀏覽代碼

Don't change web config repeatedly

Bob Mottram 8 年之前
父節點
當前提交
796560972b
共有 2 個檔案被更改,包括 116 行新增112 行删除
  1. 75
    73
      src/freedombone-app-matrix
  2. 41
    39
      src/freedombone-utils-turn

+ 75
- 73
src/freedombone-app-matrix 查看文件

59
 
59
 
60
     # append the matrix server to the web site config
60
     # append the matrix server to the web site config
61
     matrix_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
61
     matrix_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
62
-    if [[ $ONION_ONLY == "no" ]]; then
63
-        echo '# Matrix Server' >> $matrix_nginx_site
62
+    if ! grep "# End of Matrix Server" $matrix_nginx_site; then
63
+        if [[ $ONION_ONLY == "no" ]]; then
64
+            echo '# Matrix Server' >> $matrix_nginx_site
65
+            echo 'server {' >> $matrix_nginx_site
66
+            echo "  listen ${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
67
+            echo "  listen [::]:${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
68
+            echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
69
+            echo '' >> $matrix_nginx_site
70
+            echo '  # Security' >> $matrix_nginx_site
71
+            function_check nginx_ssl
72
+            nginx_ssl ${DEFAULT_DOMAIN_NAME}
73
+
74
+            function_check nginx_disable_sniffing
75
+            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
76
+
77
+            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
78
+            echo '' >> $matrix_nginx_site
79
+            echo '  # Logs' >> $matrix_nginx_site
80
+            echo '  access_log /dev/null;' >> $matrix_nginx_site
81
+            echo '  error_log /dev/null;' >> $matrix_nginx_site
82
+            echo '' >> $matrix_nginx_site
83
+            echo '  # Index' >> $matrix_nginx_site
84
+            echo '  index index.html;' >> $matrix_nginx_site
85
+            echo '' >> $matrix_nginx_site
86
+            echo '  # Location' >> $matrix_nginx_site
87
+            echo '  location / {' >> $matrix_nginx_site
88
+            function_check nginx_limits
89
+            nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
90
+            echo "      proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
91
+            echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
92
+            echo '  }' >> $matrix_nginx_site
93
+            echo '}' >> $matrix_nginx_site
94
+            echo '' >> $matrix_nginx_site
95
+            echo 'server {' >> $matrix_nginx_site
96
+            echo "  listen ${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
97
+            echo "  listen [::]:${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
98
+            echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
99
+            echo '' >> $matrix_nginx_site
100
+            echo '  # Security' >> $matrix_nginx_site
101
+            function_check nginx_ssl
102
+            nginx_ssl ${DEFAULT_DOMAIN_NAME}
103
+
104
+            function_check nginx_disable_sniffing
105
+            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
106
+
107
+            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
108
+            echo '' >> $matrix_nginx_site
109
+            echo '  # Logs' >> $matrix_nginx_site
110
+            echo '  access_log /dev/null;' >> $matrix_nginx_site
111
+            echo '  error_log /dev/null;' >> $matrix_nginx_site
112
+            echo '' >> $matrix_nginx_site
113
+            echo '  # Index' >> $matrix_nginx_site
114
+            echo '  index index.html;' >> $matrix_nginx_site
115
+            echo '' >> $matrix_nginx_site
116
+            echo '  # Location' >> $matrix_nginx_site
117
+            echo '  location / {' >> $matrix_nginx_site
118
+            function_check nginx_limits
119
+            nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
120
+            echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
121
+            echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
122
+            echo '  }' >> $matrix_nginx_site
123
+            echo '}' >> $matrix_nginx_site
124
+            echo '' >> $matrix_nginx_site
125
+        else
126
+            echo '# Matrix Server' >> $matrix_nginx_site
127
+        fi
64
         echo 'server {' >> $matrix_nginx_site
128
         echo 'server {' >> $matrix_nginx_site
65
-        echo "  listen ${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
66
-        echo "  listen [::]:${MATRIX_HTTP_PORT} ssl;" >> $matrix_nginx_site
67
-        echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
129
+        echo "    listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
130
+        echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
68
         echo '' >> $matrix_nginx_site
131
         echo '' >> $matrix_nginx_site
69
-        echo '  # Security' >> $matrix_nginx_site
70
-        function_check nginx_ssl
71
-        nginx_ssl ${DEFAULT_DOMAIN_NAME}
72
-
73
         function_check nginx_disable_sniffing
132
         function_check nginx_disable_sniffing
74
-        nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
75
-
76
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
133
+        nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
77
         echo '' >> $matrix_nginx_site
134
         echo '' >> $matrix_nginx_site
78
         echo '  # Logs' >> $matrix_nginx_site
135
         echo '  # Logs' >> $matrix_nginx_site
79
         echo '  access_log /dev/null;' >> $matrix_nginx_site
136
         echo '  access_log /dev/null;' >> $matrix_nginx_site
80
         echo '  error_log /dev/null;' >> $matrix_nginx_site
137
         echo '  error_log /dev/null;' >> $matrix_nginx_site
81
         echo '' >> $matrix_nginx_site
138
         echo '' >> $matrix_nginx_site
82
-        echo '  # Index' >> $matrix_nginx_site
83
-        echo '  index index.html;' >> $matrix_nginx_site
84
-        echo '' >> $matrix_nginx_site
85
         echo '  # Location' >> $matrix_nginx_site
139
         echo '  # Location' >> $matrix_nginx_site
86
         echo '  location / {' >> $matrix_nginx_site
140
         echo '  location / {' >> $matrix_nginx_site
87
         function_check nginx_limits
141
         function_check nginx_limits
88
-        nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
142
+        nginx_limits $DEFAULT_DOMAIN_NAME '15m'
89
         echo "      proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
143
         echo "      proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
90
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
144
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
91
         echo '  }' >> $matrix_nginx_site
145
         echo '  }' >> $matrix_nginx_site
92
         echo '}' >> $matrix_nginx_site
146
         echo '}' >> $matrix_nginx_site
93
         echo '' >> $matrix_nginx_site
147
         echo '' >> $matrix_nginx_site
94
         echo 'server {' >> $matrix_nginx_site
148
         echo 'server {' >> $matrix_nginx_site
95
-        echo "  listen ${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
96
-        echo "  listen [::]:${MATRIX_ID_HTTP_PORT} ssl;" >> $matrix_nginx_site
97
-        echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $matrix_nginx_site
149
+        echo "    listen 127.0.0.1:$MATRIX_ID_ONION_PORT default_server;" >> $matrix_nginx_site
150
+        echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
98
         echo '' >> $matrix_nginx_site
151
         echo '' >> $matrix_nginx_site
99
-        echo '  # Security' >> $matrix_nginx_site
100
-        function_check nginx_ssl
101
-        nginx_ssl ${DEFAULT_DOMAIN_NAME}
102
-
103
         function_check nginx_disable_sniffing
152
         function_check nginx_disable_sniffing
104
-        nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
105
-
106
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
153
+        nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
107
         echo '' >> $matrix_nginx_site
154
         echo '' >> $matrix_nginx_site
108
         echo '  # Logs' >> $matrix_nginx_site
155
         echo '  # Logs' >> $matrix_nginx_site
109
         echo '  access_log /dev/null;' >> $matrix_nginx_site
156
         echo '  access_log /dev/null;' >> $matrix_nginx_site
110
         echo '  error_log /dev/null;' >> $matrix_nginx_site
157
         echo '  error_log /dev/null;' >> $matrix_nginx_site
111
         echo '' >> $matrix_nginx_site
158
         echo '' >> $matrix_nginx_site
112
-        echo '  # Index' >> $matrix_nginx_site
113
-        echo '  index index.html;' >> $matrix_nginx_site
114
-        echo '' >> $matrix_nginx_site
115
         echo '  # Location' >> $matrix_nginx_site
159
         echo '  # Location' >> $matrix_nginx_site
116
         echo '  location / {' >> $matrix_nginx_site
160
         echo '  location / {' >> $matrix_nginx_site
117
         function_check nginx_limits
161
         function_check nginx_limits
118
-        nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
162
+        nginx_limits $DEFAULT_DOMAIN_NAME '15m'
119
         echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
163
         echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
120
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
164
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
121
         echo '  }' >> $matrix_nginx_site
165
         echo '  }' >> $matrix_nginx_site
122
         echo '}' >> $matrix_nginx_site
166
         echo '}' >> $matrix_nginx_site
123
-        echo '' >> $matrix_nginx_site
124
-    else
125
-        echo '# Matrix Server' >> $matrix_nginx_site
167
+        echo '# End of Matrix Server' >> $matrix_nginx_site
126
     fi
168
     fi
127
-    echo 'server {' >> $matrix_nginx_site
128
-    echo "    listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
129
-    echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
130
-    echo '' >> $matrix_nginx_site
131
-    function_check nginx_disable_sniffing
132
-    nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
133
-    echo '' >> $matrix_nginx_site
134
-    echo '  # Logs' >> $matrix_nginx_site
135
-    echo '  access_log /dev/null;' >> $matrix_nginx_site
136
-    echo '  error_log /dev/null;' >> $matrix_nginx_site
137
-    echo '' >> $matrix_nginx_site
138
-    echo '  # Location' >> $matrix_nginx_site
139
-    echo '  location / {' >> $matrix_nginx_site
140
-    function_check nginx_limits
141
-    nginx_limits $DEFAULT_DOMAIN_NAME '15m'
142
-    echo "      proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
143
-    echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
144
-    echo '  }' >> $matrix_nginx_site
145
-    echo '}' >> $matrix_nginx_site
146
-    echo '' >> $matrix_nginx_site
147
-    echo 'server {' >> $matrix_nginx_site
148
-    echo "    listen 127.0.0.1:$MATRIX_ID_ONION_PORT default_server;" >> $matrix_nginx_site
149
-    echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $matrix_nginx_site
150
-    echo '' >> $matrix_nginx_site
151
-    function_check nginx_disable_sniffing
152
-    nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
153
-    echo '' >> $matrix_nginx_site
154
-    echo '  # Logs' >> $matrix_nginx_site
155
-    echo '  access_log /dev/null;' >> $matrix_nginx_site
156
-    echo '  error_log /dev/null;' >> $matrix_nginx_site
157
-    echo '' >> $matrix_nginx_site
158
-    echo '  # Location' >> $matrix_nginx_site
159
-    echo '  location / {' >> $matrix_nginx_site
160
-    function_check nginx_limits
161
-    nginx_limits $DEFAULT_DOMAIN_NAME '15m'
162
-    echo "      proxy_pass http://localhost:${MATRIX_ID_PORT};" >> $matrix_nginx_site
163
-    echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
164
-    echo '  }' >> $matrix_nginx_site
165
-    echo '}' >> $matrix_nginx_site
166
-    echo '# End of Matrix Server' >> $matrix_nginx_site
167
 
169
 
168
     systemctl restart nginx
170
     systemctl restart nginx
169
     systemctl restart turn
171
     systemctl restart turn

+ 41
- 39
src/freedombone-utils-turn 查看文件

65
 
65
 
66
     # append the matrix server to the web site config
66
     # append the matrix server to the web site config
67
     turn_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
67
     turn_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
68
-    if [[ $ONION_ONLY == "no" ]]; then
69
-        echo '# TURN Server' >> $turn_nginx_site
68
+    if ! grep "# End of TURN Server" $turn_nginx_site; then
69
+        if [[ $ONION_ONLY == "no" ]]; then
70
+            echo '# TURN Server' >> $turn_nginx_site
71
+            echo 'server {' >> $turn_nginx_site
72
+            echo "  listen ${TURN_HTTP_PORT} ssl;" >> $turn_nginx_site
73
+            echo "  listen [::]:${TURN_HTTP_PORT} ssl;" >> $turn_nginx_site
74
+            echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $turn_nginx_site
75
+            echo '' >> $turn_nginx_site
76
+            echo '  # Security' >> $turn_nginx_site
77
+            function_check nginx_ssl
78
+            nginx_ssl ${DEFAULT_DOMAIN_NAME}
79
+
80
+            function_check nginx_disable_sniffing
81
+            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
82
+
83
+            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $turn_nginx_site
84
+            echo '' >> $turn_nginx_site
85
+            echo '  # Logs' >> $turn_nginx_site
86
+            echo '  access_log /dev/null;' >> $turn_nginx_site
87
+            echo '  error_log /dev/null;' >> $turn_nginx_site
88
+            echo '' >> $turn_nginx_site
89
+            echo '  # Index' >> $turn_nginx_site
90
+            echo '  index index.html;' >> $turn_nginx_site
91
+            echo '' >> $turn_nginx_site
92
+            echo '  # Location' >> $turn_nginx_site
93
+            echo '  location / {' >> $turn_nginx_site
94
+            function_check nginx_limits
95
+            nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
96
+            echo "      proxy_pass http://localhost:${TURN_PORT};" >> $turn_nginx_site
97
+            echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $turn_nginx_site
98
+            echo '  }' >> $turn_nginx_site
99
+            echo '}' >> $turn_nginx_site
100
+            echo '' >> $turn_nginx_site
101
+        else
102
+            echo '# TURN Server' >> $turn_nginx_site
103
+        fi
70
         echo 'server {' >> $turn_nginx_site
104
         echo 'server {' >> $turn_nginx_site
71
-        echo "  listen ${TURN_HTTP_PORT} ssl;" >> $turn_nginx_site
72
-        echo "  listen [::]:${TURN_HTTP_PORT} ssl;" >> $turn_nginx_site
73
-        echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $turn_nginx_site
105
+        echo "    listen 127.0.0.1:$TURN_ONION_PORT default_server;" >> $turn_nginx_site
106
+        echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $turn_nginx_site
74
         echo '' >> $turn_nginx_site
107
         echo '' >> $turn_nginx_site
75
-        echo '  # Security' >> $turn_nginx_site
76
-        function_check nginx_ssl
77
-        nginx_ssl ${DEFAULT_DOMAIN_NAME}
78
-
79
         function_check nginx_disable_sniffing
108
         function_check nginx_disable_sniffing
80
-        nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
81
-
82
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $turn_nginx_site
109
+        nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
83
         echo '' >> $turn_nginx_site
110
         echo '' >> $turn_nginx_site
84
         echo '  # Logs' >> $turn_nginx_site
111
         echo '  # Logs' >> $turn_nginx_site
85
         echo '  access_log /dev/null;' >> $turn_nginx_site
112
         echo '  access_log /dev/null;' >> $turn_nginx_site
86
         echo '  error_log /dev/null;' >> $turn_nginx_site
113
         echo '  error_log /dev/null;' >> $turn_nginx_site
87
         echo '' >> $turn_nginx_site
114
         echo '' >> $turn_nginx_site
88
-        echo '  # Index' >> $turn_nginx_site
89
-        echo '  index index.html;' >> $turn_nginx_site
90
-        echo '' >> $turn_nginx_site
91
         echo '  # Location' >> $turn_nginx_site
115
         echo '  # Location' >> $turn_nginx_site
92
         echo '  location / {' >> $turn_nginx_site
116
         echo '  location / {' >> $turn_nginx_site
93
         function_check nginx_limits
117
         function_check nginx_limits
94
-        nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
118
+        nginx_limits $DEFAULT_DOMAIN_NAME '15m'
95
         echo "      proxy_pass http://localhost:${TURN_PORT};" >> $turn_nginx_site
119
         echo "      proxy_pass http://localhost:${TURN_PORT};" >> $turn_nginx_site
96
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $turn_nginx_site
120
         echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $turn_nginx_site
97
         echo '  }' >> $turn_nginx_site
121
         echo '  }' >> $turn_nginx_site
98
         echo '}' >> $turn_nginx_site
122
         echo '}' >> $turn_nginx_site
99
-        echo '' >> $turn_nginx_site
100
-    else
101
-        echo '# TURN Server' >> $turn_nginx_site
123
+        echo '# End of TURN Server' >> $turn_nginx_site
102
     fi
124
     fi
103
-    echo 'server {' >> $turn_nginx_site
104
-    echo "    listen 127.0.0.1:$TURN_ONION_PORT default_server;" >> $turn_nginx_site
105
-    echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $turn_nginx_site
106
-    echo '' >> $turn_nginx_site
107
-    function_check nginx_disable_sniffing
108
-    nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
109
-    echo '' >> $turn_nginx_site
110
-    echo '  # Logs' >> $turn_nginx_site
111
-    echo '  access_log /dev/null;' >> $turn_nginx_site
112
-    echo '  error_log /dev/null;' >> $turn_nginx_site
113
-    echo '' >> $turn_nginx_site
114
-    echo '  # Location' >> $turn_nginx_site
115
-    echo '  location / {' >> $turn_nginx_site
116
-    function_check nginx_limits
117
-    nginx_limits $DEFAULT_DOMAIN_NAME '15m'
118
-    echo "      proxy_pass http://localhost:${TURN_PORT};" >> $turn_nginx_site
119
-    echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $turn_nginx_site
120
-    echo '  }' >> $turn_nginx_site
121
-    echo '}' >> $turn_nginx_site
122
-    echo '# End of TURN Server' >> $turn_nginx_site
123
 
125
 
124
     export DEBIAN_FRONTEND=noninteractive
126
     export DEBIAN_FRONTEND=noninteractive
125
     apt-get -yq install coreutils coturn \
127
     apt-get -yq install coreutils coturn \