Skip to content

Commit

Permalink
bump dependencies and fix sudo for macOS in Sonoma (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebot authored Mar 19, 2024
1 parent 400f853 commit 0edf84b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 86 deletions.
8 changes: 4 additions & 4 deletions docs/front_end/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ commonmark:
Then at last this worked in my markdown file:
<details>
<summary>Python3.10</summary>
<summary>Python3.11</summary>
Check out this bash syntax highlighted block:
```bash
brew install python@3.10
brew install python@3.11
```

</details>
Expand All @@ -47,13 +47,13 @@ Markdown for the above example:

```markdown
<details>
<summary>Python3.10</summary>
<summary>Python3.11</summary>

Below, you can change the first ``` to ```bash for syntax highlighting :)
Checkout this regular code block:

```
brew install python@3.10
brew install python@3.11
```

</details>
Expand Down
16 changes: 8 additions & 8 deletions docs/python/setuppy.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ user's `$PATH`. As an example, the command my users run for lsimg is `lsimg`,
so I create a file called that which has something like:

```python
#!/usr/bin/env python3.10
#!/usr/bin/env python3.11
import lsimg

lsimg.main()
Expand Down Expand Up @@ -91,13 +91,13 @@ setup(name='onboardme',
long_description=readme(),
long_description_content_type='text/markdown',
classifiers=['Development Status :: 3 - Alpha',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Intended Audience :: End Users/Desktop',
'TOPIC :: SYSTEM :: INSTALLATION/SETUP',
lic_class],
python_requires='>3.10',
python_requires='>3.11',
keywords='onboardme, onboarding, desktop-setup, setuptools, development',
version='0.13.7',
project_urls={
Expand Down Expand Up @@ -148,22 +148,22 @@ It translates to: Create a command called `onboardme` that calls the `main`
function of the `onboardme` package.

## Testing the package
__**Note**: I'm using python/pip version 3.10 explicitly here, but you could use any version you're testing/releasing.__
__**Note**: I'm using python/pip version 3.11 explicitly here, but you could use any version you're testing/releasing.__

Build locally first for general testing:
```bash
# this will install locally and then you can test your package and cli tools
pip3.10 install -e .
pip3.11 install -e .
```

Then do the more important build for files to uplaod to pypi:
_Make sure you have the wheel, and twine module installed:_
- `pip3.10 install wheel`
- `pip3.10 install twine`
- `pip3.11 install wheel`
- `pip3.11 install twine`

```bash
# this generates a wheel file, the thing you want to upload
python3.10 -m build --wheel
python3.11 -m build --wheel

# this checks to make sure it's probably built correctly
twine check dist/*
Expand Down
45 changes: 18 additions & 27 deletions onboardme/sudo_setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/usr/bin/env python3.10
#!/usr/bin/env python3.11
"""
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.path import exists
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():
def setup_sudo() -> None:
"""
make sure we're root on mac and kick off setting up sudo with touchid
Returns True
"""
print_header("🔒 Setting up sudo")

Expand All @@ -28,31 +26,24 @@ def setup_sudo():
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
def enable_sudo_with_touchid() -> None:
"""
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)
We look for this line in /etc/pam.d/sudo_local:
auth sufficient pam_tid.so
If file doesn't exiswt or line not found, we add it.
"""
def write_touch_id_sudo(pam_file):
# 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
new_file_contents.write("auth sufficient pam_tid.so\n")

pam_file = "/etc/pam.d/sudo_local"
touch_id_line = "^auth sufficient pam_tid.so"
if exists(pam_file):
if check_response(f'grep "{touch_id_line}" {pam_file}') != 0:
write_touch_id_sudo(pam_file)
else:
write_touch_id_sudo(pam_file)
94 changes: 48 additions & 46 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "onboardme"
version = "1.7.0"
version = "1.7.1"
description = "Install dot files and packages, including a base mode with sensible defaults to run on most computers running Debian based distros or macOS."
authors = [
"Jesse Hitch <[email protected]>",
Expand Down

0 comments on commit 0edf84b

Please sign in to comment.