From 6758bf29930ab8d4e7369abaa4ed57b510d9c7a8 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 3 Mar 2025 13:45:24 +0100 Subject: genpasswd: init --- pkgs/shell/genpasswd | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 pkgs/shell/genpasswd 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 -- cgit v1.2.3