Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active April 24, 2024 14:54
Show Gist options
  • Save AfroThundr3007730/0e2c2bd91adff0afe07902da30dbc023 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/0e2c2bd91adff0afe07902da30dbc023 to your computer and use it in GitHub Desktop.

General scripts TODO list

  • dce-dload:
    • Move final check from download_channel to sort_media
    • Consider moving jq redirects to new line
  • dod_certs:
    • Future proof bundle URL handling and PEM/DER shenanigans
  • entrypoint:
    • Convert to using say utility, convert header metadata
  • getcert:
    • Formatting, shellcheck, best practices
  • mc-generate-map:
    • Maybe move initial example to extended help text?
    • Fix curl brace locations in validate_args
    • Validate TODO and maybe inline
  • sysprep:
    • Fixup command paths, retest on modern releases
  • syncrepo and AfroBot:
    • Review issues and todos, cleanup projects
  • (everything):
    • Adjust say to stripped down version unless needed
    • Consider adjusting header metadata to an object and namespace it
  • HelperFunctions(permutate):
    • Get-StringPermutations: Validate TODO and add to gist
    • Hide-ConsoleWindow: Clean up and integrate into module
@AfroThundr3007730
Copy link
Author

Strict mode notes

#!/bin/bash

# Strict mode
set -euo pipefail

# Extended debugging
shopt -s extdebug
# may also need for subshells:
set -o functrace
# Print commands
set -x

@AfroThundr3007730
Copy link
Author

AfroThundr3007730 commented Mar 15, 2024

  • Get the other integrations setup. Some of them still need a CI action (Codeclimate and Codecov/Codacy).

  • Fix all doc releated lint issues reported in Codeclimate.

  • Fix the source related lint issues in PR #15 instead.

  • Investigate extending editorconfig rules, and maybe integration-specific config files in the repo.

  • Get gitlens diff tool config working, see here.

  • Look at using remarklint in CI directly for fixes and to also support remark-gfm.

  • Investigate using cvdupdate to replace clamavmirror.

@AfroThundr3007730
Copy link
Author

AfroThundr3007730 commented Mar 25, 2024

  • For the utils.common.sh library, add notes on GLOBAL (external) vs global (internal) variable usage.

  • Also add note in help documentation on multiple Variables sections.

  • Add top matter notes about usage and validation remaining the responsibility of the script author.

  • Sanitize all function variable usage. They all get declare [type] or local [type]. No naked declarations.

  • Update function names in help banners after some functions were renamed (e.g. copy_if_different):

    -# Dependencies: utils.files_match
    +# Dependencies: utils.check_files_match
  • In set_global_array_variable:

    -    for item in "${!var_tmp[@]}"; do
    -        declare -ag "${var_name}[$item]=${var_tmp[$item]}"
    -    done
    -    declare -agrx "$var_name"
    +    declare -n var_dst=$var_name
    +    declare -agrx "var_dst=("${var_tmp[@]}")"

    and test it (check quoting)

  • In say_heavy (heading):

    -#     -s  Initialize the function state. User may optionally specify a log file,
    -#         verbose log file, and `tee` command as positional parameters (in that
    -#         order), or omit them to disable them.
    +#     -s  Initialize the function state. User may optionally specify a log file,
    +#         verbose log file, and `tee` command arguments as positional parameters
    +#         (in that that order), or omit them to disable them.

    also this:

    -#   controlled by environment variable).
    +#   controlled via environment variable).

    and this:

    -# - utils.say_heavy warn 'Can't find the file: %s' "$my_file"
    +# - utils.say_heavy --warn 'Can't find the file: %s' "$my_file"
  • In timer:

    -    declare -gi timer_bookmark
    -    timer_bookmark=${timer_bookmark:-0}
    +    declare -gi timer_bookmark=${timer_bookmark:-0}

    Maybe needed to enforce mutually exclusive options:

    -    [[ $1 == -g ]] &&
    -        return $timer_bookmark && shift
    -    [[ $1 == -n ]] &&
    -        ((timer_bookmark++)) && shift
    -    [[ $1 == -p ]] &&
    -        ((timer_bookmark--)) && shift
    -    [[ $1 == -c ]] &&
    -        index=$timer_bookmark && shift
    +    if [[ $1 == -g ]]; then
    +        return $timer_bookmark && shift
    +    elif [[ $1 == -n ]]; then
    +        ((timer_bookmark++)) && shift
    +    elif [[ $1 == -p ]]; then
    +        ((timer_bookmark--)) && shift
    +    elif [[ $1 == -c ]]; then
    +        index=$timer_bookmark && shift
    +    fi

    Or let the user pick up the pieces if more than one is specified 🤷

  • In the help headers, maybe prepend the function name? This is more relevant for the longer ones...

  • The headers also need a delimiter to visually separate them from the code.

  • Research if the final return 0 is necessary/desirable in a library containing only functions.

@AfroThundr3007730
Copy link
Author

AfroThundr3007730 commented Mar 26, 2024

  • Update xdg_dirs.sh with fixes from .devcontainers repo, and make the initial declarations inherit existing values.

  • Then combine the versions from the gist, repo, and my code repo and put them in one spot.

  • In utils.common.sh, rename utils.timer -> utils.timer_heavy, add utils.timer_light and utils.timer (wrapper) functions.

  • Adjust functions that call themselves to do so with dynamic names (${FUNCNAME[0]}).

  • Investigate using caller with set -o functrace and update utils.call_trace accordingly.

  • Investigate bash debug and bashdb, also maybe conditional set -x on self.

  • Functions utils.ensure_(file|dir)_exists need creating. Supports the -f flag to overwrite.

  • Edit utils.add_if_missing to create the file path if it doesn't exist. Need utils.ensure_file_exists for this.

  • New function utils.set_if_existing to adjust existing config value (uncommenting if necessary).
    (see: utils.(get|set)_config_option)

  • Investingate writing a generic config/global handler that stores name, description, and defaults.

    • Would handle config load/store and variable inheritance/precedence.
    • Would handle creating default/example configs, with comments.
    • Builds on the other primitives in the library.
  • Check that utils.set_global_array_variable preserves sparse arrays (use ${!arr[@]}).

  • After the above changes, refactor syncrepo to pull in utils.common.sh as a module.

  • All scripts: fixup grep usage (-s instead of &>/dev/null, disarm arguments with --, use -F or escape strings).

  • All scripts (especially helper functions): use -- wherever possible to disarm arguments.

  • Fix this typo.

  • Upload my Rocky STIG notes.

  • Adjust syncrepo config order (needs utils.ensure_file_exists).

  • Adjust utils.call to either depend on utils.say_full or gate with DEBUG check.

  • Adjust utils.say_full (also in syncrepo) to not include control chars in non terminal output.
    Maybe even lock to interactive only (PS1 gate)?
    Or just gate it on being piped (test -t 1). More notes here.
    Or maybe new function safe_set_color

  • Syncrepo: Ensure all bools are null checked (other vars too).

  • Remove wget_rsync and replace with lftp, ensure debmirror works with rsync and http.

  • Auto update logic for syncrepo

  • Add prompt_user function to utils.common.sh

  • Adjust all external binary usage in syncrepo to be variable based.
    Probably integrate this with sanity_check existence checks.

@AfroThundr3007730
Copy link
Author

AfroThundr3007730 commented Apr 12, 2024

For the main site, fixup apaxy, error pages, normalize css. bootstrap, jquery, remove old submodules (doa/bftn), update the rest, fixup htaccess. Remove old files/directories not relevant.

Document all of the above somewhere, maybe make them all modules.

@AfroThundr3007730
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment