diff --git a/cmds/count b/cmds/count new file mode 100755 index 0000000..7434ce6 --- /dev/null +++ b/cmds/count @@ -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 diff --git a/cmds/data/.gitignore b/cmds/data/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/cmds/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/our.example.service b/our.example.service new file mode 100644 index 0000000..0442070 --- /dev/null +++ b/our.example.service @@ -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 diff --git a/our.rb b/our.rb index 409be7e..0522345 100755 --- a/our.rb +++ b/our.rb @@ -3,9 +3,10 @@ require 'socket' require 'open3' # configurable environment variables -nick = ENV['OUR_NICK'] || 'our' -channels = ENV['OUR_CHANNELS'] || '#tildetown,#bots' -prefix = ENV['OUR_PREFIX'] || "#{nick}/" +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 diff --git a/start.sh b/start.sh index c55d1ae..c9b7068 100755 --- a/start.sh +++ b/start.sh @@ -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