This commit is contained in:
Marc Beninca 2024-06-21 13:20:20 +02:00
parent 5486b279a1
commit 128c4ebb5c
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

498
cidd.sh
View file

@ -8,43 +8,43 @@
[ -n "${CIDD_GIT_PARENT}" ] || CIDD_GIT_PARENT="rwx" [ -n "${CIDD_GIT_PARENT}" ] || CIDD_GIT_PARENT="rwx"
# main # main
cd_main () { cidd_main () {
cd_set_environment_variables cidd_set_environment_variables
cd_set_packages_repositories cidd_set_packages_repositories
cd_set_packages_configuration cidd_set_packages_configuration
# #
cd_list_working_directory cidd_list_working_directory
cd_set_https_verification_off cidd_set_https_verification_off
cd_set_dns_resolving cidd_set_dns_resolving
cd_update_packages_catalog cidd_update_packages_catalog
cd_install_packages_tools cidd_install_packages_tools
cd_install_ca_certificates cidd_install_ca_certificates
cd_write_ca_certificates cidd_write_ca_certificates
cd_update_ca_certificates cidd_update_ca_certificates
cd_set_https_verification_on cidd_set_https_verification_on
cd_update_packages_catalog cidd_update_packages_catalog
cd_upgrade_packages cidd_upgrade_packages
cd_install_git cidd_install_git
cd_install_python cidd_install_python
# TODO move to Python # TODO move to Python
cd_install_rsync cidd_install_rsync
# TODO move to Python # TODO move to Python
cd_install_ssh cidd_install_ssh
cd_clean_packages_cache cidd_clean_packages_cache
cd_install_python_modules cidd_install_python_modules
cd_write_python_module cidd_write_python_module
cd_switch_to_python "${@}" cidd_switch_to_python "${@}"
} }
# steps # steps
cd_set_environment_variables () { cidd_set_environment_variables () {
cd_step "Set environment variables" cidd_step "Set environment variables"
# set path # set path
CIDD_PATH="$(realpath "${0}")" CIDD_PATH="$(realpath "${0}")"
cd_echo "CIDD_PATH" cidd_echo "CIDD_PATH"
# set operating system id # set operating system id
CIDD_OS_ID="$(cd_grep_os ID)" CIDD_OS_ID="$(cidd_grep_os ID)"
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"almalinux") CIDD_OS_ID="${CIDD_OS_ALMA}" ;; "almalinux") CIDD_OS_ID="${CIDD_OS_ALMA}" ;;
"alpine") CIDD_OS_ID="${CIDD_OS_ALPINE}" ;; "alpine") CIDD_OS_ID="${CIDD_OS_ALPINE}" ;;
@ -53,20 +53,20 @@ cd_set_environment_variables () {
"fedora") CIDD_OS_ID="${CIDD_OS_FEDORA}" ;; "fedora") CIDD_OS_ID="${CIDD_OS_FEDORA}" ;;
"rocky") CIDD_OS_ID="${CIDD_OS_ROCKY}" ;; "rocky") CIDD_OS_ID="${CIDD_OS_ROCKY}" ;;
"ubuntu") CIDD_OS_ID="${CIDD_OS_UBUNTU}" ;; "ubuntu") CIDD_OS_ID="${CIDD_OS_UBUNTU}" ;;
*) cd_error_os "CIDD_OS_ID" ;; *) cidd_error_os "CIDD_OS_ID" ;;
esac esac
# set operating system version # set operating system version
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_ARCH}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}") "${CIDD_OS_ALMA}"|"${CIDD_OS_ARCH}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}")
CIDD_OS_VERSION=$(cd_grep_os VERSION_ID \ CIDD_OS_VERSION=$(cidd_grep_os VERSION_ID \
| sed "s|^\([0-9]\+\)\..*|\1|") | sed "s|^\([0-9]\+\)\..*|\1|")
;; ;;
"${CIDD_OS_ALPINE}") "${CIDD_OS_ALPINE}")
CIDD_OS_VERSION=$(cd_grep_os VERSION_ID \ CIDD_OS_VERSION=$(cidd_grep_os VERSION_ID \
| sed "s|^\([0-9]\+\.[0-9]\+\)\..*|\1|") | sed "s|^\([0-9]\+\.[0-9]\+\)\..*|\1|")
;; ;;
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}") "${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
CIDD_OS_VERSION="$(cd_grep_os VERSION_CODENAME)" CIDD_OS_VERSION="$(cidd_grep_os VERSION_CODENAME)"
;; ;;
*) *)
esac esac
@ -75,43 +75,43 @@ cd_set_environment_variables () {
"${CIDD_OS_ALMA}"|"${CIDD_OS_ROCKY}") "${CIDD_OS_ALMA}"|"${CIDD_OS_ROCKY}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"8"|"9") ;; "8"|"9") ;;
*) cd_error_os "CIDD_OS_VERSION" ;; *) cidd_error_os "CIDD_OS_VERSION" ;;
esac esac
;; ;;
"${CIDD_OS_ALPINE}") "${CIDD_OS_ALPINE}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"3.18"|"3.19") ;; "3.18"|"3.19") ;;
*) cd_error_os "CIDD_OS_VERSION" ;; *) cidd_error_os "CIDD_OS_VERSION" ;;
esac esac
;; ;;
"${CIDD_OS_ARCH}") "${CIDD_OS_ARCH}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"20231112"|"20240101") ;; "20231112"|"20240101") ;;
*) cd_error_os "CIDD_OS_VERSION" ;; *) cidd_error_os "CIDD_OS_VERSION" ;;
esac esac
;; ;;
"${CIDD_OS_DEBIAN}") "${CIDD_OS_DEBIAN}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"bookworm"|"bullseye") ;; "bookworm"|"bullseye") ;;
*) cd_error_os "CIDD_OS_VERSION" ;; *) cidd_error_os "CIDD_OS_VERSION" ;;
esac esac
;; ;;
"${CIDD_OS_FEDORA}") "${CIDD_OS_FEDORA}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"39"|"40") ;; "39"|"40") ;;
*) cd_error_os "CIDD_OS_VERSION" ;; *) cidd_error_os "CIDD_OS_VERSION" ;;
esac esac
;; ;;
"${CIDD_OS_UBUNTU}") "${CIDD_OS_UBUNTU}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"jammy"|"noble") ;; "jammy"|"noble") ;;
*) cd_error_os "CIDD_OS_VERSION" ;; *) cidd_error_os "CIDD_OS_VERSION" ;;
esac esac
;; ;;
*) *)
esac esac
cd_split cidd_split
cd_echo "CIDD_OS_ID" "CIDD_OS_VERSION" cidd_echo "CIDD_OS_ID" "CIDD_OS_VERSION"
# universal # universal
CIDD_DNS_FILE="/etc/resolv.conf" CIDD_DNS_FILE="/etc/resolv.conf"
CIDD_PKG_CA="ca-certificates" CIDD_PKG_CA="ca-certificates"
@ -119,8 +119,8 @@ cd_set_environment_variables () {
# TODO move to Python # TODO move to Python
CIDD_PKG_RSYNC="rsync" CIDD_PKG_RSYNC="rsync"
CIDD_PYTHON_ALIAS="python3" CIDD_PYTHON_ALIAS="python3"
cd_split cidd_split
cd_echo "CIDD_DNS_FILE" "CIDD_PKG_CA" "CIDD_PKG_GIT" "CIDD_PYTHON_ALIAS" cidd_echo "CIDD_DNS_FILE" "CIDD_PKG_CA" "CIDD_PKG_GIT" "CIDD_PYTHON_ALIAS"
# set ca command & root # set ca command & root
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}") "${CIDD_OS_ALMA}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}")
@ -141,8 +141,8 @@ cd_set_environment_variables () {
;; ;;
*) *)
esac esac
cd_split cidd_split
cd_echo "CIDD_CA_ROOT" "CIDD_CMD_CA" cidd_echo "CIDD_CA_ROOT" "CIDD_CMD_CA"
# set package manager # set package manager
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_ALPINE}") "${CIDD_OS_ALPINE}")
@ -159,8 +159,8 @@ cd_set_environment_variables () {
;; ;;
*) *)
esac esac
cd_split cidd_split
cd_echo "CIDD_PM" cidd_echo "CIDD_PM"
case "${CIDD_PM}" in case "${CIDD_PM}" in
"${CIDD_PM_DNF}") "${CIDD_PM_DNF}")
CIDD_PM_CLEAN="dnf clean all" CIDD_PM_CLEAN="dnf clean all"
@ -233,11 +233,11 @@ Acquire::https::Verify-Peer False;
;; ;;
*) *)
esac esac
cd_split cidd_split
cd_echo "CIDD_PM_CLEAN" \ cidd_echo "CIDD_PM_CLEAN" \
"CIDD_PM_INSTALL" "CIDD_PM_QUERY" "CIDD_PM_UPDATE" "CIDD_PM_UPGRADE" "CIDD_PM_INSTALL" "CIDD_PM_QUERY" "CIDD_PM_UPDATE" "CIDD_PM_UPGRADE"
cd_split cidd_split
cd_echo "CIDD_PKG_PKG" "CIDD_PM_CONF_PATH" "CIDD_PM_HTTPS_PATH" cidd_echo "CIDD_PKG_PKG" "CIDD_PM_CONF_PATH" "CIDD_PM_HTTPS_PATH"
# specific # specific
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}") "${CIDD_OS_ALMA}")
@ -292,8 +292,8 @@ Acquire::https::Verify-Peer False;
;; ;;
*) *)
esac esac
cd_split cidd_split
cd_echo "CIDD_URL_DEFAULT" "CIDD_URL_CHOSEN" cidd_echo "CIDD_URL_DEFAULT" "CIDD_URL_CHOSEN"
# set python command & package # set python command & package
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_ROCKY}") "${CIDD_OS_ALMA}"|"${CIDD_OS_ROCKY}")
@ -343,8 +343,8 @@ Acquire::https::Verify-Peer False;
;; ;;
*) *)
esac esac
cd_split cidd_split
cd_echo "CIDD_PYTHON_COMMAND" "CIDD_PYTHON_PACKAGE" "CIDD_PYTHON_PACKAGES" cidd_echo "CIDD_PYTHON_COMMAND" "CIDD_PYTHON_PACKAGE" "CIDD_PYTHON_PACKAGES"
# variables # variables
[ -n "${CIDD_CA_1}" ] && CIDD_CA=true [ -n "${CIDD_CA_1}" ] && CIDD_CA=true
# continuous integration platform # continuous integration platform
@ -353,55 +353,55 @@ Acquire::https::Verify-Peer False;
if [ -n "${GITHUB_SERVER_URL}" ] ; then if [ -n "${GITHUB_SERVER_URL}" ] ; then
CIDD_SERVER_URL="${GITHUB_SERVER_URL}" CIDD_SERVER_URL="${GITHUB_SERVER_URL}"
else else
cd_error_ci "GITHUB_SERVER_URL" cidd_error_ci "GITHUB_SERVER_URL"
fi fi
if [ -n "${GITHUB_REPOSITORY}" ] ; then if [ -n "${GITHUB_REPOSITORY}" ] ; then
CIDD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")" CIDD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
CIDD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" CIDD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
else else
cd_error_ci "GITHUB_REPOSITORY" cidd_error_ci "GITHUB_REPOSITORY"
fi fi
if [ -n "${GITHUB_REF_NAME}" ] ; then if [ -n "${GITHUB_REF_NAME}" ] ; then
CIDD_PROJECT_BRANCH="${GITHUB_REF_NAME}" CIDD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
else else
cd_error_ci "GITHUB_REF_NAME" cidd_error_ci "GITHUB_REF_NAME"
fi fi
elif [ -n "${GITLAB_CI}" ] ; then elif [ -n "${GITLAB_CI}" ] ; then
# gitlab # gitlab
if [ -n "${CI_SERVER_URL}" ] ; then if [ -n "${CI_SERVER_URL}" ] ; then
CIDD_SERVER_URL="${CI_SERVER_URL}" CIDD_SERVER_URL="${CI_SERVER_URL}"
else else
cd_error_ci "CI_SERVER_URL" cidd_error_ci "CI_SERVER_URL"
fi fi
if [ -n "${CI_PROJECT_PATH}" ] ; then if [ -n "${CI_PROJECT_PATH}" ] ; then
CIDD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")" CIDD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
CIDD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")" CIDD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")"
else else
cd_error_ci "CI_PROJECT_PATH" cidd_error_ci "CI_PROJECT_PATH"
fi fi
if [ -n "${CI_COMMIT_BRANCH}" ] ; then if [ -n "${CI_COMMIT_BRANCH}" ] ; then
CIDD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}" CIDD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
else else
cd_error_ci "CI_COMMIT_BRANCH" cidd_error_ci "CI_COMMIT_BRANCH"
fi fi
else else
# unsupported # unsupported
cd_error_ci "ø" cidd_error_ci "ø"
fi fi
[ -n "${CIDD_SERVER_URL}" ] || cd_error_ci "CIDD_SERVER_URL" [ -n "${CIDD_SERVER_URL}" ] || cidd_error_ci "CIDD_SERVER_URL"
[ -n "${CIDD_PROJECTS_GROUP}" ] || cd_error_ci "CIDD_PROJECTS_GROUP" [ -n "${CIDD_PROJECTS_GROUP}" ] || cidd_error_ci "CIDD_PROJECTS_GROUP"
[ -n "${CIDD_PROJECT_NAME}" ] || cd_error_ci "CIDD_PROJECT_NAME" [ -n "${CIDD_PROJECT_NAME}" ] || cidd_error_ci "CIDD_PROJECT_NAME"
[ -n "${CIDD_PROJECT_BRANCH}" ] || cd_error_ci "CIDD_PROJECT_BRANCH" [ -n "${CIDD_PROJECT_BRANCH}" ] || cidd_error_ci "CIDD_PROJECT_BRANCH"
# #
CIDD_PROJECTS_URL="${CIDD_SERVER_URL}/${CIDD_PROJECTS_GROUP}" CIDD_PROJECTS_URL="${CIDD_SERVER_URL}/${CIDD_PROJECTS_GROUP}"
# #
cd_split cidd_split
cd_echo "CIDD_CA" cidd_echo "CIDD_CA"
cd_split cidd_split
cd_echo "CIDD_SERVER_URL" \ cidd_echo "CIDD_SERVER_URL" \
"CIDD_PROJECTS_GROUP" "CIDD_PROJECT_NAME" "CIDD_PROJECT_BRANCH" "CIDD_PROJECTS_GROUP" "CIDD_PROJECT_NAME" "CIDD_PROJECT_BRANCH"
cd_split cidd_split
cd_echo "CIDD_PROJECTS_URL" cidd_echo "CIDD_PROJECTS_URL"
# TODO move to Python # TODO move to Python
case "${CIDD_PM}" in case "${CIDD_PM}" in
"${CIDD_PM_APK}"|"${CIDD_PM_APT}") CIDD_PKG_SSH="openssh-client" ;; "${CIDD_PM_APK}"|"${CIDD_PM_APT}") CIDD_PKG_SSH="openssh-client" ;;
@ -411,32 +411,32 @@ Acquire::https::Verify-Peer False;
esac esac
} }
cd_set_packages_repositories () { cidd_set_packages_repositories () {
cd_step "Set packages repositories" cidd_step "Set packages repositories"
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}") "${CIDD_OS_ALMA}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"8") \ "8") \
cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux.repo" ;; cidd_set_packages_repositories__file="/etc/yum.repos.d/almalinux.repo" ;;
"9") \ "9") \
cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux-baseos.repo" ;; cidd_set_packages_repositories__file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
*) *)
esac esac
cd_sed "${cd_set_packages_repositories__file}" \ cidd_sed "${cidd_set_packages_repositories__file}" \
"|^mirrorlist|# mirrorlist|" \ "|^mirrorlist|# mirrorlist|" \
"|${CIDD_URL_DEFAULT}|${CIDD_URL_CHOSEN}|" \ "|${CIDD_URL_DEFAULT}|${CIDD_URL_CHOSEN}|" \
"|^# baseurl|baseurl|" "|^# baseurl|baseurl|"
;; ;;
"${CIDD_OS_ALPINE}") "${CIDD_OS_ALPINE}")
cd_set_packages_repositories__file="/etc/apk/repositories" cidd_set_packages_repositories__file="/etc/apk/repositories"
cd_write "${cd_set_packages_repositories__file}" "\ cidd_write "${cidd_set_packages_repositories__file}" "\
${CIDD_URL_CHOSEN}/v${CIDD_OS_VERSION}/main ${CIDD_URL_CHOSEN}/v${CIDD_OS_VERSION}/main
${CIDD_URL_CHOSEN}/v${CIDD_OS_VERSION}/community ${CIDD_URL_CHOSEN}/v${CIDD_OS_VERSION}/community
" "
;; ;;
"${CIDD_OS_DEBIAN}") "${CIDD_OS_DEBIAN}")
cd_set_packages_repositories__file="/etc/apt/sources.list" cidd_set_packages_repositories__file="/etc/apt/sources.list"
cd_write "${cd_set_packages_repositories__file}" "\ cidd_write "${cidd_set_packages_repositories__file}" "\
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION} main deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION} main
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-backports main deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-backports main
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-updates main deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-updates main
@ -446,19 +446,19 @@ deb ${CIDD_URL_CHOSEN}-security ${CIDD_OS_VERSION}-security main
"${CIDD_OS_ROCKY}") "${CIDD_OS_ROCKY}")
case "${CIDD_OS_VERSION}" in case "${CIDD_OS_VERSION}" in
"8") \ "8") \
cd_set_packages_repositories__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;; cidd_set_packages_repositories__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;;
"9") \ "9") \
cd_set_packages_repositories__file="/etc/yum.repos.d/rocky.repo" ;; cidd_set_packages_repositories__file="/etc/yum.repos.d/rocky.repo" ;;
*) *)
esac esac
cd_sed "${cd_set_packages_repositories__file}" \ cidd_sed "${cidd_set_packages_repositories__file}" \
"|^mirrorlist|# mirrorlist|" \ "|^mirrorlist|# mirrorlist|" \
"|${CIDD_URL_DEFAULT}|${CIDD_URL_CHOSEN}|" \ "|${CIDD_URL_DEFAULT}|${CIDD_URL_CHOSEN}|" \
"|^#baseurl|baseurl|" "|^#baseurl|baseurl|"
;; ;;
"${CIDD_OS_UBUNTU}") "${CIDD_OS_UBUNTU}")
cd_set_packages_repositories__file="/etc/apt/sources.list" cidd_set_packages_repositories__file="/etc/apt/sources.list"
cd_write "${cd_set_packages_repositories__file}" "\ cidd_write "${cidd_set_packages_repositories__file}" "\
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION} main deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION} main
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-backports main deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-backports main
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-updates main deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-updates main
@ -469,9 +469,9 @@ deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-security main
esac esac
} }
cd_set_packages_configuration () { cidd_set_packages_configuration () {
cd_step "Set packages configuration" cidd_step "Set packages configuration"
cd_write "${CIDD_PM_CONF_PATH}" "${CIDD_PM_CONF_TEXT}" cidd_write "${CIDD_PM_CONF_PATH}" "${CIDD_PM_CONF_TEXT}"
case "${CIDD_OS_ID}" in case "${CIDD_OS_ID}" in
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}") "${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
export DEBIAN_FRONTEND="noninteractive" export DEBIAN_FRONTEND="noninteractive"
@ -482,161 +482,161 @@ cd_set_packages_configuration () {
# agnostic steps # agnostic steps
cd_list_working_directory () { cidd_list_working_directory () {
cd_step "List working directory" cidd_step "List working directory"
cd_list_working_directory__path="$(realpath .)" cidd_list_working_directory__path="$(realpath .)"
cd_ls "${cd_list_working_directory__path}" cidd_ls "${cidd_list_working_directory__path}"
} }
cd_set_https_verification_off () { cidd_set_https_verification_off () {
if [ -n "${CIDD_CA}" ] || [ "${CIDD_PM}" = "${CIDD_PM_APT}" ] ; then if [ -n "${CIDD_CA}" ] || [ "${CIDD_PM}" = "${CIDD_PM_APT}" ] ; then
cd_step "Set HTTPS verification off" cidd_step "Set HTTPS verification off"
cd_mkdir "$(dirname "${CIDD_PM_HTTPS_PATH}")" cidd_mkdir "$(dirname "${CIDD_PM_HTTPS_PATH}")"
cd_write "${CIDD_PM_HTTPS_PATH}" "${CIDD_PM_HTTPS_TEXT}" cidd_write "${CIDD_PM_HTTPS_PATH}" "${CIDD_PM_HTTPS_TEXT}"
fi fi
} }
cd_set_dns_resolving () { cidd_set_dns_resolving () {
cd_step "Set DNS resolving" cidd_step "Set DNS resolving"
for cd_set_dns_resolving__server in ${CIDD_DNS} ; do for cidd_set_dns_resolving__server in ${CIDD_DNS} ; do
cd_set_dns_resolving__text="${cd_set_dns_resolving__text}\ cidd_set_dns_resolving__text="${cidd_set_dns_resolving__text}\
nameserver ${cd_set_dns_resolving__server} nameserver ${cidd_set_dns_resolving__server}
" "
done done
cd_write "${CIDD_DNS_FILE}" "${cd_set_dns_resolving__text}" cidd_write "${CIDD_DNS_FILE}" "${cidd_set_dns_resolving__text}"
} }
cd_update_packages_catalog () { cidd_update_packages_catalog () {
cd_step "Update packages catalog" cidd_step "Update packages catalog"
${CIDD_PM_UPDATE} || exit ${CIDD_PM_UPDATE} || exit
} }
cd_install_packages_tools () { cidd_install_packages_tools () {
cd_step "Install packages tools" cidd_step "Install packages tools"
cd_install_package "${CIDD_PKG_PKG}" cidd_install_package "${CIDD_PKG_PKG}"
} }
cd_install_ca_certificates () { cidd_install_ca_certificates () {
cd_step "Install CA" cidd_step "Install CA"
cd_install_package "${CIDD_PKG_CA}" cidd_install_package "${CIDD_PKG_CA}"
} }
cd_write_ca_certificates () { cidd_write_ca_certificates () {
cd_step "Write CA certificates" cidd_step "Write CA certificates"
cd_mkdir "${CIDD_CA_ROOT}" cidd_mkdir "${CIDD_CA_ROOT}"
cd_write_ca_certificates__index=1 cidd_write_ca_certificates__index=1
eval "cd_write_ca_certificates__text=\ eval "cidd_write_ca_certificates__text=\
\"\${CIDD_CA_${cd_write_ca_certificates__index}}\"" \"\${CIDD_CA_${cidd_write_ca_certificates__index}}\""
while [ -n "${cd_write_ca_certificates__text}" ] ; do while [ -n "${cidd_write_ca_certificates__text}" ] ; do
cd_write_ca_certificates__path="\ cidd_write_ca_certificates__path="\
${CIDD_CA_ROOT}/${cd_write_ca_certificates__index}.crt" ${CIDD_CA_ROOT}/${cidd_write_ca_certificates__index}.crt"
cd_split cidd_split
cd_write \ cidd_write \
"${cd_write_ca_certificates__path}" \ "${cidd_write_ca_certificates__path}" \
"${cd_write_ca_certificates__text}" "${cidd_write_ca_certificates__text}"
cd_openssl "${cd_write_ca_certificates__path}" cidd_openssl "${cidd_write_ca_certificates__path}"
cd_write_ca_certificates__index=$((cd_write_ca_certificates__index+1)) cidd_write_ca_certificates__index=$((cidd_write_ca_certificates__index+1))
eval "cd_write_ca_certificates__text=\ eval "cidd_write_ca_certificates__text=\
\"\${CIDD_CA_${cd_write_ca_certificates__index}}\"" \"\${CIDD_CA_${cidd_write_ca_certificates__index}}\""
done done
} }
cd_update_ca_certificates () { cidd_update_ca_certificates () {
cd_step "Update CA certificates" cidd_step "Update CA certificates"
${CIDD_CMD_CA} || exit ${CIDD_CMD_CA} || exit
} }
cd_set_https_verification_on () { cidd_set_https_verification_on () {
cd_step "Set HTTPS verification on" cidd_step "Set HTTPS verification on"
cd_rm "${CIDD_PM_HTTPS_PATH}" cidd_rm "${CIDD_PM_HTTPS_PATH}"
} }
cd_upgrade_packages () { cidd_upgrade_packages () {
cd_step "Upgrade packages" cidd_step "Upgrade packages"
${CIDD_PM_UPGRADE} || exit ${CIDD_PM_UPGRADE} || exit
} }
cd_install_git () { cidd_install_git () {
cd_step "Install Git" cidd_step "Install Git"
cd_install_package "${CIDD_PKG_GIT}" cidd_install_package "${CIDD_PKG_GIT}"
} }
cd_install_python () { cidd_install_python () {
cd_step "Install Python" cidd_step "Install Python"
cd_install_package "${CIDD_PYTHON_PACKAGE}" cidd_install_package "${CIDD_PYTHON_PACKAGE}"
cd_split cidd_split
cd_ln_python "${CIDD_PYTHON_COMMAND}" cidd_ln_python "${CIDD_PYTHON_COMMAND}"
} }
# TODO move to Python # TODO move to Python
cd_install_rsync () { cidd_install_rsync () {
cd_step "Install Rsync" cidd_step "Install Rsync"
cd_install_package "${CIDD_PKG_RSYNC}" cidd_install_package "${CIDD_PKG_RSYNC}"
} }
# TODO move to Python # TODO move to Python
cd_install_ssh () { cidd_install_ssh () {
cd_step "Install SSH" cidd_step "Install SSH"
cd_install_package "${CIDD_PKG_SSH}" cidd_install_package "${CIDD_PKG_SSH}"
} }
cd_clean_packages_cache () { cidd_clean_packages_cache () {
cd_step "Clean packages cache" cidd_step "Clean packages cache"
${CIDD_PM_CLEAN} || exit ${CIDD_PM_CLEAN} || exit
} }
cd_install_python_modules () { cidd_install_python_modules () {
cd_step "Install Python modules" cidd_step "Install Python modules"
cd_install_python_modules__root="$(mktemp --directory)" || exit cidd_install_python_modules__root="$(mktemp --directory)" || exit
echo "${cd_install_python_modules__root}" echo "${cidd_install_python_modules__root}"
for cd_install_python_modules__repository \ for cidd_install_python_modules__repository \
in "${CIDD_GIT_CHILD}" "${CIDD_GIT_PARENT}" ; do in "${CIDD_GIT_CHILD}" "${CIDD_GIT_PARENT}" ; do
cd_split cidd_split
cd_install_python_modules__url="\ cidd_install_python_modules__url="\
${CIDD_PROJECTS_URL}/${cd_install_python_modules__repository}" ${CIDD_PROJECTS_URL}/${cidd_install_python_modules__repository}"
echo "\ echo "\
${cd_install_python_modules__url} ${cidd_install_python_modules__url}
" "
git clone \ git clone \
"${cd_install_python_modules__url}" \ "${cidd_install_python_modules__url}" \
"${cd_install_python_modules__root}\ "${cidd_install_python_modules__root}\
/${cd_install_python_modules__repository}" \ /${cidd_install_python_modules__repository}" \
|| exit || exit
cd_install_python_modules__path="\ cidd_install_python_modules__path="\
${cd_install_python_modules__root}\ ${cidd_install_python_modules__root}\
/${cd_install_python_modules__repository}\ /${cidd_install_python_modules__repository}\
/${cd_install_python_modules__repository}" /${cidd_install_python_modules__repository}"
echo "\ echo "\
${cd_install_python_modules__path} ${cidd_install_python_modules__path}
${CIDD_PYTHON_PACKAGES}" ${CIDD_PYTHON_PACKAGES}"
cp --recursive \ cp --recursive \
"${cd_install_python_modules__path}" "${CIDD_PYTHON_PACKAGES}" \ "${cidd_install_python_modules__path}" "${CIDD_PYTHON_PACKAGES}" \
|| exit || exit
done done
cd_split cidd_split
cd_ls "${CIDD_PYTHON_PACKAGES}" cidd_ls "${CIDD_PYTHON_PACKAGES}"
cd_split cidd_split
cd_rm "${cd_install_python_modules__root}" cidd_rm "${cidd_install_python_modules__root}"
} }
cd_write_python_module () { cidd_write_python_module () {
cd_step "Write Python module" cidd_step "Write Python module"
for cd_write_python_module__variable \ for cidd_write_python_module__variable \
in OPEN DOWN VERT SPLT __UP SHUT OS_ID OS_VERSION ; do in OPEN DOWN VERT SPLT __UP SHUT OS_ID OS_VERSION ; do
cd_write_python_module__value="\ cidd_write_python_module__value="\
$(cd_echo "CIDD_${cd_write_python_module__variable}")" $(cidd_echo "CIDD_${cidd_write_python_module__variable}")"
cd_write_python_module__text="${cd_write_python_module__text}\ cidd_write_python_module__text="${cidd_write_python_module__text}\
${cd_write_python_module__value} ${cidd_write_python_module__value}
" "
done done
cd_write "${CIDD_PYTHON_PACKAGES}/env.py" "${cd_write_python_module__text}\ cidd_write "${CIDD_PYTHON_PACKAGES}/env.py" "${cidd_write_python_module__text}\
CIDD_STEP = $((CIDD_STEP+1)) CIDD_STEP = $((CIDD_STEP+1))
" "
} }
cd_switch_to_python () { cidd_switch_to_python () {
cd_step "Switch to Python" cidd_step "Switch to Python"
echo "\ echo "\
${CIDD_PATH} ${CIDD_PATH}
@ -646,122 +646,122 @@ ${CIDD_PYTHON_PACKAGES}/${CIDD_GIT_CHILD}"
# functions # functions
cd_cat () { cidd_cat () {
cd_cat__file="${1}" cidd_cat__file="${1}"
if [ -n "${cd_cat__file}" ] ; then if [ -n "${cidd_cat__file}" ] ; then
cd_open "${cd_cat__file}" cidd_open "${cidd_cat__file}"
cat "${cd_cat__file}" || exit cat "${cidd_cat__file}" || exit
cd_shut "${cd_cat__file}" cidd_shut "${cidd_cat__file}"
fi fi
} }
cd_echo () { cidd_echo () {
if [ -n "${1}" ] ; then if [ -n "${1}" ] ; then
for cd_echo__name in "${@}" ; do for cidd_echo__name in "${@}" ; do
eval "cd_echo__text=\"\${${cd_echo__name}}\"" eval "cidd_echo__text=\"\${${cidd_echo__name}}\""
echo "${cd_echo__name} = \"${cd_echo__text}\"" echo "${cidd_echo__name} = \"${cidd_echo__text}\""
done done
fi fi
} }
cd_error_ci () { cidd_error_ci () {
echo "× CI: ${*}" echo "× CI: ${*}"
exit "${CIDD_ERROR_CI}" exit "${CIDD_ERROR_CI}"
} }
cd_error_os () { cidd_error_os () {
cd_error_os__variable="${1}" cidd_error_os__variable="${1}"
printf "× OS: " printf "× OS: "
cd_echo "${cd_error_os__variable}" cidd_echo "${cidd_error_os__variable}"
exit "${CIDD_ERROR_OS}" exit "${CIDD_ERROR_OS}"
} }
cd_grep_os () { cidd_grep_os () {
cd_grep_os__variable="${1}" cidd_grep_os__variable="${1}"
if [ -n "${cd_grep_os__variable}" ] ; then if [ -n "${cidd_grep_os__variable}" ] ; then
grep "^${cd_grep_os__variable}=" "/etc/os-release" \ grep "^${cidd_grep_os__variable}=" "/etc/os-release" \
| sed "s|^${cd_grep_os__variable}=||" \ | sed "s|^${cidd_grep_os__variable}=||" \
| sed "s|^\"\(.*\)\"$|\1|" | sed "s|^\"\(.*\)\"$|\1|"
fi fi
} }
cd_install_package () { cidd_install_package () {
cd_install_package__name="${1}" cidd_install_package__name="${1}"
if [ -n "${cd_install_package__name}" ] ; then if [ -n "${cidd_install_package__name}" ] ; then
${CIDD_PM_INSTALL} "${cd_install_package__name}" || exit ${CIDD_PM_INSTALL} "${cidd_install_package__name}" || exit
fi fi
} }
cd_ln_python () { cidd_ln_python () {
cd_ln_python__command="${1}" cidd_ln_python__command="${1}"
if [ -n "${cd_ln_python__command}" ] ; then if [ -n "${cidd_ln_python__command}" ] ; then
echo "${CIDD_PYTHON_ALIAS}${cd_ln_python__command}" echo "${CIDD_PYTHON_ALIAS}${cidd_ln_python__command}"
ln -f -s "${cd_ln_python__command}" "/usr/bin/${CIDD_PYTHON_ALIAS}" \ ln -f -s "${cidd_ln_python__command}" "/usr/bin/${CIDD_PYTHON_ALIAS}" \
|| exit || exit
fi fi
} }
cd_ls () { cidd_ls () {
cd_ls__path="${1}" cidd_ls__path="${1}"
if [ -n "${cd_ls__path}" ] ; then if [ -n "${cidd_ls__path}" ] ; then
cd_open "${cd_ls__path}" cidd_open "${cidd_ls__path}"
ls -a -l "${cd_ls__path}" || exit ls -a -l "${cidd_ls__path}" || exit
cd_shut "${cd_ls__path}" cidd_shut "${cidd_ls__path}"
fi fi
} }
cd_mkdir () { cidd_mkdir () {
cd_mkdir__path="${1}" cidd_mkdir__path="${1}"
if [ -n "${cd_mkdir__path}" ] ; then if [ -n "${cidd_mkdir__path}" ] ; then
echo "${cd_mkdir__path}" echo "${cidd_mkdir__path}"
mkdir --parents "${cd_mkdir__path}" || exit mkdir --parents "${cidd_mkdir__path}" || exit
fi fi
} }
cd_open () { cidd_open () {
echo "${CIDD_OPEN}${*}" echo "${CIDD_OPEN}${*}"
} }
cd_openssl () { cidd_openssl () {
cd_openssl__file="${1}" cidd_openssl__file="${1}"
if [ -f "${cd_openssl__file}" ] ; then if [ -f "${cidd_openssl__file}" ] ; then
openssl x509 \ openssl x509 \
-in "${cd_openssl__file}" \ -in "${cidd_openssl__file}" \
-noout -text \ -noout -text \
|| exit || exit
fi fi
} }
cd_rm () { cidd_rm () {
cd_rm__path="${1}" cidd_rm__path="${1}"
if [ -e "${cd_rm__path}" ] ; then if [ -e "${cidd_rm__path}" ] ; then
echo "${cd_rm__path}" echo "${cidd_rm__path}"
rm -r "${cd_rm__path}" || exit rm -r "${cidd_rm__path}" || exit
fi fi
} }
cd_sed () { cidd_sed () {
cd_sed__file="${1}" cidd_sed__file="${1}"
shift shift
if [ -f "${cd_sed__file}" ] ; then if [ -f "${cidd_sed__file}" ] ; then
cd_cat "${cd_sed__file}" cidd_cat "${cidd_sed__file}"
for cd_sed__regex in "${@}" ; do for cidd_sed__regex in "${@}" ; do
sed --in-place "s${cd_sed__regex}g" "${cd_sed__file}" \ sed --in-place "s${cidd_sed__regex}g" "${cidd_sed__file}" \
&& cd_cat "${cd_sed__file}" \ && cidd_cat "${cidd_sed__file}" \
|| exit || exit
done done
fi fi
} }
cd_shut () { cidd_shut () {
echo "${CIDD_SHUT}${*}" echo "${CIDD_SHUT}${*}"
} }
cd_split () { cidd_split () {
echo "${CIDD_SPLT}" echo "${CIDD_SPLT}"
} }
cd_step () { cidd_step () {
CIDD_STEP=$((CIDD_STEP+1)) CIDD_STEP=$((CIDD_STEP+1))
echo "\ echo "\
${CIDD_DOWN} ${CIDD_DOWN}
@ -769,14 +769,14 @@ ${CIDD_VERT} ${CIDD_STEP} ${*}
${CIDD___UP}" ${CIDD___UP}"
} }
cd_write () { cidd_write () {
cd_write__file="${1}" cidd_write__file="${1}"
cd_write__text="${2}" cidd_write__text="${2}"
if [ -n "${cd_write__file}" ] ; then if [ -n "${cidd_write__file}" ] ; then
[ -f "${cd_write__file}" ] && cd_cat "${cd_write__file}" [ -f "${cidd_write__file}" ] && cidd_cat "${cidd_write__file}"
echo "${cd_write__file}" echo "${cidd_write__file}"
printf "%s" "${cd_write__text}" > "${cd_write__file}" || exit printf "%s" "${cidd_write__text}" > "${cidd_write__file}" || exit
cd_cat "${cd_write__file}" cidd_cat "${cidd_write__file}"
fi fi
} }
@ -814,4 +814,4 @@ CIDD___UP="${CIDD_BOX_UP}${CIDD_HORIZONTAL}"
CIDD_SHUT="${CIDD_BOX_UP}${CIDD_BOX_LEFT}" CIDD_SHUT="${CIDD_BOX_UP}${CIDD_BOX_LEFT}"
# run # run
cd_main "${@}" cidd_main "${@}"