summaryrefslogtreecommitdiffstats
path: root/pkgs/shell
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/shell')
-rw-r--r--pkgs/shell/default.nix6
-rwxr-xr-xpkgs/shell/genpasswd56
-rwxr-xr-xpkgs/shell/with-ssh37
3 files changed, 98 insertions, 1 deletions
diff --git a/pkgs/shell/default.nix b/pkgs/shell/default.nix
index 119b23e..ce6123d 100644
--- a/pkgs/shell/default.nix
+++ b/pkgs/shell/default.nix
@@ -15,7 +15,11 @@ let
assert mylib.types.filename.check name;
assert isShellScript path;
self.callPackage
- ({ pkgs }: pkgs.runCommand "${name}" {} /* sh */ ''
+ ({ pkgs }: pkgs.runCommand "${name}" {
+ meta = {
+ mainProgram = name;
+ };
+ } /* sh */ ''
mkdir -p $out/bin
touch $out/bin/${name}
chmod +x $out/bin/${name}
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
diff --git a/pkgs/shell/with-ssh b/pkgs/shell/with-ssh
new file mode 100755
index 0000000..65459e2
--- /dev/null
+++ b/pkgs/shell/with-ssh
@@ -0,0 +1,37 @@
+#! /bin/sh
+#!buildShellBin prepend-path=openssh
+#
+# usage: with-ssh [--add[=KEY] ...] [COMMAND [ARGS ...]]
+#
+
+set -efu
+
+case ${WITH_SSH_STAGE-1} in
+ 1)
+ export WITH_SSH_STAGE=2
+ exec ssh-agent "$0" "$@"
+ ;;
+ 2)
+ if test $# = 0; then
+ set -- "$SHELL"
+ fi
+ case "$1" in
+ --add)
+ shift
+ ssh-add
+ exec "$0"
+ ;;
+ --add=*)
+ key=$1; shift
+ key=${key#--add=}
+ ssh-add "$key"
+ exec "$0" "$@"
+ ;;
+ *)
+ exec "$@"
+ esac
+ ;;
+ *)
+ echo "with-ssh: error: bad stage: $WITH_SSH_STAGE" >&2
+ exit 1
+esac