aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/httpsvr68
-rwxr-xr-xscripts/key-check.sh12
-rw-r--r--scripts/readme.md3
-rwxr-xr-xscripts/snap-btrfs.sh23
-rwxr-xr-xscripts/snap-lvm.sh31
-rw-r--r--scripts/syncthing-cert.sh70
-rwxr-xr-xscripts/webhook.py70
7 files changed, 0 insertions, 277 deletions
diff --git a/scripts/httpsvr b/scripts/httpsvr
deleted file mode 100755
index ffc816a..0000000
--- a/scripts/httpsvr
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/sh
-# Stupid basic http server using OpenBSD netcat
-set -e
-
-PORT="${PORT:-8900}"
-ADDR="${ADDR:-127.0.0.1}"
-
-ncpid=
-
-send_index() {
-cat <<EOF
-HTTP/1.1 200 OK
-Server: shell
-Content-Type: text/html; charset=UTF-8
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <title>Netcat HTTP</title>
-</head>
-<body>
- Minimal HTTP server in posix SH and OpenBSD's netcat
-</body>
-</html>
-EOF
-}
-
-cleanup() {
- set +e
- kill "$ncpid" >/dev/null 2>&1
- rm "$_f" "$_inF" >/dev/null 2>&1
- exit 0
-}
-trap cleanup EXIT INT
-
-while true ; do
- _f="$(mktemp)"
-
- _inF="$(mktemp)"
- rm -f "$_inF"
- mkfifo "$_inF"
-
- #shellcheck disable=SC2002
- cat "$_inF" | nc -l "$ADDR" "$PORT" > "$_f" & # | tee /dev/fd/2 >"$_f" &
- ncpid=$!
-
- counter=0
- while [ $counter -lt 100 ] || [ -s "$_f" ] ; do
- if grep -qi "^Accept:" "$_f" ; then
- pth="$(sed -nre 's@^GET ([^ ][^ ]*) HTTP/1.1.*@\1@gp' < "$_f")"
-
- echo "Request for path: $pth"
-
- case $pth in
- /) send_index >"$_inF" ;;
- esac
-
- break
- fi
- sleep .01
- [ -s "$_f" ] && counter=$((counter += 1))
- ps $ncpid >/dev/null 2>&1 || break
- done
-
- kill $ncpid || echo ""
- rm "$_f" "$_inF"
-done
diff --git a/scripts/key-check.sh b/scripts/key-check.sh
deleted file mode 100755
index 1672bc4..0000000
--- a/scripts/key-check.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Check for a public key, and create one for the user if it
-# does not exist. Spit the key in red to stdout. Not so much for me,
-# but as a convienient script to give to others who aren't so familiar
-# with how SSH key authorization works.
-
-keyf="$HOME/.ssh/id_ed25519";
-! [ -e "$keyf" ] && ssh-keygen -t ed25519 -f "$keyf" -P "";
-printf '\033[1;31m%s\033[0m\n' "$(cat "$keyf.pub")";
-
-# One line version for pasting into chat:
-# keyf="$HOME/.ssh/id_ed25519"; ! [ -e "$keyf" ] && ssh-keygen -t ed25519 -f "$keyf" -P ""; printf '\033[1;31m%s\033[0m\n' "$(cat "$keyf.pub")";
diff --git a/scripts/readme.md b/scripts/readme.md
deleted file mode 100644
index 60c79c1..0000000
--- a/scripts/readme.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# scripts
-
-A couple of misc scripts that may be of some utility.
diff --git a/scripts/snap-btrfs.sh b/scripts/snap-btrfs.sh
deleted file mode 100755
index cc2e5a9..0000000
--- a/scripts/snap-btrfs.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-set -x
-set -e
-timestamp() {
- date +%m.%d.%y_%H.%M.%S
-}
-
-rootfs="glibc"
-snap="${rootfs}-snap"
-
-cd /ROOT
-
-if [ -e "$snap" ] ; then
- btrfs sub del "$snap"
-fi
-
-if ! [ -e "bak" ] ; then
- btrfs sub create "bak"
-fi
-
-btrfs sub snap -r "$rootfs" "bak/${rootfs}-$(timestamp)"
-btrfs sub snap "$rootfs" "$snap"
-sed -i.bak -e"s/subvol=${rootfs}/subvol=${snap}/g" "${snap}/etc/fstab"
diff --git a/scripts/snap-lvm.sh b/scripts/snap-lvm.sh
deleted file mode 100755
index 4991495..0000000
--- a/scripts/snap-lvm.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-set -e
-
-vg="x230"
-lv="root"
-snap_name="${lv}-snap"
-mountpoint="/mnt/snap"
-PERCENT="100"
-
-mount_fs() {
- _device="$1"; shift
- _opts="nouuid,rw"
- _mntpoint="$1"; shift
- if ! [ -d "$_mntpoint" ] ; then
- mkdir "$_mntpoint"
- fi
- mount -o "$_opts" "$_device" "$_mntpoint"
-}
-
-# If snapshot doesn't exist
-if ! lvm lvs "$vg/$snap_name" >/dev/null 2>&1 ; then
- lvm lvcreate "$vg/$lv" -s --name "$snap_name" -l "${PERCENT}%ORIGIN"
- mount_fs "/dev/$vg/$snap_name" "$mountpoint"
- sed -i.bak -r "s@(/dev/${vg}/${lv})@\1${snap_name}@" \
- "$mountpoint/etc/fstab"
- umount "$mountpoint"
-else
- printf 'Cannot continue snapshot "%s" already exists.\n' \
- "$vg/$snap_name"
- exit 1;
-fi
diff --git a/scripts/syncthing-cert.sh b/scripts/syncthing-cert.sh
deleted file mode 100644
index 0dd460b..0000000
--- a/scripts/syncthing-cert.sh
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/bin/sh
-set -e
-days="3650"
-keyout="syncthing.key"
-reqout="$(mktemp)"
-certout="syncthing.crt"
-alg="ED25519"
-
-help() {
-cat <<EOF
-$0 [ -c <certificate_out> ] [ -k <key_out> ] [ -448 ]
-Defaults are:
-certificate_out: 'syncthing.crt'
-key_out: 'syncthing.key'
-
-Optionally, the -448 option will generate an ED448 key instead of ED25519.
-
-EOF
-exit 1
-}
-
-while [ $# -gt 0 ] ; do case $1 in
- -c) certout="$2" ; shift ; shift ;;
- -k) keyout="$2" ; shift ; shift ;;
- -448) alg="ED448"; shift ;;
- *) help ;;
-esac ; done
-
-v3Section="
-basicConstraints = CA:FALSE
-keyUsage = digitalSignature, keyEncipherment, dataEncipherment
-extendedKeyUsage = serverAuth, clientAuth
-subjectAltName = @alt_names
-[alt_names]
-DNS.1 = syncthing
-"
-
-openssl genpkey -algorithm $alg > "$keyout"
-
-cnf="$(mktemp)"
-cat > "$cnf" <<EOF
-[req]
-distinguished_name = req_distinguished_name
-prompt = no
-req_extensions = v3_req
-[req_distinguished_name]
-OU = Automatically Generated
-O = Syncthing
-CN = syncthing
-[v3_req]
-$v3Section
-EOF
-
-extfile="$(mktemp)"
-cat > "$extfile" <<EOF
-[v3_ca]
-$v3Section
-EOF
-
-openssl req -new -out "$reqout" -key "$keyout" -config "$cnf"
-
-rm "$cnf"
-
-openssl x509 -req -days "$days" -in "$reqout" -signkey "$keyout" \
- -extensions v3_ca \
- -extfile "$extfile" \
- -out "$certout"
-
-rm "$extfile"
-rm "$reqout"
diff --git a/scripts/webhook.py b/scripts/webhook.py
deleted file mode 100755
index 3db70a8..0000000
--- a/scripts/webhook.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env python3
-import requests, json, sys
-
-expected_status = 204
-url = ""
-# Default for discord, easy enough to override
-msg = {
- "username": "{hostname} script",
- "content": "```{stdin}```",
-}
-
-customVars = {}
-
-def merge_dicts(*dict_args):
- result = {}
- for dictionary in dict_args:
- result.update(dictionary)
- return result
-
-def template(msg, fmt):
- out = {}
- for k, v in msg.items():
- if isinstance(v, dict):
- out[k] = template(v, fmt)
- else:
- out[k] = v.format(**fmt)
- return out
-
-
-def help():
- print("Usage: {} [-m msg] [-u url] [-s expected_status] [-V var content]...".format(sys.argv[0]))
- print("A small python script to send webhooks easily from the command line utilizing arguments and stdin")
- print("Only requrement is the requests library")
- print("Defaults:")
- print("\tmsg: " + json.dumps(msg))
- print("\turl: " + url)
- print("\texpected_status: ", expected_status)
- print("")
- print("The [-V var content] arguments allow you to specifiy custom vars to be overridden in the json msg.")
- sys.exit(2)
-
-n = 1
-while n < len(sys.argv):
- if sys.argv[n] == "-u":
- url = sys.argv[n+1]
- n += 2
- elif sys.argv[n] == "-m":
- msg = json.loads(sys.argv[n+1])
- n += 2
- elif sys.argv[n] == "-s":
- expected_status = int(sys.argv[n+1])
- n += 2
- elif sys.argv[n] == "-V":
- customVars[sys.argv[n+1]] = sys.argv[n+2]
- n += 3
- else:
- help()
-
-if url == "":
- sys.stderr.write("No URL provided\n")
- help()
-
-msg2 = template(msg, merge_dicts(customVars , {"stdin": sys.stdin.read()}))
-r = requests.post(url, json=msg2)
-
-if r.status_code != expected_status:
- print(r)
- print(r.text)
- sys.exit(1)
-