example fstab for nas setup. added random password function.
[feisty_meow.git] / scripts / core / functions.sh
index fe56aea63a2624d73f5603b55264d0aa56064444..3a86546be0abcc7a9f1b00b6c4c7e9cb306791a7 100644 (file)
@@ -238,6 +238,17 @@ if [ -z "$skip_all" ]; then
     nechung
   }
 
+  # generates a random password where the first parameter is the number of characters
+  # in the password (default 20) and the second parameter specifies whether to use
+  # special characters (1) or not (0).
+  # found function at http://legroom.net/2010/05/06/bash-random-password-generator
+  function random_password()
+  {
+    [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
+    cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
+    echo
+  }
+
   function function_sentinel() { return 0; }
   
   if [ ! -z "$SHELL_DEBUG" ]; then echo function definitions end....; fi