Compare commits

..

No commits in common. "979dc07d982835418f76e4eef3bf4d561aac33a0" and "5774113c403444b341100561a8384d554cfa0b71" have entirely different histories.

2 changed files with 141 additions and 133 deletions

View file

@ -217,18 +217,11 @@ Handle project workflows in a unified way:
* constants for characters * constants for characters
* dynamic substeps * dynamic substeps
* comment * comment
* frame corners * review repositories handling for systems
* packages
* configure
* apk
* pacman
* zypper
* repositories
* opensuse * opensuse
* codecs repository * codecs repository
* disable & enable https * disable & enable https
* test * test
* underscore internals
### Shell → Python ### Shell → Python

View file

@ -405,6 +405,11 @@ SPCD_OS_OPENSUSE="opensuse"
SPCD_OS_ROCKY="rocky" SPCD_OS_ROCKY="rocky"
SPCD_OS_UBUNTU="ubuntu" SPCD_OS_UBUNTU="ubuntu"
SPCD_PF_APK="apk"
SPCD_PF_DEB="deb"
SPCD_PF_PKG="pkg"
SPCD_PF_RPM="rpm"
SPCD_PM_APK="apk" SPCD_PM_APK="apk"
SPCD_PM_APT="apt" SPCD_PM_APT="apt"
SPCD_PM_DNF="dnf" SPCD_PM_DNF="dnf"
@ -591,9 +596,39 @@ ${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
spcd_os_printenv "SPCD_OS_ID" "SPCD_OS_VERSION" spcd_os_printenv "SPCD_OS_ID" "SPCD_OS_VERSION"
# universal # universal
SPCD_DNS_FILE="/etc/resolv.conf" SPCD_DNS_FILE="/etc/resolv.conf"
SPCD_PKG_CA="ca-certificates"
SPCD_PKG_DOS2UNIX="dos2unix"
SPCD_PKG_GIT="git"
SPCD_PYTHON_ALIAS="python3" SPCD_PYTHON_ALIAS="python3"
spcd_split spcd_split
spcd_os_printenv "SPCD_DNS_FILE" "SPCD_PYTHON_ALIAS" spcd_os_printenv "SPCD_DNS_FILE" \
"SPCD_PKG_CA" "SPCD_PKG_DOS2UNIX" "SPCD_PKG_GIT" "SPCD_PYTHON_ALIAS"
# set ca command & root
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}")
SPCD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
SPCD_CMD_CA="update-ca-trust"
;;
"${SPCD_OS_ALPINE}")
SPCD_CA_ROOT="/usr/local/share/ca-certificates"
SPCD_CMD_CA="update-ca-certificates"
;;
"${SPCD_OS_ARCH}")
SPCD_CA_ROOT="/etc/ca-certificates/trust-source/anchors"
SPCD_CMD_CA="update-ca-trust"
;;
"${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
SPCD_CA_ROOT="/usr/local/share/ca-certificates"
SPCD_CMD_CA="update-ca-certificates"
;;
"${SPCD_OS_OPENSUSE}")
SPCD_CA_ROOT="/etc/pki/trust/anchors"
SPCD_CMD_CA="update-ca-certificates"
;;
*) ;;
esac
spcd_split
spcd_os_printenv "SPCD_CA_ROOT" "SPCD_CMD_CA"
# set package manager # set package manager
case "${SPCD_OS_ID}" in case "${SPCD_OS_ID}" in
"${SPCD_OS_ALPINE}") "${SPCD_OS_ALPINE}")
@ -613,35 +648,105 @@ ${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
;; ;;
*) ;; *) ;;
esac esac
# set package format
case "${SPCD_PM}" in
"${SPCD_PM_APK}")
SPCD_PF="${SPCD_PF_APK}"
;;
"${SPCD_PM_APT}")
SPCD_PF="${SPCD_PF_DEB}"
;;
"${SPCD_PM_PACMAN}")
SPCD_PF="${SPCD_PF_PKG}"
;;
"${SPCD_PM_DNF}" | "${SPCD_PM_ZYPPER}")
SPCD_PF="${SPCD_PF_RPM}"
;;
*) ;;
esac
# set package manager variables # set package manager variables
spcd_split spcd_split
spcd_os_printenv "SPCD_PM" spcd_os_printenv "SPCD_PF" "SPCD_PM"
case "${SPCD_PM}" in case "${SPCD_PM}" in
"${SPCD_PM_DNF}") "${SPCD_PM_DNF}")
SPCD_PM_CLEAN="dnf clean all"
SPCD_PM_INSTALL="dnf install --assumeyes"
SPCD_PM_QUERY="rpm --query"
SPCD_PM_UPDATE="dnf makecache"
SPCD_PM_UPGRADE="dnf upgrade --assumeyes"
SPCD_PKG_PKG=""
SPCD_PM_CONF_PATH="/etc/dnf/dnf.conf"
SPCD_PM_CONF_TEXT="\
[main]
best=True
clean_requirements_on_remove=True
gpgcheck=1
installonly_limit=3
skip_if_unavailable=False
"
SPCD_PM_HTTPS_PATH="/etc/dnf/dnf.conf.d/https.conf" SPCD_PM_HTTPS_PATH="/etc/dnf/dnf.conf.d/https.conf"
SPCD_PM_HTTPS_TEXT="\ SPCD_PM_HTTPS_TEXT="\
sslverify=False sslverify=False
" "
;; ;;
"${SPCD_PM_APK}") "${SPCD_PM_APK}")
SPCD_PM_CLEAN="apk cache purge"
SPCD_PM_INSTALL="apk add"
SPCD_PM_QUERY="apk info"
SPCD_PM_UPDATE="apk update"
SPCD_PM_UPGRADE="apk upgrade"
SPCD_PKG_PKG=""
SPCD_PM_CONF_PATH=""
SPCD_PM_CONF_TEXT=""
SPCD_PM_HTTPS_PATH="/etc/apk/repositories.d/https" SPCD_PM_HTTPS_PATH="/etc/apk/repositories.d/https"
SPCD_PM_HTTPS_TEXT="\ SPCD_PM_HTTPS_TEXT="\
--no-verify --no-verify
" "
;; ;;
"${SPCD_PM_PACMAN}") "${SPCD_PM_PACMAN}")
SPCD_PM_CLEAN="pacman --sync --clean --noconfirm"
SPCD_PM_INSTALL="pacman --sync --noconfirm"
SPCD_PM_QUERY="pacman --query"
SPCD_PM_UPDATE="pacman --sync --refresh"
SPCD_PM_UPGRADE="pacman --sync --sysupgrade --noconfirm"
SPCD_PKG_PKG=""
SPCD_PM_CONF_PATH=""
SPCD_PM_CONF_TEXT=""
SPCD_PM_HTTPS_PATH="/etc/pacman.d/https.conf" SPCD_PM_HTTPS_PATH="/etc/pacman.d/https.conf"
SPCD_PM_HTTPS_TEXT="\ SPCD_PM_HTTPS_TEXT="\
SSLVerify = No SSLVerify = No
" "
;; ;;
"${SPCD_PM_APT}") "${SPCD_PM_APT}")
SPCD_PM_CLEAN="apt-get clean"
SPCD_PM_INSTALL="apt-get install --assume-yes"
SPCD_PM_QUERY="dpkg-query --show"
SPCD_PM_UPDATE="apt-get update"
SPCD_PM_UPGRADE="apt-get upgrade --assume-yes"
SPCD_PKG_PKG="apt-utils"
SPCD_PM_CONF_PATH="/etc/apt/apt.conf.d/apt.conf"
SPCD_PM_CONF_TEXT="\
Acquire::Check-Valid-Until True;
APT::Get::Show-Versions True;
APT::Install-Recommends False;
APT::Install-Suggests False;
Dir::Etc::SourceParts \"\";
"
SPCD_PM_HTTPS_PATH="/etc/apt/apt.conf.d/https" SPCD_PM_HTTPS_PATH="/etc/apt/apt.conf.d/https"
SPCD_PM_HTTPS_TEXT="\ SPCD_PM_HTTPS_TEXT="\
Acquire::https::Verify-Peer False; Acquire::https::Verify-Peer False;
" "
;; ;;
"${SPCD_PM_ZYPPER}") "${SPCD_PM_ZYPPER}")
SPCD_PM_CLEAN="zypper clean"
SPCD_PM_INSTALL="zypper --non-interactive install"
SPCD_PM_QUERY="rpm --query"
SPCD_PM_UPDATE="zypper refresh"
SPCD_PM_UPGRADE="zypper --non-interactive update"
SPCD_PKG_PKG=""
SPCD_PM_CONF_PATH=""
SPCD_PM_CONF_TEXT="\
"
SPCD_PM_HTTPS_PATH="" SPCD_PM_HTTPS_PATH=""
SPCD_PM_HTTPS_TEXT="\ SPCD_PM_HTTPS_TEXT="\
" "
@ -649,7 +754,10 @@ Acquire::https::Verify-Peer False;
*) ;; *) ;;
esac esac
spcd_split spcd_split
spcd_os_printenv "SPCD_PM_HTTPS_PATH" spcd_os_printenv "SPCD_PM_CLEAN" \
"SPCD_PM_INSTALL" "SPCD_PM_QUERY" "SPCD_PM_UPDATE" "SPCD_PM_UPGRADE"
spcd_split
spcd_os_printenv "SPCD_PKG_PKG" "SPCD_PM_CONF_PATH" "SPCD_PM_HTTPS_PATH"
# specific # specific
case "${SPCD_OS_ID}" in case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}") "${SPCD_OS_ALMA}")
@ -787,10 +895,13 @@ Acquire::https::Verify-Peer False;
${SPCD_PYTHON_VENV}/lib/${SPCD_PYTHON_COMMAND}/site-packages" ${SPCD_PYTHON_VENV}/lib/${SPCD_PYTHON_COMMAND}/site-packages"
spcd_split spcd_split
spcd_os_printenv "SPCD_PYTHON_PACKAGES" "SPCD_PYTHON_VENV_PACKAGES" spcd_os_printenv "SPCD_PYTHON_PACKAGES" "SPCD_PYTHON_VENV_PACKAGES"
# variables
# certificate authorities
[ -n "${SPCD_CA_1}" ] && SPCD_CA=true
# downloads # downloads
SPCD_DL="$(mktemp --directory)" SPCD_DL="$(mktemp --directory)"
spcd_split spcd_split
spcd_os_printenv "SPCD_DL" spcd_os_printenv "SPCD_CA" "SPCD_DL"
} }
spcd_environment_list_workspace() { spcd_environment_list_workspace() {
@ -803,38 +914,12 @@ spcd_environment_list_workspace() {
# │ steps │ functions │ # │ steps │ functions │
# ╰───────┴───────────╯ # ╰───────┴───────────╯
spcd_clean_cache() {
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk cache purge ;;
"${SPCD_PM_APT}") apt-get clean ;;
"${SPCD_PM_DNF}") dnf clean all ;;
"${SPCD_PM_PACMAN}") pacman --sync --clean --noconfirm ;;
"${SPCD_PM_ZYPPER}") zypper clean ;;
*) ;;
esac
}
spcd_install_package() { spcd_install_package() {
case "${SPCD_PM}" in spcd_install_package__name="${1}"
"${SPCD_PM_APK}") apk add "${1}" ;; if [ -n "${spcd_install_package__name}" ]; then
"${SPCD_PM_APT}") apt-get install --assume-yes "${1}" ;; ${SPCD_PM_INSTALL} "${spcd_install_package__name}"
"${SPCD_PM_DNF}") dnf install --assumeyes "${1}" ;; ${SPCD_PM_CLEAN}
"${SPCD_PM_PACMAN}") pacman --sync --noconfirm "${1}" ;; fi
"${SPCD_PM_ZYPPER}") zypper --non-interactive install "${1}" ;;
*) ;;
esac
spcd_clean_cache
}
spcd_query_package() {
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk info "${1}" ;;
"${SPCD_PM_APT}") dpkg-query --show "${1}" ;;
"${SPCD_PM_DNF}") rpm --query "${1}" ;;
"${SPCD_PM_PACMAN}") pacman --query "${1}" ;;
"${SPCD_PM_ZYPPER}") rpm --query "${1}" ;;
*) ;;
esac
} }
# ╭───────┬─────╮ # ╭───────┬─────╮
@ -927,34 +1012,7 @@ deb ${SPCD_URL_CHOSEN} ${SPCD_OS_VERSION}-security main universe
spcd_packages_set_configuration() { spcd_packages_set_configuration() {
spcd_step "Set configuration" spcd_step "Set configuration"
case "${SPCD_PM}" in spcd_os_write "${SPCD_PM_CONF_PATH}" "${SPCD_PM_CONF_TEXT}"
"${SPCD_PM_DNF}")
spcd_os_write "/etc/dnf/dnf.conf" "\
[main]
best=True
clean_requirements_on_remove=True
gpgcheck=1
installonly_limit=3
skip_if_unavailable=False
"
;;
"${SPCD_PM_APK}")
;;
"${SPCD_PM_PACMAN}")
;;
"${SPCD_PM_APT}")
spcd_os_write "/etc/apt/apt.conf.d/apt.conf" "\
Acquire::Check-Valid-Until True;
APT::Get::Show-Versions True;
APT::Install-Recommends False;
APT::Install-Suggests False;
Dir::Etc::SourceParts \"\";
"
;;
"${SPCD_PM_ZYPPER}")
;;
*) ;;
esac
case "${SPCD_OS_ID}" in case "${SPCD_OS_ID}" in
"${SPCD_OS_ARCH}") "${SPCD_OS_ARCH}")
pacman-key --init pacman-key --init
@ -968,7 +1026,7 @@ Dir::Etc::SourceParts \"\";
spcd_packages_trust_https() { spcd_packages_trust_https() {
spcd_step "Trust HTTPS" spcd_step "Trust HTTPS"
if [ -n "${SPCD_CA_1}" ] || [ "${SPCD_PM}" = "${SPCD_PM_APT}" ]; then if [ -n "${SPCD_CA}" ] || [ "${SPCD_PM}" = "${SPCD_PM_APT}" ]; then
spcd_os_mkdir "$(dirname "${SPCD_PM_HTTPS_PATH}")" spcd_os_mkdir "$(dirname "${SPCD_PM_HTTPS_PATH}")"
spcd_os_write "${SPCD_PM_HTTPS_PATH}" "${SPCD_PM_HTTPS_TEXT}" spcd_os_write "${SPCD_PM_HTTPS_PATH}" "${SPCD_PM_HTTPS_TEXT}"
fi fi
@ -976,22 +1034,12 @@ spcd_packages_trust_https() {
spcd_packages_update_catalog() { spcd_packages_update_catalog() {
spcd_step "Update catalog" spcd_step "Update catalog"
case "${SPCD_PM}" in ${SPCD_PM_UPDATE}
"${SPCD_PM_APK}") apk update ;;
"${SPCD_PM_APT}") apt-get update ;;
"${SPCD_PM_DNF}") dnf makecache ;;
"${SPCD_PM_PACMAN}") pacman --sync --refresh ;;
"${SPCD_PM_ZYPPER}") zypper refresh ;;
*) ;;
esac
} }
spcd_packages_install_tools() { spcd_packages_install_tools() {
spcd_step "Install tools" spcd_step "Install tools"
case "${SPCD_PM}" in spcd_install_package "${SPCD_PKG_PKG}"
"${SPCD_PM_APT}") spcd_install_package "apt-utils" ;;
*) ;;
esac
} }
# ╭───────┬────╮ # ╭───────┬────╮
@ -1000,32 +1048,17 @@ spcd_packages_install_tools() {
spcd_ca_install_package() { spcd_ca_install_package() {
spcd_step "Install package" spcd_step "Install package"
spcd_install_package "ca-certificates" spcd_install_package "${SPCD_PKG_CA}"
} }
spcd_ca_write_certificates() { spcd_ca_write_certificates() {
spcd_step "Write certificates" spcd_step "Write certificates"
case "${SPCD_OS_ID}" in spcd_os_mkdir "${SPCD_CA_ROOT}"
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}")
spcd_wcc__root="/etc/pki/ca-trust/source/anchors"
;;
"${SPCD_OS_ALPINE}" | "${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
spcd_wcc__root="/usr/local/share/ca-certificates"
;;
"${SPCD_OS_ARCH}")
spcd_wcc__root="/etc/ca-certificates/trust-source/anchors"
;;
"${SPCD_OS_OPENSUSE}")
spcd_wcc__root="/etc/pki/trust/anchors"
;;
*) ;;
esac
spcd_os_mkdir "${spcd_wcc__root}"
while true; do while true; do
spcd_wcc__index=$((spcd_wcc__index + 1)) spcd_wcc__index=$((spcd_wcc__index + 1))
eval "spcd_wcc__text=\"\${SPCD_CA_${spcd_wcc__index}}\"" eval "spcd_wcc__text=\"\${SPCD_CA_${spcd_wcc__index}}\""
[ -n "${spcd_wcc__text}" ] || break [ -n "${spcd_wcc__text}" ] || break
spcd_wcc__path="${spcd_wcc__root}/${spcd_wcc__index}.crt" spcd_wcc__path="${SPCD_CA_ROOT}/${spcd_wcc__index}.crt"
spcd_split spcd_split
spcd_os_write "${spcd_wcc__path}" "${spcd_wcc__text}" spcd_os_write "${spcd_wcc__path}" "${spcd_wcc__text}"
spcd_openssl_x509 "${spcd_wcc__path}" spcd_openssl_x509 "${spcd_wcc__path}"
@ -1034,21 +1067,7 @@ spcd_ca_write_certificates() {
spcd_ca_update_certificates() { spcd_ca_update_certificates() {
spcd_step "Update certificates" spcd_step "Update certificates"
case "${SPCD_OS_ID}" in ${SPCD_CMD_CA}
"${SPCD_OS_ARCH}" | \
"${SPCD_OS_ALMA}" | \
"${SPCD_OS_FEDORA}" | \
"${SPCD_OS_ROCKY}")
update-ca-trust
;;
"${SPCD_OS_ALPINE}" | \
"${SPCD_OS_DEBIAN}" | \
"${SPCD_OS_OPENSUSE}" | \
"${SPCD_OS_UBUNTU}")
update-ca-certificates
;;
*) ;;
esac
} }
# ╭───────┬──────────╮ # ╭───────┬──────────╮
@ -1062,24 +1081,17 @@ spcd_packages_verify_https() {
spcd_packages_upgrade_system() { spcd_packages_upgrade_system() {
spcd_step "Upgrade system" spcd_step "Upgrade system"
case "${SPCD_PM}" in ${SPCD_PM_UPGRADE}
"${SPCD_PM_APK}") apk upgrade ;;
"${SPCD_PM_APT}") apt-get upgrade --assume-yes ;;
"${SPCD_PM_DNF}") dnf upgrade --assumeyes ;;
"${SPCD_PM_PACMAN}") pacman --sync --sysupgrade --noconfirm ;;
"${SPCD_PM_ZYPPER}") zypper --non-interactive update ;;
*) ;;
esac
} }
spcd_packages_install_dos2unix() { spcd_packages_install_dos2unix() {
spcd_step "Install dos2unix" spcd_step "Install dos2unix"
spcd_install_package "dos2unix" spcd_install_package "${SPCD_PKG_DOS2UNIX}"
} }
spcd_packages_install_git() { spcd_packages_install_git() {
spcd_step "Install Git" spcd_step "Install Git"
spcd_install_package "git" spcd_install_package "${SPCD_PKG_GIT}"
} }
# ╭───────┬────────╮ # ╭───────┬────────╮
@ -1154,6 +1166,9 @@ spcd_install_packages() {
;; ;;
*) ;; *) ;;
esac esac
# bats
spcd_step "BATS"
spcd_install_package "bats"
# graphviz # graphviz
spcd_step "GraphViz" spcd_step "GraphViz"
spcd_install_package "graphviz" spcd_install_package "graphviz"
@ -1177,8 +1192,8 @@ spcd_install_packages() {
spcd_install_package "rsync" spcd_install_package "rsync"
# shell check # shell check
spcd_step "ShellCheck" spcd_step "ShellCheck"
case "${SPCD_PM}" in case "${SPCD_PF}" in
"${SPCD_PM_DNF}" | "${SPCD_PM_ZYPPER}") "${SPCD_PF_RPM}")
spcd_install_package "ShellCheck" spcd_install_package "ShellCheck"
;; ;;
*) spcd_install_package "shellcheck" ;; *) spcd_install_package "shellcheck" ;;
@ -1209,7 +1224,7 @@ spcd_python_write_module() {
spcd_wpm__text="${spcd_wpm__text}${spcd_wpm__value} spcd_wpm__text="${spcd_wpm__text}${spcd_wpm__value}
" "
done done
spcd_wpm__index=$((SPCD_STEP_1_INDEX + 1)) eval "spcd_wpm__index=\$((SPCD_STEP_${SPCD_STEP_LEVEL}_INDEX + 1))"
for spcd_wpm__root in \ for spcd_wpm__root in \
"${SPCD_PYTHON_PACKAGES}" "${SPCD_PYTHON_VENV_PACKAGES}"; do "${SPCD_PYTHON_PACKAGES}" "${SPCD_PYTHON_VENV_PACKAGES}"; do
spcd_os_write "${spcd_wpm__root}/env.py" "${spcd_wpm__text} spcd_os_write "${spcd_wpm__root}/env.py" "${spcd_wpm__text}