Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DietPi-Software | Matrix Synapse Server #4526

Merged
merged 48 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d3bd529
v7.4
ravenclaw900 Jun 27, 2021
7ef334a
v7.4
ravenclaw900 Jun 28, 2021
e8a84e1
v7.4
ravenclaw900 Jun 28, 2021
50588ca
v7.4
ravenclaw900 Jun 28, 2021
8a496dc
v7.4
ravenclaw900 Jun 28, 2021
d487807
v7.4
ravenclaw900 Jun 28, 2021
73fc04b
v7.4
ravenclaw900 Jun 28, 2021
c8ac6cb
v7.4
ravenclaw900 Jun 28, 2021
ac3ad70
v7.4
ravenclaw900 Jun 28, 2021
5f33b02
v7.4
ravenclaw900 Jun 28, 2021
8f59aa8
v7.4
ravenclaw900 Jun 28, 2021
02da80e
v7.4
ravenclaw900 Jun 29, 2021
0b539a9
v7.4
ravenclaw900 Jun 29, 2021
eca504c
v7.4
ravenclaw900 Jun 29, 2021
30c9951
v7.4
ravenclaw900 Jun 29, 2021
65eab59
v7.4
ravenclaw900 Jun 29, 2021
bc06021
v7.4
ravenclaw900 Jun 29, 2021
17f4ced
v7.4
ravenclaw900 Jun 29, 2021
5f07477
v7.4
ravenclaw900 Jun 29, 2021
7552f50
v7.4
ravenclaw900 Jun 29, 2021
2b42608
v7.4
ravenclaw900 Jun 29, 2021
bee4580
v7.4
ravenclaw900 Jun 29, 2021
25ebc3a
v7.4
ravenclaw900 Jun 29, 2021
ef30bdb
v7.4
ravenclaw900 Jun 29, 2021
36a3269
v7.4
ravenclaw900 Jun 29, 2021
4693733
v7.4
ravenclaw900 Jul 1, 2021
aafa387
v7.4
ravenclaw900 Jul 5, 2021
f10132b
v7.4
ravenclaw900 Jul 7, 2021
7b36e27
v7.4
MichaIng Jul 8, 2021
a6da7dc
v7.4
ravenclaw900 Jul 8, 2021
ab5f5f8
v7.4
MichaIng Jul 8, 2021
ab201f6
v7.4
MichaIng Jul 8, 2021
a28409b
v7.4
MichaIng Jul 8, 2021
acc7910
v7.4
MichaIng Jul 8, 2021
9045fb4
v7.4
MichaIng Jul 9, 2021
2be0434
v7.4
MichaIng Jul 9, 2021
c194952
v7.4
MichaIng Jul 9, 2021
c81d107
v7.4
MichaIng Jul 9, 2021
02684a4
v7.4
ravenclaw900 Jul 10, 2021
d8e5d6c
v7.4
MichaIng Jul 10, 2021
be44380
v7.4
MichaIng Jul 10, 2021
b0f64ae
v7.4
MichaIng Jul 10, 2021
b40b424
v7.4
MichaIng Jul 10, 2021
cb47098
v7.4
MichaIng Jul 10, 2021
5c9fd5f
v7.4
MichaIng Jul 10, 2021
adcab2c
v7.4
MichaIng Jul 10, 2021
7dcd90d
v7.4
MichaIng Jul 10, 2021
25a72da
v7.4
MichaIng Jul 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .meta/dietpi-survey_report
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ shopt -s extglob
do
aSOFTWARE_NAME7_4[$i]=${aSOFTWARE_NAME7_3[$i]}
done
# shellcheck disable=SC2034
aSOFTWARE_NAME7_4[125]='Synapse Server'
# shellcheck disable=SC2034
aSOFTWARE_NAME7_4[194]='PostgreSQL'

# $1 = File name
Process_File()
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ v7.4
Changes:

New Software:
- Synapse | A Matrix homeserver implementation has been added with software ID 125.
- PostgreSQL | A persistent advanced object-relational database server has been added with software ID 194.

Fixes:

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ Links to hardware and software manufacturers, sources and build instructions use
- [AdGuard Home](https://github.com/AdguardTeam/AdGuardHome)
- [Snapcast](https://github.com/badaix/snapcast)
- [K3s](https://github.com/k3s-io/k3s)
- [Synapse](https://github.com/matrix-org/synapse)

---

Expand Down
1 change: 1 addition & 0 deletions dietpi/dietpi-services
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Available services:

# - Social/Search
'openbazaar'
'synapse'

# - Hardware Projects
'pi-spc'
Expand Down
204 changes: 194 additions & 10 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,15 @@ INDEX_BROWSER_TARGET=$INDEX_BROWSER_TARGET"
aSOFTWARE_DEPS[$software_id]='188'
(( $G_HW_ARCH == 10 )) || aSOFTWARE_DEPS[$software_id]+=' 16'
aSOFTWARE_INTERACTIVE[$software_id]=1
#------------------
software_id=125

aSOFTWARE_NAME[$software_id]='Synapse Server'
ravenclaw900 marked this conversation as resolved.
Show resolved Hide resolved
aSOFTWARE_DESC[$software_id]='Matrix homeserver implementation'
aSOFTWARE_CATX[$software_id]=6
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#synapse'
aSOFTWARE_DEPS[$software_id]='130 194'
aSOFTWARE_INTERACTIVE[$software_id]=1

# Camera & Surveillance
#--------------------------------------------------------------------------------
Expand All @@ -1088,7 +1097,7 @@ INDEX_BROWSER_TARGET=$INDEX_BROWSER_TARGET"
do
aSOFTWARE_AVAIL_G_HW_MODEL[$software_id,$i]=0
done
# - ARMb8: https://github.com/silvanmelchior/RPi_Cam_Web_Interface/tree/master/bin
# - ARMv8: https://github.com/silvanmelchior/RPi_Cam_Web_Interface/tree/master/bin
aSOFTWARE_AVAIL_G_HW_ARCH[$software_id,3]=0
#------------------
software_id=136
Expand Down Expand Up @@ -1768,6 +1777,13 @@ INDEX_BROWSER_TARGET=$INDEX_BROWSER_TARGET"
aSOFTWARE_DESC[$software_id]='Persistent time-series database server'
aSOFTWARE_CATX[$software_id]=24
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/databases/#influxdb'
#------------------
software_id=194

aSOFTWARE_NAME[$software_id]='PostgreSQL'
aSOFTWARE_DESC[$software_id]='Persistent advanced object-relational database server'
aSOFTWARE_CATX[$software_id]=24
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/databases/#postgresql'

# Network Tools
#--------------------------------------------------------------------------------
Expand Down Expand Up @@ -1946,21 +1962,21 @@ INDEX_BROWSER_TARGET=$INDEX_BROWSER_TARGET"
software_id=101

aSOFTWARE_NAME[$software_id]='Logrotate'
aSOFTWARE_DESC[$software_id]='rotates log files'
aSOFTWARE_DESC[$software_id]='Rotates and compresses old log files in /var/log'
aSOFTWARE_CATX[$software_id]=-1
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/log_system/#full-logging'
#------------------
software_id=102

aSOFTWARE_NAME[$software_id]='Rsyslog'
aSOFTWARE_DESC[$software_id]='system logging'
aSOFTWARE_DESC[$software_id]='Writes system logs (journalctl) as plain text files to /var/log'
aSOFTWARE_CATX[$software_id]=-1
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/log_system/#full-logging'
#------------------
software_id=103

aSOFTWARE_NAME[$software_id]='DietPi-RAMlog'
aSOFTWARE_DESC[$software_id]='minimal, optimised logging'
aSOFTWARE_DESC[$software_id]='Makes /var/log a RAM disk, preserves file structure on reboot'
aSOFTWARE_CATX[$software_id]=-1
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/log_system/#dietpi-ramlog'

Expand Down Expand Up @@ -2373,7 +2389,7 @@ _EOF_

G_EXEC mkdir -p /mnt/dietpi_userdata/{Music,Pictures,Video,downloads} /var/www /opt
G_EXEC chown dietpi:dietpi /mnt/dietpi_userdata/{Music,Pictures,Video,downloads}
G_EXEC chmod 775 /mnt/dietpi_userdata/{Music,Pictures,Video,downloads}
G_EXEC chmod 0775 /mnt/dietpi_userdata/{Music,Pictures,Video,downloads}

}

Expand All @@ -2382,7 +2398,7 @@ _EOF_
[[ -f '/mnt/dietpi_userdata/Music/fourdee_tech.ogg' ]] && return
G_EXEC curl -sSfL https://dietpi.com/downloads/audio/fourdee_tech.ogg -o /mnt/dietpi_userdata/Music/fourdee_tech.ogg
G_EXEC chown dietpi:dietpi /mnt/dietpi_userdata/Music/fourdee_tech.ogg
G_EXEC chmod 664 /mnt/dietpi_userdata/Music/fourdee_tech.ogg
G_EXEC chmod 0664 /mnt/dietpi_userdata/Music/fourdee_tech.ogg

}

Expand Down Expand Up @@ -2989,6 +3005,41 @@ _EOF_

fi

software_id=194 # PostgreSQL
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == 1 )); then

Banner_Installing

G_DIETPI-NOTIFY 2 'Preparing database directory at: /mnt/dietpi_userdata/postgresql'
if [[ -d '/mnt/dietpi_userdata/postgresql' ]]; then

G_DIETPI-NOTIFY 2 '/mnt/dietpi_userdata/postgresql exists, will migrate containing databases'

else
# Otherwise use possibly existent /var/lib/postgresql
# - Remove possible dead symlinks/files:
G_EXEC rm -f /mnt/dietpi_userdata/postgresql
if [[ -d '/var/lib/postgresql' ]]; then

G_DIETPI-NOTIFY 2 '/var/lib/postgresql exists, will migrate containing databases'
# Failsafe: Move symlink target in case, otherwise readlink will resolve to dir
G_EXEC mv "$(readlink -f '/var/lib/postgresql')" /mnt/dietpi_userdata/postgresql

else

G_EXEC mkdir -p /mnt/dietpi_userdata/postgresql

fi

fi

G_EXEC rm -Rf /var/lib/postgresql
G_EXEC ln -s /mnt/dietpi_userdata/postgresql /var/lib/postgresql

G_AGI postgresql
ravenclaw900 marked this conversation as resolved.
Show resolved Hide resolved

fi

software_id=103 # DietPi-RAMlog
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == 1 )); then

Expand Down Expand Up @@ -3617,6 +3668,114 @@ Package: openssl libssl*\nPin: origin packages.sury.org\nPin-Priority: -1' > /et

fi

software_id=125 # Synapse Server
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == 1 )); then

Banner_Installing

# APT deps
# - ARMv6/7: Packages required to avoid import errors
if [[ $G_HW_ARCH == [12] ]]
then
G_AGI libopenjp2-7 libtiff5 libxcb1

# - ARMv8: psycopg2 and PyNaCl (dependency) need to be compiled
elif [[ $G_HW_ARCH == 3 ]]
then
G_AGI gcc libpq-dev make

# - x86_64: Only psycopg2 needs to be compiled
else
G_AGI gcc libpq-dev
fi

# Install
G_EXEC_OUTPUT=1 G_EXEC pip3 install -U matrix-synapse psycopg2

# User
Create_User -d /mnt/dietpi_userdata/synapse synapse

# Service
cat << '_EOF_' > /etc/systemd/system/synapse.service
[Unit]
Description=Synapse (DietPi)
Wants=network-online.target
After=network-online.target dietpi-boot.service

[Service]
SyslogIdentifier=Synapse
User=synapse
WorkingDirectory=/mnt/dietpi_userdata/synapse
ExecStart=synctl start --no-daemonize

[Install]
WantedBy=multi-user.target
_EOF_
# Database
local synapse_pass=$(tr -dc '[:alnum:]' < /dev/random | head -c30)
if [[ $(sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='synapse'") != 1 ]]
then
G_EXEC sudo -u postgres psql -c "CREATE ROLE synapse WITH LOGIN PASSWORD '$synapse_pass';"
else
G_EXEC sudo -u postgres psql -c "ALTER ROLE synapse WITH PASSWORD '$synapse_pass';"
fi
if [[ $(sudo -u postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='synapse'") != 1 ]]
then
G_EXEC sudo -u postgres createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse synapse
fi

# Config
if [[ ! -f '/mnt/dietpi_userdata/synapse/homeserver.yaml' ]]
then
local invalid_text=
while :
do
if G_WHIP_INPUTBOX "${invalid_text}Please enter the name for this homeserver.\nIt is recommended that this be the domain that this server will be hosted on."
then
local servername=$G_WHIP_RETURNED_VALUE
break
else
invalid_text='[ERROR] Please enter a name for your Matrix homserver.\n\n'
fi
done

if G_WHIP_BUTTON_OK_TEXT='Yes' G_WHIP_BUTTON_CANCEL_TEXT='No' G_WHIP_YESNO 'Would you like to report basic anonymous analytics, like number of users, to the Matrix foundation?'
then
local analytics='yes'
else
local analytics='no'
fi

G_EXEC mkdir -p /mnt/dietpi_userdata/synapse
G_EXEC cd /mnt/dietpi_userdata/synapse

G_EXEC python3 -m synapse.app.homeserver --server-name "$servername" --config-path /mnt/dietpi_userdata/synapse/homeserver.yaml --generate-config --report-stats="$analytics"

GCI_PASSWORD=1 G_CONFIG_INJECT 'registration_shared_secret:[[:blank:]]' "registration_shared_secret: $(openssl rand -hex 16)" homeserver.yaml
G_CONFIG_INJECT 'bind_addresses:[[:blank:]]' " bind_addresses: ['::', '0.0.0.0']" homeserver.yaml
G_CONFIG_INJECT 'name:[[:blank:]]' ' name: psycopg2' homeserver.yaml
G_EXEC sed -i "s/^[[:blank:]]*database:[[:blank:]].*/ user: synapse\n password: $synapse_pass\n database: synapse\n host: localhost\n cp_min: 5\n cp_max: 10/" homeserver.yaml

# Permissions
G_EXEC chown -R synapse:synapse .
G_EXEC chmod 0660 homeserver.yaml

G_EXEC cd /tmp/$G_PROGRAM_NAME

G_EXEC systemctl daemon-reload
G_EXEC systemctl start synapse
G_EXEC_OUTPUT=1 G_EXEC register_new_matrix_user -c /mnt/dietpi_userdata/synapse/homeserver.yaml http://localhost:8008
else
# Permissions
G_EXEC chown -R synapse:synapse /mnt/dietpi_userdata/synapse
G_EXEC chmod 0660 /mnt/dietpi_userdata/synapse/homeserver.yaml

# Update database password
G_EXEC sed -i "/^[[:blank:]]*database:\$/,/^[[:blank:]]*password:/s/^[[:blank:]]*password:.*/ password: $synapse_pass/" /mnt/dietpi_userdata/synapse/homeserver.yaml
fi

fi

software_id=128 # MPD
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == 1 )); then

Expand Down Expand Up @@ -10264,7 +10423,7 @@ _EOF_
do

G_WHIP_DEFAULT_ITEM=$port
if G_WHIP_INPUTBOX "${invalid_text}Please enter the network port, that should be used to access your WireGuard server:\n
if G_WHIP_INPUTBOX "${invalid_text}Please enter the network port that will be used to access your WireGuard server:\n
NB: This port needs to be forwarded by your router and/or opened in your firewall settings. Default value is: 51820" && disable_error=1 G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" 0; then

port=$G_WHIP_RETURNED_VALUE
Expand Down Expand Up @@ -13774,6 +13933,26 @@ _EOF_

fi

software_id=125 # Synapse Server
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 )); then

Banner_Uninstalling

if [[ -f '/etc/systemd/system/synapse.service' ]]
then
systemctl disable --now synapse
rm /etc/systemd/system/synapse.service
fi
[[ -d '/etc/systemd/system/synapse.service.d' ]] && rm -R /etc/systemd/system/synapse.service.d

pip3 uninstall -y matrix-synapse
[[ -d '/mnt/dietpi_userdata/synapse' ]] && rm -R /mnt/dietpi_userdata/synapse

sudo -u postgres dropdb synapse
sudo -u postgres dropuser synapse

fi

software_id=132
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 )); then

Expand Down Expand Up @@ -15743,9 +15922,6 @@ _EOF_

fi

#----------------------------------------------------------------------
# LINUX SOFTWARE

software_id=15
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 )); then

Expand Down Expand Up @@ -16156,6 +16332,14 @@ _EOF_
G_AGP snapclient
fi

software_id=194 # PostgreSQL
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 ))
then
Banner_Uninstalling
G_AGP postgresql 'postgresql-*'
[[ -d '/mnt/dietpi_userdata/postgresql' ]] && G_EXEC rm -R /mnt/dietpi_userdata/postgresql
fi

G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Finalise uninstall'

# Uninstall finished, set all uninstalled software to state 0 (not installed)
Expand Down