--- /dev/null
+[Unit]
+Description=MercuryMS Send Service
+After=network.target mercuryms-send.timer
+Requires=mercuryms-send.timer
+
+[Service]
+Type=oneshot
+User=mercuryms
+Group=mercuryms
+WorkingDirectory=/usr/share/mercuryms
+ExecStart=/opt/mercuryms/send.sh
+Environment="HOST=localhost"
+Environment="PORT=9099"
+Environment="TIMEOUT_SECONDS=45"
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+[Unit]
+Description=MercuryMS Timed Media Send
+After=network.target
+
+[Timer]
+OnActiveSec=1m
+Unit=mercuryms-send.service
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null
+#!/bin/bash
+sqlite3 mercuryms.sqlite "$(awk '/received/ {print "INSERT INTO SENT_MEDIA (MEDIA_ID) VALUES("$1");";}' <(sqlite3 mercuryms.sqlite "SELECT ID, PHONE_NUMBER, URI FROM MEDIA WHERE ID NOT IN (SELECT MEDIA_ID FROM SENT_MEDIA)" | timeout $TIMEOUT_SECONDS netcat $HOST $PORT))"
chown mercuryms:mercuryms /usr/share/mercuryms/mercuryms.sqlite
cp mercuryms.service /etc/systemd/system/
cp mercuryms-listen* /etc/systemd/system/
+cp mercuryms-send* /etc/systemd/system/