Created
April 28, 2015 12:46
-
-
Save philwinder/4003a8209ec8106c1b7d to your computer and use it in GitHub Desktop.
Reads a user:password file named htpasswd and updates all passwords in every *.auth file.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Use htpasswd.py to add users to htpasswd file: | |
# touch ./htpasswd | |
# ./htpasswd.py -b ./htpasswd admin password | |
# ./htpasswd.py -b ./htpasswd alice password | |
# Add usernames to group files | |
# touch ./admins.auth | |
# touch ./users.auth | |
# echo "admin:..." >> admins.auth | |
# echo "alice:..." >> users.auth | |
# Now update groups with passwords | |
# ./updateGroups.rb | |
passwords = File.new('./htpasswd','r') | |
while pwline = passwords.gets | |
pwline.strip! | |
next if pwline.empty? | |
user, _ = pwline.split(':') | |
%x(sed -i 's/#{user}:.*/#{pwline.gsub('/','\/')}/g' *.auth) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment