Skip to content

Instantly share code, notes, and snippets.

@fvoges
Last active August 29, 2015 14:09
Show Gist options
  • Save fvoges/2370bc2c70f371ed35f9 to your computer and use it in GitHub Desktop.
Save fvoges/2370bc2c70f371ed35f9 to your computer and use it in GitHub Desktop.
Script to generate random passwords for the PE answer files
#!/bin/bash
# Created: Tue Nov 11 09:45:31 2014
# Author: Federico Voges <federico@puppetlabs.com>
#
# Simple script to change all the passwords in the PE answer files.
# It should run from a directory containing the answer files.
# It will scan all .txt files looking for "q_.*password", generate a new
# password for each unique answer and replace the password on all files
# The console admin user password is hardcoded to "puppetlabs"
# Simple password generator
function pwgen {
local l=$1
local symbols=('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' '-' '_')
local max=${#symbols[@]}
local pass=""
i=0
while [ $i -lt $l ]
do
pass="${pass}${symbols[$[$RANDOM%$max]]}"
((i++))
done
echo ${pass}
}
regex="s:^q_puppet_enterpriseconsole_auth_password.*:q_puppet_enterpriseconsole_auth_password=puppetlabs:;"
for line in $(grep -h ^q_.*password *.txt|sed -e 's:=.*::' |sort -u )
do
pass=$(pwgen 22)
regex="${regex} s:^${line}.*=.*:${line}='${pass}':;"
done
sed -i.bak -e "${regex}" *.txt
@fvoges
Copy link
Author

fvoges commented Nov 20, 2014

Original version logic was less than optimal (and by less than optimal I mean I fucked up). It was overwriting the .bak once for each password. So the .bak files were useless.

Now it should work as expected.

The console password is hardcoded to puppetlabs now and you are going to change it anyway (you ARE going to change it, right?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment