From fb8ff9af61290e15b980ba732fa5364d65edfab5 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 15:20:25 +0200 Subject: [PATCH 1/7] comments --- cd.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cd.sh b/cd.sh index 3466b53..f1b7806 100644 --- a/cd.sh +++ b/cd.sh @@ -38,7 +38,7 @@ cd_main () { cd_set_environment_variables () { cd_step "Set environment variables" - # operating system + # set operating system id CD_OS_ID="$(cd_grep_os ID)" case "${CD_OS_ID}" in "almalinux") CD_OS_ID="${CD_OS_ALMA}" ;; @@ -50,6 +50,7 @@ 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 \ @@ -63,6 +64,7 @@ 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,7 +110,7 @@ cd_set_environment_variables () { CD_PKG_GIT="git" cd_split cd_echo "CD_DNS_FILE" "CD_PKG_CA" "CD_PKG_GIT" - # shared + # set ca command & root case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") CD_CA_ROOT="/etc/pki/ca-trust/source/anchors" @@ -129,7 +131,7 @@ cd_set_environment_variables () { esac cd_split cd_echo "CD_CA_ROOT" "CD_CMD_CA" - # common + # set package manager case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") CD_PM="${CD_PM_DNF}" @@ -253,7 +255,7 @@ Dir::Etc::SourceParts \"\"; esac cd_split cd_echo "CD_URL_DEFAULT" "CD_URL_CHOSEN" - # python + # set python command & package case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_ROCKY}") CD_PYTHON_COMMAND="python3.11" @@ -286,6 +288,7 @@ 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" From 117d073138d91542ad6b732c1b183305a990f59a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 15:22:38 +0200 Subject: [PATCH 2/7] cd_step any --- cd.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cd.sh b/cd.sh index f1b7806..6a9b219 100644 --- a/cd.sh +++ b/cd.sh @@ -638,14 +638,12 @@ cd_split () { } cd_step () { - if [ "${1}" ] ; then - CD_STEP=$((CD_STEP+1)) - echo -n "\ + CD_STEP=$((CD_STEP+1)) + echo -n "\ ╭─╌╌┄┄┈┈ -│ ${CD_STEP} ${1} +│ ${CD_STEP} ${@} ╰─╌╌┄┄┈┈ " - fi } cd_write () { From 1f8d5b0a8652ac60e06d0acc17d60551f7b42673 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 15:32:15 +0200 Subject: [PATCH 3/7] cd_split constant --- cd.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cd.sh b/cd.sh index 6a9b219..fff9929 100644 --- a/cd.sh +++ b/cd.sh @@ -633,16 +633,16 @@ local file cd_split () { echo -n "\ -╶─╌╌┄┄┈┈ +╶${CD_SPLIT} " } cd_step () { CD_STEP=$((CD_STEP+1)) echo -n "\ -╭─╌╌┄┄┈┈ +╭${CD_SPLIT} │ ${CD_STEP} ${@} -╰─╌╌┄┄┈┈ +╰${CD_SPLIT} " } @@ -675,5 +675,7 @@ CD_PM_APT="apt" CD_PM_DNF="dnf" CD_PM_PACMAN="pacman" +CD_SPLIT="─╌╌┄┄┈┈" + # run cd_main From ae496a66afd692d166edcf239b5fdc2e3ed9a952 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 15:47:50 +0200 Subject: [PATCH 4/7] cd_sed --- cd.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cd.sh b/cd.sh index fff9929..e8da6a4 100644 --- a/cd.sh +++ b/cd.sh @@ -620,14 +620,15 @@ cd_rm () { cd_sed () { local expression -local file - if [ -f "${1}" ] ; then - file="${1}" - shift - for expression in "${@}" ; do - sed --in-place "s${expression}g" "${file}" || exit - done +local file="${1}" +shift + if [ -f "${file}" ] ; then cd_cat "${file}" + for expression in "${@}" ; do + sed --in-place "s${expression}g" "${file}" \ + && cd_cat "${file}" \ + || exit + done fi } From 9838ed3a6c3bb307e2ada30eba8d2082966240c5 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 15:49:30 +0200 Subject: [PATCH 5/7] cd_rm --- cd.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cd.sh b/cd.sh index e8da6a4..e2b9b3b 100644 --- a/cd.sh +++ b/cd.sh @@ -612,9 +612,10 @@ local file="${1}" } cd_rm () { - if [ -e "${1}" ] ; then - echo "← ${1}" - rm -r "${1}" || exit +local path="${1}" + if [ -e "${path}" ] ; then + echo "← ${path}" + rm -r "${path}" || exit fi } From 86902bea36972e5068adc4a52410394e3fde3f9c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 15:58:11 +0200 Subject: [PATCH 6/7] cd_openssl test --- cd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cd.sh b/cd.sh index e2b9b3b..2a5fe85 100644 --- a/cd.sh +++ b/cd.sh @@ -606,7 +606,7 @@ cd_mkdir () { cd_openssl () { local file="${1}" - if [ "${file}" ] ; then + if [ -f "${file}" ] ; then openssl x509 -noout -text -in "${file}" || exit fi } From 64c65167bacf2ba9b1891ea8ac141189918b5a06 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 23 May 2024 16:04:04 +0200 Subject: [PATCH 7/7] cd_python_alias --- cd.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cd.sh b/cd.sh index 2a5fe85..ee3241f 100644 --- a/cd.sh +++ b/cd.sh @@ -108,8 +108,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_echo "CD_DNS_FILE" "CD_PKG_CA" "CD_PKG_GIT" "CD_PYTHON_ALIAS" # set ca command & root case "${CD_OS_ID}" in "${CD_OS_ALMA}"|"${CD_OS_FEDORA}"|"${CD_OS_ROCKY}") @@ -297,7 +298,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/python3/dist-packages" + CD_PYTHON_PACKAGES="/usr/lib/${CD_PYTHON_ALIAS}/dist-packages" ;; esac cd_split @@ -535,7 +536,7 @@ ${self} ↓ ${1} " - "${CD_PYTHON_COMMAND}" -m "${1}" "${CD_STEP}" "${self}" + "${CD_PYTHON_ALIAS}" -m "${1}" "${CD_STEP}" "${self}" } # functions @@ -584,9 +585,10 @@ cd_install_package () { } cd_ln_python () { - if [ "${1}" ] ; then - echo "python3 → ${1}" - ln -f -s "${1}" "/usr/bin/python3" || exit +local command="${1}" + if [ "${command}" ] ; then + echo "${CD_PYTHON_ALIAS} → ${command}" + ln -f -s "${command}" "/usr/bin/${CD_PYTHON_ALIAS}" || exit fi }