Browse Source

add README and LICENSE

Xuu 7 months ago
parent
commit
d829b58096
11 changed files with 135 additions and 17 deletions
  1. 26 0
      LICENSE
  2. 83 0
      README.md
  3. 1 1
      VERSION
  4. 9 2
      cmd/skillet/config.go
  5. 10 6
      cmd/skillet/skillet.go
  6. 0 1
      shell/cmd
  7. 0 2
      shell/commands-available/whoami
  8. 2 2
      shell/commands-enabled/dnscheck
  9. 0 1
      shell/db/note/key
  10. 0 0
      shell/db/taunts
  11. 4 2
      shell/run

+ 26 - 0
LICENSE

@@ -0,0 +1,26 @@
+Copyright 2020 Jon Lundy <jon@xuu.cc>
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors
+may be used to endorse or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 83 - 0
README.md

@@ -0,0 +1,83 @@
+# Skillet IRC Bot
+
+Skillet runs commands on shell and returns the output. It also supports control through UNIX sockets.
+
+## Install
+
+```sh
+go get -U sour.is/x/skillet
+```
+
+create script directory
+
+```sh
+wget https://git.sour.is/attachments/67c5c7f8-3997-4796-b9b5-8fb8e2d8401e -O shell.tgz
+tar xvJf shell.tgz
+```
+
+## Config
+
+Skillet can be configured by command args, environment vars, or a config.toml file.
+
+```sh
+Usage:
+  skillet version
+  skillet [-v  | -vv] connect [-u <UnixSocket>]
+
+Options:
+  -v                                             Log info to console.
+  -vv                                            Log debug to console.
+  -c <ConfigDir>, --config=<ConfigDir>           Set Config Directory.
+  -u <UnixSocket>                                Listen for commands on unix socket.
+  --tls                                          Enable TLS
+  --tls-cert <cert>                              Use TLS Cert
+  --tls-key <key>                                Use TLS Key
+
+Config:
+  The config file is read from the following locations:
+    - <ConfigDir>
+    - /etc/opt/sour.is/skillet/
+    - Working Directory
+```
+
+Environ variables
+
+| Variable                 | Notes                                                       |
+|:-------------------------|:------------------------------------------------------------|
+| `SKILLET_IRC_TLS`        | enable TLS connection                                       |
+| `SKILLET_IRC_TLSCERT`    | Use TLS Client Cert                                         |
+| `SKILLET_IRC_TLSKEY`     | Use TLS Client Cert Key                                     |
+| `SKILLET_IRC_HOST`       | Hostname and port to connect (ex. irc.host:6669)            |
+| `SKILLET_IRC_NICK`       | Bot Nick to use                                             |
+| `SKILLET_IRC_CHAN`       | Default channel to join (default: #skillet)                 |
+| `SKILLET_IRC_PASS`       | (optional) Password to authenticate with host               |
+| `SKILLET_IRC_OPER`       | Nick of super user (default: none)                          |
+| `SKILLET_IRC_UNIX`       | (optional) Listen on socket (ex. /tmp/skillet.sock)         |
+| `SKILLET_IRC_CMDTIMEOUT` | (optional) Timeout for shell commands (default: 30 seconds) |
+
+Config File
+
+```ini
+[irc]
+# config for connecting to server here.
+host = "localhost:6669"
+chan = "#skillet"
+nick = "skillet"
+# pass = "secret password"
+# oper = "somenick"
+# unix = "/tmp/skillet.sock"
+
+[irc.cmd]
+run = "./run"
+timeout = 30
+
+[irc.opts]
+# config to pass to shell here.
+```
+
+## Running
+
+```sh
+cd shell
+skillet
+```

+ 1 - 1
VERSION

@@ -1 +1 @@
-0.5.19
+0.5.20

+ 9 - 2
cmd/skillet/config.go

@@ -46,7 +46,13 @@ Config:
 var defaultConfig = `
 [irc]
 # config for connecting to server here.
-cmd = "./run"
+nick = "skillet"
+chan = "#skillet"
+host = "localhost:6669"
+
+[irc.cmd]
+run = "./run"
+timeout = 30
 
 [irc.opts]
 # config to pass to shell here.
@@ -62,7 +68,8 @@ var automaticEnv = []string{
 	"irc.pass",
 	"irc.oper",
 	"irc.unix",
-	"irc.cmd",
+	"irc.cmd.run",
+	"irc.cmd.timeout",
 }
 
 var args map[string]interface{}

+ 10 - 6
cmd/skillet/skillet.go

@@ -22,8 +22,6 @@ import (
 	"sour.is/x/toolbox/log"
 )
 
-var defaultEnv []string
-
 func main() {
 	ctx, cancel := context.WithCancel(context.Background())
 
@@ -57,11 +55,10 @@ func run(ctx context.Context) {
 	PASS := viper.GetString("irc.pass")
 	OPER := viper.GetString("irc.oper")
 	TLS := viper.GetBool("irc.tls")
-	CMD := viper.GetString("irc.cmd")
+
+	CMD := viper.GetString("irc.cmd.run")
+	OPTS := viper.GetStringMapString("irc.opts")
 	CMDTIMEOUT := time.Duration(viper.GetInt64("irc.cmd.timeout")) * time.Second
-	if CMDTIMEOUT == 0 {
-		CMDTIMEOUT = 30 * time.Second
-	}
 
 	cfg := irc.NewConfig(NICK)
 
@@ -92,6 +89,7 @@ func run(ctx context.Context) {
 		c.LogPanic(l)
 	}
 
+	defaultEnv := make([]string, 0, len(OPTS)+6)
 	defaultEnv = append(defaultEnv,
 		fmt.Sprintf("HOME=%v", os.Getenv("HOME")),
 		fmt.Sprintf("PATH=%v", os.Getenv("PATH")),
@@ -101,6 +99,12 @@ func run(ctx context.Context) {
 		fmt.Sprintf("SKILLET_IRC_HOST=%v", HOST),
 	)
 
+	for name, value := range OPTS {
+		name = strings.ToUpper(name)
+		name = strings.ReplaceAll(name, ".", "_")
+		defaultEnv = append(defaultEnv, fmt.Sprintf("SKILLET_OPT_%s=%s", name, value))
+	}
+
 	cl := irc.Client(cfg)
 	cl.EnableStateTracking()
 

+ 0 - 1
shell/cmd

@@ -1 +0,0 @@
-commands-enabled/

+ 0 - 2
shell/commands-available/whoami

@@ -1,7 +1,5 @@
 #!/bin/bash
 
-. settings
-
 echo "You are nick: $SKILLET_NICK ident: $SKILLET_IDENT host: $SKILLET_HOST"
 echo "+ NOTICE $SKILLET_IRC_CHAN"
 printenv | grep SKILLET | tr '\n' ' '

+ 2 - 2
shell/commands-enabled/dnscheck

@@ -2,8 +2,8 @@
 
 echo "Checking dns servers... (please wait) $HOST"
 
-PASTE_SH=https://git.dn42.us/dn42/go-paste/raw/master/public/paste.sh
-REGISTRY_DNS=https://git.dn42.us/dn42/registry/raw/object-fix/data/dns/
+PASTE_SH=https://git.dn42.dev/dn42/go-paste/raw/master/public/paste.sh
+REGISTRY_DNS=https://git.dn42.dev/dn42/registry/raw/object-fix/data/dns/
 
 check_servers() {
 	ZONE=$1

+ 0 - 1
shell/db/note/key

@@ -1 +0,0 @@
-value

+ 0 - 0
shell/db/taunts


+ 4 - 2
shell/run

@@ -16,9 +16,11 @@
 #
 # Exemple : hooks-enabled/pubmsg 'mandark' '~mandark@mandark.fr' '#zomgffs' '' 'say Hello world !'
 
-#>&2 echo "$*"
+>&2 echo "$*"
 
-. settings
+if [ -f settings ]; then
+  . settings
+fi
 
 now=$(date "+%Y-%m-%d %H:%M:%S")
 hook="$0"