From bb280b4f45200ce4caafa64ffcf16eec8db54237 Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 15:02:27 +0100 Subject: [PATCH 01/10] reworking how we process configurations --- README.md | 8 +- docs/onboardme/getting-started.md | 33 ++- onboardme/__init__.py | 26 +- onboardme/config/onboardme_config.yaml | 85 ------- onboardme/config/packages.yaml | 320 ------------------------- onboardme/constants.py | 10 + onboardme/env_config.py | 88 +++---- onboardme/help_text.py | 8 +- onboardme/pkg_management.py | 17 +- pyproject.toml | 9 +- 10 files changed, 97 insertions(+), 507 deletions(-) delete mode 100644 onboardme/config/onboardme_config.yaml delete mode 100644 onboardme/config/packages.yaml diff --git a/README.md b/README.md index 836123ae..5a6c7858 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ We install and upgrade libraries and apps using common package managers.
onboardme provides a currated list of default packages -- checkout the [default packages](./onboardme/config/packages.yaml) +- checkout the [default packages] - supports `brew`, `apt`, `snap`, `flatpak`, and `pip` (and you can add your own 😄) - group together packages for different kinds of environments - onboardme provides default package groups: @@ -60,13 +60,13 @@ onboardme keeps your neovim plugins installed and up to date with [packer] under If you haven't already made the switch from Vim to [NeoVim], you can try out NeoVim today with `onboardme` :D We used to support both neovim _and_ vim, but these days none of the primary developers of this repo use pure vim anymore, so we can't ensure it's up to standards. All of your knowledge from vim is still helpful in neovim though, and we highly recommend switching as neovim has a lot more features and a very active plugin community :) NeoVim maintains a guide on how to switch from vim [here](https://neovim.io/doc/user/nvim.html#nvim-from-vim). - We will stop official support for configuring vim, outside of installing the package across Debian/MacOS, in v1.0.0. This just means we won't be running anything to configure your vim plugins anymore, but you can still always add it to a package manager in [`packages.yaml`](#configuration). + We will stop official support for configuring vim, outside of installing the package across Debian/MacOS, in v1.0.0. This just means we won't be running anything to configure your vim plugins anymore, but you can still always add it to a package manager in [`packages.yml`](#configuration).
### Easy `yaml` config files - [XDG Base Directory Spec] use for [config files](#configuration) - - Uses `$XDG_CONFIG_HOME/onboardme/onboardme_config.yml` and `$XDG_CONFIG_HOME/onboardme/packages.yml` + - Uses `$XDG_CONFIG_HOME/onboardme/config.yml` and `$XDG_CONFIG_HOME/onboardme/packages.yml` ### Other useful (but optional) configurations - Enable touchID for sudo on macOS @@ -145,7 +145,7 @@ onboardme has lots of CLI options, but you can also use config files. You have t Config files are in `~/.config/onboardme/` (will use `$XDG_CONFIG_HOME`, if defined). Examples below:
-config.yaml +config.yml ```yaml diff --git a/docs/onboardme/getting-started.md b/docs/onboardme/getting-started.md index a957daf8..2f249eba 100644 --- a/docs/onboardme/getting-started.md +++ b/docs/onboardme/getting-started.md @@ -38,22 +38,17 @@ onboardme --help ### Config files -`onboardme` uses a `config.yaml` in its installation directory that has defaults. +`onboardme` uses a `config.yml` in its installation directory that has defaults. Those defaults can be altered per machine by creating a config file like:
- `~/.config/onboardme/config.yaml` + `~/.config/onboardme/config.yml` ```yaml --- # ______________________________________________________________ # - # Config file for the onboardme cli command. # - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # - # - This is the default config file that pip will install into: # - # $PYTHON_PATH/lib/onboardme/config/onboardme_config.yaml # - # # - # - If this files exists as: ~/.config/onboardme/config.yaml # - # then its loaded instead of the default config # + # Config file for the onboardme cli: # + # ~/.config/onboardme/config.yml # # -------------------------------------------------------------- # log: @@ -81,8 +76,10 @@ Those defaults can be altered per machine by creating a config file like: dot_files: # personal git repo URL for your dot files, defaults to jessebot/dot_files git_url: "https://github.com/jessebot/dot_files.git" + # the branch to use for the git repo above, defaults to main git_branch: "main" + # !CAREFUL: runs a `git reset --hard`, which will overwite/delete files in ~ # that conflict with the above defined git repo url and branch. # You should run the following to get the files that would be overwritten: @@ -110,8 +107,6 @@ Those defaults can be altered per machine by creating a config file like: # uncomment these to add them as default installed package groups # - gaming # - work - # - # Coming soon: to edit the specific packages: ~/.config/onboardme/packages.yaml # known safe remote hosts that you expect to be able to ping and SSH into remote_hosts: [] @@ -128,7 +123,7 @@ Those defaults can be altered per machine by creating a config file like:
We also use a package file called -[`packages.yaml`](https://github.com/jessebot/onboardme/blob/main/onboardme/config/packages.yaml) +[`packages.yml`](https://github.com/jessebot/dot_files/blob/main/.config/onboardme/packages.yml) which you can also place in your `~/.config/onboardme` directory, to take precedence over our defaults. @@ -137,13 +132,13 @@ precedence over our defaults. Steps refer to a specific function in the list of functions we run and can be configured for both macOS and Linux seperately. These steps include: -- setting up dot files in your home directory (.bashrc, .vimrc, etc) +- setting up dot files in your home directory (.bashrc, etc) - managing packages using package managers (brew, pip3.11, apt, snap, flatpak) - installing fonts - setting up basic TUI IDE, neovim (vim is optional) - setting up groups -They can be configured via the `steps` parameter in the `config.yaml` above, +They can be configured via the `steps` parameter in the `config.yml` above, or via the the cli like: ```bash @@ -170,7 +165,7 @@ The dot files for your home directory are installed from a git URL and branch that you can configure either via the config file, or the cli. If your local files conflict with the files in the repo, we will not overwrite them by default. If you always want your local dot files overwritten, you can pass in the `-O` switch -or `--overwrite` option or set `overwrite` in your local `~/.config/onboardme/config.yaml`. +or `--overwrite` option or set `overwrite` in your local `~/.config/onboardme/config.yml`. ### `onboardme` cli ```bash @@ -178,7 +173,7 @@ or `--overwrite` option or set `overwrite` in your local `~/.config/onboardme/co onboardme --git_url https://github.com/jessebot/dot_files.git --git_branch main --overwrite ``` -### `config.yaml` +### `config.yml` ```yaml dot_files: @@ -191,7 +186,7 @@ dot_files: ### Package Management All of the packages are installed using package managers, and each package manager has groups of packages they can install. You can specify specific -package _managers_ and package _groups_ via the `config.yaml` file, or via the cli. +package _managers_ and package _groups_ via the `config.yml` file, or via the cli. By default, we install the `default` package _groups_ for all package _managers_. This includes everything you need for a basic cli experience and a slim ide. @@ -213,7 +208,7 @@ slim ide PLUS GUI tools, like vlc and freetube. onboardme --pkg_groups default --pkg_groups gui ``` -##### `config.yaml` +##### `config.yml` ```yaml package: @@ -233,7 +228,7 @@ _Note: This will not install/upgrade the default package group._ onboardme --pkg_managers brew --pkg_groups devops ``` -##### `config.yaml` +##### `config.yml` ```yaml package: diff --git a/onboardme/__init__.py b/onboardme/__init__.py index 6e05923d..994aeccf 100755 --- a/onboardme/__init__.py +++ b/onboardme/__init__.py @@ -12,9 +12,8 @@ import logging from rich.logging import RichHandler from .help_text import RichCommand, options_help -from .constants import VERSION, OS +from .constants import VERSION, OS, STEPS, PKG_MNGRS from .env_config import check_os_support, process_configs, USR_CONFIG_FILE -from .env_config import DEFAULTS as OPTS from .console_logging import print_manual_steps from .dot_files import setup_dot_files from .pkg_management import run_pkg_mngrs @@ -42,7 +41,7 @@ def setup_logger(level="", log_file=""): # these are params to be passed into logging.basicConfig opts = {'level': log_level, 'format': "%(message)s", 'datefmt': "[%X]"} - # we only log to a file if one was passed into config.yaml or the cli + # we only log to a file if one was passed into config.yml or the cli if not log_file: if USR_CONFIG_FILE: log_file = USR_CONFIG_FILE['log'].get('file', None) @@ -78,14 +77,13 @@ def setup_logger(level="", log_file=""): @option('--log_level', '-l', metavar='LOGLEVEL', help=HELP['log_level'], type=Choice(['debug', 'info', 'warn', 'error'])) @option('--log_file', '-o', metavar='LOGFILE', help=HELP['log_file']) -@option('--steps', '-s', metavar='STEP', multiple=True, - type=Choice(OPTS['steps'][OS[0]]), help=HELP['steps']) +@option('--steps', '-s', metavar='STEP', multiple=True, type=Choice(STEPS), + help=HELP['steps']) @option('--git_url', '-u', metavar='URL', help=HELP['git_url']) @option('--git_branch', '-b', metavar='BRANCH', help=HELP['git_branch']) @option('--overwrite', '-O', is_flag=True, help=HELP['overwrite']) @option('--pkg_managers', '-p', metavar='PKG_MANAGER', multiple=True, - type=Choice(OPTS['package']['managers'][OS[0]]), - help=HELP['pkg_managers']) + type=Choice(PKG_MNGRS), help=HELP['pkg_managers']) @option('--pkg_groups', '-g', metavar='PKG_GROUP', multiple=True, type=Choice(['default', 'gaming', 'gui', 'devops']), help=HELP['pkg_groups']) @@ -93,19 +91,19 @@ def setup_logger(level="", log_file=""): @option('--remote_host', '-r', metavar="IP_ADDR", multiple=True, help=HELP['remote_host']) @option('--version', is_flag=True, help=HELP['version']) -def main(log_level: str = "", +def main(log_level: str = "WARN", log_file: str = "", - steps: str = "", - git_url: str = "", - git_branch: str = "", + steps: str = STEPS.join(','), + git_url: str = "https://github.com/jessebot/dot_files.git", + git_branch: str = "main", overwrite: bool = False, - pkg_managers: str = "", - pkg_groups: str = "", + pkg_managers: str = PKG_MNGRS.join(','), + pkg_groups: str = "default", firewall: bool = False, remote_host: str = "", version: bool = False): """ - If present, config: XDG_CONFIG_HOME/onboardme/[packages.yaml, config.yaml] + If present, config: XDG_CONFIG_HOME/onboardme/[packages.yml, config.yml] If run with no options on Linux, it will install brew, pip3.11, apt, flatpak, and snap packages. On mac, it only installs brew/pip3.11 packages. config loading tries to load: cli options and then .config/onboardme/* diff --git a/onboardme/config/onboardme_config.yaml b/onboardme/config/onboardme_config.yaml deleted file mode 100644 index ec79e9eb..00000000 --- a/onboardme/config/onboardme_config.yaml +++ /dev/null @@ -1,85 +0,0 @@ ---- -# ______________________________________________________________ # -# Config file for the onboardme cli command. # -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # -# - This is the default config file that pip will install into: # -# $PYTHON_PATH/lib/onboardme/config/onboardme_config.yaml # -# # -# - If this files exists as: ~/.config/onboardme/config.yaml # -# then its loaded instead of the default config # -# -------------------------------------------------------------- # - - -log: - # Full path to a file you'd like to log to. Creates file if it doesn't exist - file: "" - # what level of logs to output (DEBUG, INFO, WARN, ERROR) - level: "INFO" - # don't output anything to the console, if set and log file passed in, still - # creates a log file. unstable. - # quiet: false - - -# steps refer to a specific function in the list of functions we run -steps: - # these are mac specific steps - Darwin: - - dot_files - - packages - - font_setup - - neovim_setup - - sudo_setup - # these are linux specific steps - Linux: - - dot_files - - packages - - font_setup - # - vim_setup # you can install vim instead of, or in addition to, neovim - - neovim_setup - - group_setup - -dot_files: - # personal git repo URL for your dot files, defaults to jessebot/dot_files - git_url: "https://github.com/jessebot/dot_files.git" - # the branch to use for the git repo above, defaults to main - git_branch: "main" - # !CAREFUL: runs a `git reset --hard`, which will overwite/delete files in ~ - # that conflict with the above defined git repo url and branch. - # You should run the following to get the files that would be overwritten: - # onboardme -s dot_files - overwrite: false - -# This is the basic package config. -package: - # Remove any of the below pkg managers to only run the remaining pkg managers - managers: - # these are macOS specific steps - Darwin: - - brew - - pip3.11 - # these are linux specific steps - Linux: - - brew - - pip3.11 - - apt - - snap - - flatpak - # list of extra existing packages groups to install - groups: - - default - # uncomment these to add them as default installed package groups - # - gaming - # - work - -# Coming soon: to edit the specific packages: ~/.config/onboardme/packages.yaml - -# known safe remote hosts that you expect to be able to ping and SSH into -remote_hosts: [] - # - 192.168.42.42 - -# setup iptable on Linux only -firewall: false - -### TODO: make this work, it's a nice dream though. -# any URL we can curl to download a folder from -# wallpapers_download_url: "" diff --git a/onboardme/config/packages.yaml b/onboardme/config/packages.yaml deleted file mode 100644 index 3ee618fc..00000000 --- a/onboardme/config/packages.yaml +++ /dev/null @@ -1,320 +0,0 @@ ---- -brew: - emoji: "🍺" - commands: - list: "brew list -1" - update: "brew update --quiet" - upgrade: "brew upgrade --quiet" - install: "brew install " - cleanup: "brew cleanup" - # these are essentially just extra git repos to query for installs/updates - taps: - macOS: - - "wez/wezterm" - - "zegervdv/zathura" - - "homebrew/cask-fonts" - packages: - # these are all for both macOS and Debian - default: - - w3m # TUI browser - - pandoc # mardown rendering - - wget - - zellij # tmux replacement :) - # recording a shell session to share with others - - asciinema - - neovim # TUI IDE is neovim - - neomutt # TUI email client - - offlineimap # fetch your mail locally for neomutt - # fuzzy search, helps with completion and searching - - fzf - # ls replacement written in rust: https://github.com/Peltoche/lsd - - lsd - # A cat(1) clone with syntax highlighting and Git integration. - - bat - - rich-cli # pretty formatting and syntax highlighting - # file TUI: https://www.geeksforgeeks.org/ranger-a-cli-file-manager/ - - ranger - # preview videos in the terminal. commented by default because it is big - # - ffmpegthumbnailer - # cat images in the terminal (e.g. img2sixel imagename.png) - - libsixel - # for working with images and making lsimg work - - imagemagick - # ag command: like grep or ack, but more modern, for searching file text - - the_silver_searcher - # diff, but with colors - - colordiff - # prettier top alternatives - - btop # C++ top - bigger than bottom, still testing - - bottom # rust top - # quick system metrics, typically used as an MOTD - - fastfetch - # prettier du/df outputs: https://github.com/muesli/duf - - duf - # rainbow text - - lolcat - # blocky fonts: https://devhints.io/figlet - - figlet - - toilet - # less: b/c you get new features if you stay up2date, & brew is up2date - - less - # steam locamotive - - sl - # The Matrix screensaver for the terminal - - cmatrix - # a cow that says things - - cowsay - # revision control system stuff - - git - - gitui # terminal user interface for git - - gh # github cli - - glab # gitlab cli - # programming languages and their package managers - - go - - node # node.js - - rustup # installs cargo and rust - # linter for YAML - - yamllint - - jq # for parsing json via cli - - yq # it's like jq but for yaml - # search stackoverflow e.g. howdoi extend a dictionary in python - - howdoi - # get the quick, short text of how to use various commands - - tealdeer - # generating SSL certs and random strings - - openssl@3 - # password management - - bitwarden-cli - # anti virus - - clamav - # TUI for gpg keys, for the lazy, like me - - gpg-tui - # spotify daemon - - spotifyd - # spotify TUI - - spotify-tui - # macOS specific stuff. Won't work with LinuxBrew - macOS: - # python 3.11 already ships with Debian bookworm, only needed for macOS - - python@3.11 - # for hiding the top bar on an M1 - - topnotch - # for testing apis and downloading things - - curl - # current version of bash :) - - bash - # so that bash completion stuff works - - "bash-completion@2" - # zathura is a document viewer - - zathura - - zathura-pdf-mupdf - - "--cask font-mononoki" - - "--cask font-hack-nerd-font" - # this lets us resize windows on macOS - - "--cask rectangle" - # Default browser - - "--cask firefox" - # File server cloud replacement, not ready yet - # - "--cask nextcloud" - # wezterm: Rust based terminal the is cross-OS-compatible - - "--cask wez/wezterm/wezterm" - # gives us the default gnu/linux sed we all know and love - - "gnu-sed" - # remap keys on macOS - - "--cask karabiner-elements" - # primary media player - - "--cask vlc" - # youtube replacement - - "--cask freetube" - # firewall - - "--cask lulu" - # password manager - - "--cask bitwarden" - # VPN - - "--cask protonvpn" - # email - - "--cask protonmail-bridge" - # libreoffice is a FOSS office suite that replaces Google Docs/Office365 - - "--cask libreoffice" - devops: - - "docker" - # docker desktop - - "--cask docker" - # colima is a docker desktop replacement - - "colima" - # for backups - - restic - # terraform for building stuff - - terraform - - tflint - - terraform-docs - # cli for k8s (kubernetes) - - kubectl - # kubectl plugin manager - - krew - # terminal based dashbaord for k8s - - k9s - # package manager for k8s - - helm - # gitops continuous delivery for k8s configs - - argocd - # KinD (Kubernetes in Docker), for small k8s clusters for testing - - kind - # other useful goodies - # manage multiple versions of terraform - - tfenv - # Bitnami sealed-secrets cli: encrypt secrets in yaml files for gitops - # - kubeseal - work: - # for work chats - - "--cask slack" - - "--cask zoom" - -apt: - emoji: "🙃" - commands: - list: "scripts/get_apt_list.sh" - update: "sudo apt-get update -y" - upgrade: "sudo apt-get upgrade -y" - install: "sudo apt-get install -y " - cleanup: "sudo apt-get autoremove -y" - packages: - default: - - bash-completion - - curl - - gcc-11 - - build-essential - - python3 - - python3-dev - - python3-pip - - mono-complete - - silversearcher-ag # grep alternative - # this should let you use the a yubikey for auth - - libpam-yubico - # vpn - - wireguard - # troubleshooting - - sysstat - # networking and firewall - - iptables - - net-tools - # package manager - - snapd - # print a pretty pallete to see all colors the terminal can render - - colortest - # help fix locale issues - - "locales-all" - devops: - - docker-ce - - docker-ce-cli - - docker.io - - containerd.io - # like top but for GPUs - - nvtop - gui: - # package manager for gui apps - - flatpak - # needed for freetube - - youtube-dl - # this lets you install flatpak packages via the gui - - gnome-software-plugin-flatpak - # gui firewall - - gufw - # pdf viewer with themeing - - zathura - # commented out till nextcloud is working - # - nextcloud-desktop - # libreoffice is a FOSS office suite that replaces Google Docs/Office365 - - libreoffice - # GUI interface for pulseaudio, so you can disable audio devices - - pavucontrol - gaming: - # helpful for gaming on linux - - "nvidia-driver-libs:i386" - - "steam:i386" - # to format disks to exFAT; FAT is too thin for modern windows 10 ISOs - # - exfat-utils - -flatpak: - emoji: "🫓 " - commands: - setup: "flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo" - list: "flatpak list --user --columns=application" - install: "flatpak install --user --app -y " - packages: - gui: - - "org.freedesktop.Platform/x86_64/21.08" - # password manager - - com.bitwarden.desktop - # youtube alternative - - io.freetubeapp.FreeTube - - org.wezfurlong.wezterm - gaming: - - lutris - -snap: - emoji: "🫰 " - commands: - upgrade: "sudo snap refresh" - list: "snap list" - install: "sudo snap install " - packages: - gui: - - core - # screen debugger/sharing tool for android - - scrcpy - # media player - - vlc - -# most of this is actually for powerline, my shell prompt -pip3.11: - emoji: "🐍" - commands: - # this is just till there's a better solution than pipx for Debian Bookworm - # ref: https://salsa.debian.org/cpython-team/python3/-/blob/master/debian/README.venv - setup: "sudo rm /usr/lib/python3.*/EXTERNALLY-MANAGED" - list: "pip3.11 list" - install: "pip3.11 install --upgrade --user " - packages: - default: - # keep ourselves up to date - - onboardme - # powerline: for the internal ip address prompt segment - - netifaces - # powerline: supposed to work spotify info - - dbus - # neovim: needed for neovim's python3 interface, I think - - pynvim - # this is for git pre-commits - - pre-commit - # for git commits - # powerline: (status line for tmux/BASH) - - "git+ssh://git@github.com/powerline/powerline" - - powerline-kubernetes - - powerline-gitstatus - # python development: linting/auto-linting - - ruff - - flake8 - - pyflakes - - autoflake - - poetry - - build - - twine - macOS: - # this is for hacking on the iterm2 python api - - iterm2 - devops: - # this is a k8s tool to spin up clusters on your local machine - - smol-k8s-lab - # need this for python notebooks - - ipykernel - # classic python notebooks - - notebook - # latest jupyter notebooks - - jupyterlab - # notebook-driven development platform - - nbdev - # notebooks in the terminal 💚 - - euporie - # this is for markdown notebook docs and such - - quarto diff --git a/onboardme/constants.py b/onboardme/constants.py index 3f5257ef..ef1574c0 100644 --- a/onboardme/constants.py +++ b/onboardme/constants.py @@ -23,3 +23,13 @@ SYSINFO = uname() # this will be something like ('Darwin', 'x86_64') OS = (SYSINFO.sysname, SYSINFO.machine) + +# step config is different per OS +STEPS = ['dot_files','packages','font_setup','neovim_setup','group_setup'] +if OS[0] == 'Darwin': + STEPS.append('sudo_setup') + +# package manager config is different per OS +PKG_MNGRS = ['brew','pip3.11'] +if OS[0] == 'Linux': + PKG_MNGRS.extend(['apt','snap','flatpak']) diff --git a/onboardme/env_config.py b/onboardme/env_config.py index aa72c0c2..211cf951 100755 --- a/onboardme/env_config.py +++ b/onboardme/env_config.py @@ -1,33 +1,44 @@ """ -environment variable loading library for onboardme +config variable processing library for onboardme """ + import logging as log + # for system data, environment data, and checking/joining paths from os import path +from pathlib import Path + # rich helps pretty print everything from rich.prompt import Confirm import yaml # custom libs -from .constants import OS, PWD, ONBOARDME_CONFIG_DIR +from .constants import OS, ONBOARDME_CONFIG_DIR from .console_logging import print_panel +import wget + + +default_dotfiles = ("https://raw.githubusercontent.com/jessebot/dot_files/" + "main/.config/onboardme/") + def load_cfg(config_file: str) -> dict: """ load yaml config files for onboardme """ - # make sure the path is valid - if path.exists(config_file): - with open(config_file, 'r') as yaml_file: - return yaml.safe_load(yaml_file) - # return empty dict if there was no file - return {} + config_full_path = path.join(ONBOARDME_CONFIG_DIR, config_file) + + # defaults + if not path.exists(config_full_path): + Path(ONBOARDME_CONFIG_DIR).mkdir(exist_ok=True) + wget.download(default_dotfiles + config_file, config_full_path) + with open(config_full_path, 'r') as yaml_file: + return yaml.safe_load(yaml_file) -# defaults -DEFAULTS = load_cfg(f"{PWD}/config/onboardme_config.yaml") -USR_CONFIG_FILE = load_cfg(path.join(ONBOARDME_CONFIG_DIR, 'config.yaml')) + +USR_CONFIG_FILE = load_cfg("config.yml") def check_os_support(): @@ -51,7 +62,7 @@ def check_os_support(): "[cornflower_blue]Compatibility Check") -def process_steps(steps: list, firewall=False, browser=False): +def process_steps(steps: list, firewall=False, browser=False) -> list: """ process which steps to run for which OS, which steps the user passed in, and then make sure dependent steps are always run. @@ -62,23 +73,24 @@ def process_steps(steps: list, firewall=False, browser=False): """ if steps: steps_list = list(steps) - # setting up vim is useless if we don't have a .vimrc - if 'vim_setup' in steps_list and 'dot_files' not in steps_list: + # setting up neovim is useless if we don't have an init.vim or init.lua + if 'neovim_setup' in steps_list and 'dot_files' not in steps_list: steps_list.append('dot_files') - if browser: - steps_list.append('browser_setup') + 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 = DEFAULTS['steps'][OS[0]] + default_order = ['dot_files', 'packages', 'font_setup', 'neovim_setup'] + if OS[0] == 'Linux': + default_order.append('group_setup') + else: + default_order.append('sudo_setup') # Rearrange list by other list order Using list comprehension - result_steps = [ele for ele in default_order if ele in steps] - - return result_steps + return [ele for ele in default_order if ele in steps] def sort_pkgmngrs(package_managers_list: list) -> list: @@ -88,16 +100,11 @@ def sort_pkgmngrs(package_managers_list: list) -> list: Takes list of package manager str and reorders them be (if they exist): ['brew', 'pip3.11', 'apt', 'snap', 'flatpak'] - Returns reordered_list """ - reordered_list = [] - package_managers = ['brew', 'pip3.11', 'apt', 'snap', 'flatpak'] - - for mngr in package_managers: - if mngr in package_managers_list: - reordered_list.append(mngr) + pkg_mngr_default_order = ['brew', 'pip3.11', 'apt', 'snap', 'flatpak'] - return reordered_list + # Rearrange list by other list order Using list comprehension + return [ele for ele in pkg_mngr_default_order if ele in package_managers_list] def fill_in_defaults(defaults: dict, user_config: dict, @@ -120,10 +127,12 @@ def fill_in_defaults(defaults: dict, user_config: dict, return user_config -def process_configs(overwrite=False, repo="", git_branch="", pkg_mngrs=[], - pkg_groups=[], firewall=False, remote_host="", steps=[]): +def process_configs(overwrite: bool, repo: str, git_branch: str, + pkg_mngrs: list, pkg_groups: list, firewall: bool, + remote_host: str, steps: list, log_file: str, + log_level: str) -> dict: """ - process the config in ~/.config/onboardme/config.yaml if it exists, + process the config in ~/.config/onboardme/config.yml if it exists, then process the cli dict, and fill in defaults for anything not explicitly defined. Returns full final config as dict for use in script. """ @@ -132,9 +141,10 @@ def process_configs(overwrite=False, repo="", git_branch="", pkg_mngrs=[], if type(remote_host) is str: remote_host = [remote_host] + cli_dict = {'package': {'managers': {OS[0]: pkg_mngrs}, 'groups': pkg_groups}, - 'log': {'file': None, 'level': ""}, + 'log': {'file': log_file, 'level': log_level}, 'remote_hosts': remote_host, 'firewall': firewall, 'steps': {OS[0]: steps}, @@ -142,22 +152,18 @@ def process_configs(overwrite=False, repo="", git_branch="", pkg_mngrs=[], 'git_url': repo, 'git_branch': git_branch}} log.debug(f"cli_dict is:\n{cli_dict}\n") - if USR_CONFIG_FILE: - log.debug(f"🗂 ⚙️ user_config_file: \n{USR_CONFIG_FILE}\n") - - usr_cfgs = fill_in_defaults(DEFAULTS, USR_CONFIG_FILE) - log.debug(f"after usr config file filled in with defaults: {usr_cfgs}") - - final_defaults = fill_in_defaults(cli_dict, usr_cfgs, True) - else: - final_defaults = fill_in_defaults(DEFAULTS, cli_dict) + log.debug(f"🗂 ⚙️ user_config_file: \n{USR_CONFIG_FILE}\n") + final_defaults = fill_in_defaults(cli_dict, USR_CONFIG_FILE, True) log.debug(" final config after filling cli_dict in with defaults:\n" f"{final_defaults}\n") + # make sure the steps are in a valid order valid_steps = process_steps(final_defaults['steps'][OS[0]], final_defaults['remote_hosts']) final_defaults['steps'][OS[0]] = valid_steps + + # make sure the package managers are in a valid order sorted_mngrs = sort_pkgmngrs(final_defaults['package']['managers'][OS[0]]) final_defaults['package']['managers'][OS[0]] = sorted_mngrs diff --git a/onboardme/help_text.py b/onboardme/help_text.py index f433c6c1..d704186f 100755 --- a/onboardme/help_text.py +++ b/onboardme/help_text.py @@ -11,10 +11,10 @@ from rich.theme import Theme # custom local module -from .constants import OS, VERSION -from .env_config import DEFAULTS +from .constants import VERSION, STEPS, PKG_MNGRS +# this is for creating new help text svgs for the READMEs RECORD = False @@ -34,8 +34,8 @@ def options_help() -> dict: Help text for all the options/switches for main() """ dot_file_url = '[meta]https://github.com/jessebot/dot_files[/meta]' - step_choices = pretty_choices(DEFAULTS['steps'][OS[0]]) - pkg_mngr_choices = pretty_choices(DEFAULTS['package']['managers'][OS[0]]) + step_choices = pretty_choices(STEPS) + pkg_mngr_choices = pretty_choices(PKG_MNGRS) logging_choices = pretty_choices(['debug', 'info', 'warn', 'error']) pkg_group_choices = pretty_choices(['default', 'devops', 'gui', 'gaming']) diff --git a/onboardme/pkg_management.py b/onboardme/pkg_management.py index e315a7b2..4c5c99dd 100755 --- a/onboardme/pkg_management.py +++ b/onboardme/pkg_management.py @@ -3,26 +3,13 @@ from pathlib import Path import shutil -from .constants import OS, PWD, HOME_DIR, ONBOARDME_CONFIG_DIR +from .constants import OS, PWD, HOME_DIR from .console_logging import print_header from .console_logging import print_sub_header as sub_header from .env_config import load_cfg from .subproc import subproc -def load_packages_config() -> dict: - """ - Checks if user has local config file before procceding with default config - """ - # check to make sure the user didn't pass in their own packages.yaml - usr_pkg_config = path.join(ONBOARDME_CONFIG_DIR, 'packages.yaml') - if path.exists(usr_pkg_config): - return load_cfg(usr_pkg_config) - else: - default_config = path.join(PWD, 'config/packages.yaml') - return load_cfg(default_config) - - def rotate_github_ssh_keys() -> None: """ update SSH pub keys for github.com @@ -90,7 +77,7 @@ def run_pkg_mngrs(pkg_mngrs: list, pkg_groups=[]) -> None: rotate_github_ssh_keys() - pkg_mngrs_list_of_dicts = load_packages_config() + pkg_mngrs_list_of_dicts = load_cfg('packages.yml') # we iterate through pkg_mngrs which should already be sorted for pkg_mngr in pkg_mngrs: pkg_mngr_dict = pkg_mngrs_list_of_dicts[pkg_mngr] diff --git a/pyproject.toml b/pyproject.toml index 8b2121f3..933d51f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,9 @@ [tool.poetry] name = "onboardme" -version = "0.20.0" +version = "1.0.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 "] +authors = ["Jesse Hitch ", + "Max Roby "] license = "AGPL-3.0-or-later" readme = "README.md" documentation = "https://jessebot.github.io/onboardme/onboardme" @@ -17,9 +18,7 @@ classifiers = ["Development Status :: 3 - Alpha", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)"] packages = [{include = "onboardme"}] include = ["onboardme/scripts/update_apt_sources.sh", - "onboardme/scripts/get_apt_list.sh", - "onboardme/config/onboardme_config.yaml", - "onboardme/config/packages.yaml"] + "onboardme/scripts/get_apt_list.sh"] [tool.poetry.dependencies] python = "^3.11" From f77ccad6c3cf978d8bc16119bdf14d4d803c3857 Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 15:31:58 +0100 Subject: [PATCH 02/10] add contributing guidelines --- .pre-commit-config.yml | 8 ++++++++ CONTRIBUTING.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 .pre-commit-config.yml create mode 100644 CONTRIBUTING.md diff --git a/.pre-commit-config.yml b/.pre-commit-config.yml new file mode 100644 index 00000000..ec09eca7 --- /dev/null +++ b/.pre-commit-config.yml @@ -0,0 +1,8 @@ +repos: + - repo: https://github.com/python-poetry/poetry + rev: '1.2.2' + hooks: + # make sure the poetry config does not get committed in a broken state + - id: poetry-check + # make sure the lock file is up-to-date when committing changes + - id: poetry-lock diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..77bd870c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +# Contributing +Always happy to review pull requests and merge any fixes, or features, that would help onboardme. + +Here's some guidelines on how we code. + +## Getting Started + +
+ Prereqs + +- Install [poetry], which we use for dependency management and packaging in python. + +- If using vim/neovim, we recommend installing the [jedi language server]. onboardme will install it for you with the following: +```bash +# if you have existing dot files that you don't mind overwriting, use append -O +onboardme -s dot_files,neovim_setup --git_url https://github.com/jessebot/onboardme.git +``` + +
+ +Once you have the pre-reqs installed you can fork the [repo] and then clone your fork: + +```bash +# this should be YOUR fork, but for an example, we're using the actual repo +git clone git@github.com:jessebot/onboardme.git +cd onboardme +``` + +Use `poetry` and `pre-commit` to install onboardme depedencies: +```bash +poetry install +pre-commit install +``` + +Now you can proceed as normal for python development and when you're done, just commit the changes and the pre-commit hooks will run any linting and tests we have. When everything passes, open up a PR against the main repo and we'll get it reviewed :) + + +[repo]: https://github.com/jessebot/onboardme/ "onboardme repo" +[pre-commit]: https://pre-commit.com/#install "pre-commit, for running actions before commits" +[poetry]: https://python-poetry.org/docs/#installation "poetry, tool for dependency management and packaging in Python" +[jedi language server]: https://github.com/pappasam/jedi-language-server#editor-setup From 75db6d9e06238e3e8d6ad4c4e3d7824f70708c1a Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 16:31:28 +0100 Subject: [PATCH 03/10] remove the last vim setup stuff --- onboardme/__init__.py | 2 +- onboardme/ide_setup.py | 90 +++++++----------------------------------- 2 files changed, 16 insertions(+), 76 deletions(-) diff --git a/onboardme/__init__.py b/onboardme/__init__.py index 994aeccf..6c127308 100755 --- a/onboardme/__init__.py +++ b/onboardme/__init__.py @@ -143,7 +143,7 @@ def main(log_level: str = "WARN", pkg_groups = usr_pref['package']['groups'] run_pkg_mngrs(pkg_mngrs, pkg_groups) - elif step in ['vim_setup', 'neovim_setup', 'font_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}') func = getattr(ide_setup, step) diff --git a/onboardme/ide_setup.py b/onboardme/ide_setup.py index 7eb69d3a..203b275e 100644 --- a/onboardme/ide_setup.py +++ b/onboardme/ide_setup.py @@ -9,8 +9,6 @@ from git import Repo, RemoteProgress from os import path from pathlib import Path -import wget -from xdg_base_dirs import xdg_config_home # custom libs from .constants import HOME_DIR, OS @@ -18,79 +16,6 @@ from .subproc import subproc -def vim_setup() -> None: - """ - Installs vim-plug: does a wget on plug.vim - Installs vim plugins: calls vim with +Plug[Install,Upgrade,Upgrade] - Compiles youcompleteme if necessary - """ - print_header('[b]vim-plug[/b] and [green][i]Vim[/i][/green] plugins ' - 'installation [dim]and[/dim] upgrades') - - # this is to make sure we have the correct plugin directory - vim_dir = path.join(xdg_config_home(), 'vim') - if not path.exists(vim_dir): - vim_dir = path.join(HOME_DIR, '.vim') - xdg = False - else: - xdg = True - - # trick to not run youcompleteme init every single time - init_ycm = False - ycm_dir = path.join(vim_dir, 'plugged/YouCompleteMe') - if not path.exists(ycm_dir): - init_ycm = True - - # this is for installing vim-plug - autoload_dir = path.join(vim_dir, 'autoload') - if not path.exists(autoload_dir): - print_msg('[i]Creating dir structure & downloading [b]vim-plug[/b]...') - Path(autoload_dir).mkdir(parents=True, exist_ok=True) - url = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/' - wget.download(url + 'plug.vim', autoload_dir) - - # installs the vim plugins if not installed, updates vim-plug, and then - # updates all currently installed plugins - plug_cmds = "--not-a-term +PlugInstall +PlugUpgrade +PlugUpdate +qall!" - if xdg: - subproc([f'vim -u {vim_dir}/vimrc {plug_cmds}'], quiet=True) - else: - subproc([f'vim {plug_cmds}'], quiet=True) - - print_sub_header('Vim Plugins installed.') - - # if we need to install YouCompleteMe, run the compile script - if init_ycm: - if path.exists(ycm_dir): - print_sub_header("Compiling YouCompleteMe vim plugin.") - # This is for you complete me, which is a python completion module - subproc(["chmod +x install.py", "python3.11 install.py --all"], - cwd=ycm_dir) - - -def neovim_setup() -> None: - """ - neovim plugins have a setup mostly already handled in your plugins.lua: - https://github.com/wbthomason/packer.nvim#bootstrapping - This is the command that works via the cli: - nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' - - uses special command (with packer bootstrapped) to have packer setup your - your configuration (or simply run updates) and close once all operations - are completed - - This may switch to lazy soon - """ - print_header('[b]packer[/b] and [green][i]NeoVim[/i][/green] plugins ' - 'installation [dim]and[/dim] upgrades') - - # updates all currently installed plugins (still need to do :PackerCompile) - commands = ["nvim --headless +PackerSync"] - subproc(commands) - - print_sub_header('NeoVim Plugins installed.') - - def font_setup() -> None: """ On Linux: @@ -143,3 +68,18 @@ def update(self, op_code, cur_count, max_count=None, print_msg('[i][dim]The fonts should be installed, however, you have ' + 'to set your terminal font to the new font. I rebooted too.') + + +def neovim_setup() -> None: + """ + Installs all + Runs this command that works via the cli: + nvim --headless "+Lazy! sync" +qa + """ + print_header('[green][i]NeoVim[/i][/green] plugins installation ' + '[dim]and[/dim] upgrades via [green]lazy.nvim[/green]') + + # updates all currently plugins + subproc(['nvim --headless "+Lazy! sync" +qa']) + + print_sub_header('NeoVim Plugins installed.') From 3f42509a864745af137543f3ea1cf1187ea68c1c Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 16:33:13 +0100 Subject: [PATCH 04/10] removing more vim stuff --- README.md | 2 -- docs/onboardme/known_nonsense.md | 3 --- 2 files changed, 5 deletions(-) diff --git a/README.md b/README.md index 5a6c7858..ec9454a3 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,6 @@ onboardme keeps your neovim plugins installed and up to date with [packer] under If you haven't already made the switch from Vim to [NeoVim], you can try out NeoVim today with `onboardme` :D We used to support both neovim _and_ vim, but these days none of the primary developers of this repo use pure vim anymore, so we can't ensure it's up to standards. All of your knowledge from vim is still helpful in neovim though, and we highly recommend switching as neovim has a lot more features and a very active plugin community :) NeoVim maintains a guide on how to switch from vim [here](https://neovim.io/doc/user/nvim.html#nvim-from-vim). - We will stop official support for configuring vim, outside of installing the package across Debian/MacOS, in v1.0.0. This just means we won't be running anything to configure your vim plugins anymore, but you can still always add it to a package manager in [`packages.yml`](#configuration). -
### Easy `yaml` config files diff --git a/docs/onboardme/known_nonsense.md b/docs/onboardme/known_nonsense.md index 55f822e3..ea012db7 100644 --- a/docs/onboardme/known_nonsense.md +++ b/docs/onboardme/known_nonsense.md @@ -7,8 +7,5 @@ permalink: /onboardme/known_nonsense # Problems we're aware of that are caused externally -## vim -- [:python3 command broken in vim after python3.10.6_2 -> 3.10.7 upgrade](https://github.com/orgs/Homebrew/discussions/3734) - ## misc - [perl: warning: Setting locale failed](https://github.com/jessebot/onboardme/issues/87) From f3e69133c730fa94e4edcbeb549f8fe1392b2eaa Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 17:25:21 +0100 Subject: [PATCH 05/10] sourcing user config as default config; fixing pre-commit --- .gitignore | 4 --- ...mmit-config.yml => .pre-commit-config.yaml | 2 +- onboardme/__init__.py | 24 +++++++------- onboardme/constants.py | 27 +++++++++++++++- onboardme/env_config.py | 31 +------------------ 5 files changed, 40 insertions(+), 48 deletions(-) rename .pre-commit-config.yml => .pre-commit-config.yaml (90%) diff --git a/.gitignore b/.gitignore index 328d5dc9..09e08a1c 100644 --- a/.gitignore +++ b/.gitignore @@ -54,10 +54,6 @@ coverage.xml # any locally generated log stuff: *.log -# Flask stuff: -instance/ -.webassets-cache - # PyBuilder target/ diff --git a/.pre-commit-config.yml b/.pre-commit-config.yaml similarity index 90% rename from .pre-commit-config.yml rename to .pre-commit-config.yaml index ec09eca7..c9f81ebb 100644 --- a/.pre-commit-config.yml +++ b/.pre-commit-config.yaml @@ -5,4 +5,4 @@ repos: # make sure the poetry config does not get committed in a broken state - id: poetry-check # make sure the lock file is up-to-date when committing changes - - id: poetry-lock + # - id: poetry-lock diff --git a/onboardme/__init__.py b/onboardme/__init__.py index 6c127308..4cb83001 100755 --- a/onboardme/__init__.py +++ b/onboardme/__init__.py @@ -91,17 +91,17 @@ def setup_logger(level="", log_file=""): @option('--remote_host', '-r', metavar="IP_ADDR", multiple=True, help=HELP['remote_host']) @option('--version', is_flag=True, help=HELP['version']) -def main(log_level: str = "WARN", - log_file: str = "", - steps: str = STEPS.join(','), - git_url: str = "https://github.com/jessebot/dot_files.git", - git_branch: str = "main", - overwrite: bool = False, - pkg_managers: str = PKG_MNGRS.join(','), - pkg_groups: str = "default", - firewall: bool = False, - remote_host: str = "", - version: bool = False): +def main(log_level: str = USR_CONFIG_FILE['log']['level'], + log_file: str = USR_CONFIG_FILE['log']['file'], + steps: str = USR_CONFIG_FILE['steps'][OS[0]], + git_url: str = USR_CONFIG_FILE['dot_files']['git_url'], + git_branch: str = USR_CONFIG_FILE['dot_files']['git_branch'], + overwrite: bool = USR_CONFIG_FILE['dot_files']['overwrite'], + pkg_managers: str = USR_CONFIG_FILE['package']['managers'][OS[0]], + pkg_groups: str = USR_CONFIG_FILE['package']['groups'], + firewall: bool = USR_CONFIG_FILE['firewall'], + remote_host=USR_CONFIG_FILE['remote_hosts'], + version=False) -> bool: """ If present, config: XDG_CONFIG_HOME/onboardme/[packages.yml, config.yml] If run with no options on Linux, it will install brew, pip3.11, apt, @@ -157,7 +157,7 @@ def main(log_level: str = "WARN", configure_firewall(remote_host) print_manual_steps() - return + return True if __name__ == '__main__': diff --git a/onboardme/constants.py b/onboardme/constants.py index ef1574c0..382e9159 100644 --- a/onboardme/constants.py +++ b/onboardme/constants.py @@ -8,6 +8,9 @@ from importlib.metadata import version as get_version from xdg_base_dirs import xdg_config_home from os import getenv, path, uname +from pathlib import Path +import wget +import yaml # version of onboardme @@ -15,7 +18,6 @@ # pathing XDG_CONFIG_DIR = xdg_config_home() -ONBOARDME_CONFIG_DIR = path.join(xdg_config_home(), 'onboardme') PWD = path.dirname(__file__) HOME_DIR = getenv("HOME") @@ -33,3 +35,26 @@ PKG_MNGRS = ['brew','pip3.11'] if OS[0] == 'Linux': PKG_MNGRS.extend(['apt','snap','flatpak']) + + +default_dotfiles = ("https://raw.githubusercontent.com/jessebot/dot_files/" + "main/.config/onboardme/") + + +def load_cfg(config_file='config.yml') -> dict: + """ + load yaml config files for onboardme + """ + config_dir = path.join(xdg_config_home(), 'onboardme') + config_full_path = path.join(config_dir, config_file) + + # defaults + if not path.exists(config_full_path): + Path(config_dir).mkdir(exist_ok=True) + wget.download(default_dotfiles + config_file, config_full_path) + + with open(config_full_path, 'r') as yaml_file: + return yaml.safe_load(yaml_file) + + +USR_CONFIG_FILE = load_cfg() diff --git a/onboardme/env_config.py b/onboardme/env_config.py index 211cf951..079734fe 100755 --- a/onboardme/env_config.py +++ b/onboardme/env_config.py @@ -4,42 +4,13 @@ import logging as log -# for system data, environment data, and checking/joining paths -from os import path -from pathlib import Path - # rich helps pretty print everything from rich.prompt import Confirm -import yaml # custom libs -from .constants import OS, ONBOARDME_CONFIG_DIR +from .constants import OS, USR_CONFIG_FILE from .console_logging import print_panel -import wget - - -default_dotfiles = ("https://raw.githubusercontent.com/jessebot/dot_files/" - "main/.config/onboardme/") - - -def load_cfg(config_file: str) -> dict: - """ - load yaml config files for onboardme - """ - config_full_path = path.join(ONBOARDME_CONFIG_DIR, config_file) - - # defaults - if not path.exists(config_full_path): - Path(ONBOARDME_CONFIG_DIR).mkdir(exist_ok=True) - wget.download(default_dotfiles + config_file, config_full_path) - - with open(config_full_path, 'r') as yaml_file: - return yaml.safe_load(yaml_file) - - -USR_CONFIG_FILE = load_cfg("config.yml") - def check_os_support(): """ From 625a95a8dbeacb92014724f11a8acb7491cc0cc9 Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 18:41:09 +0100 Subject: [PATCH 06/10] fix default values --- onboardme/__init__.py | 61 ++++++++++++++++++++++--------------- onboardme/env_config.py | 8 +++++ onboardme/pkg_management.py | 3 +- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/onboardme/__init__.py b/onboardme/__init__.py index 4cb83001..fdb35b7b 100755 --- a/onboardme/__init__.py +++ b/onboardme/__init__.py @@ -12,8 +12,8 @@ import logging from rich.logging import RichHandler from .help_text import RichCommand, options_help -from .constants import VERSION, OS, STEPS, PKG_MNGRS -from .env_config import check_os_support, process_configs, USR_CONFIG_FILE +from .constants import VERSION, OS, STEPS, PKG_MNGRS, USR_CONFIG_FILE +from .env_config import check_os_support, process_configs from .console_logging import print_manual_steps from .dot_files import setup_dot_files from .pkg_management import run_pkg_mngrs @@ -75,33 +75,40 @@ def setup_logger(level="", log_file=""): # each of these is an option in the cli and variable we use later on @command(cls=RichCommand) @option('--log_level', '-l', metavar='LOGLEVEL', help=HELP['log_level'], - type=Choice(['debug', 'info', 'warn', 'error'])) -@option('--log_file', '-o', metavar='LOGFILE', help=HELP['log_file']) + type=Choice(['debug', 'info', 'warn', 'error']), + default=USR_CONFIG_FILE['log']['level']) +@option('--log_file', '-o', metavar='LOGFILE', help=HELP['log_file'], + default=USR_CONFIG_FILE['log']['file']) @option('--steps', '-s', metavar='STEP', multiple=True, type=Choice(STEPS), - help=HELP['steps']) -@option('--git_url', '-u', metavar='URL', help=HELP['git_url']) -@option('--git_branch', '-b', metavar='BRANCH', help=HELP['git_branch']) -@option('--overwrite', '-O', is_flag=True, help=HELP['overwrite']) + help=HELP['steps'], default=USR_CONFIG_FILE['steps'][OS[0]]) +@option('--git_url', '-u', metavar='URL', help=HELP['git_url'], + default=USR_CONFIG_FILE['dot_files']['git_url']) +@option('--git_branch', '-b', metavar='BRANCH', help=HELP['git_branch'], + default=USR_CONFIG_FILE['dot_files']['git_branch']) +@option('--overwrite', '-O', is_flag=True, help=HELP['overwrite'], + default=USR_CONFIG_FILE['dot_files']['overwrite']) @option('--pkg_managers', '-p', metavar='PKG_MANAGER', multiple=True, - type=Choice(PKG_MNGRS), help=HELP['pkg_managers']) + type=Choice(PKG_MNGRS), help=HELP['pkg_managers'], + default=USR_CONFIG_FILE['package']['managers'][OS[0]]) @option('--pkg_groups', '-g', metavar='PKG_GROUP', multiple=True, type=Choice(['default', 'gaming', 'gui', 'devops']), - help=HELP['pkg_groups']) -@option('--firewall', '-f', is_flag=True, help=HELP['firewall']) + help=HELP['pkg_groups'], default=USR_CONFIG_FILE['package']['groups']) +@option('--firewall', '-f', is_flag=True, help=HELP['firewall'], + default=USR_CONFIG_FILE['firewall']) @option('--remote_host', '-r', metavar="IP_ADDR", multiple=True, - help=HELP['remote_host']) -@option('--version', is_flag=True, help=HELP['version']) -def main(log_level: str = USR_CONFIG_FILE['log']['level'], - log_file: str = USR_CONFIG_FILE['log']['file'], - steps: str = USR_CONFIG_FILE['steps'][OS[0]], - git_url: str = USR_CONFIG_FILE['dot_files']['git_url'], - git_branch: str = USR_CONFIG_FILE['dot_files']['git_branch'], - overwrite: bool = USR_CONFIG_FILE['dot_files']['overwrite'], - pkg_managers: str = USR_CONFIG_FILE['package']['managers'][OS[0]], - pkg_groups: str = USR_CONFIG_FILE['package']['groups'], - firewall: bool = USR_CONFIG_FILE['firewall'], - remote_host=USR_CONFIG_FILE['remote_hosts'], - version=False) -> bool: + help=HELP['remote_host'], default=USR_CONFIG_FILE['remote_hosts']) +@option('--version', is_flag=True, help=HELP['version'], default=False) +def main(log_level, + log_file, + steps, + git_url, + git_branch, + overwrite, + pkg_managers, + pkg_groups, + firewall, + remote_host, + version) -> bool: """ If present, config: XDG_CONFIG_HOME/onboardme/[packages.yml, config.yml] If run with no options on Linux, it will install brew, pip3.11, apt, @@ -121,8 +128,12 @@ def main(log_level: str = USR_CONFIG_FILE['log']['level'], log = setup_logger(log_level, log_file) # then process any local user config files, cli opts, and defaults + log.debug(USR_CONFIG_FILE['steps'][OS[0]]) + log.debug(steps) + usr_pref = process_configs(overwrite, git_url, git_branch, pkg_managers, - pkg_groups, firewall, remote_host, steps) + pkg_groups, firewall, remote_host, steps, + log_file, log_level) if log: log.debug(f"User passed in the following preferences:\n{usr_pref}\n") diff --git a/onboardme/env_config.py b/onboardme/env_config.py index 079734fe..b6c88f45 100755 --- a/onboardme/env_config.py +++ b/onboardme/env_config.py @@ -123,6 +123,14 @@ def process_configs(overwrite: bool, repo: str, git_branch: str, 'git_url': repo, 'git_branch': git_branch}} log.debug(f"cli_dict is:\n{cli_dict}\n") + + if OS[0] == 'Darwin': + USR_CONFIG_FILE['package']['managers'].pop('Linux') + USR_CONFIG_FILE['steps'].pop('Linux') + else: + USR_CONFIG_FILE['package']['managers'].pop('Darwin') + USR_CONFIG_FILE['steps'].pop('Darwin') + log.debug(f"🗂 ⚙️ user_config_file: \n{USR_CONFIG_FILE}\n") final_defaults = fill_in_defaults(cli_dict, USR_CONFIG_FILE, True) diff --git a/onboardme/pkg_management.py b/onboardme/pkg_management.py index 4c5c99dd..3f143261 100755 --- a/onboardme/pkg_management.py +++ b/onboardme/pkg_management.py @@ -3,10 +3,9 @@ from pathlib import Path import shutil -from .constants import OS, PWD, HOME_DIR +from .constants import OS, PWD, HOME_DIR, load_cfg from .console_logging import print_header from .console_logging import print_sub_header as sub_header -from .env_config import load_cfg from .subproc import subproc From 31837515e227a110bdd9bbda2e7d67dbb89857db Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 18:45:34 +0100 Subject: [PATCH 07/10] cleaning up some more debug lines --- onboardme/__init__.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/onboardme/__init__.py b/onboardme/__init__.py index fdb35b7b..7af6d083 100755 --- a/onboardme/__init__.py +++ b/onboardme/__init__.py @@ -98,22 +98,17 @@ def setup_logger(level="", log_file=""): @option('--remote_host', '-r', metavar="IP_ADDR", multiple=True, help=HELP['remote_host'], default=USR_CONFIG_FILE['remote_hosts']) @option('--version', is_flag=True, help=HELP['version'], default=False) -def main(log_level, - log_file, +def main(log_level, log_file, steps, - git_url, - git_branch, - overwrite, - pkg_managers, - pkg_groups, - firewall, - remote_host, + git_url, git_branch, overwrite, + pkg_managers, pkg_groups, + firewall, remote_host, version) -> bool: """ - If present, config: XDG_CONFIG_HOME/onboardme/[packages.yml, config.yml] If run with no options on Linux, it will install brew, pip3.11, apt, flatpak, and snap packages. On mac, it only installs brew/pip3.11 packages. - config loading tries to load: cli options and then .config/onboardme/* + config loading tries to load: cli options and then defaults back to: + $XDG_CONFIG_HOME/onboardme/config.yml """ # only return the version if --version was passed in @@ -127,10 +122,7 @@ def main(log_level, # setup logging immediately log = setup_logger(log_level, log_file) - # then process any local user config files, cli opts, and defaults - log.debug(USR_CONFIG_FILE['steps'][OS[0]]) - log.debug(steps) - + # makes sure we only overwrite config file prefs if cli opts are passed in usr_pref = process_configs(overwrite, git_url, git_branch, pkg_managers, pkg_groups, firewall, remote_host, steps, log_file, log_level) From 127c3aae9e9f4fb5e72a9a6b2c6d7896283faa9f Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 21:06:24 +0100 Subject: [PATCH 08/10] move docker images into docker folder --- Dockerfile.brew => docker/Dockerfile.brew | 0 Dockerfile.setup => docker/Dockerfile.setup | 1 - 2 files changed, 1 deletion(-) rename Dockerfile.brew => docker/Dockerfile.brew (100%) rename Dockerfile.setup => docker/Dockerfile.setup (97%) diff --git a/Dockerfile.brew b/docker/Dockerfile.brew similarity index 100% rename from Dockerfile.brew rename to docker/Dockerfile.brew diff --git a/Dockerfile.setup b/docker/Dockerfile.setup similarity index 97% rename from Dockerfile.setup rename to docker/Dockerfile.setup index 99659a4b..b7dbcaec 100644 --- a/Dockerfile.setup +++ b/docker/Dockerfile.setup @@ -22,6 +22,5 @@ USER friend # Run setup.sh RUN wget https://raw.githubusercontent.com/jessebot/onboardme/main/setup.sh && \ - chmod +x setup.sh && \ chmod 777 setup.sh && \ yes| /bin/bash setup.sh From f5ca8b7d7913d58366413ab6865677894185e61c Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 21:14:00 +0100 Subject: [PATCH 09/10] remove packer references and replace with lazy --- README.md | 7 +++---- docs/ide/neovim/neovim.md | 4 +--- docs/onboardme/onboardme.md | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ec9454a3..e44dc688 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,7 @@ We install and upgrade libraries and apps using common package managers. ### NeoVim Plugin Installtion and Updates -onboardme keeps your neovim plugins installed and up to date with [packer] under the hood. -(Lazy support rolling out soon) +onboardme keeps your neovim plugins installed and up to date with [lazy.nvim] under the hood.
Why no vim though? @@ -163,7 +162,7 @@ steps: - packages # adds nerdfonts - font_setup - # runs :PackerSync + # runs :Lazy sync to install all your plugins - neovim_setup # sets up touchID for sudo - sudo_setup @@ -290,4 +289,4 @@ Get started with testing kubernetes locally, even on metal with [smol k8s lab](h [dot files]: https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#Unix_and_Unix-like_environments "wiki entry for dot file explanation" [XDG Base Directory Spec]: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html [NeoVim]: https://neovim.io/ "neovim, vim improved" -[packer]: https://github.com/wbthomason/packer.nvim +[lazy.nvim]: https://github.com/folke/lazy.nvim "lazy.nvim, a plugin manager for neovim" diff --git a/docs/ide/neovim/neovim.md b/docs/ide/neovim/neovim.md index 225911f1..28e90c3b 100644 --- a/docs/ide/neovim/neovim.md +++ b/docs/ide/neovim/neovim.md @@ -53,9 +53,7 @@ After that, launch neovim with `nvim` and then do your normal plugin manager flo ## Plugins -Most plugins will work out of the box, but you'll probably have issues with -Python plugins. You can learn more about those and other things to do with vim-plug -and packer [here](https://jessebot.github.io/onboardme/neovim/plugins). +Most plugins will work out of the box, but you'll probably have issues with Python plugins. You can learn more about those and other things to do with vim-plug, lazy, and packer [here](https://jessebot.github.io/onboardme/neovim/plugins). ## Known issues between vim and neovim diff --git a/docs/onboardme/onboardme.md b/docs/onboardme/onboardme.md index 67fb0219..6a9bca51 100644 --- a/docs/onboardme/onboardme.md +++ b/docs/onboardme/onboardme.md @@ -78,7 +78,7 @@ Here's the steps we take depending on what OS we run on. Each step can also be c | Git fetch dot files | n/a: fetched from a configured git repo | Debian, macOS | | Installs apps using package managers | `./onboardme/config/packages.yaml` | Debian, macOS | | Installs fonts | n/a | Debian, macOS | -| Installs packer.nvm + neovim plugins | plugins fetched from configured git repo | Debian, macOS | +| Installs lazy.nvim + neovim plugins | plugins fetched from configured git repo | Debian, macOS | | Adds user to the docker group | n/a | Debian | | sudo using touchID | n/a | macOS | @@ -151,4 +151,4 @@ It works great in combination with onboardme :) [w3m]: https://w3m.sourceforge.net/ "w3m home page" [WireGuard]: https://www.wireguard.com/ "wireguard home page" [XDG Base Directory Spec]: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html -[packer]: https://github.com/wbthomason/packer.nvim +[lazy.nvim]: https://github.com/folke/lazy.nvim "lazy.nvim, a plugin manager for neovim" From ff3cb69a15b13d659076511e1f85a4a7ba8104d8 Mon Sep 17 00:00:00 2001 From: Jesse Hitch Date: Sat, 18 Mar 2023 21:29:30 +0100 Subject: [PATCH 10/10] add default packages link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e44dc688..79d6ad8a 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,7 @@ Get started with testing kubernetes locally, even on metal with [smol k8s lab](h [default dot files]: https://github.com/jessebot/dot_files "default dot files for onboardme" [help text]: https://raw.githubusercontent.com/jessebot/onboardme/main/docs/onboardme/screenshots/help_text.svg "an svg of the command: onboardme --help" [Getting Started Docs]: https://jessebot.github.io/onboardme/onboardme/getting-started "getting started documentation" +[default packages]: https://github.com/jessebot/dot_files/blob/main/.config/onboardme/packages.yml "default installed packages for onboardme" [dot files]: https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#Unix_and_Unix-like_environments "wiki entry for dot file explanation"