diff --git a/cd.sh b/cd.sh index ee3241f..3466b53 100644 --- a/cd.sh +++ b/cd.sh @@ -38,7 +38,7 @@ cd_main () { cd_set_environment_variables () { cd_step "Set environment variables" - # set operating system id + # operating system CD_OS_ID="$(cd_grep_os ID)" case "${CD_OS_ID}" in "almalinux") CD_OS_ID="${CD_OS_ALMA}" ;; @@ -50,7 +50,6 @@ cd_set_environment_variables () { "ubuntu") CD_OS_ID="${CD_OS_UBUNTU}" ;; *) cd_error_os "CD_OS_ID" ;; esac - # set operating system version case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_ARCH}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") CD_OS_VERSION=$(cd_grep_os VERSION_ID \ @@ -64,7 +63,6 @@ cd_set_environment_variables () { CD_OS_VERSION="$(cd_grep_os VERSION_CODENAME)" ;; esac - # check operating system version case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_ROCKY}") case "${CD_OS_VERSION}" in @@ -108,10 +106,9 @@ cd_set_environment_variables () { CD_DNS_FILE="/etc/resolv.conf" CD_PKG_CA="ca-certificates" CD_PKG_GIT="git" - CD_PYTHON_ALIAS="python3" cd_split - cd_echo "CD_DNS_FILE" "CD_PKG_CA" "CD_PKG_GIT" "CD_PYTHON_ALIAS" - # set ca command & root + cd_echo "CD_DNS_FILE" "CD_PKG_CA" "CD_PKG_GIT" + # shared case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") CD_CA_ROOT="/etc/pki/ca-trust/source/anchors" @@ -132,7 +129,7 @@ cd_set_environment_variables () { esac cd_split cd_echo "CD_CA_ROOT" "CD_CMD_CA" - # set package manager + # common case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") CD_PM="${CD_PM_DNF}" @@ -256,7 +253,7 @@ Dir::Etc::SourceParts \"\"; esac cd_split cd_echo "CD_URL_DEFAULT" "CD_URL_CHOSEN" - # set python command & package + # python case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_ROCKY}") CD_PYTHON_COMMAND="python3.11" @@ -289,7 +286,6 @@ Dir::Etc::SourceParts \"\"; CD_PYTHON_PACKAGE="python3" ;; esac - # set python packages case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") CD_PYTHON_PACKAGES="/usr/lib64/${CD_PYTHON_COMMAND}/site-packages" @@ -298,7 +294,7 @@ Dir::Etc::SourceParts \"\"; CD_PYTHON_PACKAGES="/usr/lib/${CD_PYTHON_COMMAND}/site-packages" ;; "${CD_OS_DEBIAN}"|"${CD_OS_UBUNTU}") - CD_PYTHON_PACKAGES="/usr/lib/${CD_PYTHON_ALIAS}/dist-packages" + CD_PYTHON_PACKAGES="/usr/lib/python3/dist-packages" ;; esac cd_split @@ -536,7 +532,7 @@ ${self} ↓ ${1} " - "${CD_PYTHON_ALIAS}" -m "${1}" "${CD_STEP}" "${self}" + "${CD_PYTHON_COMMAND}" -m "${1}" "${CD_STEP}" "${self}" } # functions @@ -585,10 +581,9 @@ cd_install_package () { } cd_ln_python () { -local command="${1}" - if [ "${command}" ] ; then - echo "${CD_PYTHON_ALIAS} → ${command}" - ln -f -s "${command}" "/usr/bin/${CD_PYTHON_ALIAS}" || exit + if [ "${1}" ] ; then + echo "python3 → ${1}" + ln -f -s "${1}" "/usr/bin/python3" || exit fi } @@ -608,46 +603,46 @@ cd_mkdir () { cd_openssl () { local file="${1}" - if [ -f "${file}" ] ; then + if [ "${file}" ] ; then openssl x509 -noout -text -in "${file}" || exit fi } cd_rm () { -local path="${1}" - if [ -e "${path}" ] ; then - echo "← ${path}" - rm -r "${path}" || exit + if [ -e "${1}" ] ; then + echo "← ${1}" + rm -r "${1}" || exit fi } cd_sed () { local expression -local file="${1}" -shift - if [ -f "${file}" ] ; then - cd_cat "${file}" +local file + if [ -f "${1}" ] ; then + file="${1}" + shift for expression in "${@}" ; do - sed --in-place "s${expression}g" "${file}" \ - && cd_cat "${file}" \ - || exit + sed --in-place "s${expression}g" "${file}" || exit done + cd_cat "${file}" fi } cd_split () { echo -n "\ -╶${CD_SPLIT} +╶─╌╌┄┄┈┈ " } cd_step () { - CD_STEP=$((CD_STEP+1)) - echo -n "\ -╭${CD_SPLIT} -│ ${CD_STEP} ${@} -╰${CD_SPLIT} + if [ "${1}" ] ; then + CD_STEP=$((CD_STEP+1)) + echo -n "\ +╭─╌╌┄┄┈┈ +│ ${CD_STEP} ${1} +╰─╌╌┄┄┈┈ " + fi } cd_write () { @@ -679,7 +674,5 @@ CD_PM_APT="apt" CD_PM_DNF="dnf" CD_PM_PACMAN="pacman" -CD_SPLIT="─╌╌┄┄┈┈" - # run cd_main