Skip to content

Instantly share code, notes, and snippets.

@philwinder
Created April 28, 2015 12:46
Show Gist options
  • Save philwinder/4003a8209ec8106c1b7d to your computer and use it in GitHub Desktop.
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.
#!/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