-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·93 lines (72 loc) · 2.59 KB
/
setup.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
#!/bin/bash
# Fail the script if any command fails
set -e
# Define variables
VENV_DIR="matrix-env"
CONFIG_FILE="homeserver.yaml"
DOMAIN="unifyhn.de" # Use your actual domain name
CUSTOM_PORT=8081 # Custom port to run Synapse on
# Step 1: Install Python3 and virtualenv if not installed
if ! command -v python3 &> /dev/null
then
echo "Python3 is not installed. Please install Python3 to proceed."
exit 1
fi
if ! python3 -m venv --help &> /dev/null
then
echo "virtualenv is not installed. Installing now..."
sudo apt-get install python3-venv -y
fi
# Step 2: Create a virtual environment if it doesn't exist
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment..."
python3 -m venv $VENV_DIR
fi
# Step 3: Activate the virtual environment
echo "Activating virtual environment..."
source $VENV_DIR/bin/activate
# Step 4: Install dependencies from requirements.txt
if [ ! -f "requirements.txt" ]; then
echo "requirements.txt not found!"
exit 1
fi
echo "Installing dependencies from requirements.txt..."
pip install --upgrade pip
pip install -r requirements.txt
# Step 5: Generate Synapse configuration if it doesn't exist
if [ ! -f "$CONFIG_FILE" ]; then
echo "Generating Matrix Synapse configuration..."
synapse_homeserver --server-name $DOMAIN --config-path $CONFIG_FILE --generate-config --report-stats=no
else
echo "Matrix Synapse configuration already exists."
fi
# Step 6: Modify homeserver.yaml using Python script
echo "Modifying $CONFIG_FILE to enable registration and set port $CUSTOM_PORT..."
python3 <<EOF
import yaml
config_file = "$CONFIG_FILE"
port = $CUSTOM_PORT
# Load YAML configuration
with open(config_file, "r") as file:
config = yaml.safe_load(file)
# Enable registration
config["enable_registration"] = True
config["enable_registration_without_verification"] = True
# Update listeners to use port 8081 and bind to 0.0.0.0 for external access
for listener in config["listeners"]:
if listener["type"] == "http":
listener["port"] = port
listener["bind_addresses"] = ["0.0.0.0"]
# Set the server name to unifyhn.de
config["server_name"] = "unifyhn.de"
# Save changes back to the YAML file
with open(config_file, "w") as file:
yaml.dump(config, file)
print(f"Updated {config_file}: enable_registration, set port to {port}, and domain to unifyhn.de")
EOF
# Step 7: Restart the Matrix Synapse server
echo "Restarting Matrix Synapse server on port $CUSTOM_PORT..."
synctl restart
# Step 8: Deactivate the virtual environment
deactivate
echo "Setup completed. Matrix Synapse server is running on port $CUSTOM_PORT, and registration is enabled."