Created
November 8, 2012 13:00
-
-
Save colinfrei/4038664 to your computer and use it in GitHub Desktop.
Capistrano recipe to add an htaccess file when deploying
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
# [...] | |
set :htaccess_username, "User" | |
set :htaccess_password, "Password" | |
#set :htaccess_password_hashed, "zJDC6IeGdG8QU" | |
before "deploy:create_symlink", "deploy:htaccess_protect" | |
# [...] |
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
namespace :deploy do | |
desc "Add .htaccess protection" | |
task :htaccess_protect do | |
_cset(:htaccess_username) { abort "Please specify an htaccess username, set :htaccess_username, 'foo'" } | |
unless exists?(:htaccess_password_hashed) | |
_cset(:htaccess_password) { abort "Please specify htaccess_password or htaccess_password_hashed" } | |
set :htaccess_password_hashed, "#{htaccess_password}".crypt('httpauth') | |
end | |
# This appends to the end of the file, so don't run it multiple times! | |
run "echo '#{htaccess_username}:#{htaccess_password_hashed}' >> #{File.join(current_path, '.htpasswd')}" | |
run "echo 'AuthType Basic' >> #{File.join(current_path, '.htaccess')}" | |
run "echo 'AuthName \"Restricted\"' >> #{File.join(current_path, '.htaccess')}" | |
run "echo 'AuthUserFile #{File.join(current_path, '.htpasswd')}' >> #{File.join(current_path, '.htaccess')}" | |
run "echo 'Require valid-user' >> #{File.join(current_path, '.htaccess')}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment