e516c1243a872f7eec5e0a35d835d69e0944bd8b

Author
Pavle Portic <pavle.portic@tilda.center>
Committer
Pavle Portic <pavle.portic@tilda.center>
Date

Message

Update genpass script

Diff

 1diff --git a/dot_local/bin/executable_genpass b/dot_local/bin/executable_genpass
 2index e8456259f10029f4788536a6b288990d45725028..c63f5c442f15617f2c437bacfae7a5bf7ec3d915 100644
 3--- a/dot_local/bin/executable_genpass
 4+++ b/dot_local/bin/executable_genpass
 5@@ -7,18 +7,21 @@ function usage()
 6   local invalid_argument=$3
 7   local invalid_option=$4
 8 
 9-  local help="Usage: genpass -c COUNT [OPTION]
10+  local help="Usage: genpass -c COUNT [OPTION] [SET]
11 
12 Generate random password from /dev/urandom using the character set chosen
13 
14 Option (pick one character set):"
15-  local help_options="    \-a ,\--all\ \ Use all ASCII characters
16-    \-s ,\--special\ \ Limited set of special characters that shouldn't cause problems
17-    \-an ,\--alphanumeric\ \ a-z, A-Z, 0-9
18-    \-al ,\--alpha\ \ a-z, A-Z
19-    \-n ,\--numeric\ \ 0-9
20-    \-h ,\--hex\ \ 0-9, a-z
21-    \-c ,\--count \<length>\ Length of password to generate
22+  local help_options="    \-a ,\--all\ all printable characters, not including space
23+    \-lt ,\--limited\ all except special characters [A-Za-z0-9%+,-./:=@^_]
24+    \-an ,\--alphanumeric\ letters and digits
25+    \-al ,\--alpha\ letters
26+    \-u ,\--upper\ upper case letters
27+    \-l ,\--lower\ lower case letters
28+    \-n ,\--numeric\ digits
29+    \-h ,\--hex\ hexadecimal digits
30+    \-c ,\--count <length>\ Length of password to generate
31+    \[SET]\ \ Other character SET compatible with tr
32 "
33 
34   if [ "$missing_required" != "" ]
35@@ -53,22 +56,37 @@ key="$1"
36 case $key in
37   -a|--all)
38     all="true"
39+    characters="[:graph:]"
40+    shift
41+    ;;
42+  -lt|--limited)
43+    special="true"
44     characters="A-Za-z0-9%+,-./:=@^_"
45     shift
46     ;;
47   -an|--alphanumeric)
48     alphanumeric="true"
49-    characters="A-Za-z0-9"
50+    characters="[:alnum:]"
51     shift
52     ;;
53   -al|--alpha)
54     alpha="true"
55-    characters="A-Za-z"
56+    characters="[:alpha:]"
57+    shift
58+    ;;
59+  -u|--upper)
60+    upper="true"
61+    characters="[:upper:]"
62+    shift
63+    ;;
64+  -l|--lower)
65+    lower="true"
66+    characters="[:lower:]"
67     shift
68     ;;
69   -n|--numeric)
70     numeric="true"
71-    characters="0-9"
72+    characters="[:digit:]"
73     shift
74     ;;
75   -h|--hex)
76@@ -101,5 +119,15 @@ done
77 }
78 
79 init_args $@
80+
81+if [ -z $characters ]; then
82+  if [ -z $POSITIONAL ]; then
83+    echo "Missing at least one character set"
84+    exit 2
85+  else
86+    characters=$POSITIONAL
87+  fi
88+fi
89+
90 < /dev/urandom tr -dc $characters | head -c $count
91