diff --git a/readme.md b/readme.md index 8bb324b..559e788 100644 --- a/readme.md +++ b/readme.md @@ -213,11 +213,8 @@ Handle project workflows in a unified way: ### Shell -* banner - * constants for characters - * dynamic substeps * comment -* frame corners +* drawing characters constants * packages * configure * apk diff --git a/spcd/bootstrap.sh b/spcd/bootstrap.sh index db3dcb3..137ac96 100644 --- a/spcd/bootstrap.sh +++ b/spcd/bootstrap.sh @@ -5,13 +5,18 @@ # ╰──────────╯ [ -n "${SPCD_CMD_SUM}" ] || SPCD_CMD_SUM="sha512sum" + [ -n "${SPCD_DNS_1}" ] || SPCD_DNS_1="9.9.9.9" + [ -n "${SPCD_GIT_MAIN}" ] || SPCD_GIT_MAIN="spcd" [ -n "${SPCD_GIT_ROOT}" ] || SPCD_GIT_ROOT="rwx" + [ -n "${SPCD_GIT_SHUNIT}" ] || SPCD_GIT_SHUNIT="shunit2" + [ -n "${SPCD_REF_FEATURE}" ] || SPCD_REF_FEATURE="f" [ -n "${SPCD_REF_RELEASE}" ] || SPCD_REF_RELEASE="main" [ -n "${SPCD_REF_STAGING}" ] || SPCD_REF_STAGING="dev" + [ -n "${SPCD_URL_ALPINE}" ] || SPCD_URL_ALPINE="https://dl-cdn.alpinelinux.org" [ -n "${SPCD_URL_ARCH}" ] || @@ -31,56 +36,55 @@ [ -n "${SPCD_URL_UBUNTU}" ] || SPCD_URL_UBUNTU="https://ubuntu.mirrors.ovh.net" -#╶──────────────────────────────────────╴ +# ╭───────────╮ +# │ internals │ +# ╰───────────╯ -# ╭──────────╮ -# │ internal │ -# ╰──────────╯ - -spcd_fill() { - spcd_fill__index=${1} - while [ "${spcd_fill__index}" -gt 0 ]; do +_spcd_fill() { + _spcd_fill__index=${1} + while [ "${_spcd_fill__index}" -gt 0 ]; do printf "%s" "${2}" - spcd_fill__index=$((spcd_fill__index - 1)) + _spcd_fill__index=$((_spcd_fill__index - 1)) done + unset _spcd_fill__index } -# ╭──────────┬────────╮ -# │ internal │ banner │ -# ╰──────────┴────────╯ +# ╭───────────┬────────╮ +# │ internals │ banner │ +# ╰───────────┴────────╯ -SPCD_BANNER_DOWN_AND_HORIZONTAL="┬" -SPCD_BANNER_DOWN_AND_LEFT="╮" -SPCD_BANNER_DOWN_AND_RIGHT="╭" -SPCD_BANNER_HORIZONTAL="─" -SPCD_BANNER_UP_AND_HORIZONTAL="┴" -SPCD_BANNER_UP_AND_LEFT="╯" -SPCD_BANNER_UP_AND_RIGHT="╰" -SPCD_BANNER_VERTICAL="│" +_SPCD_BANNER_DOWN_AND_HORIZONTAL="┬" +_SPCD_BANNER_DOWN_AND_LEFT="╮" +_SPCD_BANNER_DOWN_AND_RIGHT="╭" +_SPCD_BANNER_HORIZONTAL="─" +_SPCD_BANNER_UP_AND_HORIZONTAL="┴" +_SPCD_BANNER_UP_AND_LEFT="╯" +_SPCD_BANNER_UP_AND_RIGHT="╰" +_SPCD_BANNER_VERTICAL="│" -spcd_banner_add() { +_spcd_banner_add() { if [ -n "${1}" ]; then spcd_ba__text=" ${1} " spcd_ba__length=${#spcd_ba__text} spcd_ba__filler="$( - spcd_fill "${spcd_ba__length}" "${SPCD_BANNER_HORIZONTAL}" + _spcd_fill "${spcd_ba__length}" "${_SPCD_BANNER_HORIZONTAL}" )" - if [ -n "${SPCD_BANNER_MIDDLE}" ]; then - spcd_banner_split + if [ -n "${__SPCD_BANNER_MIDDLE}" ]; then + _spcd_banner_split else - spcd_banner_open + _spcd_banner_open fi - spcd_banner_append \ + _spcd_banner_append \ "${spcd_ba__filler}" "${spcd_ba__text}" "${spcd_ba__filler}" fi } -spcd_banner_add_index() { +_spcd_banner_add_index() { unset spcd_bai__label unset spcd_bai__level while true; do spcd_bai__level=$((spcd_bai__level + 1)) - eval "spcd_bai__value=\"\${SPCD_STEP_${spcd_bai__level}_INDEX}\"" + eval "spcd_bai__value=\"\${__SPCD_STEP_${spcd_bai__level}_INDEX}\"" [ -n "${spcd_bai__value}" ] || break if [ -n "${spcd_bai__label}" ]; then spcd_bai__label="${spcd_bai__label}.${spcd_bai__value}" @@ -88,126 +92,125 @@ spcd_banner_add_index() { spcd_bai__label="${spcd_bai__value}" fi done - spcd_banner_add "${spcd_bai__label}" + _spcd_banner_add "${spcd_bai__label}" } -spcd_banner_append() { +_spcd_banner_append() { if [ -n "${3}" ]; then - SPCD_BANNER_TOP="${SPCD_BANNER_TOP}${1}" - SPCD_BANNER_MIDDLE="${SPCD_BANNER_MIDDLE}${2}" - SPCD_BANNER_BOTTOM="${SPCD_BANNER_BOTTOM}${3}" + __SPCD_BANNER_TOP="${__SPCD_BANNER_TOP}${1}" + __SPCD_BANNER_MIDDLE="${__SPCD_BANNER_MIDDLE}${2}" + __SPCD_BANNER_BOTTOM="${__SPCD_BANNER_BOTTOM}${3}" fi } -spcd_banner_close() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_LEFT}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_LEFT}" -} - -spcd_banner_echo() { +_spcd_banner_echo() { echo "\ -${SPCD_BANNER_TOP} -${SPCD_BANNER_MIDDLE} -${SPCD_BANNER_BOTTOM}" +${__SPCD_BANNER_TOP} +${__SPCD_BANNER_MIDDLE} +${__SPCD_BANNER_BOTTOM}" } -spcd_banner_open() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_RIGHT}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_RIGHT}" +_spcd_banner_open() { + _spcd_banner_append \ + "${_SPCD_BANNER_DOWN_AND_RIGHT}" \ + "${_SPCD_BANNER_VERTICAL}" \ + "${_SPCD_BANNER_UP_AND_RIGHT}" } -spcd_banner_render() { - spcd_banner_unset - spcd_banner_add_index - spcd_banner_add "S" +_spcd_banner_render() { + _spcd_banner_wipe + _spcd_banner_add "S" + _spcd_banner_add_index # unset spcd_br__level while true; do spcd_br__level=$((spcd_br__level + 1)) - eval "spcd_br__value=\"\${SPCD_STEP_${spcd_br__level}_LABEL}\"" + eval "spcd_br__value=\"\${__SPCD_STEP_${spcd_br__level}_LABEL}\"" [ -n "${spcd_br__value}" ] || break - spcd_banner_add "${spcd_br__value}" + _spcd_banner_add "${spcd_br__value}" done # - spcd_banner_close - spcd_banner_echo - spcd_banner_unset + _spcd_banner_shut + _spcd_banner_echo + _spcd_banner_wipe } -spcd_banner_split() { - spcd_banner_append \ - "${SPCD_BANNER_DOWN_AND_HORIZONTAL}" \ - "${SPCD_BANNER_VERTICAL}" \ - "${SPCD_BANNER_UP_AND_HORIZONTAL}" +_spcd_banner_shut() { + _spcd_banner_append \ + "${_SPCD_BANNER_DOWN_AND_LEFT}" \ + "${_SPCD_BANNER_VERTICAL}" \ + "${_SPCD_BANNER_UP_AND_LEFT}" } -spcd_banner_unset() { +_spcd_banner_split() { + _spcd_banner_append \ + "${_SPCD_BANNER_DOWN_AND_HORIZONTAL}" \ + "${_SPCD_BANNER_VERTICAL}" \ + "${_SPCD_BANNER_UP_AND_HORIZONTAL}" +} + +_spcd_banner_wipe() { unset \ - SPCD_BANNER_TOP \ - SPCD_BANNER_MIDDLE \ - SPCD_BANNER_BOTTOM + __SPCD_BANNER_TOP \ + __SPCD_BANNER_MIDDLE \ + __SPCD_BANNER_BOTTOM } -# ╭──────────┬───────╮ -# │ internal │ error │ -# ╰──────────┴───────╯ +# ╭───────────┬───────╮ +# │ internals │ error │ +# ╰───────────┴───────╯ -SPCD_ERROR_CI=1 -SPCD_ERROR_OS=2 +_SPCD_ERROR_CI=1 +_SPCD_ERROR_OS=2 -# ╭──────────┬───────╮ -# │ internal │ frame │ -# ╰──────────┴───────╯ +# ╭───────────┬───────╮ +# │ internals │ frame │ +# ╰───────────┴───────╯ -SPCD_FRAME_DOWN_AND_RIGHT="╭" -SPCD_FRAME_UP_AND_RIGHT="╰" +_SPCD_FRAME_TOP="╭╴" +_SPCD_FRAME_BOTTOM="╰╴" -spcd_frame_open() { - echo "${SPCD_FRAME_DOWN_AND_RIGHT}${1}" +_spcd_frame_open() { + echo "${_SPCD_FRAME_TOP}${1}" } -spcd_frame_shut() { - echo "${SPCD_FRAME_UP_AND_RIGHT}${1}" +_spcd_frame_shut() { + echo "${_SPCD_FRAME_BOTTOM}${1}" } -# ╭──────────┬────╮ -# │ internal │ os │ -# ╰──────────┴────╯ +# ╭───────────┬────╮ +# │ internals │ os │ +# ╰───────────┴────╯ -spcd_os_cat() { - spcd_cat__file="${1}" - if [ -n "${spcd_cat__file}" ]; then - spcd_frame_open "${spcd_cat__file}" - cat "${spcd_cat__file}" - spcd_frame_shut "${spcd_cat__file}" +_spcd_os_cat() { + if [ -n "${1}" ]; then + _spcd_frame_open "${1}" + cat "${1}" + _spcd_frame_shut "${1}" fi } -# ╭──────────┬──────╮ -# │ internal │ rule │ -# ╰──────────┴──────╯ +# ╭───────────┬──────╮ +# │ internals │ rule │ +# ╰───────────┴──────╯ -SPCD_RULE_HORIZONTAL="─" -SPCD_RULE_LEFT="╴" -SPCD_RULE_RIGHT="╶" +_SPCD_RULE_LEFT="╶" +_SPCD_RULE_MIDDLE="─" +_SPCD_RULE_RIGHT="╴" -# ╭──────────┬──────╮ -# │ internal │ step │ -# ╰──────────┴──────╯ +# ╭───────────┬──────╮ +# │ internals │ step │ +# ╰───────────┴──────╯ -SPCD_STEP_LEVEL=1 - -spcd_step_wipe() { +_spcd_step_wipe() { unset \ - "SPCD_STEP_${SPCD_STEP_LEVEL}_INDEX" \ - "SPCD_STEP_${SPCD_STEP_LEVEL}_LABEL" + "__SPCD_STEP_${__SPCD_STEP_LEVEL}_INDEX" \ + "__SPCD_STEP_${__SPCD_STEP_LEVEL}_LABEL" } -#╶──────────────────────────────────────╴ +# ╭───────────╮ +# │ functions │ +# ╰───────────╯ # ╭───────────┬───────╮ # │ functions │ error │ @@ -215,14 +218,14 @@ spcd_step_wipe() { spcd_error_ci() { echo "× CI: ${*}" - exit "${SPCD_ERROR_CI}" + exit "${_SPCD_ERROR_CI}" } spcd_error_os() { spcd_error_os__variable="${1}" printf "× OS: " spcd_os_printenv "${spcd_error_os__variable}" - exit "${SPCD_ERROR_OS}" + exit "${_SPCD_ERROR_OS}" } # ╭───────────┬─────╮ @@ -277,9 +280,9 @@ spcd_os_grep() { spcd_os_ls() { spcd_os_ls__path="${1}" if [ -n "${spcd_os_ls__path}" ]; then - spcd_frame_open "${spcd_os_ls__path}" + _spcd_frame_open "${spcd_os_ls__path}" ls -a -l "${spcd_os_ls__path}" - spcd_frame_shut "${spcd_os_ls__path}" + _spcd_frame_shut "${spcd_os_ls__path}" fi } @@ -302,10 +305,9 @@ spcd_os_printenv() { } spcd_os_rm() { - spcd_os_rm__path="${1}" - if [ -e "${spcd_os_rm__path}" ]; then - echo "← ${spcd_os_rm__path}" - rm -r "${spcd_os_rm__path}" + if [ -e "${1}" ]; then + echo "← ${1}" + rm -r "${1}" fi } @@ -313,10 +315,10 @@ spcd_os_sed() { spcd_os_sed__file="${1}" shift if [ -f "${spcd_os_sed__file}" ]; then - spcd_os_cat "${spcd_os_sed__file}" + _spcd_os_cat "${spcd_os_sed__file}" for spcd_os_sed__regex in "${@}"; do sed --in-place "s${spcd_os_sed__regex}g" "${spcd_os_sed__file}" && - spcd_os_cat "${spcd_os_sed__file}" + _spcd_os_cat "${spcd_os_sed__file}" done fi } @@ -326,10 +328,10 @@ spcd_os_write() { spcd_os_write__text="${2}" if [ -n "${spcd_os_write__file}" ]; then [ -f "${spcd_os_write__file}" ] && - spcd_os_cat "${spcd_os_write__file}" + _spcd_os_cat "${spcd_os_write__file}" echo "→ ${spcd_os_write__file}" printf "%s" "${spcd_os_write__text}" >"${spcd_os_write__file}" - spcd_os_cat "${spcd_os_write__file}" + _spcd_os_cat "${spcd_os_write__file}" fi } @@ -362,7 +364,7 @@ spcd_python_pip() { # ╰───────────┴───────╯ spcd_split() { - echo "${SPCD_RULE_RIGHT}${SPCD_RULE_HORIZONTAL}${SPCD_RULE_LEFT}" + echo "${_SPCD_RULE_LEFT}${_SPCD_RULE_MIDDLE}${_SPCD_RULE_RIGHT}" } # ╭───────────┬──────╮ @@ -371,26 +373,29 @@ spcd_split() { spcd_step() { if [ -n "${1}" ]; then - spcd_step__prefix="SPCD_STEP_${SPCD_STEP_LEVEL}" + [ -n "${__SPCD_STEP_LEVEL}" ] || __SPCD_STEP_LEVEL=1 + spcd_step__prefix="__SPCD_STEP_${__SPCD_STEP_LEVEL}" spcd_step__index="${spcd_step__prefix}_INDEX" eval "${spcd_step__index}=\$((${spcd_step__index} + 1))" eval "${spcd_step__prefix}_LABEL=\"${1}\"" - spcd_banner_render + _spcd_banner_render fi } spcd_step_in() { [ -n "${1}" ] && spcd_step "${1}" - SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL + 1)) - spcd_step_wipe + __SPCD_STEP_LEVEL=$((__SPCD_STEP_LEVEL + 1)) + _spcd_step_wipe } spcd_step_out() { - spcd_step_wipe - SPCD_STEP_LEVEL=$((SPCD_STEP_LEVEL - 1)) + _spcd_step_wipe + __SPCD_STEP_LEVEL=$((__SPCD_STEP_LEVEL - 1)) } -#╶──────────────────────────────────────╴ +# ╭───────╮ +# │ steps │ +# ╰───────╯ # ╭───────┬───────────╮ # │ steps │ constants │ @@ -938,10 +943,8 @@ installonly_limit=3 skip_if_unavailable=False " ;; - "${SPCD_PM_APK}") - ;; - "${SPCD_PM_PACMAN}") - ;; + "${SPCD_PM_APK}") ;; + "${SPCD_PM_PACMAN}") ;; "${SPCD_PM_APT}") spcd_os_write "/etc/apt/apt.conf.d/apt.conf" "\ Acquire::Check-Valid-Until True; @@ -951,8 +954,7 @@ APT::Install-Suggests False; Dir::Etc::SourceParts \"\"; " ;; - "${SPCD_PM_ZYPPER}") - ;; + "${SPCD_PM_ZYPPER}") ;; *) ;; esac case "${SPCD_OS_ID}" in @@ -1209,7 +1211,7 @@ spcd_python_write_module() { spcd_wpm__text="${spcd_wpm__text}${spcd_wpm__value} " done - spcd_wpm__index=$((SPCD_STEP_1_INDEX + 1)) + spcd_wpm__index=$((__SPCD_STEP_1_INDEX + 1)) for spcd_wpm__root in \ "${SPCD_PYTHON_PACKAGES}" "${SPCD_PYTHON_VENV_PACKAGES}"; do spcd_os_write "${spcd_wpm__root}/env.py" "${spcd_wpm__text} @@ -1228,8 +1230,6 @@ ${SPCD_PYTHON_ALIAS} / ${spcd_stp__name}" "${SPCD_PYTHON_ALIAS}" -m "${spcd_stp__name}" } -#╶──────────────────────────────────────╴ - # ╭──────╮ # │ main │ # ╰──────╯