From 759958b126419858db553355ff07e06c412aed80 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 28 Aug 2025 23:14:42 -0500 Subject: [PATCH] Consolidate some scripts; simplify unneeded logic; take OS as arg --- README.md | 21 ++++++++------------ box_setup | 43 ++++++++++++++++++++++++++++++++++++----- copy_configs | 8 +++----- install_programs | 21 ++++++-------------- make_config_dirs | 14 -------------- make_dirs | 23 ++++++++++++++++++++++ make_org_structure_dirs | 8 -------- set_script_env_vars | 28 --------------------------- 8 files changed, 78 insertions(+), 88 deletions(-) delete mode 100755 make_config_dirs create mode 100755 make_dirs delete mode 100755 make_org_structure_dirs delete mode 100644 set_script_env_vars diff --git a/README.md b/README.md index 9b78f55..22376f0 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ # repo containing configs and scripts to set up a box ### script run -- [prerequisites below are fulfilled] +- fulfill prerequisites below - git clone this repo -- from the repo's root directory, run `./box_setup` +- from the repo's root directory, run `./box_setup ` ### prerequisites - package manager is configured (i.e. source repos, mirrors, etc. configured) - zsh is installed (scripts are written for zsh) -- sudo access is configured for current user (2025-01-27, not needed on macos) -- export the env var `BOX_SETUP_OS` to indicate the operating system - - options defined in `set_script_env_vars` file +- sudo access is configured for current user (as of 2025-01-27, not needed on macos) - system-specific items below are fulfilled ##### prereqs, os specific, linux-placeholder @@ -31,18 +29,15 @@ ### todo items - add logic to the main run script to handle cloning of this repo -- add logic to the main run script to set `BOX_SETUP_OS` var, either input param or detect -- config for ghostty +- config for window manager for linux (first, decide which wm to use) +- config for terminal emulator (currently ghostty) - config for mpd, mpc, ncmpcpp - config for mpv - config for gimp, `src_files/.config/GIMP` (dir) - set things in gtkrc only? still need to nest that within a sub dir? - - or maybe just configure in gimp's gui, copy the whole resulting dir into - `src_files/.config/GIMP` (edit out and delete what i don't need) and call it a day -- decide on window manager for linux, then do config -- look into xquartz for macos (x/xorg emulation or something?) -- build in flags/logic for skipping certain installs/builds (and maybe configs?) on a - given system (i.e. don't install on a company box, on a server, etc.) + - or configure in gimp, copy resulting dir to `src_files/.config/GIMP`, call it a day +- maybe build in flags/logic for skipping certain installs/builds (and maybe configs?) + on a given system (i.e. don't install on a company box, on a server, etc.) - decide on and implement approach for languages and versioning - asdf, or language-specific version managers? - docker? or alternatives like podman? any license concerns? diff --git a/box_setup b/box_setup index 3620600..b6f7c55 100755 --- a/box_setup +++ b/box_setup @@ -1,9 +1,42 @@ #!/bin/zsh -source set_script_env_vars +[[ -z $1 ]] && + echo "OS must be passed as an arg (options: arch, artix, debian, macos)" && + echo "example: ./box_setup arch" && + exit 1 + +# set env vars for installs +local install_cmd='' +local update_pkg_manager_and_defs_cmd='' +local update_pkgs_cmd='' +case $1 in + (arch | artix) + install_cmd="sudo pacman -S" + update_pkg_manager_and_defs_cmd='' # don't; update system instead? + update_pkgs_cmd='sudo pacman -Syu' + ;; + (debian) + install_cmd="sudo apt install" + update_pkg_manager_and_defs_cmd='sudo apt update' + update_pkgs_cmd='sudo apt upgrade' + ;; + (macos) + install_cmd="brew install" + update_pkg_manager_and_defs_cmd='brew update' + update_pkgs_cmd='brew upgrade' + ;; +esac + +export BOX_SETUP_INSTALL_COMMAND="$install_cmd" +export BOX_SETUP_UPDATE_PKG_MANAGER_AND_DEFS_CMD="$update_pkg_manager_and_defs_cmd" +export BOX_SETUP_UPDATE_PKGS_CMD="$update_pkgs_cmd" + +# make dirs and copy configs/dotfiles source ./src_files/.config/zsh/.zshenv -./make_config_dirs +./make_dirs ./copy_configs -source $ZDOTDIR/.zshenv ; source $ZDOTDIR/.zshrc -./make_org_structure_dirs -./install_programs # TODO: do installs overwrite configs? if so, fix; worst case, re-copy + +# install programs +source $ZDOTDIR/.zshenv +source $ZDOTDIR/.zshrc +./install_programs diff --git a/copy_configs b/copy_configs index 8378f80..5b731de 100755 --- a/copy_configs +++ b/copy_configs @@ -1,7 +1,6 @@ #!/bin/zsh -execute() { log "execute $@" && "$@" } -log() { echo "$@" } +execute() { echo "executing: $@" && "$@" } copy_file() { local from=$1 @@ -30,14 +29,13 @@ copy_dir() { link_dir() { local src_dir=$1 local link_dir=$2 - log "deleting existing link/dir: $link_dir" [[ -h "$link_dir" ]] && rm $link_dir [[ -d "$link_dir" ]] && rm -rf $link_dir - log "sym-linking $link_dir -> $src_dir" + echo "sym-linking $link_dir -> $src_dir" ln -s $src_dir $link_dir } -log "---------------- dotfiles ----------------" +echo "---- copying dotfiles -------------------------" copy_file src_files/.config/zsh/.zshenv $HOME # duplicate, copy anyway, ensures $ZDOTDIR diff --git a/install_programs b/install_programs index 13c6029..60bff91 100755 --- a/install_programs +++ b/install_programs @@ -1,31 +1,22 @@ #!/bin/zsh local single_script_filter="" -local dry="0" - -execute() { - log "execute $@" - [[ $dry != "1" ]] && "$@" -} - -log() { - [[ $dry != "1" ]] && echo "$@" || echo "[DRY RUN]: $@" -} while [[ $# > 0 ]]; do - [[ $1 == "--dry" ]] && dry="1" || single_script_filter="$1" + single_script_filter="$1" # if using param, export BOX_SETUP_OS first if needed shift done -log "install_programs // single_script_filter: $single_script_filter" +echo "---- installing programs ----------------------" + local scripts=$(find ./installs_and_builds -maxdepth 1 -mindepth 1 -type f | sort) for script in ${=scripts}; do if [[ -x $script ]]; then if echo "$script" | grep -qv "$single_script_filter"; then - log "filter is $single_script_filter // ignoring: $script" - continue + continue # $single_script_filter set, ignore others fi - execute ./$script + echo "executing: $script" + ./$script fi done diff --git a/make_config_dirs b/make_config_dirs deleted file mode 100755 index 32641bd..0000000 --- a/make_config_dirs +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/zsh - -source ./src_files/.config/zsh/.zshenv # source these vars for use below - -[[ ! -d "$DIR_LOCAL" ]] && mkdir "$DIR_LOCAL" -[[ ! -d "$DIR_BIN" ]] && mkdir "$DIR_BIN" -[[ ! -d "$DIR_BUILD" ]] && mkdir "$DIR_BUILD" -[[ ! -d "$DIR_SCRIPTS" ]] && mkdir "$DIR_SCRIPTS" -[[ ! -d "$DIR_TMP" ]] && mkdir "$DIR_TMP" - -[[ ! -d "$XDG_CONFIG_HOME" ]] && mkdir "$XDG_CONFIG_HOME" -[[ ! -d "$XDG_CACHE_HOME" ]] && mkdir "$XDG_CACHE_HOME" -[[ ! -d "$XDG_DATA_HOME" ]] && mkdir "$XDG_DATA_HOME" -[[ ! -d "$XDG_STATE_HOME" ]] && mkdir "$XDG_STATE_HOME" diff --git a/make_dirs b/make_dirs new file mode 100755 index 0000000..e68b2de --- /dev/null +++ b/make_dirs @@ -0,0 +1,23 @@ +#!/bin/zsh + +source ./src_files/.config/zsh/.zshenv # ensure env vars set for use below + +# some standard/common dirs, some overlap/use in XDG dirs +[[ ! -d "$DIR_LOCAL" ]] && mkdir "$DIR_LOCAL" +[[ ! -d "$DIR_BIN" ]] && mkdir "$DIR_BIN" +[[ ! -d "$DIR_BUILD" ]] && mkdir "$DIR_BUILD" +[[ ! -d "$DIR_SCRIPTS" ]] && mkdir "$DIR_SCRIPTS" +[[ ! -d "$DIR_TMP" ]] && mkdir "$DIR_TMP" + +# dirs related to XDG Base Directory specification +[[ ! -d "$XDG_CONFIG_HOME" ]] && mkdir "$XDG_CONFIG_HOME" +[[ ! -d "$XDG_CACHE_HOME" ]] && mkdir "$XDG_CACHE_HOME" +[[ ! -d "$XDG_DATA_HOME" ]] && mkdir "$XDG_DATA_HOME" +[[ ! -d "$XDG_STATE_HOME" ]] && mkdir "$XDG_STATE_HOME" + +# dirs for how i'm organizing my system +[[ ! -d "$DIR_HOME_BOX" ]] && mkdir $DIR_HOME_BOX +[[ ! -d "$DIR_DEV" ]] && mkdir $DIR_DEV +[[ ! -d "$DIR_DEV/git" ]] && mkdir $DIR_DEV/git +[[ ! -d "$DIR_DEV/git/me" ]] && mkdir $DIR_DEV/git/me +[[ ! -d "$DIR_DEV/git/other" ]] && mkdir $DIR_DEV/git/other diff --git a/make_org_structure_dirs b/make_org_structure_dirs deleted file mode 100755 index 9cad170..0000000 --- a/make_org_structure_dirs +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/zsh - -[[ ! -d "$DIR_HOME_BOX" ]] && mkdir $DIR_HOME_BOX - -[[ ! -d "$DIR_DEV" ]] && mkdir $DIR_DEV -[[ ! -d "$DIR_DEV/git" ]] && mkdir $DIR_DEV/git -[[ ! -d "$DIR_DEV/git/me" ]] && mkdir $DIR_DEV/git/me -[[ ! -d "$DIR_DEV/git/other" ]] && mkdir $DIR_DEV/git/other diff --git a/set_script_env_vars b/set_script_env_vars deleted file mode 100644 index 2c889a3..0000000 --- a/set_script_env_vars +++ /dev/null @@ -1,28 +0,0 @@ -[[ -z $BOX_SETUP_OS ]] && - echo "BOX_SETUP_OS must be set; options: arch, artix, debian, macos" && - exit 1 - -local install_cmd='' -local update_pkg_manager_and_defs_cmd='' -local update_pkgs_cmd='' -case $BOX_SETUP_OS in - (arch | artix) - install_cmd="sudo pacman -S" - update_pkg_manager_and_defs_cmd='' # don't; update system instead? - update_pkgs_cmd='sudo pacman -Syu' - ;; - (debian) - install_cmd="sudo apt install" - update_pkg_manager_and_defs_cmd='sudo apt update' - update_pkgs_cmd='sudo apt upgrade' - ;; - (macos) - install_cmd="brew install" - update_pkg_manager_and_defs_cmd='brew update' - update_pkgs_cmd='brew upgrade' - ;; -esac - -export BOX_SETUP_INSTALL_COMMAND="$install_cmd" -export BOX_SETUP_UPDATE_PKG_MANAGER_AND_DEFS_CMD="$update_pkg_manager_and_defs_cmd" -export BOX_SETUP_UPDATE_PKGS_CMD="$update_pkgs_cmd"