summaryrefslogtreecommitdiff
path: root/bin/common
diff options
context:
space:
mode:
Diffstat (limited to 'bin/common')
-rwxr-xr-xbin/common/cx2
-rwxr-xr-xbin/common/saf24
-rwxr-xr-xbin/common/sync-install.sh58
-rwxr-xr-xbin/common/toush10
4 files changed, 94 insertions, 0 deletions
diff --git a/bin/common/cx b/bin/common/cx
new file mode 100755
index 0000000..88fb817
--- /dev/null
+++ b/bin/common/cx
@@ -0,0 +1,2 @@
+#!/bin/sh
+[ -x "$1" ] && chmod -x "$1" || chmod +x "$1"
diff --git a/bin/common/saf b/bin/common/saf
new file mode 100755
index 0000000..0c6fbc4
--- /dev/null
+++ b/bin/common/saf
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Simple Ass Fetch by futxlii
+
+red="$(printf '\033[31m')"
+green="$(printf '\033[32m')"
+blue="$(printf '\033[34m')"
+reset="$(printf '\033[0m')"
+
+for file in /etc/os-release /usr/lib/os-release
+do
+ [ -f "$file" ] && . "$file" && break
+done
+
+KERNEL="$(uname -r)"
+UPTIME="$(uptime -p)"; UPTIME="${UPTIME##up }"
+SHELL="$(basename "$SHELL")"
+
+cat <<EOF
+ ${red}- ${blue}${ID:-"unknown"}
+ ${red}- ${blue}$KERNEL
+ ${red}- ${blue}$UPTIME
+ ${red}- ${blue}$SHELL${reset}
+EOF
diff --git a/bin/common/sync-install.sh b/bin/common/sync-install.sh
new file mode 100755
index 0000000..e26c74d
--- /dev/null
+++ b/bin/common/sync-install.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+die ()
+{
+ echo "$@" >&2
+}
+
+read_char ()
+{
+ old_stty_cfg=$(stty -g)
+ stty raw -echo
+ dd ibs=1 count=1 2> /dev/null
+ stty $old_stty_cfg
+}
+
+confirm ()
+{
+ printf "$1 "
+ read_char | grep "[yY]"
+}
+
+usage()
+{
+ >&2 printf 'Usage: %s <remote> <destination>\n' "${0##*/}"
+}
+
+[ $# -lt 2 ] && usage && exit 1
+REMOTE="$1"
+DEST="$2"
+SCRIPT="${3:-sync.sh}"
+
+if ! ssh $REMOTE test -w $DEST 2> /dev/null
+then
+ die "Not a valid remote or destination."
+ exit 1
+fi
+
+die "─────────────────────────────────────────────────────────────"
+cat <<EOF | tee "$SCRIPT" >&2
+#!/bin/sh
+
+THISDIR="\$(dirname "\$(readlink -f "\$0")")"
+inotifywait -m -e create,modify,delete --format "%f" "\$THISDIR" |
+while read FILE
+do
+ rsync -aP "\$THISDIR/" "$REMOTE:$DEST"
+ sleep 1m
+done
+EOF
+die "─────────────────────────────────────────────────────────────"
+die "located at $(readlink -f "$SCRIPT")"
+
+if confirm "good?"
+then
+ chmod +x "$SCRIPT"
+else
+ rm -f "$SCRIPT"
+fi
diff --git a/bin/common/toush b/bin/common/toush
new file mode 100755
index 0000000..eb2d7cf
--- /dev/null
+++ b/bin/common/toush
@@ -0,0 +1,10 @@
+#!/bin/sh
+# idea from https://codeberg.org/futxlii/bin/toush :)
+
+shebang='#!/bin/sh'
+
+[ -f "$1" ] && exit 1
+
+printf '%s\n\n' "$shebang" > "$1" &&
+ chmod +x "$1" && $EDITOR "$1"
+grep -qv "$shebang\|^$" "$1" || rm "$1"