e9f4a7001fd18e9c768bb639d9361ac202c31591

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

Message

Remove genpass function and replace with extended bash script

Diff

This diff is truncated to protect this page.

  1diff --git a/dot_config/zsh/functions/genpass b/dot_config/zsh/functions/genpass
  2deleted file mode 100644
  3index 8448ef1f5e81c9a8ac028679bdf6bc5e992c6231..0000000000000000000000000000000000000000
  4--- a/dot_config/zsh/functions/genpass
  5+++ /dev/null
  6@@ -1,3 +0,0 @@
  7-# Function to generate random string from /dev/urandom
  8-
  9-< /dev/urandom tr -dc 'A-Za-z0-9%+,-./:=@^_' | head -c $1
 10diff --git a/dot_local/bin/executable_genpass b/dot_local/bin/executable_genpass
 11new file mode 100644
 12index 0000000000000000000000000000000000000000..e8456259f10029f4788536a6b288990d45725028
 13--- /dev/null
 14+++ b/dot_local/bin/executable_genpass
 15@@ -0,0 +1,105 @@
 16+#!/usr/bin/bash
 17+
 18+function usage()
 19+{
 20+  local just_help=$1
 21+  local missing_required=$2
 22+  local invalid_argument=$3
 23+  local invalid_option=$4
 24+
 25+  local help="Usage: genpass -c COUNT [OPTION]
 26+
 27+Generate random password from /dev/urandom using the character set chosen
 28+
 29+Option (pick one character set):"
 30+  local help_options="    \-a ,\--all\ \ Use all ASCII characters
 31+    \-s ,\--special\ \ Limited set of special characters that shouldn't cause problems
 32+    \-an ,\--alphanumeric\ \ a-z, A-Z, 0-9
 33+    \-al ,\--alpha\ \ a-z, A-Z
 34+    \-n ,\--numeric\ \ 0-9
 35+    \-h ,\--hex\ \ 0-9, a-z
 36+    \-c ,\--count \<length>\ Length of password to generate
 37+"
 38+
 39+  if [ "$missing_required" != "" ]
 40+  then
 41+    echo "Missing required argument: $missing_required"
 42+  fi
 43+
 44+  if [ "$invalid_option" != "" ] && [ "$invalid_value" = "" ]
 45+  then
 46+    echo "Invalid option: $invalid_option"
 47+  elif [ "$invalid_value" != "" ]
 48+  then
 49+    echo "Invalid value: $invalid_value for option: --$invalid_option"
 50+  fi
 51+
 52+  echo -e "
 53+"
 54+  echo "$help"
 55+  echo "$help_options" | column -t -s'\'
 56+  return
 57+}
 58+function init_args()
 59+{
 60+REQ_ARGS=("count" )
 61+
 62+# get command line arguments
 63+POSITIONAL=()
 64+while [[ $# -gt 0 ]]
 65+do
 66+key="$1"
 67+
 68+case $key in
 69+  -a|--all)
 70+    all="true"
 71+    characters="A-Za-z0-9%+,-./:=@^_"
 72+    shift
 73+    ;;
 74+  -an|--alphanumeric)
 75+    alphanumeric="true"
 76+    characters="A-Za-z0-9"
 77+    shift
 78+    ;;
 79+  -al|--alpha)
 80+    alpha="true"
 81+    characters="A-Za-z"
 82+    shift
 83+    ;;
 84+  -n|--numeric)
 85+    numeric="true"
 86+    characters="0-9"
 87+    shift
 88+    ;;
 89+  -h|--hex)
 90+    hex="true"
 91+    characters="0-9a-f"
 92+    shift
 93+    ;;
 94+  -c|--count)
 95+    count="$2"
 96+    shift 2
 97+    ;;
 98+  *)
 99+    POSITIONAL+=("$1") # saves unknown option in array
100+    shift
101+    ;;
102+esac
103+done
104+
105+for i in "${REQ_ARGS[@]}"; do
106+  # $i is the string of the variable name
107+  # ${!i} is a parameter expression to get the value
108+  # of the variable whose name is i.
109+  req_var=${!i}
110+  if [ "$req_var" = "" ]
111+  then
112+    usage "" "--$i"
113+    exit
114+  fi