changeset 651:bdc9eddf3743

[pwgen] rewrite in shell script
author nanaya <me@nanaya.pro>
date Wed, 25 Nov 2020 01:43:25 +0900
parents 6ca63cec0879
children 9c0a70dd9ead
files bin/pwgen
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/bin/pwgen	Sat Oct 17 07:10:41 2020 +0900
+++ b/bin/pwgen	Wed Nov 25 01:43:25 2020 +0900
@@ -1,9 +1,11 @@
-#!/usr/bin/env ruby
+#!/bin/sh
 
-require 'securerandom'
+set -e
+set -u
 
-length = ARGV[0].to_i
-length = 12 if length <= 0
-5.times do |n|
-  puts "#{n}: #{SecureRandom.urlsafe_base64(length).slice(0, length)}"
-end
+_length="${1:-12}"
+
+for i in 1 2 3 4 5; do
+  printf "%s: " "$i"
+  openssl rand -base64 "$_length" | tr '/+' '-_' | cut -c "1-$_length"
+done