Add persistent storage in CMDS_DIR/data

main
Stef Dunlap 2022-08-24 00:05:36 -04:00
parent 47425fdd85
commit e6d32c5cab
5 changed files with 45 additions and 5 deletions

9
cmds/count 100755
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
DIR=$(dirname -- $0)
DATA="$DIR/data/count"
old_number=$(cat "$DATA")
new_number=$((old_number + 1))
echo $new_number > $DATA
echo $new_number

2
cmds/data/.gitignore vendored 100644
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,18 @@
[Unit]
Description=our
After=our.service
[Service]
Type=simple
WorkingDirectory=/home/kindrobot/spacework/our
ExecStart=/home/kindrobot/spacework/our/our.rb
Environment="OUR_NICK=your"
Environment="OUR_CHANNELS=#bots"
Environment="OUR_CMDS_DIR=/home/kindrobot/spacework/our/cmds/"
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target

4
our.rb
View File

@ -6,6 +6,7 @@ require 'open3'
nick = ENV['OUR_NICK'] || 'our'
channels = ENV['OUR_CHANNELS'] || '#tildetown,#bots'
prefix = ENV['OUR_PREFIX'] || "#{nick}/"
cmds_dir = ENV['OUR_CMDS_DIR'] || '/town/our'
module IRC
@ -82,8 +83,9 @@ i.hook do |msg|
target, content = msg.args
next unless content.delete_prefix! prefix
cmd, args = content.split(' ', 2)
cmd = '/town/our/' + cmd
cmd = "#{cmds_dir}/#{cmd}"
args ||= ''
next unless File.exists? cmd
if not File.executable? cmd

View File

@ -1,4 +1,13 @@
#!/usr/bin/env bash
DIR=$(dirname -- $0)
/usr/bin/bwrap --unshare-all --ro-bind / / --share-net --dev /dev --tmpfs /tmp $DIR/our.rb
OUR_CMDS_DIR=${OUR_CMDS_DIR:-/town/our}
/usr/bin/bwrap \
--unshare-all \
--ro-bind / / \
--bind "$OUR_CMDS_DIR/data" "$OUR_CMDS_DIR/data" \
--share-net \
--dev /dev \
--tmpfs /tmp \
$DIR/our.rb