Skip to content

Commit

Permalink
setup-system: when updating, less prompts
Browse files Browse the repository at this point in the history
setup-{git,ssh}, ssh-helper, {git,ssh}.bash:
- fix 1password prompts not remembering, and move SSH_IDENTITY_AGENT from the extinct ssh.bash to the extant git.bash

setup-{git,go,node,python,ruby,rust}:
- implement an <action> and --configure combination that reduces prompts in an intuitive way

/close #186
  • Loading branch information
balupton committed Mar 28, 2024
1 parent 1b0cdf7 commit 89c6a52
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lint:
enabled:
- actionlint@1.6.27
- black@24.3.0
- checkov@3.2.47
- checkov@3.2.48
- eslint@8.57.0
- flake8@7.0.0
- git-diff-check@SYSTEM
Expand Down
19 changes: 15 additions & 4 deletions commands/setup-git
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function setup_git() (
Configures git, gpg, and ssh for your preferences and for the system capabilities.
USAGE:
setup-git [...options]
setup-git [...options] [install|update|setup|configure]
OPTIONS:
--configure
Configuration guide.
Whether to prompt, confirm, or save configuration changes.
EOF
if test "$#" -ne 0; then
echo-error "$@"
Expand All @@ -38,12 +38,20 @@ function setup_git() (
}

# process
local item option_configure='no'
local item option_configure=''
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
# install|update|setup|configure
'setup') ;;
'update')
option_configure='no'
;;
'install' | 'configure')
option_configure='yes'
;;
'--no-configure'* | '--configure'*)
option_configure="$(get-flag-value --affirmative --fallback="$option_configure" -- "$item")"
;;
Expand Down Expand Up @@ -98,6 +106,9 @@ function setup_git() (
local KRYPTON_GPG='' # deprecated, use GPG_SIGNING_KEY=krypton
local HUB_PROTOCOL='' # deprecated, replaced by GIT_PROTOCOL
load_dorothy_config 'git.bash'
if test "$GPG_SIGNING_KEY" = '1password'; then
GPG_SIGNING_KEY='op'
fi

# handle deprecations
if test "$KRYPTON_GPG" = 'yes'; then
Expand Down Expand Up @@ -439,7 +450,7 @@ function setup_git() (
# =====================================
# SSH

ssh-helper configure
ssh-helper setup --configure="$option_configure"

# =====================================
# Authenticate with CLIs
Expand Down
35 changes: 22 additions & 13 deletions commands/setup-go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ function setup_go() (

function help {
cat <<-EOF >/dev/stderr
Setup the Go ecosystem.
USAGE:
setup-go [--flags]
setup-go [...options] [install|update|setup|configure]
FLAGS:
OPTIONS:
--configure
Configuration guide.
--optional
Only setup if it is needed by packages.
Whether to prompt, confirm, or save configuration changes.
--linting
Install linting tools.
Expand All @@ -42,29 +41,39 @@ function setup_go() (
}

# process
local item option_configure='no' option_optional=''
local item option_configure=''
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--no-optional'* | '--optional'*)
option_optional="$(get-flag-value --affirmative --fallback="$option_optional" -- "$item")"
# install|update|setup|configure
'setup') ;;
'update')
option_configure='no'
;;
'--no-linting'* | '--linting'*)
GO_LINTING_INSTALL="$(get-flag-value --affirmative --fallback="$GO_LINTING_INSTALL" -- "$item")"
'install' | 'configure')
option_configure='yes'
;;
'--no-configure'* | '--configure'*)
option_configure="$(get-flag-value --affirmative --fallback="$option_configure" -- "$item")"
;;
'--no-linting'* | '--linting'*)
GO_LINTING_INSTALL="$(get-flag-value --affirmative --fallback="$GO_LINTING_INSTALL" -- "$item")"
;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done

# check
if test "$option_optional" = 'yes' -a "${#GO_INSTALL[@]}" -eq 0 && ! confirm --negative --ppid=$$ -- 'Setup Go?'; then
return 0
if test "${#GO_INSTALL[@]}" -eq 0 -a "$GO_LINTING_INSTALL" != 'yes'; then
if test "$option_configure" = 'no'; then
echo-style --dim='Setup of Go ecosystem skipped.'
return 0
elif ! confirm --negative --ppid=$$ -- 'Setup Go ecosystem?'; then
return 0
fi
fi

# =====================================
Expand Down
32 changes: 21 additions & 11 deletions commands/setup-node
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ function setup_node() (
# help
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Setup the Node.js ecosystem.
USAGE:
setup-node [--flags]
setup-node [...options] [install|update|setup|configure]
FLAGS:
OPTIONS:
--configure
Configuration guide.
--optional
Only setup if it is needed by packages.
Whether to prompt, confirm, or save configuration changes.
EOF
if test "$#" -ne 0; then
echo-error "$@"
Expand All @@ -57,14 +57,19 @@ function setup_node() (
}

# process
local item option_configure='no' option_optional=''
local item option_configure=''
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--no-optional'* | '--optional'*)
option_optional="$(get-flag-value --affirmative --fallback="$option_optional" -- "$item")"
# install|update|setup|configure
'setup') ;;
'update')
option_configure='no'
;;
'install' | 'configure')
option_configure='yes'
;;
'--no-configure'* | '--configure'*)
option_configure="$(get-flag-value --affirmative --fallback="$option_configure" -- "$item")"
Expand All @@ -75,8 +80,13 @@ function setup_node() (
done

# check
if test "$option_optional" = 'yes' -a "${#NPM_INSTALL[@]}" -eq 0 && ! confirm --negative --ppid=$$ -- 'Setup Node.js?'; then
return 0
if test "${#NPM_INSTALL[@]}" -eq 0; then
if test "$option_configure" = 'no'; then
echo-style --dim='Setup of Node.js ecosystem skipped.'
return 0
elif ! confirm --negative --ppid=$$ -- 'Setup Node.js ecosystem?'; then
return 0
fi
fi

# =====================================
Expand Down
45 changes: 30 additions & 15 deletions commands/setup-python
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function setup_python() (

function help {
cat <<-EOF >/dev/stderr
Setup the Python ecosystem.
USAGE:
setup-python [--flags]
setup-python [...options] [install|update|setup|configure]
FLAGS:
--optional
Only setup if it is needed by packages.
OPTIONS:
--configure
Whether to prompt, confirm, or save configuration changes.
EOF
if test "$#" -ne 0; then
echo-error "$@"
Expand All @@ -46,23 +48,36 @@ function setup_python() (
}

# process
local item option_optional=''
local item option_configure=''
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--no-optional'* | '--optional'*)
option_optional="$(get-flag-value --affirmative --fallback="$option_optional" -- "$item")"
# install|update|setup|configure
'setup') ;;
'update')
option_configure='no'
;;
'install' | 'configure')
option_configure='yes'
;;
'--no-configure'* | '--configure'*)
option_configure="$(get-flag-value --affirmative --fallback="$option_configure" -- "$item")"
;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done

# check
if test "$option_optional" = 'yes' -a -z "${PYTHON_INSTALL[*]}${PIP_INSTALL[*]}${PYTHON2_PIP_INSTALL[*]}${PYTHON3_PIP_INSTALL[*]}${PIPX_INSTALL[*]}" && ! confirm --negative --ppid=$$ -- 'Setup Python?'; then
return 0
if test -z "${PYTHON_INSTALL[*]}${PIP_INSTALL[*]}${PYTHON2_PIP_INSTALL[*]}${PYTHON3_PIP_INSTALL[*]}${PIPX_INSTALL[*]}"; then
if test "$option_configure" = 'no'; then
echo-style --dim='Setup of Python ecosystem skipped.'
return 0
elif ! confirm --negative --ppid=$$ -- 'Setup Python ecosystem?'; then
return 0
fi
fi

# =====================================
Expand Down Expand Up @@ -133,7 +148,7 @@ function setup_python() (
fi

# download pip
echo-segment --h3="download pip"
echo-segment --h3='download pip'
pip_installer="$(
fs-temp \
--directory='setup-python' \
Expand All @@ -147,14 +162,14 @@ function setup_python() (
-- down "$pip_installer_url" --filepath="$pip_installer"
chmod +x "$pip_installer"
echo-style --dim="installer: $pip_installer"
echo-segment --g3="download pip"
echo-segment --g3='download pip'

# install pip, depending on the situation, it may or may not have --break-system-packages
echo-segment --h3="install pip"
echo-segment --h3='install pip'
eval-helper --quiet \
-- "$bin" "$pip_installer" --user --break-system-packages || eval-helper --quiet \
-- "$bin" "$pip_installer" --user
echo-segment --g3="install pip"
echo-segment --g3='install pip'
source "$DOROTHY/sources/environment.sh"

# echo
Expand All @@ -177,14 +192,14 @@ function setup_python() (
# pipx
if test "$python_version" -eq 3; then
# install pipx
echo-segment --h3="install pipx"
echo-segment --h3='install pipx'
fs-rm --quiet --no-confirm -- "$HOME/.local/pipx" # fix: Not removing existing venv /Users/balupton/.local/pipx/venvs/youtube-dl because it was not created in this session
eval-helper --quiet \
-- "$bin" -m \
pip install --user --break-system-packages --upgrade --force-reinstall --no-warn-script-location \
pipx || :
source "$DOROTHY/sources/environment.sh"
echo-segment --g3="install pipx"
echo-segment --g3='install pipx'

# install pipx packages
echo-segment --h3="install ${#pipx_install[@]} pipx packages"
Expand Down
37 changes: 26 additions & 11 deletions commands/setup-ruby
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ function setup_ruby() (

function help {
cat <<-EOF >/dev/stderr
Setup the Ruby ecosystem.
USAGE:
setup-ruby [--flags]
setup-ruby [...options] [install|update|setup|configure]
FLAGS:
--optional
Only setup if it is needed by packages.
OPTIONS:
--configure
Whether to prompt, confirm, or save configuration changes.
EOF
if test "$#" -ne 0; then
echo-error "$@"
Expand All @@ -50,29 +52,42 @@ function setup_ruby() (
}

# process
local item option_optional=''
local item option_configure=''
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--no-optional'* | '--optional'*)
option_optional="$(get-flag-value --affirmative --fallback="$option_optional" -- "$item")"
# install|update|setup|configure
'setup') ;;
'update')
option_configure='no'
;;
'install' | 'configure')
option_configure='yes'
;;
'--no-configure'* | '--configure'*)
option_configure="$(get-flag-value --affirmative --fallback="$option_configure" -- "$item")"
;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done

# check
if test "$option_optional" = 'yes' -a "${#GEM_INSTALL[@]}" -eq 0 && ! confirm --negative --ppid=$$ -- 'Setup Ruby?'; then
return 0
if test "${#GEM_INSTALL[@]}" -eq 0; then
if test "$option_configure" = 'no'; then
echo-style --dim='Setup of Ruby ecosystem skipped.'
return 0
elif ! confirm --negative --ppid=$$ -- 'Setup Ruby ecosystem?'; then
return 0
fi
fi

# =====================================
# Start

echo-segment --h1="Setup Ruby"
echo-segment --h1='Setup Ruby'

# =====================================
# Install
Expand Down Expand Up @@ -148,7 +163,7 @@ function setup_ruby() (
# =====================================
# Finish

echo-segment --g1="Setup Ruby"
echo-segment --g1='Setup Ruby'
)

# fire if invoked standalone
Expand Down

0 comments on commit 89c6a52

Please sign in to comment.