forked from webpro/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
731 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env ruby | ||
# Source: https://github.com/MikeMcQuaid/dotfiles/blob/master/bin/touchid-enable-pam-sudo | ||
# Enables sudo authentication using TouchID. | ||
|
||
pam_sudo_filename = '/etc/pam.d/sudo' | ||
pam_sudo_contents = File.read(pam_sudo_filename) | ||
if pam_sudo_contents.include?('pam_tid.so') | ||
puts 'TouchID PAM sudo module already enabled!' unless ARGV.include?('--quiet') | ||
exit | ||
end | ||
|
||
first_line = '# sudo: auth account password session' | ||
first_line_regex = /^#{first_line}$/ | ||
unless pam_sudo_contents.match?(first_line_regex) | ||
warn "Error: #{pam_sudo_filename} is not in the expected format!" | ||
abort | ||
end | ||
|
||
if Process.uid != 0 | ||
puts "Rerunning #{$0} with sudo..." | ||
exec 'sudo', $0 | ||
end | ||
|
||
pam_sudo_contents.sub!( | ||
first_line_regex, | ||
"#{first_line}\nauth sufficient pam_tid.so" | ||
) | ||
|
||
File.write(pam_sudo_filename, pam_sudo_contents) | ||
puts 'TouchID PAM sudo module now enabled!' |
Oops, something went wrong.