about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-05-04 18:20:16 +0200
committerRory& <root@rory.gay>2025-05-04 18:20:16 +0200
commit5f2258123360b2fd74b643e9e0096b61565fffd9 (patch)
tree7225354243c0ab6d50b252d0c6626936791ce68b
parentAdd support for ignoring users, change internal API (diff)
downloadMatrixAntiDmSpam-5f2258123360b2fd74b643e9e0096b61565fffd9.tar.xz
Add simple install scripts
-rw-r--r--MatrixAntiDmSpam@.service15
-rwxr-xr-xinstall-user-units.sh32
-rwxr-xr-xinstall.sh33
3 files changed, 80 insertions, 0 deletions
diff --git a/MatrixAntiDmSpam@.service b/MatrixAntiDmSpam@.service
new file mode 100644

index 0000000..490547f --- /dev/null +++ b/MatrixAntiDmSpam@.service
@@ -0,0 +1,15 @@ +# User service +[Unit] +Description=Matrix Anti DM Spam - ~/.config/MatrixAntiDmSpam/appsettings.%i.json +After=network.target + +[Service] +Type=simple +WorkingDirectory=%h/.config/MatrixAntiDmSpam +Environment=DOTNET_ENVIRONMENT=%i +ExecStart=/usr/bin/env dotnet /opt/MatrixAntiDmSpam/MatrixAntiDmSpam.dll +CPUSchedulingPolicy=idle +IOSchedulingClass=3 + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/install-user-units.sh b/install-user-units.sh new file mode 100755
index 0000000..ac5b03b --- /dev/null +++ b/install-user-units.sh
@@ -0,0 +1,32 @@ +#! /usr/bin/env sh + + +cp MatrixAntiDmSpam@.service "$HOME/.config/systemd/user/MatrixAntiDmSpam@.service" + +if [ ! -d "$HOME/.config/MatrixAntiDmSpam" ]; then + mkdir -p "$HOME/.config/MatrixAntiDmSpam" + cp -v MatrixAntiDmSpam/appsettings.Development.json "$HOME/.config/MatrixAntiDmSpam/appsettings.Template.json" + echo "Please copy and edit the template configuration to your liking." + echo "The template is located at $HOME/.config/MatrixAntiDmSpam/appsettings.Template.json" + echo "Please rename it to appsettings.{profile}.json." + echo "Once you have done so, re-run this script, and you will find the services named as 'MatrixAntiDmSpam@{profile}.service'" + exit +fi + +cp MatrixAntiDmSpam@.service "$HOME/.config/systemd/user/MatrixAntiDmSpam@.service" +find "$HOME/.config/MatrixAntiDmSpam" -maxdepth 1 -type f | while read -r line; do + # enable unit + + name="$(basename "$line")" + environmentName="$(echo "$name" | cut -d'.' -f2)" + echo "Found environment ${environmentName}: $line" + + if [ "$environmentName" = "Template" ] || [ "$environmentName" = ".json" ]; then + echo "Skipping template file ${name}" + continue + fi + + systemctl --user daemon-reload + systemctl --user enable "MatrixAntiDmSpam@${environmentName}" + systemctl --user restart "MatrixAntiDmSpam@${environmentName}" +done diff --git a/install.sh b/install.sh new file mode 100755
index 0000000..e849263 --- /dev/null +++ b/install.sh
@@ -0,0 +1,33 @@ +#! /usr/bin/env sh + +if ! command -v dotnet &> /dev/null +then + echo "'dotnet' could not be found, please refer to your distribution's documentation to install it." + echo "Hint: NixOS: nix shell nixpkgs#dotnet-sdk_9" + echo "Hint: Fedora: sudo dnf5 install dotnet-sdk-9.0" + exit1 +fi + +if [ ! -f "MatrixAntiDmSpam.sln" ]; then + echo "Please run this script from the root of the repository." + exit 1 +fi + +cd MatrixAntiDmSpam || exit 1 +echo "Elevation required to install the service!" + +if [ ! -d "/opt/MatrixAntiDmSpam" ]; then + echo "Creating directory /opt/MatrixAntiDmSpam" + sudo mkdir -p /opt/MatrixAntiDmSpam +fi + +# Ensure working directory is clean +sudo rm -rf /opt/MatrixAntiDmSpam +rm -rf bin/target + +# Build +dotnet publish -c Release -o bin/target -p:PublishSingleFile=false + +# Install +rm -rv bin/target/appsettings*.json +sudo rsync -raP --delete-during bin/target/ /opt/MatrixAntiDmSpam