#!/bin/bash # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # This script will set up a basic systemd service and timer for DiscoRSS # You can optionally edit the entries here before running it, or you can # use systemctl --user edit --full discorss.service or discorss.timer # after installing them. printf "\e[1;34mDisco\e[1;38;5;208mRSS\e[0m Install Helper Script\n\n" workingDir=$(pwd) # bail if we're on a non-systemd system, suggest cron if [[ -d /run/systemd/system ]]; then printf "systemd detected..." else printf "This script and DiscoRSS in general are optimized for systemd! You can use cron as a substitute but I haven't written any documentation for it, so you're on your own for now!" exit 127 # command not found exit code fi printf "Would you like the systemd service and timer files created for you? [y/n]: " read answer if [[ "$answer" =~ ^([yY])$ ]]; then cat << EOF > discorss.service # Autogenerated by install.sh [Unit] Description=Discord RSS feeder Wants=discorss.timer [Service] Type=oneshot TimeoutStartSec=120 ExecStart=$workingDir/discorss.py [Install] WantedBy=default.target EOF cat << EOF > discorss.timer # Autogenerated by install.sh [Unit] Description=Timer for DiscoRSS Requires=discorss.service [Timer] Unit=discorss.service OnCalendar=*:0/5:00 AccuracySec=1s [Install] WantedBy=timers.target EOF printf "Making ~/.config/systemd/user in case it doesn't exist ...\n" mkdir -p -v ~/.config/systemd/user/ printf "Copying service and timer files there ... \n" cp discorss.service ~/.config/systemd/user/ cp discorss.timer ~/.config/systemd/user/ rm -f discorss.service rm -f discorss.timer printf "Reloading systemd daemon ... \n\n" systemctl --user daemon-reload else printf "This script is intended to be automatically run. It's designed with systemd in mind, but you are free to use any automation tools. You can look at this script for examples of how to structure systemd user services and timers.\nOf course, you could always run it by hand, if you really want to :)\n\n" fi printf "Would you like a basic example config created for you? [y/n]: " read answer1 if [[ "$answer1" =~ ^([yY])$ ]]; then mkdir -p -v ~/.config/discorss cat << EOF > ~/.config/discorss/discorss.conf { "feeds": [ { "name": "Phoronix", "siteurl": "https://www.phoronix.com/", "url": "http://www.phoronix.com/rss.php", "webhook": "PASTE WEBHOOK URL HERE", "offset": 0 } ] } EOF printf "\nMake sure to edit \e[1;34m~/.config/discorss/discorss.conf\e[0m and add in your custom feeds and webhook URLS! The script will just error out if you don't do this." else printf "\nMake sure to create a config at \e[1;34m~/.config/discorss/discorss.conf\e[0m and follow the pattern shown in the README." fi printf "\nWould you like to have the timer enabled and started now? [y/n]: " read answer if [[ "$answer" =~ ^([yY])$ ]]; then systemctl --user enable --now discorss.timer printf "\ndiscorss.timer enabled and started. \e[1;31mDon't enable or start discorss.service\e[0m -- the timer does this automatically." else printf "\nDon't forget to run \e[1;32msystemctl --user enable --now discorss.timer\e[0m when you are ready! \e[1;31mDon't enable or start discorss.service\e[0m -- the timer does this automatically." fi printf "\n\nYou should be almost ready to go! Double-check your config files, and check \e[1;32msystemctl --user list-timers\e[0m once the discorss.timer is enabled to see when it will fire next. The default is every 5 minutes." printf "\nRemember, if you need help or encounter any bugs, contact me via the issues tracker on the git repository where you got this from!\n"