summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2025-03-03 13:45:24 +0100
committertv <tv@krebsco.de>2025-03-03 13:45:24 +0100
commit6758bf29930ab8d4e7369abaa4ed57b510d9c7a8 (patch)
treef8caf0ca035fe21eb1e9b6d8079a59403ae4d5a4
parent239819e7c13bac8a11ddfb9ea27127b3d3e9a978 (diff)
genpasswd: init
-rwxr-xr-xpkgs/shell/genpasswd56
1 files changed, 56 insertions, 0 deletions
diff --git a/pkgs/shell/genpasswd b/pkgs/shell/genpasswd
new file mode 100755
index 0000000..a6d96aa
--- /dev/null
+++ b/pkgs/shell/genpasswd
@@ -0,0 +1,56 @@
+#! /bin/sh
+#!buildShellBin path=coreutils
+#
+# NAME
+# genpasswd - generate a password
+#
+# SYNOPSIS
+# genpasswd [OPTION]...
+#
+# DESCRIPTION
+# Produce a random string of a given length and alphabet to standard
+# output.
+#
+# --length=number (default: 71)
+# Specify the number of bytes to produce.
+#
+# --alphabet=string (default: -+.,=/A-Za-z0-9_)
+# Specify the list of characters that can be produced.
+# The string gets interpreted by tr and may contain single-character
+# collating elements. See tr(1) for details.
+#
+# --newline=bool (default: true)
+# Specify whether a newline should be appended to the output.
+#
+
+set -efu
+
+alphabet=-+.,=/A-Za-z0-9_
+length=71
+newline=true
+
+while test $# -gt 0; do
+ case $1 in
+ --alphabet=*)
+ alphabet=${1//--alphabet=}
+ shift
+ ;;
+ --length=*)
+ length=${1//--length=}
+ shift
+ ;;
+ --newline=true|--newline=false)
+ newline=${1//--newline=}
+ shift
+ ;;
+ *)
+ echo "$0: bad argument: $1" >&2
+ exit 1
+ esac
+done
+
+tr -dc -- "$alphabet" < /dev/urandom | dd status=none bs="$length" count=1
+
+case $newline in true)
+ echo
+esac