Last active
August 29, 2015 14:09
-
-
Save fvoges/2370bc2c70f371ed35f9 to your computer and use it in GitHub Desktop.
Script to generate random passwords for the PE answer files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Created: Tue Nov 11 09:45:31 2014 | |
# Author: Federico Voges <[email protected]> | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?)