diff --git a/README.md b/README.md index ec497cc..998d2c6 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ with an email address you want to use as a team: ``` -teams-bot init --email das_synthikat@systemli.org --password p455w0rD +teams-bot init --email helpdesk@example.org --password p455w0rD ``` This command will show a QR code; @@ -44,13 +44,50 @@ Now to run it, simply execute: ``` -teams-bot init --email das_synthikat@systemli.org --password p455w0rD +teams-bot init --email helpdesk@example.org --password p455w0rD ``` The bot only works as long as this command is running. Read more about [running bots on bots.delta.chat](https://bots.delta.chat/howto.html). + +### Deploy with pyinfra + +If you use [pyinfra](https://pyinfra.com/) to manage a server, +you can deploy this bot with it. +Just import it into your [deploy.py file](https://docs.pyinfra.com/en/2.x/getting-started.html#create-a-deploy) like this: + +``` +from teams_bot.pyinfra import deploy_teams_bot + +deploy_teams_bot( + unix_user='root', # an existing UNIX user (doesn't need root or sudo privileges) + bot_email='helpdesk@example.org', # the email address your team wants to use + bot_passwd='p4ssw0rd', # the password to the email account +) +``` + +After you deployed it, +you need to do two steps manually: + +First, +login to the user with ssh +and run +`export $(cat ~/.env | xargs) && ~/.local/lib/teams-bot.venv/bin/teams-bot init` +to initialize the bot, +create the crew, +and join the crew. + +Then run +`systemctl --user start teams-bot` +to start the bot +and keep it running in the background. + +You can view the log output +with `journalctl --user -fu teams-bot` +to confirm that it works. + ## Development Environment To get started with developing, diff --git a/setup.cfg b/setup.cfg index aa6c24d..33dafbd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,6 +21,7 @@ packages = find: python_requires = >=3.8 install_requires = click + pyinfra pickleDB qrcode deltachat diff --git a/src/teams_bot/pyinfra_assets/setup-venv.sh b/src/teams_bot/pyinfra_assets/setup-venv.sh new file mode 100644 index 0000000..4c4a65b --- /dev/null +++ b/src/teams_bot/pyinfra_assets/setup-venv.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +python3 -m venv ~/.local/lib/teams-bot.venv +source ~/.local/lib/teams-bot.venv/bin/activate +pip install -U pip wheel + diff --git a/src/teams_bot/pyinfra_assets/teams-bot.service.j2 b/src/teams_bot/pyinfra_assets/teams-bot.service.j2 new file mode 100644 index 0000000..08ac6e6 --- /dev/null +++ b/src/teams_bot/pyinfra_assets/teams-bot.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=run deltachat teams-bot: {{ bot_email }} + +[Service] +ExecStart=/home/{{ unix_user }}/.local/lib/teams-bot.venv/bin/teams-bot run -v +EnvironmentFile=/home/{{ unix_user }}/.env +Restart=on-failure +RestartSec=5s + +[Install] +WantedBy=multi-user.target