2016-12-30 15:50:52 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# matrix server
|
|
|
|
#
|
|
|
|
# https://raw.githubusercontent.com/silvio/docker-matrix
|
2017-05-04 22:43:17 +02:00
|
|
|
# https://matrix.org/blog/2016/02/10/advanced-synapse-setup-with-lets-encrypt
|
|
|
|
#
|
|
|
|
# Test by visiting https://$MATRIX_DOMAIN_NAME/_matrix/key/v2/server/auto
|
2016-12-30 15:50:52 +01:00
|
|
|
#
|
2017-05-05 13:35:24 +02:00
|
|
|
# If working then telnet $MATRIX_DOMAIN_NAME 8448 should return a response
|
|
|
|
#
|
2016-12-30 15:50:52 +01:00
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2017-02-09 12:34:58 +01:00
|
|
|
# Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net>
|
2016-12-30 15:50:52 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-02-08 18:50:24 +01:00
|
|
|
# Login username is @username:domain
|
|
|
|
|
2017-02-07 14:50:25 +01:00
|
|
|
VARIANTS='full full-vim chat'
|
2016-12-30 15:50:52 +01:00
|
|
|
|
|
|
|
IN_DEFAULT_INSTALL=0
|
2017-02-07 14:50:25 +01:00
|
|
|
SHOW_ON_ABOUT=1
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2017-02-09 12:34:58 +01:00
|
|
|
MATRIX_DOMAIN_NAME=
|
|
|
|
MATRIX_CODE=
|
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
MATRIX_DATA_DIR='/var/lib/matrix'
|
2017-02-09 12:34:58 +01:00
|
|
|
MATRIX_HTTP_PORT=8448
|
2017-02-08 20:16:40 +01:00
|
|
|
MATRIX_PORT=8008
|
2016-12-31 14:00:02 +01:00
|
|
|
MATRIX_ID_PORT=8081
|
2017-01-01 21:40:08 +01:00
|
|
|
MATRIX_ONION_PORT=8109
|
|
|
|
MATRIX_ID_ONION_PORT=8111
|
2016-12-30 15:50:52 +01:00
|
|
|
MATRIX_REPO="https://github.com/matrix-org/synapse"
|
2017-05-04 22:43:17 +02:00
|
|
|
MATRIX_COMMIT='c45dc6c62aa2a2e83a10d8116a709dfd8c144e3c'
|
2016-12-30 17:53:24 +01:00
|
|
|
REPORT_STATS="no"
|
2016-12-30 18:34:30 +01:00
|
|
|
MATRIX_SECRET=
|
2016-12-30 15:50:52 +01:00
|
|
|
|
|
|
|
matrix_variables=(ONION_ONLY
|
|
|
|
MY_USERNAME
|
2016-12-30 18:34:30 +01:00
|
|
|
MATRIX_SECRET
|
2017-02-09 12:34:58 +01:00
|
|
|
DEFAULT_DOMAIN_NAME
|
|
|
|
MATRIX_DOMAIN_NAME
|
|
|
|
MATRIX_CODE)
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2016-12-30 22:51:35 +01:00
|
|
|
function matrix_nginx {
|
2017-02-09 12:34:58 +01:00
|
|
|
matrix_nginx_site=/etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
|
|
|
|
if [[ $ONION_ONLY == "no" ]]; then
|
2017-05-05 13:35:24 +02:00
|
|
|
echo 'server {' >> $matrix_nginx_site
|
|
|
|
echo " listen 0.0.0.0:443;" >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo " server_name ${MATRIX_DOMAIN_NAME};" >> $matrix_nginx_site
|
2016-12-30 22:51:35 +01:00
|
|
|
echo '' >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo ' # Security' >> $matrix_nginx_site
|
|
|
|
function_check nginx_ssl
|
|
|
|
nginx_ssl ${MATRIX_DOMAIN_NAME}
|
|
|
|
|
2016-12-30 22:51:35 +01:00
|
|
|
function_check nginx_disable_sniffing
|
2017-02-09 12:34:58 +01:00
|
|
|
nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
|
|
|
|
|
|
|
|
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
|
2016-12-30 22:51:35 +01:00
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
echo ' # Logs' >> $matrix_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $matrix_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $matrix_nginx_site
|
|
|
|
echo '' >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo ' # Index' >> $matrix_nginx_site
|
|
|
|
echo ' index index.html;' >> $matrix_nginx_site
|
|
|
|
echo '' >> $matrix_nginx_site
|
2016-12-30 22:51:35 +01:00
|
|
|
echo ' # Location' >> $matrix_nginx_site
|
2017-05-04 18:42:08 +02:00
|
|
|
echo ' location /_matrix {' >> $matrix_nginx_site
|
2016-12-30 22:51:35 +01:00
|
|
|
function_check nginx_limits
|
2017-02-09 12:34:58 +01:00
|
|
|
nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
|
2017-05-04 18:42:08 +02:00
|
|
|
echo ' proxy_pass http://localhost:8008;' >> $matrix_nginx_site
|
|
|
|
echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
2016-12-30 22:51:35 +01:00
|
|
|
echo ' }' >> $matrix_nginx_site
|
|
|
|
echo '}' >> $matrix_nginx_site
|
2017-01-01 21:40:08 +01:00
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
echo 'server {' >> $matrix_nginx_site
|
2017-05-05 13:35:24 +02:00
|
|
|
echo " listen 0.0.0.0:8448;" >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo " server_name ${MATRIX_DOMAIN_NAME};" >> $matrix_nginx_site
|
2017-01-01 21:40:08 +01:00
|
|
|
echo '' >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo ' # Security' >> $matrix_nginx_site
|
|
|
|
function_check nginx_ssl
|
|
|
|
nginx_ssl ${MATRIX_DOMAIN_NAME}
|
|
|
|
|
2017-01-01 21:40:08 +01:00
|
|
|
function_check nginx_disable_sniffing
|
2017-02-09 12:34:58 +01:00
|
|
|
nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
|
|
|
|
|
|
|
|
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
|
2017-01-01 21:40:08 +01:00
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
echo ' # Logs' >> $matrix_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $matrix_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $matrix_nginx_site
|
|
|
|
echo '' >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo ' # Index' >> $matrix_nginx_site
|
|
|
|
echo ' index index.html;' >> $matrix_nginx_site
|
|
|
|
echo '' >> $matrix_nginx_site
|
2017-01-01 21:40:08 +01:00
|
|
|
echo ' # Location' >> $matrix_nginx_site
|
2017-05-04 18:42:08 +02:00
|
|
|
echo ' location /_matrix {' >> $matrix_nginx_site
|
2017-01-01 21:40:08 +01:00
|
|
|
function_check nginx_limits
|
2017-02-09 12:34:58 +01:00
|
|
|
nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
|
2017-05-04 18:42:08 +02:00
|
|
|
echo ' proxy_pass http://localhost:8008;' >> $matrix_nginx_site
|
|
|
|
echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
2017-01-01 21:40:08 +01:00
|
|
|
echo ' }' >> $matrix_nginx_site
|
|
|
|
echo '}' >> $matrix_nginx_site
|
2017-02-09 12:34:58 +01:00
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
else
|
|
|
|
echo -n '' > $matrix_nginx_site
|
|
|
|
fi
|
|
|
|
echo 'server {' >> $matrix_nginx_site
|
|
|
|
echo " listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
|
|
|
|
echo " server_name $MATRIX_DOMAIN_NAME;" >> $matrix_nginx_site
|
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $MATRIX_DOMAIN_NAME
|
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
echo ' # Logs' >> $matrix_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $matrix_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $matrix_nginx_site
|
|
|
|
echo '' >> $matrix_nginx_site
|
|
|
|
echo ' # Location' >> $matrix_nginx_site
|
|
|
|
echo ' location / {' >> $matrix_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $MATRIX_DOMAIN_NAME '15m'
|
|
|
|
echo " proxy_pass http://localhost:${MATRIX_PORT}/_matrix;" >> $matrix_nginx_site
|
|
|
|
echo ' proxy_set_header X-Forwarded-For $remote_addr;' >> $matrix_nginx_site
|
|
|
|
echo ' }' >> $matrix_nginx_site
|
|
|
|
echo '}' >> $matrix_nginx_site
|
|
|
|
|
|
|
|
if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
|
|
|
|
mkdir -p /var/www/$MATRIX_DOMAIN_NAME/htdocs
|
|
|
|
fi
|
|
|
|
|
|
|
|
function_check add_ddns_domain
|
|
|
|
add_ddns_domain $MATRIX_DOMAIN_NAME
|
|
|
|
|
|
|
|
function_check create_site_certificate
|
|
|
|
create_site_certificate $MATRIX_DOMAIN_NAME
|
2016-12-31 00:54:44 +01:00
|
|
|
|
2016-12-31 00:57:44 +01:00
|
|
|
systemctl restart nginx
|
2016-12-31 15:26:22 +01:00
|
|
|
systemctl restart turn
|
|
|
|
systemctl restart matrix
|
2016-12-31 15:40:46 +01:00
|
|
|
|
|
|
|
# wait for nginx to start otherwise user add fails later
|
|
|
|
sleep 5
|
2016-12-30 22:51:35 +01:00
|
|
|
}
|
|
|
|
|
2016-12-31 12:26:10 +01:00
|
|
|
function matrix_generate_homeserver_file {
|
2016-12-30 15:50:52 +01:00
|
|
|
local filepath="${1}"
|
|
|
|
|
|
|
|
cd /etc/matrix
|
|
|
|
python -m synapse.app.homeserver \
|
|
|
|
--config-path "${filepath}" \
|
|
|
|
--generate-config \
|
|
|
|
--report-stats ${REPORT_STATS} \
|
2017-02-09 12:34:58 +01:00
|
|
|
--server-name ${MATRIX_DOMAIN_NAME}
|
2016-12-30 15:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function matrix_configure_homeserver_yaml {
|
|
|
|
local turnkey="${1}"
|
|
|
|
local filepath="${2}"
|
|
|
|
|
|
|
|
local ymltemp="$(mktemp)"
|
|
|
|
|
2017-02-09 12:34:58 +01:00
|
|
|
awk -v TURNURIES="turn_uris: [\"turn:${MATRIX_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=tcp\"]" \
|
2016-12-30 15:50:52 +01:00
|
|
|
-v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
|
|
|
|
-v PIDFILE="pid_file: ${MATRIX_DATA_DIR}/homeserver.pid" \
|
|
|
|
-v DATABASE="database: \"${MATRIX_DATA_DIR}/homeserver.db\"" \
|
2016-12-30 23:00:48 +01:00
|
|
|
-v LOGFILE="log_file: \"/dev/null\"" \
|
2016-12-30 15:50:52 +01:00
|
|
|
-v MEDIASTORE="media_store_path: \"${MATRIX_DATA_DIR}/media_store\"" \
|
|
|
|
'{
|
|
|
|
sub(/turn_shared_secret: "YOUR_SHARED_SECRET"/, TURNSHAREDSECRET);
|
|
|
|
sub(/turn_uris: \[\]/, TURNURIES);
|
|
|
|
sub(/pid_file: \/homeserver.pid/, PIDFILE);
|
2016-12-30 20:35:11 +01:00
|
|
|
sub(/database: "\/homeserver.db"/, DATABASE);
|
2016-12-30 15:50:52 +01:00
|
|
|
sub(/log_file: "\/homeserver.log"/, LOGFILE);
|
|
|
|
sub(/media_store_path: "\/media_store"/, MEDIASTORE);
|
|
|
|
print;
|
|
|
|
}' "${filepath}" > "${ymltemp}"
|
|
|
|
|
|
|
|
mv ${ymltemp} "${filepath}"
|
2016-12-30 21:00:50 +01:00
|
|
|
|
2017-05-05 13:35:24 +02:00
|
|
|
sed -i 's|8448|8449|g' "${filepath}"
|
|
|
|
sed -i 's|tls:.*|tls: False|g' "${filepath}"
|
|
|
|
sed -i 's|no_tls: .*|no_tls: True|g' "${filepath}"
|
2017-03-31 14:37:04 +02:00
|
|
|
sed -i ':a;N;$!ba;s/ tls: [^\n]*/ tls: False/2' "${filepath}"
|
2016-12-30 21:00:50 +01:00
|
|
|
sed -i 's|enable_registration_captcha.*|enable_registration_captcha: False|g' "${filepath}"
|
2016-12-30 23:27:46 +01:00
|
|
|
sed -i "s|database: \".*|database: \"${MATRIX_DATA_DIR}/homeserver.db\"|g" "${filepath}"
|
2016-12-30 23:23:38 +01:00
|
|
|
sed -i "s|media_store_path:.*|media_store_path: \"${MATRIX_DATA_DIR}/media_store\"|g" "${filepath}"
|
|
|
|
sed -i "s|pid_file:.*|pid_file: \"${MATRIX_DATA_DIR}/homeserver.pid\"|g" "${filepath}"
|
2016-12-30 23:45:22 +01:00
|
|
|
sed -i "s|log_file:.*|log_file: \"/dev/null\"|g" "${filepath}"
|
2017-01-01 21:40:08 +01:00
|
|
|
sed -i 's|bind_address:.*|bind_address: 127.0.0.1|g' "${filepath}"
|
2017-05-04 12:31:14 +02:00
|
|
|
sed -i "s|bind_addresses:.*|bind_addresses: ['127.0.0.1']|g" "${filepath}"
|
|
|
|
sed -i 's|x_forwarded:.*|x_forwarded: false|g' "${filepath}"
|
2017-02-09 12:34:58 +01:00
|
|
|
sed -i "s|server_name:.*|server_name: \"${MATRIX_DOMAIN_NAME}\"|g" "${filepath}"
|
|
|
|
sed -i "/trusted_third_party_id_servers:/a - ${MATRIX_DOMAIN_NAME}" "${filepath}"
|
|
|
|
sed -i "s|- ${MATRIX_DOMAIN_NAME}| - ${MATRIX_DOMAIN_NAME}|g" "${filepath}"
|
2017-05-04 12:31:14 +02:00
|
|
|
sed -i "s|enable_registration:.*|enable_registration: False|g" "${filepath}"
|
2016-12-30 15:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function matrix_diff {
|
|
|
|
DIFFPARAMS="${DIFFPARAMS:-Naur}"
|
2017-02-09 12:34:58 +01:00
|
|
|
MATRIX_DOMAIN_NAME="${MATRIX_DOMAIN_NAME:-demo_server_name}"
|
2016-12-30 15:50:52 +01:00
|
|
|
REPORT_STATS="${REPORT_STATS:-no_or_yes}"
|
2017-02-09 12:34:58 +01:00
|
|
|
export MATRIX_DOMAIN_NAME REPORT_STATS
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2016-12-30 16:52:46 +01:00
|
|
|
matrix_generate_synapse_file $INSTALL_DIR/homeserver.synapse.yaml
|
|
|
|
diff -${DIFFPARAMS} $INSTALL_DIR/homeserver.synapse.yaml ${MATRIX_DATA_DIR}/homeserver.yaml
|
|
|
|
rm $INSTALL_DIR/homeserver.synapse.yaml
|
2016-12-30 15:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function matrix_generate {
|
|
|
|
breakup="0"
|
2017-02-09 12:34:58 +01:00
|
|
|
[[ -z "${MATRIX_DOMAIN_NAME}" ]] && echo "STOP! environment variable MATRIX_DOMAIN_NAME must be set" && breakup="1"
|
2016-12-30 15:50:52 +01:00
|
|
|
[[ -z "${REPORT_STATS}" ]] && echo "STOP! environment variable REPORT_STATS must be set to 'no' or 'yes'" && breakup="1"
|
|
|
|
[[ "${breakup}" == "1" ]] && exit 1
|
|
|
|
|
|
|
|
[[ "${REPORT_STATS}" != "yes" ]] && [[ "${REPORT_STATS}" != "no" ]] && \
|
|
|
|
echo "STOP! REPORT_STATS needs to be 'no' or 'yes'" && breakup="1"
|
|
|
|
|
2016-12-31 12:26:10 +01:00
|
|
|
homeserver_config=${MATRIX_DATA_DIR}/homeserver.yaml
|
|
|
|
if [ -f $homeserver_config ]; then
|
|
|
|
rm $homeserver_config
|
|
|
|
fi
|
|
|
|
matrix_generate_homeserver_file $homeserver_config
|
|
|
|
matrix_configure_homeserver_yaml "${turnkey}" $homeserver_config
|
|
|
|
}
|
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
function remove_user_matrix {
|
|
|
|
remove_username="$1"
|
|
|
|
|
|
|
|
${PROJECT_NAME}-pass -u $remove_username --rmapp matrix
|
|
|
|
|
2016-12-30 17:04:35 +01:00
|
|
|
# TODO: There is no user removal script within synapse
|
2016-12-30 15:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_user_matrix {
|
|
|
|
new_username="$1"
|
|
|
|
new_user_password="$2"
|
2017-05-04 18:42:08 +02:00
|
|
|
is_admin_user='-a'
|
|
|
|
|
|
|
|
if [[ "$new_username" != "$MY_USERNAME" ]]; then
|
|
|
|
is_admin_user=''
|
|
|
|
fi
|
2016-12-30 15:50:52 +01:00
|
|
|
|
|
|
|
${PROJECT_NAME}-pass -u $new_username -a matrix -p "$new_user_password"
|
|
|
|
|
2017-01-01 23:03:46 +01:00
|
|
|
if [[ $ONION_ONLY == 'no' ]]; then
|
2017-05-04 18:42:08 +02:00
|
|
|
retval=$(register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" $is_admin_user https://${MATRIX_DOMAIN_NAME})
|
2017-01-01 23:03:46 +01:00
|
|
|
else
|
2017-05-04 18:42:08 +02:00
|
|
|
retval=$(register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" $is_admin_user http://${MATRIX_DOMAIN_NAME})
|
2017-01-01 23:03:46 +01:00
|
|
|
fi
|
2016-12-31 00:28:05 +01:00
|
|
|
echo "0"
|
2016-12-30 15:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_interactive_matrix {
|
2017-02-09 12:34:58 +01:00
|
|
|
if [ ! $ONION_ONLY ]; then
|
|
|
|
ONION_ONLY='no'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $ONION_ONLY != "no" ]]; then
|
|
|
|
MATRIX_DOMAIN_NAME='matrix.local'
|
|
|
|
write_config_param "MATRIX_DOMAIN_NAME" "$MATRIX_DOMAIN_NAME"
|
|
|
|
else
|
|
|
|
function_check interactive_site_details
|
|
|
|
interactive_site_details "matrix" "MATRIX_DOMAIN_NAME" "MATRIX_CODE"
|
2017-02-09 13:26:03 +01:00
|
|
|
if [ ! $MATRIX_DOMAIN_NAME ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
read_config_param "MATRIX_DOMAIN_NAME"
|
|
|
|
read_config_param "MATRIX_CODE"
|
2017-02-09 12:34:58 +01:00
|
|
|
fi
|
2016-12-30 15:50:52 +01:00
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|
|
|
|
|
|
|
|
function change_password_matrix {
|
|
|
|
curr_username="$1"
|
|
|
|
new_user_password="$2"
|
|
|
|
|
|
|
|
#${PROJECT_NAME}-pass -u "$curr_username" -a matrix -p "$new_user_password"
|
|
|
|
}
|
|
|
|
|
|
|
|
function reconfigure_matrix {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_matrix {
|
2017-01-03 15:01:52 +01:00
|
|
|
if [ ! -d /etc/matrix ]; then
|
|
|
|
return
|
|
|
|
fi
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl stop turn
|
|
|
|
systemctl stop matrix
|
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
function_check set_repo_commit
|
|
|
|
set_repo_commit /etc/matrix "matrix commit" "$MATRIX_COMMIT" $MATRIX_REPO
|
2016-12-31 14:31:40 +01:00
|
|
|
cd /etc/matrix
|
|
|
|
pip install --upgrade --process-dependency-links .
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2017-02-08 12:13:05 +01:00
|
|
|
sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
|
2016-12-31 15:12:08 +01:00
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
chown -R matrix:matrix /etc/matrix
|
2016-12-30 19:38:09 +01:00
|
|
|
chown -R matrix:matrix $MATRIX_DATA_DIR
|
2016-12-31 15:34:21 +01:00
|
|
|
|
2017-02-08 18:50:24 +01:00
|
|
|
pip install --upgrade --force "pynacl==0.3.0"
|
|
|
|
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl start turn
|
|
|
|
systemctl start matrix
|
2016-12-30 15:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_local_matrix {
|
|
|
|
source_directory=/etc/matrix
|
|
|
|
if [ -d $source_directory ]; then
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl stop turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl stop matrix
|
2016-12-31 17:02:44 +01:00
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
function_check backup_directory_to_usb
|
|
|
|
backup_directory_to_usb $source_directory matrix
|
2016-12-30 19:38:09 +01:00
|
|
|
source_directory=$MATRIX_DATA_DIR
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
backup_directory_to_usb $source_directory matrixdata
|
|
|
|
fi
|
2016-12-31 17:02:44 +01:00
|
|
|
|
|
|
|
systemctl start turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl start matrix
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_local_matrix {
|
|
|
|
if [ -d /etc/matrix ]; then
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl stop turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl stop matrix
|
|
|
|
|
|
|
|
temp_restore_dir=/root/tempmatrix
|
|
|
|
function_check restore_directory_from_usb
|
|
|
|
restore_directory_from_usb $temp_restore_dir matrix
|
|
|
|
cp -r $temp_restore_dir/etc/matrix/* /etc/matrix
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
function_check backup_unmount_drive
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 3783
|
|
|
|
fi
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
chown -R matrix:matrix /etc/matrix
|
|
|
|
|
|
|
|
temp_restore_dir=/root/tempmatrixdata
|
|
|
|
restore_directory_from_usb $temp_restore_dir matrixdata
|
2016-12-30 19:38:09 +01:00
|
|
|
cp -r $temp_restore_dir$MATRIX_DATA_DIR/* $MATRIX_DATA_DIR
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
function_check backup_unmount_drive
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 78352
|
|
|
|
fi
|
|
|
|
rm -rf $temp_restore_dir
|
2016-12-30 19:38:09 +01:00
|
|
|
chown -R matrix:matrix $MATRIX_DATA_DIR
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl start turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl start matrix
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_matrix {
|
|
|
|
source_directory=/etc/matrix
|
|
|
|
if [ -d $source_directory ]; then
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl stop turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl stop matrix
|
2016-12-31 17:02:44 +01:00
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
function_check backup_directory_to_friend
|
|
|
|
backup_directory_to_friend $source_directory matrix
|
2016-12-30 19:38:09 +01:00
|
|
|
source_directory=$MATRIX_DATA_DIR
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
backup_directory_to_friend $source_directory matrixdata
|
|
|
|
fi
|
2016-12-31 17:02:44 +01:00
|
|
|
|
|
|
|
systemctl start turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl start matrix
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-12-30 17:10:20 +01:00
|
|
|
function restore_remote_matrix {
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ -d /etc/matrix ]; then
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl stop turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl stop matrix
|
|
|
|
|
|
|
|
temp_restore_dir=/root/tempmatrix
|
|
|
|
function_check restore_directory_from_friend
|
|
|
|
restore_directory_from_friend $temp_restore_dir matrix
|
|
|
|
cp -r $temp_restore_dir/etc/matrix/* /etc/matrix
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
exit 38935
|
|
|
|
fi
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
chown -R matrix:matrix /etc/matrix
|
|
|
|
|
|
|
|
temp_restore_dir=/root/tempmatrixdata
|
|
|
|
restore_directory_from_friend $temp_restore_dir matrixdata
|
2016-12-30 19:38:09 +01:00
|
|
|
cp -r $temp_restore_dir$MATRIX_DATA_DIR/* $MATRIX_DATA_DIR
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
exit 60923
|
|
|
|
fi
|
|
|
|
rm -rf $temp_restore_dir
|
2016-12-30 19:38:09 +01:00
|
|
|
chown -R matrix:matrix $MATRIX_DATA_DIR
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2016-12-31 17:02:44 +01:00
|
|
|
systemctl start turn
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl start matrix
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_matrix {
|
2017-02-09 13:43:54 +01:00
|
|
|
firewall_remove ${MATRIX_HTTP_PORT}
|
2017-01-01 21:40:08 +01:00
|
|
|
|
2017-02-09 12:34:58 +01:00
|
|
|
nginx_dissite $MATRIX_DOMAIN_NAME
|
|
|
|
remove_certs $MATRIX_DOMAIN_NAME
|
|
|
|
if [ -f /etc/nginx/sites-available/$MATRIX_DOMAIN_NAME ]; then
|
|
|
|
rm /etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
|
|
|
|
fi
|
|
|
|
if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
|
|
|
|
rm -rf /var/www/$MATRIX_DOMAIN_NAME
|
|
|
|
fi
|
|
|
|
function_check remove_ddns_domain
|
|
|
|
remove_ddns_domain $MATRIX_DOMAIN_NAME
|
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
systemctl stop matrix
|
2016-12-30 16:52:46 +01:00
|
|
|
|
|
|
|
function_check remove_turn
|
|
|
|
remove_turn
|
|
|
|
|
|
|
|
systemctl disable matrix
|
2017-02-07 17:03:45 +01:00
|
|
|
if [ -f /etc/systemd/system/matrix.service ]; then
|
|
|
|
rm /etc/systemd/system/matrix.service
|
|
|
|
fi
|
2016-12-30 15:50:52 +01:00
|
|
|
apt-get -y remove --purge coturn
|
|
|
|
cd /etc/matrix
|
|
|
|
pip uninstall .
|
|
|
|
rm -rf $MATRIX_DATA_DIR
|
|
|
|
rm -rf /etc/matrix
|
|
|
|
deluser matrix
|
|
|
|
delgroup matrix
|
2017-01-01 21:40:08 +01:00
|
|
|
remove_onion_service matrix ${MATRIX_ONION_PORT}
|
|
|
|
remove_onion_service matrix ${MATRIX_ID_ONION_PORT}
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2017-02-09 12:34:58 +01:00
|
|
|
#sed -i "/# Matrix Server/,/# End of Matrix Server/d" /etc/nginx/sites-available/${MATRIX_DOMAIN_NAME}
|
2016-12-30 23:11:17 +01:00
|
|
|
systemctl restart nginx
|
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
remove_completion_param install_matrix
|
|
|
|
sed -i '/matrix/d' $COMPLETION_FILE
|
|
|
|
}
|
|
|
|
|
2016-12-31 12:26:10 +01:00
|
|
|
function install_home_server {
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ ! -d /etc/matrix ]; then
|
|
|
|
function_check git_clone
|
|
|
|
git_clone $MATRIX_REPO /etc/matrix
|
|
|
|
if [ ! -d /etc/matrix ]; then
|
|
|
|
echo $'Unable to clone matrix repo'
|
|
|
|
exit 6724683
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd /etc/matrix
|
|
|
|
git checkout $MATRIX_COMMIT -b $MATRIX_COMMIT
|
|
|
|
set_completion_param "matrix commit" "$MATRIX_COMMIT"
|
2016-12-30 17:39:38 +01:00
|
|
|
if [ ! -d $INSTALL_DIR/matrix ]; then
|
|
|
|
mkdir -p $INSTALL_DIR/matrix
|
|
|
|
fi
|
2017-02-07 16:48:54 +01:00
|
|
|
rm -rf /usr/local/lib/python2.7/dist-packages/ldap*
|
|
|
|
if [ -d $INSTALL_DIR/matrix ]; then
|
|
|
|
rm -rf $INSTALL_DIR/matrix/*
|
|
|
|
fi
|
2016-12-30 17:39:38 +01:00
|
|
|
pip install --upgrade --process-dependency-links . -b $INSTALL_DIR/matrix
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
2016-12-31 12:26:10 +01:00
|
|
|
echo $'Failed to install matrix home server'
|
2016-12-30 15:50:52 +01:00
|
|
|
exit 782542
|
|
|
|
fi
|
|
|
|
|
2016-12-31 13:04:34 +01:00
|
|
|
if [ ! -d $MATRIX_DATA_DIR ]; then
|
|
|
|
mkdir $MATRIX_DATA_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
groupadd matrix
|
|
|
|
useradd -c "Matrix system account" -d $MATRIX_DATA_DIR -m -r -g matrix matrix
|
2017-03-31 14:37:04 +02:00
|
|
|
usermod -a -G www-data matrix
|
2016-12-31 13:04:34 +01:00
|
|
|
|
2016-12-30 16:52:46 +01:00
|
|
|
function_check install_turn
|
|
|
|
install_turn
|
2016-12-30 18:34:30 +01:00
|
|
|
MATRIX_SECRET="${turnkey}"
|
2016-12-30 16:52:46 +01:00
|
|
|
|
|
|
|
function_check matrix_generate
|
|
|
|
matrix_generate
|
|
|
|
|
2016-12-30 19:44:44 +01:00
|
|
|
if [[ -z ${MATRIX_DATA_DIR}/homeserver.yaml ]]; then
|
2016-12-30 18:42:52 +01:00
|
|
|
echo $'homeserver.yaml is zero size'
|
|
|
|
exit 783724
|
|
|
|
fi
|
|
|
|
|
2017-02-08 19:21:29 +01:00
|
|
|
# Disable the web client
|
2017-02-08 18:50:24 +01:00
|
|
|
sed -i 's|web_client:.*|web_client: False|g' $MATRIX_DATA_DIR/homeserver.yaml
|
2017-02-09 13:41:06 +01:00
|
|
|
sed -i 's|, webclient||g' $MATRIX_DATA_DIR/homeserver.yaml
|
2017-05-04 13:48:26 +02:00
|
|
|
sed -i "/- '0.0.0.0'/d" $MATRIX_DATA_DIR/homeserver.yaml
|
2017-02-08 18:50:24 +01:00
|
|
|
|
2016-12-31 12:26:10 +01:00
|
|
|
chmod -R 700 $MATRIX_DATA_DIR/homeserver.yaml
|
2016-12-30 18:42:52 +01:00
|
|
|
chown -R matrix:matrix /etc/matrix
|
2016-12-30 19:38:09 +01:00
|
|
|
chown -R matrix:matrix $MATRIX_DATA_DIR
|
2016-12-30 18:42:52 +01:00
|
|
|
|
2017-01-01 22:35:21 +01:00
|
|
|
sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
|
2016-12-31 15:12:08 +01:00
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
echo '[Unit]' > /etc/systemd/system/matrix.service
|
2016-12-30 21:39:30 +01:00
|
|
|
echo 'Description=Synapse Matrix homeserver' >> /etc/systemd/system/matrix.service
|
2016-12-30 17:14:41 +01:00
|
|
|
echo 'After=network.target nginx.target' >> /etc/systemd/system/matrix.service
|
2016-12-30 15:50:52 +01:00
|
|
|
echo '' >> /etc/systemd/system/matrix.service
|
|
|
|
echo '[Service]' >> /etc/systemd/system/matrix.service
|
|
|
|
echo 'Type=simple' >> /etc/systemd/system/matrix.service
|
|
|
|
echo 'User=matrix' >> /etc/systemd/system/matrix.service
|
|
|
|
echo "WorkingDirectory=/etc/matrix" >> /etc/systemd/system/matrix.service
|
2017-05-04 22:43:17 +02:00
|
|
|
echo "ExecStartPre=/usr/bin/python -m synapse.app.homeserver --config-path ${MATRIX_DATA_DIR}/homeserver.yaml --generate-keys" >> /etc/systemd/system/matrix.service
|
2016-12-30 21:47:04 +01:00
|
|
|
echo "ExecStart=/usr/bin/python -m synapse.app.homeserver --config-path ${MATRIX_DATA_DIR}/homeserver.yaml" >> /etc/systemd/system/matrix.service
|
2017-05-04 22:43:17 +02:00
|
|
|
echo 'Restart=on-failure' >> /etc/systemd/system/matrix.service
|
2016-12-30 15:50:52 +01:00
|
|
|
echo 'RestartSec=10' >> /etc/systemd/system/matrix.service
|
|
|
|
echo '' >> /etc/systemd/system/matrix.service
|
|
|
|
echo '[Install]' >> /etc/systemd/system/matrix.service
|
|
|
|
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/matrix.service
|
|
|
|
systemctl enable matrix
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start matrix
|
|
|
|
|
2017-02-07 17:29:51 +01:00
|
|
|
# wait for the database to be created
|
|
|
|
sleep 5
|
|
|
|
|
2016-12-31 12:26:10 +01:00
|
|
|
if [ ! -f $MATRIX_DATA_DIR/homeserver.db ]; then
|
|
|
|
echo $'No matrix home server database was created'
|
2017-02-07 17:29:51 +01:00
|
|
|
exit 23782
|
2016-12-31 12:26:10 +01:00
|
|
|
fi
|
|
|
|
chmod -R 700 $MATRIX_DATA_DIR/homeserver.db
|
2016-12-30 15:50:52 +01:00
|
|
|
|
2017-01-01 21:40:08 +01:00
|
|
|
MATRIX_ONION_HOSTNAME=$(add_onion_service matrix ${MATRIX_PORT} ${MATRIX_ONION_PORT})
|
|
|
|
MATRIX_ID_ONION_HOSTNAME=$(add_onion_service matrixid ${MATRIX_ID_PORT} ${MATRIX_ID_ONION_PORT})
|
2016-12-30 15:50:52 +01:00
|
|
|
if [ ! ${MATRIX_PASSWORD} ]; then
|
|
|
|
if [ -f ${IMAGE_PASSWORD_FILE} ]; then
|
|
|
|
MATRIX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
|
|
else
|
|
|
|
MATRIX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-02-09 13:43:54 +01:00
|
|
|
firewall_add matrix ${MATRIX_HTTP_PORT}
|
2017-01-01 21:40:08 +01:00
|
|
|
|
2016-12-30 18:34:30 +01:00
|
|
|
rm -rf ${MATRIX_DATA_DIR}/Maildir
|
|
|
|
rm -rf ${MATRIX_DATA_DIR}/.mutt
|
|
|
|
rm -f ${MATRIX_DATA_DIR}/.muttrc
|
|
|
|
rm -f ${MATRIX_DATA_DIR}/.mutt-alias
|
|
|
|
rm -f ${MATRIX_DATA_DIR}/.procmailrc
|
|
|
|
rm -f ${MATRIX_DATA_DIR}/.emacs-mutt
|
2016-12-31 12:26:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_matrix {
|
|
|
|
if [ ! -d $INSTALL_DIR ]; then
|
|
|
|
mkdir -p $INSTALL_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${ONION_ONLY} == 'no' ]]; then
|
2017-02-09 12:34:58 +01:00
|
|
|
if [ ! -f /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.pem ]; then
|
2016-12-31 12:26:10 +01:00
|
|
|
echo $'Obtaining certificate for the main domain'
|
2017-02-09 12:34:58 +01:00
|
|
|
create_site_certificate ${MATRIX_DOMAIN_NAME} 'yes'
|
2016-12-31 12:26:10 +01:00
|
|
|
fi
|
|
|
|
fi
|
2016-12-30 18:34:30 +01:00
|
|
|
|
2016-12-31 12:26:10 +01:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt-get -yq install coreutils \
|
|
|
|
curl file gcc git libevent-2.0-5 \
|
|
|
|
libevent-dev libffi-dev libffi6 \
|
|
|
|
libgnutls28-dev libjpeg62-turbo \
|
|
|
|
libjpeg62-turbo-dev libldap-2.4-2 \
|
|
|
|
libldap2-dev libsasl2-dev \
|
|
|
|
libsqlite3-dev libssl-dev \
|
|
|
|
libssl1.0.0 libtool libxml2 \
|
|
|
|
libxml2-dev libxslt1-dev libxslt1.1 \
|
|
|
|
make python python-dev \
|
|
|
|
python-pip python-psycopg2 \
|
|
|
|
python-virtualenv sqlite unzip \
|
|
|
|
zlib1g zlib1g-dev
|
|
|
|
|
|
|
|
pip install --upgrade pip
|
|
|
|
pip install --upgrade python-ldap
|
|
|
|
pip install --upgrade lxml
|
|
|
|
|
2016-12-31 14:02:54 +01:00
|
|
|
function_check install_home_server
|
2016-12-31 12:26:10 +01:00
|
|
|
install_home_server
|
2016-12-31 14:02:54 +01:00
|
|
|
|
|
|
|
function_check update_default_domain
|
2016-12-31 12:26:10 +01:00
|
|
|
update_default_domain
|
2016-12-31 14:02:54 +01:00
|
|
|
|
2017-02-08 18:50:24 +01:00
|
|
|
pip install --upgrade --force "pynacl==0.3.0"
|
2016-12-31 15:34:21 +01:00
|
|
|
|
2016-12-31 14:02:54 +01:00
|
|
|
function_check matrix_nginx
|
2016-12-30 22:51:35 +01:00
|
|
|
matrix_nginx
|
|
|
|
|
2017-05-04 18:42:08 +02:00
|
|
|
if [[ $(add_user_matrix "${MY_USERNAME}" "${MATRIX_PASSWORD}" | tail -n 1) != "0" ]]; then
|
|
|
|
echo $'Failed to add matrix admin user';
|
|
|
|
exit 879352
|
|
|
|
fi
|
2016-12-30 17:59:03 +01:00
|
|
|
|
2016-12-30 15:50:52 +01:00
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|