Skip to content

Commit

Permalink
v7.4 (#4526)
Browse files Browse the repository at this point in the history
+ DietPi-Software | Add Synapse Matrix homeserver with software ID 125
+ DietPi-Software | Add PostgreSQL database server with software ID 194
+ DietPi-Software | Enhance logging related software descriptions
  • Loading branch information
ravenclaw900 authored Jul 11, 2021
1 parent 9d67771 commit 6527ece
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .meta/dietpi-survey_report
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,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:
- DietPi-Software | X.Org X Server: Resolved an issue where the X server failed on PINE A64 as the wrong DDX driver packages were installed. Many thanks to @exadeci for reporting this issue: https://github.com/MichaIng/DietPi/issues/4541
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
2 changes: 2 additions & 0 deletions dietpi/dietpi-services
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Available services:
# - Databases
'redis-server'
'mariadb'
'postgresql'

# - PHP
'php7.2-fpm'
Expand Down Expand Up @@ -167,6 +168,7 @@ Available services:

# - Social/Search
'openbazaar'
'synapse'

# - Hardware Projects
'pi-spc'
Expand Down
246 changes: 234 additions & 12 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'
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 @@ -2990,6 +3006,52 @@ _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

# Disable TCP/IP listener and assure that UNIX domain socket is enabled at expected path
# NB: On Stretch (PGSQL v9.6) conf.d is not yet included by default and we skip the step there. It listens on localhost only, hence has no security impact.
for i in /etc/postgresql/*/main/conf.d
do
[[ -d $i ]] || continue
echo "# Disable TCP listener and assure that UNIX socket is enabled at expected path
# NB: Do not edit this file, instead override settings via e.g.: conf.d/99local.conf
listen_addresses = ''
unix_socket_directories = '/run/postgresql'" > "$i/00dietpi.conf"
done

fi

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

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

fi

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

Banner_Installing

# APT deps
# - ARMv6/7: Packages required to avoid Pillow import errors with piwheels build
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
(( $G_DISTRO > 4 )) || G_AGI libffi-dev # cffi build on Stretch

# - x86_64: Only psycopg2 needs to be compiled
else
G_AGI gcc libpq-dev
(( $G_DISTRO > 4 )) || G_AGI libffi-dev # cffi build on Stretch
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 postgresql.service

[Service]
Type=notify
SyslogIdentifier=Synapse
User=synapse
WorkingDirectory=/mnt/dietpi_userdata/synapse
ExecStart=$(command -v python3) -m synapse.app.homeserver -c homeserver.yaml -c homeserver.yaml.d/
ExecReload=/bin/kill -HUP \$MAINPID

[Install]
WantedBy=multi-user.target
_EOF_
# Database
G_EXEC systemctl start postgresql
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

# Pre-create drop-in config for database access details
G_EXEC mkdir -p /mnt/dietpi_userdata/synapse/homeserver.yaml.d
cat << _EOF_ > /mnt/dietpi_userdata/synapse/homeserver.yaml.d/00-dietpi.yaml
# PostgreSQL access details
# NB: Do not edit this file, instead override settings via e.g.: homeserver.yaml.d/99-local.conf
database:
name: psycopg2
args:
host: /run/postgresql
port: 5432
user: synapse
password: $synapse_pass
database: synapse
cp_min: 5
cp_max: 10
_EOF_
# 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 cd /mnt/dietpi_userdata/synapse

# Create initial config
G_EXEC python3 -m synapse.app.homeserver -H "$servername" -c homeserver.yaml --generate-config --report-stats "$analytics"

# Enable registrations via random shared secret
GCI_PASSWORD=1 G_CONFIG_INJECT 'registration_shared_secret:[[:blank:]]' "registration_shared_secret: $(openssl rand -hex 16)" homeserver.yaml

# Allow remote access
G_CONFIG_INJECT 'bind_addresses:[[:blank:]]' " bind_addresses: ['::', '0.0.0.0']" homeserver.yaml

# Log to journal with log level WARNING
G_EXEC sed -i 's/ handlers: \[.*\]$/ handlers: [console]/' "$servername.log.config"
G_EXEC sed -i 's/ level: .*/ level: WARNING/' "$servername.log.config"

# Permissions
G_EXEC chown -R synapse:synapse .
G_EXEC chmod -R 0660 homeserver.yaml{,.d/*.yaml}
G_EXEC chmod 0770 homeserver.yaml.d

# Register new user (interactive)
G_EXEC systemctl daemon-reload
G_EXEC systemctl start synapse
G_EXEC_OUTPUT=1 G_EXEC register_new_matrix_user -c homeserver.yaml http://127.0.0.1:8008

G_EXEC cd /tmp/$G_PROGRAM_NAME
else
# Permissions
G_EXEC chown -R synapse:synapse /mnt/dietpi_userdata/synapse
G_EXEC chmod -R 0660 /mnt/dietpi_userdata/synapse/homeserver.yaml{,.d/*.yaml}
G_EXEC chmod 0770 /mnt/dietpi_userdata/synapse/homeserver.yaml.d
fi

fi

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

Expand Down Expand Up @@ -10265,7 +10461,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 @@ -13775,6 +13971,25 @@ _EOF_

fi

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

Banner_Uninstalling

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

command -v pip3 > /dev/null && pip3 uninstall -y matrix-synapse
command -v dropdb > /dev/null && sudo -u postgres dropdb synapse
command -v dropuser > /dev/null && sudo -u postgres dropuser synapse

fi

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

Expand Down Expand Up @@ -15744,9 +15959,6 @@ _EOF_

fi

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

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

Expand Down Expand Up @@ -16126,9 +16338,10 @@ _EOF_
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 )); then

Banner_Uninstalling
pip3 uninstall -y pip
command -v pip3 > /dev/null && pip3 uninstall -y pip
G_AGP python3-pip # Pre-v6.32
[[ -f '/etc/pip.conf' ]] && rm /etc/pip.conf
[[ -f '/etc/pip.conf' ]] && G_EXEC rm /etc/pip.conf
G_EXEC rm -Rf /{root,home/*}/.cache/pip

fi

Expand Down Expand Up @@ -16157,6 +16370,15 @@ _EOF_
G_AGP snapclient
fi

software_id=194 # PostgreSQL
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 ))
then
Banner_Uninstalling
G_AGP postgresql 'postgresql-*'
G_EXEC rm -Rf /etc/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

0 comments on commit 6527ece

Please sign in to comment.