Compare commits

..

No commits in common. "351c9742ef29283df0b9a0f02343612e70037ab0" and "31ca2c6117fd9726944205e63f20163b207d570a" have entirely different histories.

2 changed files with 121 additions and 129 deletions

View file

@ -255,7 +255,6 @@ Handle project workflows in a unified way:
* venv * venv
* create * create
* activate * activate
* query package
* relay environment module name * relay environment module name
#### Python #### Python

View file

@ -27,10 +27,9 @@ _SPCD_BANNER_VERTICAL="│"
_spcd_banner_add() { _spcd_banner_add() {
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
local text length filler local text=" ${1} "
text=" ${1} " local length=${#text}
length=${#text} local filler="$(_spcd_fill "${length}" "${_SPCD_BANNER_HORIZONTAL}")"
filler="$(_spcd_fill "${length}" "${_SPCD_BANNER_HORIZONTAL}")"
if [ -n "${__SPCD_BANNER_MIDDLE}" ]; then if [ -n "${__SPCD_BANNER_MIDDLE}" ]; then
_spcd_banner_split _spcd_banner_split
else else
@ -300,10 +299,10 @@ spcd_split() {
spcd_step() { spcd_step() {
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
[ -n "${__SPCD_STEP_LEVEL}" ] || __SPCD_STEP_LEVEL=1 [ -n "${__SPCD_STEP_LEVEL}" ] || __SPCD_STEP_LEVEL=1
local prefix="__SPCD_STEP_${__SPCD_STEP_LEVEL}" spcd_step__prefix="__SPCD_STEP_${__SPCD_STEP_LEVEL}"
local index="${prefix}_INDEX" spcd_step__index="${spcd_step__prefix}_INDEX"
eval "${index}=\$((${index} + 1))" eval "${spcd_step__index}=\$((${spcd_step__index} + 1))"
eval "${prefix}_LABEL=\"${1}\"" eval "${spcd_step__prefix}_LABEL=\"${1}\""
_spcd_banner_render _spcd_banner_render
fi fi
} }
@ -335,14 +334,12 @@ spcd_txt_get() {
spcd_txt_locale() { spcd_txt_locale() {
# LANGUAGE # LANGUAGE
local name
local value
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
value="${1}" spcd_step__locale__value="${1}"
else else
value="${_SPCD_TXT_LOCALE_DEFAULT}" spcd_step__locale__value="${_SPCD_TXT_LOCALE_DEFAULT}"
fi fi
value="${value}.${_SPCD_TXT_CHARSET}" spcd_step__locale__value="${spcd_step__locale__value}.${_SPCD_TXT_CHARSET}"
set -- \ set -- \
"LANG" \ "LANG" \
"LC_CTYPE" \ "LC_CTYPE" \
@ -357,8 +354,8 @@ spcd_txt_locale() {
"LC_TELEPHONE" \ "LC_TELEPHONE" \
"LC_MEASUREMENT" \ "LC_MEASUREMENT" \
"LC_IDENTIFICATION" "LC_IDENTIFICATION"
for name in "${@}"; do for spcd_step__locale__name in "${@}"; do
export "${name}=${value}" export "${spcd_step__locale__name}=${spcd_step__locale__value}"
done done
} }
@ -411,14 +408,11 @@ spcd_step__environment_defaults_print() {
"URL_PYTHON" \ "URL_PYTHON" \
"URL_ROCKY" \ "URL_ROCKY" \
"URL_UBUNTU" "URL_UBUNTU"
local item for spcd_step_edp__item in "${@}"; do
local name spcd_step_edp__name="SPCD_${spcd_step_edp__item}"
local value eval "spcd_step_edp__value=\"\${${spcd_step_edp__name}}\""
for item in "${@}"; do if [ -n "${spcd_step_edp__value}" ]; then
name="SPCD_${item}" spcd_os_printenv "${spcd_step_edp__name}"
eval "value=\"\${${name}}\""
if [ -n "${value}" ]; then
spcd_os_printenv "${name}"
fi fi
done done
} }
@ -756,7 +750,8 @@ ${SPCD_PYTHON_VENV}/lib/${SPCD_PYTHON_COMMAND}/site-packages"
spcd_step__environment_list_workspace() { spcd_step__environment_list_workspace() {
spcd_step "List workspace" spcd_step "List workspace"
spcd_os_ls "$(realpath .)" spcd_lwd__path="$(realpath .)"
spcd_os_ls "${spcd_lwd__path}"
} }
# ╭──────┬───────────╮ # ╭──────┬───────────╮
@ -776,12 +771,11 @@ spcd_clean_cache() {
spcd_git_clone() { spcd_git_clone() {
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
local name path url spcd_gc__name="$(basename "${1}")"
name="$(basename "${1}")" spcd_gc__path="${SPCD_DL}/${spcd_gc__name}"
path="${SPCD_DL}/${name}" spcd_gc__url="$(spcd_git_url "${1}")"
url="$(spcd_git_url "${1}")" git clone "${spcd_gc__url}" "${spcd_gc__path}"
git clone "${url}" "${path}" echo "${spcd_gc__path}"
echo "${path}"
fi fi
} }
@ -819,23 +813,22 @@ spcd_install_package() {
} }
spcd_python_ln() { spcd_python_ln() {
local command="${1}" spcd_python_ln__command="${1}"
if [ -n "${command}" ]; then if [ -n "${spcd_python_ln__command}" ]; then
echo "${SPCD_PYTHON_ALIAS}${command}" echo "${SPCD_PYTHON_ALIAS}${spcd_python_ln__command}"
ln -f -s "${command}" \ ln -f -s "${spcd_python_ln__command}" \
"/usr/bin/${SPCD_PYTHON_ALIAS}" "/usr/bin/${SPCD_PYTHON_ALIAS}"
fi fi
} }
spcd_python_pip() { spcd_python_pip() {
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
local name path target spcd_pp__name="$(basename "${1}")"
name="$(basename "${1}")" spcd_pp__path="$(spcd_git_clone "${1}")"
path="$(spcd_git_clone "${1}")" spcd_pp__path="${spcd_pp__path}/${spcd_pp__name}"
path="${path}/${name}" spcd_pp__target="${SPCD_PYTHON_VENV_PACKAGES}"
target="${SPCD_PYTHON_VENV_PACKAGES}" cp --recursive "${spcd_pp__path}" "${spcd_pp__target}"
cp --recursive "${path}" "${target}" echo "${spcd_pp__target}/${spcd_pp__name}"
echo "${target}/${name}"
fi fi
} }
@ -856,16 +849,15 @@ spcd_query_package() {
spcd_step__dns() { spcd_step__dns() {
spcd_step "DNS" spcd_step "DNS"
local index value text
while true; do while true; do
index=$((index + 1)) spcd_sdr__index=$((spcd_sdr__index + 1))
eval "value=\"\${SPCD_DNS_${index}}\"" eval "spcd_sdr__value=\"\${SPCD_DNS_${spcd_sdr__index}}\""
[ -n "${value}" ] || break [ -n "${spcd_sdr__value}" ] || break
text="${text}\ spcd_sdr__text="${spcd_sdr__text}\
nameserver ${value} nameserver ${spcd_sdr__value}
" "
done done
spcd_os_write "/etc/resolv.conf" "${text}" spcd_os_write "/etc/resolv.conf" "${spcd_sdr__text}"
} }
# ╭──────┬──────────╮ # ╭──────┬──────────╮
@ -874,7 +866,6 @@ nameserver ${value}
spcd_step__packages_set_repositories() { spcd_step__packages_set_repositories() {
spcd_step "Set repositories" spcd_step "Set repositories"
local file
case "${SPCD_OS_ID}" in case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}") "${SPCD_OS_ALMA}")
case "${SPCD_OS_VERSION}" in case "${SPCD_OS_VERSION}" in
@ -906,8 +897,8 @@ spcd_step__packages_set_repositories() {
;; ;;
*) ;; *) ;;
esac esac
for file in "${@}"; do for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/yum.repos.d/almalinux${file}.repo" \ spcd_os_sed "/etc/yum.repos.d/almalinux${spcd_spr__file}.repo" \
"|^mirrorlist|#mirrorlist|" \ "|^mirrorlist|#mirrorlist|" \
"|https://repo.almalinux.org|${SPCD_URL_ALMA}|" \ "|https://repo.almalinux.org|${SPCD_URL_ALMA}|" \
"|^# baseurl|baseurl|" "|^# baseurl|baseurl|"
@ -937,14 +928,14 @@ deb ${SPCD_URL_DEBIAN}-security ${SPCD_OS_VERSION}-security main
"-updates-testing" \ "-updates-testing" \
"-updates" \ "-updates" \
"" ""
for file in "${@}"; do for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/yum.repos.d/fedora${file}.repo" \ spcd_os_sed "/etc/yum.repos.d/fedora${spcd_spr__file}.repo" \
"|^metalink|#metalink|" "\ "|^metalink|#metalink|" "\
|http://download.example/pub/fedora/linux|${SPCD_URL_FEDORA}|" \ |http://download.example/pub/fedora/linux|${SPCD_URL_FEDORA}|" \
"|^#baseurl|baseurl|" "|^#baseurl|baseurl|"
done done
spcd_os_sed "/etc/yum.repos.d/fedora-cisco-openh264.repo" \ spcd_os_sed "/etc/yum.repos.d/fedora-cisco-openh264.repo" \
"|^enabled=1|enabled=0|" "|^enabled=1|#enabled=0|"
;; ;;
"${SPCD_OS_OPENSUSE}") "${SPCD_OS_OPENSUSE}")
set -- \ set -- \
@ -961,12 +952,12 @@ deb ${SPCD_URL_DEBIAN}-security ${SPCD_OS_VERSION}-security main
"source" \ "source" \
"update-non-oss" \ "update-non-oss" \
"update" "update"
for file in "${@}"; do for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/zypp/repos.d/repo-${file}.repo" \ spcd_os_sed "/etc/zypp/repos.d/repo-${spcd_spr__file}.repo" \
"|http://download.opensuse.org|${SPCD_URL_OPENSUSE}|" "|http://download.opensuse.org|${SPCD_URL_OPENSUSE}|"
done done
spcd_os_sed "/etc/zypp/repos.d/repo-openh264.repo" \ spcd_os_sed "/etc/zypp/repos.d/repo-openh264.repo" \
"|^enabled=1|enabled=0|" "|^enabled=1|#enabled=0|"
;; ;;
"${SPCD_OS_ROCKY}") "${SPCD_OS_ROCKY}")
case "${SPCD_OS_VERSION}" in case "${SPCD_OS_VERSION}" in
@ -995,8 +986,8 @@ deb ${SPCD_URL_DEBIAN}-security ${SPCD_OS_VERSION}-security main
;; ;;
*) ;; *) ;;
esac esac
for file in "${@}"; do for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/yum.repos.d/${file}.repo" \ spcd_os_sed "/etc/yum.repos.d/${spcd_spr__file}.repo" \
"|^mirrorlist|#mirrorlist|" \ "|^mirrorlist|#mirrorlist|" \
"|http://dl.rockylinux.org|${SPCD_URL_ROCKY}|" \ "|http://dl.rockylinux.org|${SPCD_URL_ROCKY}|" \
"|^#baseurl|baseurl|" "|^#baseurl|baseurl|"
@ -1054,29 +1045,28 @@ Dir::Etc::SourceParts \"\";
spcd_step__packages_trust_https() { spcd_step__packages_trust_https() {
spcd_step "Trust HTTPS" spcd_step "Trust HTTPS"
local path text
if [ -n "${SPCD_CA_1}" ] || [ "${SPCD_PM}" = "${SPCD_PM_APT}" ]; then if [ -n "${SPCD_CA_1}" ] || [ "${SPCD_PM}" = "${SPCD_PM_APT}" ]; then
path="$(spcd_https_path)" spcd_pth__path="$(spcd_https_path)"
if [ -n "${path}" ]; then if [ -n "${spcd_pth__path}" ]; then
spcd_os_mkdir "$(dirname "${path}")" spcd_os_mkdir "$(dirname "${spcd_pth__path}")"
case "${SPCD_PM}" in case "${SPCD_PM}" in
"${SPCD_PM_APK}") text="\ "${SPCD_PM_APK}") spcd_pth__text="\
--no-verify --no-verify
" ;; " ;;
"${SPCD_PM_APT}") text="\ "${SPCD_PM_APT}") spcd_pth__text="\
Acquire::https::Verify-Peer False; Acquire::https::Verify-Peer False;
" ;; " ;;
"${SPCD_PM_DNF}") text="\ "${SPCD_PM_DNF}") spcd_pth__text="\
sslverify=False sslverify=False
" ;; " ;;
"${SPCD_PM_PACMAN}") text="\ "${SPCD_PM_PACMAN}") spcd_pth__text="\
SSLVerify = No SSLVerify = No
" ;; " ;;
"${SPCD_PM_ZYPPER}") ;; "${SPCD_PM_ZYPPER}") ;;
*) ;; *) ;;
esac esac
[ -n "${text}" ] && [ -n "${spcd_pth__text}" ] &&
spcd_os_write "${path}" "${text}" spcd_os_write "${spcd_pth__path}" "${spcd_pth__text}"
fi fi
fi fi
} }
@ -1112,31 +1102,30 @@ spcd_step__ca_install_package() {
spcd_step__ca_write_certificates() { spcd_step__ca_write_certificates() {
spcd_step "Write certificates" spcd_step "Write certificates"
local root index text path
case "${SPCD_OS_ID}" in case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}") "${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}")
root="/etc/pki/ca-trust/source/anchors" spcd_wcc__root="/etc/pki/ca-trust/source/anchors"
;; ;;
"${SPCD_OS_ALPINE}" | "${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}") "${SPCD_OS_ALPINE}" | "${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
root="/usr/local/share/ca-certificates" spcd_wcc__root="/usr/local/share/ca-certificates"
;; ;;
"${SPCD_OS_ARCH}") "${SPCD_OS_ARCH}")
root="/etc/ca-certificates/trust-source/anchors" spcd_wcc__root="/etc/ca-certificates/trust-source/anchors"
;; ;;
"${SPCD_OS_OPENSUSE}") "${SPCD_OS_OPENSUSE}")
root="/etc/pki/trust/anchors" spcd_wcc__root="/etc/pki/trust/anchors"
;; ;;
*) ;; *) ;;
esac esac
spcd_os_mkdir "${root}" spcd_os_mkdir "${spcd_wcc__root}"
while true; do while true; do
index=$((index + 1)) spcd_wcc__index=$((spcd_wcc__index + 1))
eval "text=\"\${SPCD_CA_${index}}\"" eval "spcd_wcc__text=\"\${SPCD_CA_${spcd_wcc__index}}\""
[ -n "${text}" ] || break [ -n "${spcd_wcc__text}" ] || break
path="${root}/${index}.crt" spcd_wcc__path="${spcd_wcc__root}/${spcd_wcc__index}.crt"
spcd_split spcd_split
spcd_os_write "${path}" "${text}" spcd_os_write "${spcd_wcc__path}" "${spcd_wcc__text}"
spcd_openssl_x509 "${path}" spcd_openssl_x509 "${spcd_wcc__path}"
done done
} }
@ -1165,10 +1154,9 @@ spcd_step__ca_update_certificates() {
spcd_step__packages_verify_https() { spcd_step__packages_verify_https() {
spcd_step "Verify HTTPS" spcd_step "Verify HTTPS"
local path spcd_pvh__path="$(spcd_https_path)"
path="$(spcd_https_path)" if [ -n "${spcd_pvh__path}" ]; then
if [ -n "${path}" ]; then spcd_os_rm "${spcd_pvh__path}"
spcd_os_rm "${path}"
fi fi
} }
@ -1180,20 +1168,21 @@ spcd_step__packages_install_locales() {
case "${SPCD_PM}" in case "${SPCD_PM}" in
"${SPCD_PM_APK}") spcd_install_package "musl-locales" ;; "${SPCD_PM_APK}") spcd_install_package "musl-locales" ;;
"${SPCD_PM_APT}") "${SPCD_PM_APT}")
local locale text unset spcd_step__pil__text
for locale in "${@}"; do for spcd_step__pil__locale in "${@}"; do
text="${text}\ spcd_step__pil__text="${spcd_step__pil__text}\
${locale}.${_SPCD_TXT_CHARSET} ${_SPCD_TXT_CHARSET} ${spcd_step__pil__locale}.${_SPCD_TXT_CHARSET} ${_SPCD_TXT_CHARSET}
" "
done done
spcd_os_write "/etc/locale.gen" "${text}" spcd_os_write "/etc/locale.gen" "${spcd_step__pil__text}"
spcd_install_package "locales" spcd_install_package "locales"
;; ;;
"${SPCD_PM_DNF}") "${SPCD_PM_DNF}")
local locale language for spcd_step__pil__locale in "${@}"; do
for locale in "${@}"; do spcd_step__pil__lang="$(
language="$(echo "${locale}" | cut -d _ -f 1)" echo "${spcd_step__pil__locale}" | cut -d _ -f 1
spcd_install_package "glibc-langpack-${language}" )"
spcd_install_package "glibc-langpack-${spcd_step__pil__lang}"
done done
;; ;;
"${SPCD_PM_PACMAN}") spcd_install_package "glibc-locales" ;; "${SPCD_PM_PACMAN}") spcd_install_package "glibc-locales" ;;
@ -1258,33 +1247,31 @@ index-url = ${SPCD_URL_PYTHON}/simple
spcd_step__python_modules() { spcd_step__python_modules() {
spcd_step_in "Modules" spcd_step_in "Modules"
local target path script check spcd_ipm__target="${SPCD_PYTHON_VENV_PACKAGES}"
target="${SPCD_PYTHON_VENV_PACKAGES}"
spcd_step "List" spcd_step "List"
spcd_os_ls "${target}" spcd_os_ls "${spcd_ipm__target}"
spcd_step "Main" spcd_step "Main"
path="$(spcd_python_pip "${SPCD_GIT_SPCD}")" spcd_ipm__path="$(spcd_python_pip "${SPCD_GIT_SPCD}")"
# check matching of file and variable # check matching of file and variable
spcd_step "Check" spcd_step "Check"
script="${path}/bootstrap.sh" spcd_ipm__script="${spcd_ipm__path}/bootstrap.sh"
ls -l "${script}" ls -l "${spcd_ipm__script}"
check="${script}.${SPCD_CMD_SUM}" spcd_ipm__check="${spcd_ipm__script}.${SPCD_CMD_SUM}"
"${SPCD_CMD_SUM}" "${script}" >"${check}" "${SPCD_CMD_SUM}" "${spcd_ipm__script}" >"${spcd_ipm__check}"
printf "%s" "${SPCD}" >"${script}" printf "%s" "${SPCD}" >"${spcd_ipm__script}"
ls -l "${script}" ls -l "${spcd_ipm__script}"
dos2unix "${script}" dos2unix "${spcd_ipm__script}"
ls -l "${script}" ls -l "${spcd_ipm__script}"
"${SPCD_CMD_SUM}" -c "${check}" || spcd_error_ci "SPCD" "${SPCD_CMD_SUM}" -c "${spcd_ipm__check}" || spcd_error_ci "SPCD"
spcd_step "Root" spcd_step "Root"
spcd_python_pip "${SPCD_GIT_RWX}" spcd_python_pip "${SPCD_GIT_RWX}"
spcd_step "List" spcd_step "List"
spcd_os_ls "${target}" spcd_os_ls "${spcd_ipm__target}"
spcd_step_out spcd_step_out
} }
spcd_step__install_packages() { spcd_step__install_packages() {
spcd_step_in "OS packages" spcd_step_in "OS packages"
local file
# epel # epel
spcd_step "EPEL" spcd_step "EPEL"
case "${SPCD_OS_ID}" in case "${SPCD_OS_ID}" in
@ -1305,16 +1292,16 @@ spcd_step__install_packages() {
;; ;;
*) ;; *) ;;
esac esac
for file in "${@}"; do for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/yum.repos.d/epel${file}.repo" \ spcd_os_sed "/etc/yum.repos.d/epel${spcd_spr__file}.repo" \
"|^metalink|#metalink|" \ "|^metalink|#metalink|" \
"|https://download.example/pub/epel|${SPCD_URL_EPEL}|" \ "|https://download.example/pub/epel|${SPCD_URL_EPEL}|" \
"|^#baseurl|baseurl|" "|^#baseurl|baseurl|"
done done
file="/etc/yum.repos.d/epel-cisco-openh264.repo" spcd_spr__file="/etc/yum.repos.d/epel-cisco-openh264.repo"
if [ -f "${spcd_spr__file}" ]; then if [ -f "${spcd_spr__file}" ]; then
spcd_os_sed "${file}" \ spcd_os_sed "${spcd_spr__file}" \
"|^enabled=1|enabled=0|" "|^enabled=1|#enabled=0|"
fi fi
;; ;;
*) ;; *) ;;
@ -1365,42 +1352,48 @@ spcd_step__install_packages() {
spcd_step__python_write_module() { spcd_step__python_write_module() {
spcd_step "Write module" spcd_step "Write module"
local variable value text index root for spcd_wpm__variable in \
for variable in \
OS_ID OS_VERSION \ OS_ID OS_VERSION \
PROJECT_ROOT PROJECT_PATH PROJECT_NAME \ PROJECT_ROOT PROJECT_PATH PROJECT_NAME \
PYTHON_VENV_BINARIES PYTHON_VENV_PACKAGES \ PYTHON_VENV_BINARIES PYTHON_VENV_PACKAGES \
OPEN DOWN VERT SPLT __UP SHUT; do OPEN DOWN VERT SPLT __UP SHUT; do
value="$(spcd_os_printenv "SPCD_${variable}")" spcd_wpm__value="$(spcd_os_printenv "SPCD_${spcd_wpm__variable}")"
text="${text}${value} spcd_wpm__text="${spcd_wpm__text}${spcd_wpm__value}
" "
done done
index=$((__SPCD_STEP_1_INDEX + 1)) spcd_wpm__index=$((__SPCD_STEP_1_INDEX + 1))
for 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 "${root}/env.py" "${text} spcd_os_write "${spcd_wpm__root}/env.py" "${spcd_wpm__text}
SPCD_STEP = ${index} SPCD_STEP = ${spcd_wpm__index}
" "
done done
} }
spcd_step__python_switch() { spcd_step__python_switch() {
spcd_step "Switch" spcd_step "Switch"
local name path spcd_stp__name="$(basename "${SPCD_GIT_SPCD}")"
name="$(basename "${SPCD_GIT_SPCD}")" spcd_stp__path="$(realpath "${0}")"
path="$(realpath "${0}")"
echo "\ echo "\
${path} ${spcd_stp__path}
${SPCD_PYTHON_ALIAS} / ${name}" ${SPCD_PYTHON_ALIAS} / ${spcd_stp__name}"
"${SPCD_PYTHON_ALIAS}" -m "${name}" "${SPCD_PYTHON_ALIAS}" -m "${spcd_stp__name}"
} }
# ╭──────╮ # ╭──────╮
# │ main │ # │ main │
# ╰──────╯ # ╰──────╯
spcd_test_local() {
local local_variable="KO!"
non_local_variable="OK"
}
spcd_main() { spcd_main() {
spcd_test_local
echo "local_variable = \"${local_variable}\""
echo "non_local_variable = \"${non_local_variable}\""
# environment # environment
spcd_txt_locale spcd_txt_locale
# #