-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 use the built in fingerprint sensor on mac for sudo (#92)
* add touchid setup for sudo for macOS * update version * only run on macOS * fix formatting to be prettier
- Loading branch information
Showing
7 changed files
with
82 additions
and
19 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
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
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,58 @@ | ||
#!/usr/bin/env python3.10 | ||
""" | ||
Name: onbaordme.sudo_setup | ||
DESCRIPTION: setup pam module for sudo and add user to sudo group | ||
AUTHOR: Jesse Hitch | ||
LICENSE: GNU AFFERO GENERAL PUBLIC LICENSE Version 3 | ||
""" | ||
|
||
import logging as log | ||
from os import geteuid | ||
from os import system as check_response | ||
|
||
# custom libs | ||
from .console_logging import print_header, print_sub_header | ||
from .subproc import subproc | ||
|
||
|
||
def setup_sudo(): | ||
""" | ||
make sure we're root on mac and kick off setting up sudo with touchid | ||
Returns True | ||
""" | ||
print_header("🔒 Setting up sudo") | ||
|
||
# check if running as root | ||
if geteuid() != 0: | ||
subproc(["sudo onboardme -s sudo_setup"], spinner=False) | ||
print_sub_header("🧑💻 sudo using TouchId is enabled.") | ||
else: | ||
enable_sudo_with_touchid() | ||
return True | ||
|
||
|
||
def enable_sudo_with_touchid(): | ||
""" | ||
We look for this line in /etc/pam.d/sudo: | ||
auth sufficient pam_tid.so | ||
If not found, we add it. | ||
return True | ||
""" | ||
pam_file = "/etc/pam.d/sudo" | ||
if check_response(f'grep "pam_tid.so" {pam_file}') != 0: | ||
log.info(f"TouchID not found in {pam_file}. Attempting to add it.") | ||
|
||
# read in the file and modify the second line to have pam_tid.so | ||
new_contents = [] | ||
with open(pam_file, 'r') as file_contents: | ||
for index, line in enumerate(file_contents.readlines()): | ||
new_contents.append(line) | ||
if index == 1: | ||
touchid = "auth sufficient pam_tid.so\n" | ||
new_contents.append(touchid) | ||
|
||
# write back the altered file | ||
with open(pam_file, 'w') as new_file_contents: | ||
for line in new_contents: | ||
new_file_contents.write(line) | ||
return True |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "onboardme" | ||
version = "0.15.3" | ||
version = "0.15.4" | ||
description = "An onboarding tool to install dot files and packages including a default mode with sensible defaults to run on most Debian/macOS machines." | ||
authors = ["Jesse Hitch <[email protected]>"] | ||
license = "AGPL-3.0-or-later" | ||
|