Compare commits

...

7 commits

Author SHA1 Message Date
64c65167ba
cd_python_alias
Some checks failed
/ job (push) Failing after 5m4s
2024-05-23 16:04:04 +02:00
86902bea36
cd_openssl test 2024-05-23 15:58:11 +02:00
9838ed3a6c
cd_rm 2024-05-23 15:49:30 +02:00
ae496a66af
cd_sed 2024-05-23 15:47:50 +02:00
1f8d5b0a86
cd_split constant 2024-05-23 15:32:15 +02:00
117d073138
cd_step any 2024-05-23 15:22:38 +02:00
fb8ff9af61
comments 2024-05-23 15:20:25 +02:00

65
cd.sh
View file

@ -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
@ -106,9 +108,10 @@ 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"
# shared
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}")
CD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
@ -129,7 +132,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 +256,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 +289,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"
@ -294,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
@ -532,7 +536,7 @@ ${self}
${1}
"
"${CD_PYTHON_COMMAND}" -m "${1}" "${CD_STEP}" "${self}"
"${CD_PYTHON_ALIAS}" -m "${1}" "${CD_STEP}" "${self}"
}
# functions
@ -581,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
}
@ -603,46 +608,46 @@ cd_mkdir () {
cd_openssl () {
local file="${1}"
if [ "${file}" ] ; then
if [ -f "${file}" ] ; then
openssl x509 -noout -text -in "${file}" || exit
fi
}
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
}
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
}
cd_split () {
echo -n "\
─╌╌┄┄┈┈
${CD_SPLIT}
"
}
cd_step () {
if [ "${1}" ] ; then
CD_STEP=$((CD_STEP+1))
echo -n "\
╭─╌╌┄┄┈┈
${CD_STEP} ${1}
╰─╌╌┄┄┈┈
CD_STEP=$((CD_STEP+1))
echo -n "\
${CD_SPLIT}
${CD_STEP} ${@}
${CD_SPLIT}
"
fi
}
cd_write () {
@ -674,5 +679,7 @@ CD_PM_APT="apt"
CD_PM_DNF="dnf"
CD_PM_PACMAN="pacman"
CD_SPLIT="─╌╌┄┄┈┈"
# run
cd_main