Skip to content

Commit

Permalink
introduce new cronjob setup feature (#276)
Browse files Browse the repository at this point in the history
* introduce new cronjob setup feature

* add cron to allowed STEPS

* update docs; update env config parsing for cron step

* fix subproc function call to provide a list

* add note in README about cronjobs
  • Loading branch information
jessebot authored Oct 20, 2024
1 parent 1849fa9 commit 66b2774
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 253 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ See the [dockerhub page](https://hub.docker.com/r/jessebot/onboardme) for more i
- Enable touchID for sudo on macOS
- Add your user to the docker group
- Install [nerdfonts](https://www.nerdfonts.com) (defaults to mononoki and Symbols Only)
- Install [cronjobs](https://github.com/jessebot/onboardme/pull/276) to keep everything up to date everywhere, everyday :)

</details>

Expand Down
2 changes: 2 additions & 0 deletions docs/onboardme/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ Those defaults can be altered per machine by creating a config file like:
Darwin:
- dot_files
- packages
- cron
- font_setup
- neovim_setup
- sudo_setup
# these are linux specific steps
Linux:
- dot_files
- packages
- cron
- font_setup
- neovim_setup
- group_setup
Expand Down
322 changes: 159 additions & 163 deletions docs/onboardme/screenshots/help_text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions onboardme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .pkg_management import run_pkg_mngrs
from .sudo_setup import setup_sudo
from .firewall import configure_firewall
from .cron import cron_setup


HELP = options_help()
Expand Down Expand Up @@ -214,6 +215,10 @@ def main(log_level,
pkg_groups = usr_pref['package']['groups']
run_pkg_mngrs(pkg_mngrs, pkg_groups, no_upgrade)

elif step == 'cron':
# install cronjobs
cron_setup()

elif step in ['neovim_setup', 'font_setup']:
# import step's function from ide_setup.py in same directory
import_module('onboardme.ide_setup', package=f'.{step}')
Expand Down
2 changes: 1 addition & 1 deletion onboardme/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
OS = (SYSINFO.sysname, SYSINFO.machine)

# step config is different per OS
STEPS = ['dot_files','packages','font_setup','neovim_setup','group_setup']
STEPS = ['dot_files','packages','cron','font_setup','neovim_setup','group_setup']
if OS[0] == 'Darwin':
STEPS.append('sudo_setup')

Expand Down
48 changes: 48 additions & 0 deletions onboardme/cron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
NAME: onboardme.cron
DESC: install cron jobs for the user and root
AUTHORS: Jesse Hitch
LICENSE: GNU AFFERO GENERAL PUBLIC LICENSE
"""

import logging as log
from os import path
from pathlib import Path

# custom libs
from getpass import getuser

from .constants import HOME_DIR, OS
from .console_logging import print_header, print_msg
from .subproc import subproc


def cron_setup() -> None:
"""
Installs crontab to run onboardme for user only functions
On Linux:
installs crontab for root to run apt commands
"""
print_header('⏰ [i]crontab[/i] installations')
if 'Linux' in OS:
cron_dir = "/etc/crontab.d"

# install root level cronjobs
root_crontab = f'{HOME_DIR}/.config/cron/root/crontab'

# do a shallow clone of the repo
if path.exists(root_crontab):
log.info('Installing root crontab.')
subproc([f'sudo cp {root_crontab} {cron_dir}/root'])
print_msg('[i]root crontab installed.')
else:
cron_dir = "/var/at/tabs"

# install user level cronjobs
user_crontab = f'{HOME_DIR}/.config/cron/user/crontab'
if path.exists(user_crontab):
log.info('Installing user crontab.')
username = getuser()
subproc([f'sudo cp {user_crontab} {cron_dir}/{username}'])
print_msg('[i]User crontab installed.')
6 changes: 5 additions & 1 deletion onboardme/env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ def process_steps(steps: list, firewall: bool = False, browser: bool = False) ->
if 'neovim_setup' in steps_list and 'dot_files' not in steps_list:
steps_list.append('dot_files')

# need cron files to setup crontabs
if 'cron' in steps_list and 'dot_files' not in steps_list:
steps_list.append('dot_files')

if firewall and 'Linux' in OS:
# currently don't have a great firewall on macOS, sans lulu
steps_list.append('firewall_setup')

removed_duplicates = set(steps_list)
steps = list(removed_duplicates)
default_order = ['dot_files', 'packages', 'font_setup', 'neovim_setup']
default_order = ['dot_files', 'packages', 'cron', 'font_setup', 'neovim_setup']
if OS[0] == 'Linux':
default_order.append('group_setup')
else:
Expand Down
176 changes: 89 additions & 87 deletions poetry.lock

Large diffs are not rendered by default.

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.9.2"
version = "1.10.0"
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 66b2774

Please sign in to comment.