2024-04-27 15:47:23 +00:00
|
|
|
#! /usr/bin/env sh
|
2024-04-26 13:38:22 +00:00
|
|
|
|
2024-05-02 08:27:18 +00:00
|
|
|
# defaults
|
|
|
|
CD_DEFAULT_DNS="\
|
2024-04-29 13:10:51 +00:00
|
|
|
9.9.9.9 \
|
|
|
|
"
|
2024-05-02 08:27:18 +00:00
|
|
|
|
2024-04-29 13:14:49 +00:00
|
|
|
CD_PYTHON_MODULES="\
|
|
|
|
cd \
|
|
|
|
rwx \
|
|
|
|
"
|
2024-04-26 11:38:38 +00:00
|
|
|
|
2024-05-02 08:19:18 +00:00
|
|
|
# main
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_main () {
|
2024-04-27 15:36:14 +00:00
|
|
|
cd_set_environment
|
2024-05-02 08:27:18 +00:00
|
|
|
cd_set_dns_resolving
|
2024-04-27 15:36:14 +00:00
|
|
|
cd_set_packages_repositories
|
|
|
|
cd_set_packages_configuration
|
2024-04-30 11:46:23 +00:00
|
|
|
cd_write_ca_certificates
|
2024-05-02 06:38:49 +00:00
|
|
|
cd_set_https_verification_off
|
2024-04-27 15:36:14 +00:00
|
|
|
cd_update_packages_catalog
|
|
|
|
cd_install_packages_tools
|
2024-04-30 10:31:56 +00:00
|
|
|
cd_install_ca_certificates
|
|
|
|
cd_update_ca_certificates
|
2024-05-02 06:38:49 +00:00
|
|
|
cd_set_https_verification_on
|
2024-04-27 15:36:14 +00:00
|
|
|
cd_update_packages_catalog
|
|
|
|
cd_upgrade_packages
|
|
|
|
cd_install_git
|
|
|
|
cd_install_python
|
|
|
|
cd_clean_packages_cache
|
2024-04-29 13:14:49 +00:00
|
|
|
cd_install_python_modules ${CD_PYTHON_MODULES}
|
|
|
|
cd_execute_python_module ${CD_PYTHON_MODULES}
|
2024-04-27 15:36:14 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 08:19:18 +00:00
|
|
|
# steps
|
2024-04-27 19:47:02 +00:00
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_set_environment () {
|
2024-05-02 07:59:17 +00:00
|
|
|
local variable
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Set environment"
|
2024-04-29 15:37:15 +00:00
|
|
|
#
|
2024-04-29 15:53:51 +00:00
|
|
|
CD_CA_PACKAGE="ca-certificates"
|
2024-04-27 21:36:26 +00:00
|
|
|
CD_DNS_FILE="/etc/resolv.conf"
|
2024-04-29 15:25:30 +00:00
|
|
|
CD_GIT_PACKAGE="git"
|
2024-04-29 15:37:15 +00:00
|
|
|
CD_PYTHON_COMMAND="python3"
|
2024-04-28 10:44:28 +00:00
|
|
|
#
|
2024-04-27 09:59:30 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}")
|
2024-05-02 08:19:18 +00:00
|
|
|
case "${CD_OS_VERSION}" in
|
|
|
|
"bookworm"|"bullseye") cd_nop ;;
|
2024-05-02 08:33:34 +00:00
|
|
|
*) cd_error_os "CD_OS_VERSION" ;;
|
2024-05-02 08:19:18 +00:00
|
|
|
esac
|
2024-05-02 09:12:09 +00:00
|
|
|
CD_CA_ROOT="/usr/local/share/ca-certificates"
|
2024-04-29 15:23:10 +00:00
|
|
|
CD_PYTHON_PACKAGE="python3"
|
2024-04-27 21:36:26 +00:00
|
|
|
CD_PYTHON_PACKAGES="/usr/lib/python3/dist-packages"
|
2024-04-27 09:59:30 +00:00
|
|
|
;;
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_ALMA}")
|
2024-04-29 15:23:10 +00:00
|
|
|
case "${CD_OS_VERSION}" in
|
2024-05-02 09:12:09 +00:00
|
|
|
"8"|"9") cd_nop ;;
|
2024-05-02 08:33:34 +00:00
|
|
|
*) cd_error_os "CD_OS_VERSION" ;;
|
2024-04-29 15:23:10 +00:00
|
|
|
esac
|
2024-05-02 07:59:17 +00:00
|
|
|
CD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
|
2024-05-02 09:12:09 +00:00
|
|
|
CD_PYTHON_PACKAGE="python3.11"
|
|
|
|
CD_PYTHON_PACKAGES="/usr/lib64/python3.11/site-packages"
|
2024-04-29 15:23:10 +00:00
|
|
|
;;
|
2024-05-02 08:33:34 +00:00
|
|
|
*) cd_error_os "CD_OS_NAME" ;;
|
2024-04-27 09:59:30 +00:00
|
|
|
esac
|
2024-04-29 08:58:37 +00:00
|
|
|
# ci / github
|
|
|
|
if [ "${GITHUB_ACTIONS}" ] ; then
|
|
|
|
CD_SERVER_URL="${GITHUB_SERVER_URL}"
|
|
|
|
CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
|
2024-04-29 10:15:49 +00:00
|
|
|
CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
|
|
|
|
CD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
|
2024-04-29 08:58:37 +00:00
|
|
|
# ci / gitlab
|
|
|
|
elif [ "${GITLAB_CI}" ] ; then
|
|
|
|
CD_SERVER_URL="${CI_SERVER_URL}"
|
|
|
|
CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
|
2024-04-29 10:15:49 +00:00
|
|
|
CD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")"
|
|
|
|
CD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
|
2024-04-29 08:58:37 +00:00
|
|
|
# ci / none
|
2024-04-27 09:59:30 +00:00
|
|
|
else
|
2024-04-29 09:08:29 +00:00
|
|
|
cd_error_ci "ø"
|
2024-04-27 09:59:30 +00:00
|
|
|
fi
|
2024-04-29 08:58:37 +00:00
|
|
|
#
|
2024-04-29 09:08:29 +00:00
|
|
|
[ "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL"
|
|
|
|
[ "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP"
|
2024-04-29 10:15:49 +00:00
|
|
|
[ "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME"
|
|
|
|
[ "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH"
|
2024-04-29 08:58:37 +00:00
|
|
|
#
|
|
|
|
CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}"
|
2024-04-27 09:56:16 +00:00
|
|
|
CD_PROJECT_URL="${CD_PROJECTS_URL}/${CD_PROJECT_NAME}"
|
2024-04-28 10:44:28 +00:00
|
|
|
#
|
2024-05-02 07:59:17 +00:00
|
|
|
cd_echo "CD_OS_NAME" "CD_OS_VERSION"
|
|
|
|
cd_split
|
|
|
|
cd_echo "CD_DNS_FILE"
|
|
|
|
cd_split
|
|
|
|
cd_echo "CD_PYTHON_PACKAGE" "CD_PYTHON_PACKAGES" "CD_CA_ROOT"
|
|
|
|
cd_split
|
|
|
|
cd_echo "CD_SERVER_URL" \
|
|
|
|
"CD_PROJECTS_GROUP" "CD_PROJECT_NAME" "CD_PROJECT_BRANCH"
|
|
|
|
cd_split
|
|
|
|
cd_echo "CD_PROJECTS_URL" "CD_PROJECT_URL"
|
2024-04-27 09:56:16 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_set_dns_resolving () {
|
2024-04-26 12:18:44 +00:00
|
|
|
local server
|
2024-05-02 08:27:18 +00:00
|
|
|
local servers
|
2024-04-27 21:36:26 +00:00
|
|
|
local text=""
|
|
|
|
cd_step "Set DNS resolving"
|
2024-05-02 08:57:24 +00:00
|
|
|
[ "${CD_DNS}" ] && servers="${CD_DNS}" || servers="${CD_DEFAULT_DNS}"
|
2024-05-02 08:27:18 +00:00
|
|
|
for server in ${servers} ; do
|
2024-04-27 15:40:52 +00:00
|
|
|
text="${text}nameserver ${server}
|
2024-04-26 12:18:44 +00:00
|
|
|
"
|
|
|
|
done
|
2024-04-26 14:29:40 +00:00
|
|
|
cd_write "${CD_DNS_FILE}" "${text}"
|
2024-04-26 12:18:44 +00:00
|
|
|
}
|
2024-03-25 11:26:38 +00:00
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_set_packages_repositories () {
|
2024-04-29 20:41:28 +00:00
|
|
|
local expression
|
|
|
|
local file
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Set packages repositories"
|
2024-04-26 14:13:35 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}")
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_write "/etc/apt/sources.list" "\
|
2024-05-02 08:19:18 +00:00
|
|
|
deb https://deb.debian.org/debian ${CD_OS_VERSION} main
|
|
|
|
deb https://deb.debian.org/debian ${CD_OS_VERSION}-backports main
|
|
|
|
deb https://deb.debian.org/debian ${CD_OS_VERSION}-updates main
|
|
|
|
deb https://deb.debian.org/debian-security ${CD_OS_VERSION}-security main
|
2024-04-26 14:13:35 +00:00
|
|
|
"
|
|
|
|
;;
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_ALMA}")
|
2024-04-29 20:41:28 +00:00
|
|
|
file="/etc/yum.repos.d/almalinux.repo"
|
2024-04-29 21:07:52 +00:00
|
|
|
cd_sed "${file}" "|^m|# m|" "|^# b|b|"
|
2024-04-29 20:43:51 +00:00
|
|
|
cd_cat "${file}"
|
2024-04-29 20:41:28 +00:00
|
|
|
;;
|
2024-04-26 14:13:35 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_set_packages_configuration () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Set packages configuration"
|
2024-04-26 13:54:37 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}")
|
2024-04-27 21:36:26 +00:00
|
|
|
export DEBIAN_FRONTEND="noninteractive"
|
|
|
|
cd_write "/etc/apt/apt.conf.d/apt.conf" "\
|
2024-04-25 13:33:58 +00:00
|
|
|
Acquire::Check-Valid-Until True;
|
2024-04-05 15:49:25 +00:00
|
|
|
APT::Get::Show-Versions True;
|
2024-04-08 08:07:37 +00:00
|
|
|
APT::Install-Recommends False;
|
|
|
|
APT::Install-Suggests False;
|
2024-04-26 14:03:17 +00:00
|
|
|
Dir::Etc::SourceParts \"\";
|
2024-04-26 13:54:37 +00:00
|
|
|
"
|
|
|
|
;;
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_ALMA}") cd_mkdir "/etc/dnf/dnf.conf.d" ;;
|
2024-04-26 13:54:37 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-30 11:46:23 +00:00
|
|
|
cd_write_ca_certificates () {
|
|
|
|
local index
|
|
|
|
local text
|
|
|
|
cd_step "Copy CA"
|
2024-05-02 07:33:50 +00:00
|
|
|
cd_mkdir "${CD_CA_ROOT}"
|
2024-04-30 11:46:23 +00:00
|
|
|
index=1
|
|
|
|
eval "text=\${CD_CA_${index}}"
|
|
|
|
while [ "${text}" ] ; do
|
2024-05-02 07:33:50 +00:00
|
|
|
cd_write "${CD_CA_ROOT}/${index}.crt" "${text}"
|
2024-05-01 18:23:33 +00:00
|
|
|
CD_CA=$((CD_CA+1))
|
2024-04-30 11:46:23 +00:00
|
|
|
index=$((index+1))
|
|
|
|
eval "text=\${CD_CA_${index}}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_set_https_verification_off () {
|
2024-05-02 06:38:49 +00:00
|
|
|
if [ "${CD_CA}" ] ; then
|
|
|
|
cd_step "Set HTTPS verification off"
|
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}")
|
2024-05-02 06:38:49 +00:00
|
|
|
cd_write "/etc/apt/apt.conf.d/https" "\
|
2024-04-26 14:23:30 +00:00
|
|
|
Acquire::https::Verify-Peer False;
|
|
|
|
"
|
2024-05-02 06:38:49 +00:00
|
|
|
;;
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_ALMA}")
|
2024-05-02 06:38:49 +00:00
|
|
|
cd_write "/etc/dnf/dnf.conf.d/https.conf" "\
|
2024-04-29 17:57:18 +00:00
|
|
|
sslverify=False
|
|
|
|
"
|
2024-05-02 06:38:49 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2024-04-26 14:23:30 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_update_packages_catalog () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Update packages catalog"
|
2024-04-26 14:27:36 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") apt-get update || exit ;;
|
|
|
|
"${CD_OS_ALMA}") dnf makecache || exit ;;
|
2024-04-26 14:27:36 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-27 19:36:51 +00:00
|
|
|
cd_install_packages_tools () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Install packages tools"
|
2024-04-27 19:36:51 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") cd_install_package "apt-utils" ;;
|
|
|
|
"${CD_OS_ALMA}") echo "TODO" ;;
|
2024-04-27 19:36:51 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-30 10:31:56 +00:00
|
|
|
cd_install_ca_certificates () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Install CA"
|
2024-04-29 15:53:51 +00:00
|
|
|
cd_install_package "${CD_CA_PACKAGE}"
|
2024-04-26 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2024-04-30 10:31:56 +00:00
|
|
|
cd_update_ca_certificates () {
|
2024-04-27 21:58:48 +00:00
|
|
|
cd_step "Update CA"
|
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") update-ca-certificates || exit ;;
|
|
|
|
"${CD_OS_ALMA}") update-ca-trust || exit ;;
|
2024-04-27 21:58:48 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-27 19:40:50 +00:00
|
|
|
cd_set_https_verification_on () {
|
2024-05-02 06:38:49 +00:00
|
|
|
if [ "${CD_CA}" ] ; then
|
|
|
|
cd_step "Set HTTPS verification on"
|
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") cd_rm "/etc/apt/apt.conf.d/https" ;;
|
|
|
|
"${CD_OS_ALMA}") cd_rm "/etc/dnf/dnf.conf.d/https.conf" ;;
|
2024-05-02 06:38:49 +00:00
|
|
|
esac
|
|
|
|
fi
|
2024-04-26 14:50:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 19:42:29 +00:00
|
|
|
cd_upgrade_packages () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Upgrade packages"
|
2024-04-26 14:35:15 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") apt-get upgrade --assume-yes || exit ;;
|
|
|
|
"${CD_OS_ALMA}") dnf upgrade --assumeyes || exit ;;
|
2024-04-26 14:35:15 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-27 19:42:29 +00:00
|
|
|
cd_install_git () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Install Git"
|
2024-04-29 15:25:30 +00:00
|
|
|
cd_install_package "${CD_GIT_PACKAGE}"
|
2024-04-26 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 19:42:29 +00:00
|
|
|
cd_install_python () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Install Python"
|
2024-04-29 15:58:57 +00:00
|
|
|
cd_install_package "${CD_PYTHON_PACKAGE}"
|
2024-04-26 14:39:24 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 17:56:19 +00:00
|
|
|
cd_clean_packages_cache () {
|
2024-04-27 21:36:26 +00:00
|
|
|
cd_step "Clean packages cache"
|
2024-04-26 14:53:41 +00:00
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") apt-get clean || exit ;;
|
|
|
|
"${CD_OS_ALMA}") dnf clean all || exit ;;
|
2024-04-26 14:53:41 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-04-28 21:29:31 +00:00
|
|
|
cd_install_python_modules () {
|
|
|
|
local path
|
2024-04-26 18:09:11 +00:00
|
|
|
local repository
|
|
|
|
local root
|
2024-04-28 21:29:31 +00:00
|
|
|
local url
|
|
|
|
cd_step "Install Python modules"
|
2024-04-26 18:09:11 +00:00
|
|
|
root="$(mktemp --directory)" || exit
|
2024-04-28 21:41:12 +00:00
|
|
|
echo "${root}"
|
2024-04-27 15:47:23 +00:00
|
|
|
for repository in "${@}" ; do
|
2024-04-30 11:45:05 +00:00
|
|
|
cd_split
|
2024-04-28 21:29:31 +00:00
|
|
|
url="${CD_PROJECTS_URL}/${repository}"
|
2024-05-01 18:33:24 +00:00
|
|
|
echo -n "\
|
2024-04-28 21:29:31 +00:00
|
|
|
${url}
|
|
|
|
↓
|
|
|
|
"
|
2024-04-26 18:09:11 +00:00
|
|
|
git clone \
|
2024-04-28 21:29:31 +00:00
|
|
|
"${url}" "${root}/${repository}" \
|
2024-04-26 18:29:26 +00:00
|
|
|
|| exit
|
2024-04-28 21:29:31 +00:00
|
|
|
path="${root}/${repository}/${repository}"
|
|
|
|
echo -n "\
|
|
|
|
${path}
|
|
|
|
↓
|
|
|
|
${CD_PYTHON_PACKAGES}
|
|
|
|
"
|
2024-04-26 19:30:36 +00:00
|
|
|
cp --recursive \
|
2024-04-28 21:29:31 +00:00
|
|
|
"${path}" "${CD_PYTHON_PACKAGES}" \
|
2024-04-26 18:29:26 +00:00
|
|
|
|| exit
|
2024-04-26 18:09:11 +00:00
|
|
|
done
|
2024-05-01 18:33:24 +00:00
|
|
|
cd_split
|
2024-04-28 21:29:31 +00:00
|
|
|
cd_rm "${root}"
|
2024-04-26 16:54:09 +00:00
|
|
|
}
|
|
|
|
|
2024-04-28 13:42:36 +00:00
|
|
|
cd_execute_python_module () {
|
|
|
|
local self
|
2024-04-28 15:49:06 +00:00
|
|
|
cd_step "Execute Python module"
|
2024-04-28 13:42:36 +00:00
|
|
|
self="$(realpath "${0}")"
|
|
|
|
echo -n "\
|
|
|
|
${self}
|
|
|
|
↓
|
|
|
|
${1}
|
|
|
|
"
|
2024-04-28 15:49:06 +00:00
|
|
|
"${CD_PYTHON_COMMAND}" -m "${1}" "${CD_STEP}" "${self}"
|
2024-04-26 17:00:43 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 08:19:18 +00:00
|
|
|
# functions
|
2024-04-27 19:38:43 +00:00
|
|
|
|
2024-04-28 10:35:43 +00:00
|
|
|
cd_cat () {
|
|
|
|
if [ -f "${1}" ] ; then
|
2024-04-30 11:44:12 +00:00
|
|
|
echo "╭╴$(realpath "${1}")"
|
2024-04-28 11:00:18 +00:00
|
|
|
cat "${1}" || exit
|
2024-04-28 10:35:43 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-05-02 07:59:17 +00:00
|
|
|
cd_echo () {
|
|
|
|
local name
|
|
|
|
if [ "${1}" ] ; then
|
|
|
|
for name in "${@}" ; do
|
|
|
|
eval "echo ${name}=\${${name}}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-04-29 09:01:48 +00:00
|
|
|
cd_error_ci () {
|
|
|
|
echo "× CI: ${1}"
|
|
|
|
exit 1
|
|
|
|
}
|
2024-05-02 08:33:34 +00:00
|
|
|
|
2024-04-29 09:01:48 +00:00
|
|
|
cd_error_os () {
|
2024-05-02 08:33:34 +00:00
|
|
|
local variable="${1}"
|
|
|
|
echo -n "× OS: "
|
|
|
|
cd_echo "${variable}"
|
2024-04-29 09:01:48 +00:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
2024-05-02 14:46:08 +00:00
|
|
|
cd_get_string () {
|
|
|
|
[ "${1}" ] && echo "${1}" | cut -d "=" -f 2 | cut -d "\"" -f 2
|
|
|
|
}
|
|
|
|
|
2024-04-27 19:38:43 +00:00
|
|
|
cd_install_package () {
|
|
|
|
if [ "${1}" ] ; then
|
|
|
|
case "${CD_OS_NAME}" in
|
2024-05-02 09:10:54 +00:00
|
|
|
"${CD_OS_DEBIAN}") apt-get install --assume-yes "${1}" || exit ;;
|
|
|
|
"${CD_OS_ALMA}") dnf install --assumeyes "${1}" || exit ;;
|
2024-04-27 19:38:43 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-04-29 18:16:14 +00:00
|
|
|
cd_mkdir () {
|
|
|
|
if [ "${1}" ] ; then
|
|
|
|
echo "→ ${1}"
|
|
|
|
mkdir --parents "${1}" || exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-05-02 08:28:34 +00:00
|
|
|
cd_nop () { true ; }
|
2024-05-02 08:19:18 +00:00
|
|
|
|
2024-04-28 11:00:18 +00:00
|
|
|
cd_rm () {
|
2024-04-28 21:29:31 +00:00
|
|
|
if [ -e "${1}" ] ; then
|
2024-04-29 18:16:14 +00:00
|
|
|
echo "← $(realpath "${1}")"
|
2024-04-28 21:29:31 +00:00
|
|
|
rm --recursive "${1}" || exit
|
2024-04-28 11:00:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-04-29 21:07:52 +00:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-04-30 10:36:33 +00:00
|
|
|
cd_split () {
|
|
|
|
echo -n "\
|
|
|
|
╶─╌╌┄┄┈┈
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2024-04-27 19:24:59 +00:00
|
|
|
cd_step () {
|
|
|
|
if [ "${1}" ] ; then
|
|
|
|
CD_STEP=$((CD_STEP+1))
|
2024-04-29 10:51:48 +00:00
|
|
|
echo -n "\
|
2024-04-30 10:36:33 +00:00
|
|
|
╭─╌╌┄┄┈┈
|
2024-04-29 10:23:22 +00:00
|
|
|
│ ${CD_STEP} ${1}
|
2024-04-30 10:36:33 +00:00
|
|
|
╰─╌╌┄┄┈┈
|
2024-04-27 19:24:59 +00:00
|
|
|
"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cd_write () {
|
|
|
|
local file="${1}"
|
|
|
|
local text="${2}"
|
|
|
|
if [ "${file}" ] ; then
|
2024-05-02 08:29:43 +00:00
|
|
|
echo -n "${text}" > "${file}" || exit
|
2024-04-29 18:07:17 +00:00
|
|
|
cd_cat "${file}"
|
2024-04-27 19:24:59 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-05-02 09:10:54 +00:00
|
|
|
# constants
|
|
|
|
|
|
|
|
CD_OS_ALMA="alma"
|
|
|
|
CD_OS_DEBIAN="debian"
|
|
|
|
|
2024-05-02 08:19:18 +00:00
|
|
|
# run
|
2024-04-29 13:14:49 +00:00
|
|
|
cd_main
|