spcd/cidd.sh

818 lines
24 KiB
Bash
Raw Normal View History

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
2024-06-21 11:15:22 +00:00
[ -n "${CIDD_DNS}" ] || CIDD_DNS="\
2024-04-29 13:10:51 +00:00
9.9.9.9 \
"
2024-06-21 11:15:22 +00:00
[ -n "${CIDD_GIT_CHILD}" ] || CIDD_GIT_CHILD="cd"
[ -n "${CIDD_GIT_PARENT}" ] || CIDD_GIT_PARENT="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-05-03 10:55:28 +00:00
cd_set_environment_variables
2024-04-27 15:36:14 +00:00
cd_set_packages_repositories
2024-05-04 20:36:30 +00:00
cd_set_packages_configuration
2024-05-04 10:52:28 +00:00
#
cd_list_working_directory
2024-05-02 06:38:49 +00:00
cd_set_https_verification_off
2024-05-04 10:14:30 +00:00
cd_set_dns_resolving
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
2024-05-03 15:20:44 +00:00
cd_write_ca_certificates
2024-04-30 10:31:56 +00:00
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
2024-05-30 18:38:32 +00:00
# TODO move to Python
cd_install_rsync
2024-05-30 19:29:06 +00:00
# TODO move to Python
cd_install_ssh
2024-04-27 15:36:14 +00:00
cd_clean_packages_cache
2024-06-01 18:03:08 +00:00
cd_install_python_modules
2024-06-04 19:13:08 +00:00
cd_write_python_module
cd_switch_to_python "${@}"
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-05-03 10:55:28 +00:00
cd_set_environment_variables () {
cd_step "Set environment variables"
2024-06-08 14:21:46 +00:00
# set path
2024-06-21 11:15:22 +00:00
CIDD_PATH="$(realpath "${0}")"
cd_echo "CIDD_PATH"
2024-05-23 13:20:25 +00:00
# set operating system id
2024-06-21 11:15:22 +00:00
CIDD_OS_ID="$(cd_grep_os ID)"
case "${CIDD_OS_ID}" in
"almalinux") CIDD_OS_ID="${CIDD_OS_ALMA}" ;;
"alpine") CIDD_OS_ID="${CIDD_OS_ALPINE}" ;;
"arch") CIDD_OS_ID="${CIDD_OS_ARCH}" ;;
"debian") CIDD_OS_ID="${CIDD_OS_DEBIAN}" ;;
"fedora") CIDD_OS_ID="${CIDD_OS_FEDORA}" ;;
"rocky") CIDD_OS_ID="${CIDD_OS_ROCKY}" ;;
"ubuntu") CIDD_OS_ID="${CIDD_OS_UBUNTU}" ;;
*) cd_error_os "CIDD_OS_ID" ;;
2024-05-04 15:25:36 +00:00
esac
2024-05-23 13:20:25 +00:00
# set operating system version
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_ARCH}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}")
CIDD_OS_VERSION=$(cd_grep_os VERSION_ID \
2024-05-04 11:36:19 +00:00
| sed "s|^\([0-9]\+\)\..*|\1|")
2024-05-04 11:35:35 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}")
CIDD_OS_VERSION=$(cd_grep_os VERSION_ID \
2024-05-04 11:36:19 +00:00
| sed "s|^\([0-9]\+\.[0-9]\+\)\..*|\1|")
2024-05-03 11:03:47 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
CIDD_OS_VERSION="$(cd_grep_os VERSION_CODENAME)"
2024-05-05 18:27:18 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-03 10:55:28 +00:00
esac
2024-05-23 13:20:25 +00:00
# check operating system version
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_ROCKY}")
case "${CIDD_OS_VERSION}" in
2024-05-04 16:27:32 +00:00
"8"|"9") ;;
2024-06-21 11:15:22 +00:00
*) cd_error_os "CIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}")
case "${CIDD_OS_VERSION}" in
2024-05-04 16:27:32 +00:00
"3.18"|"3.19") ;;
2024-06-21 11:15:22 +00:00
*) cd_error_os "CIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ARCH}")
case "${CIDD_OS_VERSION}" in
2024-05-05 18:27:18 +00:00
"20231112"|"20240101") ;;
2024-06-21 11:15:22 +00:00
*) cd_error_os "CIDD_OS_VERSION" ;;
2024-05-05 18:27:18 +00:00
esac
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}")
case "${CIDD_OS_VERSION}" in
2024-05-04 16:27:32 +00:00
"bookworm"|"bullseye") ;;
2024-06-21 11:15:22 +00:00
*) cd_error_os "CIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_FEDORA}")
case "${CIDD_OS_VERSION}" in
2024-05-06 09:36:27 +00:00
"39"|"40") ;;
2024-06-21 11:15:22 +00:00
*) cd_error_os "CIDD_OS_VERSION" ;;
2024-05-06 09:36:27 +00:00
esac
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_UBUNTU}")
case "${CIDD_OS_VERSION}" in
2024-05-06 09:56:45 +00:00
"jammy"|"noble") ;;
2024-06-21 11:15:22 +00:00
*) cd_error_os "CIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-04 16:27:32 +00:00
esac
2024-06-08 14:21:46 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_OS_ID" "CIDD_OS_VERSION"
2024-05-04 14:30:40 +00:00
# universal
2024-06-21 11:15:22 +00:00
CIDD_DNS_FILE="/etc/resolv.conf"
CIDD_PKG_CA="ca-certificates"
CIDD_PKG_GIT="git"
2024-05-30 18:38:32 +00:00
# TODO move to Python
2024-06-21 11:15:22 +00:00
CIDD_PKG_RSYNC="rsync"
CIDD_PYTHON_ALIAS="python3"
2024-05-04 15:37:32 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_DNS_FILE" "CIDD_PKG_CA" "CIDD_PKG_GIT" "CIDD_PYTHON_ALIAS"
2024-05-23 13:20:25 +00:00
# set ca command & root
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}")
CIDD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
CIDD_CMD_CA="update-ca-trust"
2024-05-10 20:40:01 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}")
CIDD_CA_ROOT="/usr/local/share/ca-certificates"
CIDD_CMD_CA="update-ca-certificates"
2024-05-04 15:47:07 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ARCH}")
CIDD_CA_ROOT="/etc/ca-certificates/trust-source/anchors"
CIDD_CMD_CA="update-ca-trust"
2024-05-05 20:06:09 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
CIDD_CA_ROOT="/usr/local/share/ca-certificates"
CIDD_CMD_CA="update-ca-certificates"
2024-05-04 15:12:08 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-04 15:10:00 +00:00
esac
2024-05-04 15:47:07 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_CA_ROOT" "CIDD_CMD_CA"
2024-05-23 13:20:25 +00:00
# set package manager
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALPINE}")
CIDD_PM="${CIDD_PM_APK}"
2024-05-23 14:40:03 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
CIDD_PM="${CIDD_PM_APT}"
2024-05-23 14:40:03 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALMA}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}")
CIDD_PM="${CIDD_PM_DNF}"
2024-05-23 14:40:03 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ARCH}")
CIDD_PM="${CIDD_PM_PACMAN}"
2024-05-23 14:40:03 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-23 14:40:03 +00:00
esac
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_PM"
case "${CIDD_PM}" in
"${CIDD_PM_DNF}")
CIDD_PM_CLEAN="dnf clean all"
CIDD_PM_INSTALL="dnf install --assumeyes"
CIDD_PM_QUERY="rpm --query"
CIDD_PM_UPDATE="dnf makecache"
CIDD_PM_UPGRADE="dnf upgrade --assumeyes"
CIDD_PKG_PKG=""
CIDD_PM_CONF_PATH="/etc/dnf/dnf.conf"
CIDD_PM_CONF_TEXT="\
2024-05-04 16:16:12 +00:00
[main]
best=True
clean_requirements_on_remove=True
gpgcheck=1
installonly_limit=3
skip_if_unavailable=False
"
2024-06-21 11:15:22 +00:00
CIDD_PM_HTTPS_PATH="/etc/dnf/dnf.conf.d/https.conf"
CIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
sslverify=False
"
2024-05-04 15:50:43 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_PM_APK}")
CIDD_PM_CLEAN="apk cache purge"
CIDD_PM_INSTALL="apk add"
CIDD_PM_QUERY="apk info"
CIDD_PM_UPDATE="apk update"
CIDD_PM_UPGRADE="apk upgrade"
CIDD_PKG_PKG=""
CIDD_PM_CONF_PATH=""
CIDD_PM_CONF_TEXT=""
CIDD_PM_HTTPS_PATH="/etc/apk/repositories.d/https"
CIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
--no-verify
"
2024-05-04 15:50:43 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_PM_PACMAN}")
CIDD_PM_CLEAN="pacman --sync --clean --noconfirm"
CIDD_PM_INSTALL="pacman --sync --noconfirm"
CIDD_PM_QUERY="pacman --query"
CIDD_PM_UPDATE="pacman --sync --refresh"
CIDD_PM_UPGRADE="pacman --sync --sysupgrade --noconfirm"
CIDD_PKG_PKG=""
CIDD_PM_CONF_PATH=""
CIDD_PM_CONF_TEXT=""
CIDD_PM_HTTPS_PATH="/etc/pacman.d/https.conf"
CIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
SSLVerify = No
"
2024-05-05 20:09:26 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_PM_APT}")
CIDD_PM_CLEAN="apt-get clean"
CIDD_PM_INSTALL="apt-get install --assume-yes"
CIDD_PM_QUERY="dpkg-query --show"
CIDD_PM_UPDATE="apt-get update"
CIDD_PM_UPGRADE="apt-get upgrade --assume-yes"
CIDD_PKG_PKG="apt-utils"
CIDD_PM_CONF_PATH="/etc/apt/apt.conf.d/apt.conf"
CIDD_PM_CONF_TEXT="\
2024-05-04 16:16:12 +00:00
Acquire::Check-Valid-Until True;
APT::Get::Show-Versions True;
APT::Install-Recommends False;
APT::Install-Suggests False;
Dir::Etc::SourceParts \"\";
"
2024-06-21 11:15:22 +00:00
CIDD_PM_HTTPS_PATH="/etc/apt/apt.conf.d/https"
CIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
Acquire::https::Verify-Peer False;
"
2024-05-04 15:50:43 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-04 15:50:43 +00:00
esac
2024-05-04 15:54:04 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_PM_CLEAN" \
"CIDD_PM_INSTALL" "CIDD_PM_QUERY" "CIDD_PM_UPDATE" "CIDD_PM_UPGRADE"
2024-05-04 16:16:12 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_PKG_PKG" "CIDD_PM_CONF_PATH" "CIDD_PM_HTTPS_PATH"
2024-05-04 17:33:07 +00:00
# specific
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}")
CIDD_URL_DEFAULT="https://repo.almalinux.org/almalinux"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}")
CIDD_URL_DEFAULT="https://dl-cdn.alpinelinux.org/alpine"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ARCH}")
CIDD_URL_DEFAULT="https://geo.mirror.pkgbuild.com"
2024-05-06 11:42:33 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}")
CIDD_URL_DEFAULT="http://deb.debian.org/debian"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_FEDORA}")
CIDD_URL_DEFAULT="http://download.example/pub/fedora/linux/releases"
2024-05-06 09:36:27 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ROCKY}")
CIDD_URL_DEFAULT="http://dl.rockylinux.org/\$contentdir"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_UBUNTU}")
CIDD_URL_DEFAULT="http://archive.ubuntu.com/ubuntu"
2024-05-04 18:17:46 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-04 18:17:46 +00:00
esac
2024-06-21 11:15:22 +00:00
CIDD_URL_CHOSEN="${CIDD_URL_DEFAULT}"
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}")
[ -n "${CIDD_URL_ALMA}" ] && CIDD_URL_CHOSEN="${CIDD_URL_ALMA}"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}")
[ -n "${CIDD_URL_ALPINE}" ] && CIDD_URL_CHOSEN="${CIDD_URL_ALPINE}"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ARCH}")
[ -n "${CIDD_URL_ARCH}" ] && CIDD_URL_CHOSEN="${CIDD_URL_ARCH}"
2024-06-02 14:29:41 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}")
[ -n "${CIDD_URL_DEBIAN}" ] && CIDD_URL_CHOSEN="${CIDD_URL_DEBIAN}" \
|| CIDD_URL_CHOSEN="https://deb.debian.org/debian"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_FEDORA}")
[ -n "${CIDD_URL_FEDORA}" ] && CIDD_URL_CHOSEN="${CIDD_URL_FEDORA}" \
|| CIDD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases"
2024-05-06 09:36:27 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ROCKY}")
[ -n "${CIDD_URL_ROCKY}" ] && CIDD_URL_CHOSEN="${CIDD_URL_ROCKY}" \
|| CIDD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_UBUNTU}")
[ -n "${CIDD_URL_UBUNTU}" ] && CIDD_URL_CHOSEN="${CIDD_URL_UBUNTU}" \
|| CIDD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu"
2024-05-04 18:17:46 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-04 17:33:07 +00:00
esac
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_URL_DEFAULT" "CIDD_URL_CHOSEN"
2024-05-23 13:20:25 +00:00
# set python command & package
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_ROCKY}")
CIDD_PYTHON_COMMAND="python3.11"
CIDD_PYTHON_PACKAGE="python3.11"
;;
"${CIDD_OS_ALPINE}")
CIDD_PYTHON_COMMAND="python3.11"
CIDD_PYTHON_PACKAGE="python3"
;;
"${CIDD_OS_ARCH}")
CIDD_PYTHON_COMMAND="python3.12"
CIDD_PYTHON_PACKAGE="python"
;;
"${CIDD_OS_DEBIAN}")
case "${CIDD_OS_VERSION}" in
"bookworm") CIDD_PYTHON_COMMAND="python3.11" ;;
"bullseye") CIDD_PYTHON_COMMAND="python3.9" ;;
2024-06-08 17:44:32 +00:00
*)
2024-05-03 19:03:07 +00:00
esac
2024-06-21 11:15:22 +00:00
CIDD_PYTHON_PACKAGE="python3"
2024-05-03 19:03:07 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_FEDORA}")
CIDD_PYTHON_COMMAND="python3.12"
CIDD_PYTHON_PACKAGE="python3"
2024-05-06 09:36:27 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_UBUNTU}")
case "${CIDD_OS_VERSION}" in
"noble") CIDD_PYTHON_COMMAND="python3.12" ;;
"jammy") CIDD_PYTHON_COMMAND="python3.10" ;;
2024-06-08 17:44:32 +00:00
*)
2024-05-04 18:35:29 +00:00
esac
2024-06-21 11:15:22 +00:00
CIDD_PYTHON_PACKAGE="python3"
2024-05-06 09:45:21 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-05-06 09:45:21 +00:00
esac
2024-05-23 13:20:25 +00:00
# set python packages
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}"|"${CIDD_OS_FEDORA}"|"${CIDD_OS_ROCKY}")
CIDD_PYTHON_PACKAGES="/usr/lib64/${CIDD_PYTHON_COMMAND}/site-packages"
2024-05-06 09:45:21 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}"|"${CIDD_OS_ARCH}")
CIDD_PYTHON_PACKAGES="/usr/lib/${CIDD_PYTHON_COMMAND}/site-packages"
2024-05-06 09:45:21 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
CIDD_PYTHON_PACKAGES="/usr/lib/${CIDD_PYTHON_ALIAS}/dist-packages"
2024-05-04 18:35:29 +00:00
;;
2024-06-08 17:44:32 +00:00
*)
2024-04-27 09:59:30 +00:00
esac
2024-05-04 16:00:01 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_PYTHON_COMMAND" "CIDD_PYTHON_PACKAGE" "CIDD_PYTHON_PACKAGES"
2024-05-04 14:23:02 +00:00
# variables
2024-06-21 11:15:22 +00:00
[ -n "${CIDD_CA_1}" ] && CIDD_CA=true
2024-05-03 11:06:52 +00:00
# continuous integration platform
2024-06-08 16:11:41 +00:00
if [ -n "${GITHUB_ACTIONS}" ] ; then
2024-05-04 20:57:17 +00:00
# github → gitea → forgejo
2024-06-08 21:14:27 +00:00
if [ -n "${GITHUB_SERVER_URL}" ] ; then
2024-06-21 11:15:22 +00:00
CIDD_SERVER_URL="${GITHUB_SERVER_URL}"
2024-06-08 21:14:27 +00:00
else
cd_error_ci "GITHUB_SERVER_URL"
fi
if [ -n "${GITHUB_REPOSITORY}" ] ; then
2024-06-21 11:15:22 +00:00
CIDD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
CIDD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
2024-06-08 21:14:27 +00:00
else
cd_error_ci "GITHUB_REPOSITORY"
fi
if [ -n "${GITHUB_REF_NAME}" ] ; then
2024-06-21 11:15:22 +00:00
CIDD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
2024-06-08 21:14:27 +00:00
else
cd_error_ci "GITHUB_REF_NAME"
fi
2024-06-08 16:11:41 +00:00
elif [ -n "${GITLAB_CI}" ] ; then
2024-05-03 11:06:52 +00:00
# gitlab
2024-06-08 21:14:27 +00:00
if [ -n "${CI_SERVER_URL}" ] ; then
2024-06-21 11:15:22 +00:00
CIDD_SERVER_URL="${CI_SERVER_URL}"
2024-06-08 21:14:27 +00:00
else
cd_error_ci "CI_SERVER_URL"
fi
if [ -n "${CI_PROJECT_PATH}" ] ; then
2024-06-21 11:15:22 +00:00
CIDD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
CIDD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")"
2024-06-08 21:14:27 +00:00
else
cd_error_ci "CI_PROJECT_PATH"
fi
if [ -n "${CI_COMMIT_BRANCH}" ] ; then
2024-06-21 11:15:22 +00:00
CIDD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
2024-06-08 21:14:27 +00:00
else
cd_error_ci "CI_COMMIT_BRANCH"
fi
2024-04-27 09:59:30 +00:00
else
2024-05-03 11:06:52 +00:00
# unsupported
2024-04-29 09:08:29 +00:00
cd_error_ci "ø"
2024-04-27 09:59:30 +00:00
fi
2024-06-21 11:15:22 +00:00
[ -n "${CIDD_SERVER_URL}" ] || cd_error_ci "CIDD_SERVER_URL"
[ -n "${CIDD_PROJECTS_GROUP}" ] || cd_error_ci "CIDD_PROJECTS_GROUP"
[ -n "${CIDD_PROJECT_NAME}" ] || cd_error_ci "CIDD_PROJECT_NAME"
[ -n "${CIDD_PROJECT_BRANCH}" ] || cd_error_ci "CIDD_PROJECT_BRANCH"
2024-04-29 08:58:37 +00:00
#
2024-06-21 11:15:22 +00:00
CIDD_PROJECTS_URL="${CIDD_SERVER_URL}/${CIDD_PROJECTS_GROUP}"
2024-04-28 10:44:28 +00:00
#
2024-05-02 07:59:17 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_CA"
2024-05-04 14:23:02 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_SERVER_URL" \
"CIDD_PROJECTS_GROUP" "CIDD_PROJECT_NAME" "CIDD_PROJECT_BRANCH"
2024-05-02 07:59:17 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_echo "CIDD_PROJECTS_URL"
2024-05-30 19:29:06 +00:00
# TODO move to Python
2024-06-21 11:15:22 +00:00
case "${CIDD_PM}" in
"${CIDD_PM_APK}"|"${CIDD_PM_APT}") CIDD_PKG_SSH="openssh-client" ;;
"${CIDD_PM_DNF}") CIDD_PKG_SSH="openssh-clients" ;;
"${CIDD_PM_PACMAN}") CIDD_PKG_SSH="openssh" ;;
2024-06-08 17:33:46 +00:00
*)
2024-05-30 19:29:06 +00:00
esac
2024-04-27 09:56:16 +00:00
}
2024-04-27 17:56:19 +00:00
cd_set_packages_repositories () {
2024-04-27 21:36:26 +00:00
cd_step "Set packages repositories"
2024-06-21 11:15:22 +00:00
case "${CIDD_OS_ID}" in
"${CIDD_OS_ALMA}")
case "${CIDD_OS_VERSION}" in
2024-06-08 15:28:38 +00:00
"8") \
cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux.repo" ;;
"9") \
cd_set_packages_repositories__file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
2024-06-08 17:33:46 +00:00
*)
2024-05-04 20:51:23 +00:00
esac
2024-06-08 15:28:38 +00:00
cd_sed "${cd_set_packages_repositories__file}" \
2024-05-03 17:02:51 +00:00
"|^mirrorlist|# mirrorlist|" \
2024-06-21 11:15:22 +00:00
"|${CIDD_URL_DEFAULT}|${CIDD_URL_CHOSEN}|" \
2024-05-03 17:02:51 +00:00
"|^# baseurl|baseurl|"
2024-04-29 20:41:28 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ALPINE}")
2024-06-08 15:28:38 +00:00
cd_set_packages_repositories__file="/etc/apk/repositories"
cd_write "${cd_set_packages_repositories__file}" "\
2024-06-21 11:15:22 +00:00
${CIDD_URL_CHOSEN}/v${CIDD_OS_VERSION}/main
${CIDD_URL_CHOSEN}/v${CIDD_OS_VERSION}/community
2024-05-04 10:50:20 +00:00
"
2024-05-04 10:41:08 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_DEBIAN}")
2024-06-08 15:28:38 +00:00
cd_set_packages_repositories__file="/etc/apt/sources.list"
cd_write "${cd_set_packages_repositories__file}" "\
2024-06-21 11:15:22 +00:00
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION} main
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-backports main
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION}-updates main
deb ${CIDD_URL_CHOSEN}-security ${CIDD_OS_VERSION}-security main
2024-05-03 19:03:07 +00:00
"
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_ROCKY}")
case "${CIDD_OS_VERSION}" in
2024-06-08 15:28:38 +00:00
"8") \
cd_set_packages_repositories__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;;
"9") \
cd_set_packages_repositories__file="/etc/yum.repos.d/rocky.repo" ;;
2024-06-08 17:33:46 +00:00
*)
2024-05-04 20:51:23 +00:00
esac
2024-06-08 15:28:38 +00:00
cd_sed "${cd_set_packages_repositories__file}" \
2024-05-04 20:51:23 +00:00
"|^mirrorlist|# mirrorlist|" \
2024-06-21 11:15:22 +00:00
"|${CIDD_URL_DEFAULT}|${CIDD_URL_CHOSEN}|" \
2024-05-04 20:51:23 +00:00
"|^#baseurl|baseurl|"
2024-05-04 19:39:20 +00:00
;;
2024-06-21 11:15:22 +00:00
"${CIDD_OS_UBUNTU}")
2024-06-08 15:28:38 +00:00
cd_set_packages_repositories__file="/etc/apt/sources.list"
cd_write "${cd_set_packages_repositories__file}" "\
2024-06-21 11:15:22 +00:00
deb ${CIDD_URL_CHOSEN} ${CIDD_OS_VERSION} 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}-security main
2024-05-04 21:47:31 +00:00
"
2024-05-04 19:39:20 +00:00
;;
2024-06-08 17:33:46 +00:00
*)
2024-04-26 14:13:35 +00:00
esac
}
2024-05-04 20:36:30 +00:00
cd_set_packages_configuration () {
cd_step "Set packages configuration"
2024-06-21 11:15:22 +00:00
cd_write "${CIDD_PM_CONF_PATH}" "${CIDD_PM_CONF_TEXT}"
case "${CIDD_OS_ID}" in
"${CIDD_OS_DEBIAN}"|"${CIDD_OS_UBUNTU}")
2024-05-04 20:36:30 +00:00
export DEBIAN_FRONTEND="noninteractive"
;;
2024-06-08 17:33:46 +00:00
*)
2024-05-04 20:36:30 +00:00
esac
}
2024-05-03 21:19:30 +00:00
# agnostic steps
2024-05-04 10:52:28 +00:00
cd_list_working_directory () {
cd_step "List working directory"
2024-06-08 17:21:59 +00:00
cd_list_working_directory__path="$(realpath .)"
cd_ls "${cd_list_working_directory__path}"
2024-05-04 10:52:28 +00:00
}
2024-04-27 17:56:19 +00:00
cd_set_https_verification_off () {
2024-06-21 11:15:22 +00:00
if [ -n "${CIDD_CA}" ] || [ "${CIDD_PM}" = "${CIDD_PM_APT}" ] ; then
2024-05-03 18:20:26 +00:00
cd_step "Set HTTPS verification off"
2024-06-21 11:15:22 +00:00
cd_mkdir "$(dirname "${CIDD_PM_HTTPS_PATH}")"
cd_write "${CIDD_PM_HTTPS_PATH}" "${CIDD_PM_HTTPS_TEXT}"
2024-05-03 18:20:26 +00:00
fi
2024-04-26 14:23:30 +00:00
}
2024-05-04 10:14:30 +00:00
cd_set_dns_resolving () {
cd_step "Set DNS resolving"
2024-06-21 11:15:22 +00:00
for cd_set_dns_resolving__server in ${CIDD_DNS} ; do
2024-06-08 15:20:13 +00:00
cd_set_dns_resolving__text="${cd_set_dns_resolving__text}\
nameserver ${cd_set_dns_resolving__server}
2024-05-04 10:14:30 +00:00
"
done
2024-06-21 11:15:22 +00:00
cd_write "${CIDD_DNS_FILE}" "${cd_set_dns_resolving__text}"
2024-05-04 10:14: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-06-21 11:15:22 +00:00
${CIDD_PM_UPDATE} || exit
2024-04-26 14:27:36 +00:00
}
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-06-21 11:15:22 +00:00
cd_install_package "${CIDD_PKG_PKG}"
2024-04-27 19:36:51 +00:00
}
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-06-21 11:15:22 +00:00
cd_install_package "${CIDD_PKG_CA}"
2024-04-26 14:44:34 +00:00
}
2024-05-03 15:20:44 +00:00
cd_write_ca_certificates () {
2024-05-03 19:28:37 +00:00
cd_step "Write CA certificates"
2024-06-21 11:15:22 +00:00
cd_mkdir "${CIDD_CA_ROOT}"
2024-06-08 14:39:44 +00:00
cd_write_ca_certificates__index=1
eval "cd_write_ca_certificates__text=\
2024-06-21 11:15:22 +00:00
\"\${CIDD_CA_${cd_write_ca_certificates__index}}\""
2024-06-08 16:11:41 +00:00
while [ -n "${cd_write_ca_certificates__text}" ] ; do
2024-06-08 14:39:44 +00:00
cd_write_ca_certificates__path="\
2024-06-21 11:15:22 +00:00
${CIDD_CA_ROOT}/${cd_write_ca_certificates__index}.crt"
2024-05-04 07:50:13 +00:00
cd_split
2024-06-08 14:39:44 +00:00
cd_write \
"${cd_write_ca_certificates__path}" \
"${cd_write_ca_certificates__text}"
cd_openssl "${cd_write_ca_certificates__path}"
cd_write_ca_certificates__index=$((cd_write_ca_certificates__index+1))
eval "cd_write_ca_certificates__text=\
2024-06-21 11:15:22 +00:00
\"\${CIDD_CA_${cd_write_ca_certificates__index}}\""
2024-05-03 15:20:44 +00:00
done
}
2024-04-30 10:31:56 +00:00
cd_update_ca_certificates () {
2024-05-03 19:28:37 +00:00
cd_step "Update CA certificates"
2024-06-21 11:15:22 +00:00
${CIDD_CMD_CA} || exit
2024-04-27 21:58:48 +00:00
}
2024-04-27 19:40:50 +00:00
cd_set_https_verification_on () {
2024-05-04 18:38:46 +00:00
cd_step "Set HTTPS verification on"
2024-06-21 11:15:22 +00:00
cd_rm "${CIDD_PM_HTTPS_PATH}"
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-06-21 11:15:22 +00:00
${CIDD_PM_UPGRADE} || exit
2024-04-26 14:35:15 +00:00
}
2024-04-27 19:42:29 +00:00
cd_install_git () {
2024-04-27 21:36:26 +00:00
cd_step "Install Git"
2024-06-21 11:15:22 +00:00
cd_install_package "${CIDD_PKG_GIT}"
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-06-21 11:15:22 +00:00
cd_install_package "${CIDD_PYTHON_PACKAGE}"
2024-05-03 22:24:14 +00:00
cd_split
2024-06-21 11:15:22 +00:00
cd_ln_python "${CIDD_PYTHON_COMMAND}"
2024-04-26 14:39:24 +00:00
}
2024-05-30 18:38:32 +00:00
# TODO move to Python
cd_install_rsync () {
cd_step "Install Rsync"
2024-06-21 11:15:22 +00:00
cd_install_package "${CIDD_PKG_RSYNC}"
2024-05-30 18:38:32 +00:00
}
2024-05-30 19:29:06 +00:00
# TODO move to Python
cd_install_ssh () {
cd_step "Install SSH"
2024-06-21 11:15:22 +00:00
cd_install_package "${CIDD_PKG_SSH}"
2024-05-30 19:29:06 +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-06-21 11:15:22 +00:00
${CIDD_PM_CLEAN} || exit
2024-04-26 14:53:41 +00:00
}
2024-04-28 21:29:31 +00:00
cd_install_python_modules () {
cd_step "Install Python modules"
2024-06-08 15:15:53 +00:00
cd_install_python_modules__root="$(mktemp --directory)" || exit
echo "${cd_install_python_modules__root}"
for cd_install_python_modules__repository \
2024-06-21 11:15:22 +00:00
in "${CIDD_GIT_CHILD}" "${CIDD_GIT_PARENT}" ; do
2024-04-30 11:45:05 +00:00
cd_split
2024-06-08 15:15:53 +00:00
cd_install_python_modules__url="\
2024-06-21 11:15:22 +00:00
${CIDD_PROJECTS_URL}/${cd_install_python_modules__repository}"
2024-06-08 09:56:38 +00:00
echo "\
2024-06-08 15:15:53 +00:00
${cd_install_python_modules__url}
2024-06-08 09:56:38 +00:00
"
2024-04-26 18:09:11 +00:00
git clone \
2024-06-08 15:15:53 +00:00
"${cd_install_python_modules__url}" \
"${cd_install_python_modules__root}\
/${cd_install_python_modules__repository}" \
2024-04-26 18:29:26 +00:00
|| exit
2024-06-08 15:15:53 +00:00
cd_install_python_modules__path="\
${cd_install_python_modules__root}\
/${cd_install_python_modules__repository}\
/${cd_install_python_modules__repository}"
2024-06-08 09:56:38 +00:00
echo "\
2024-06-08 15:15:53 +00:00
${cd_install_python_modules__path}
2024-04-28 21:29:31 +00:00
2024-06-21 11:15:22 +00:00
${CIDD_PYTHON_PACKAGES}"
2024-04-26 19:30:36 +00:00
cp --recursive \
2024-06-21 11:15:22 +00:00
"${cd_install_python_modules__path}" "${CIDD_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-06-21 11:15:22 +00:00
cd_ls "${CIDD_PYTHON_PACKAGES}"
2024-06-06 09:36:06 +00:00
cd_split
2024-06-08 15:15:53 +00:00
cd_rm "${cd_install_python_modules__root}"
2024-04-26 16:54:09 +00:00
}
2024-06-04 19:13:08 +00:00
cd_write_python_module () {
cd_step "Write Python module"
2024-06-08 17:15:47 +00:00
for cd_write_python_module__variable \
in OPEN DOWN VERT SPLT __UP SHUT OS_ID OS_VERSION ; do
cd_write_python_module__value="\
2024-06-21 11:15:22 +00:00
$(cd_echo "CIDD_${cd_write_python_module__variable}")"
2024-06-08 17:15:47 +00:00
cd_write_python_module__text="${cd_write_python_module__text}\
${cd_write_python_module__value}
"
done
2024-06-21 11:15:22 +00:00
cd_write "${CIDD_PYTHON_PACKAGES}/env.py" "${cd_write_python_module__text}\
CIDD_STEP = $((CIDD_STEP+1))
2024-06-04 07:18:54 +00:00
"
2024-06-04 19:13:08 +00:00
}
cd_switch_to_python () {
cd_step "Switch to Python"
2024-06-08 09:56:38 +00:00
echo "\
2024-06-21 11:15:22 +00:00
${CIDD_PATH}
2024-04-28 13:42:36 +00:00
2024-06-21 11:15:22 +00:00
${CIDD_PYTHON_PACKAGES}/${CIDD_GIT_CHILD}"
"${CIDD_PYTHON_ALIAS}" -m "${CIDD_GIT_CHILD}" "${@}"
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 () {
2024-06-08 14:10:45 +00:00
cd_cat__file="${1}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_cat__file}" ] ; then
2024-06-08 14:10:45 +00:00
cd_open "${cd_cat__file}"
cat "${cd_cat__file}" || exit
cd_shut "${cd_cat__file}"
2024-04-28 10:35:43 +00:00
fi
}
2024-05-02 07:59:17 +00:00
cd_echo () {
2024-06-08 16:11:41 +00:00
if [ -n "${1}" ] ; then
2024-06-08 14:09:18 +00:00
for cd_echo__name in "${@}" ; do
2024-06-17 16:56:31 +00:00
eval "cd_echo__text=\"\${${cd_echo__name}}\""
echo "${cd_echo__name} = \"${cd_echo__text}\""
2024-05-02 07:59:17 +00:00
done
fi
}
2024-04-29 09:01:48 +00:00
cd_error_ci () {
2024-06-08 14:08:06 +00:00
echo "× CI: ${*}"
2024-06-21 11:15:22 +00:00
exit "${CIDD_ERROR_CI}"
2024-04-29 09:01:48 +00:00
}
2024-05-02 08:33:34 +00:00
2024-04-29 09:01:48 +00:00
cd_error_os () {
2024-06-08 14:08:06 +00:00
cd_error_os__variable="${1}"
2024-06-07 13:45:18 +00:00
printf "× OS: "
2024-06-08 14:08:06 +00:00
cd_echo "${cd_error_os__variable}"
2024-06-21 11:15:22 +00:00
exit "${CIDD_ERROR_OS}"
2024-04-29 09:01:48 +00:00
}
2024-05-03 10:42:35 +00:00
cd_grep_os () {
2024-06-08 11:24:43 +00:00
cd_grep_os__variable="${1}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_grep_os__variable}" ] ; then
2024-06-08 11:24:43 +00:00
grep "^${cd_grep_os__variable}=" "/etc/os-release" \
| sed "s|^${cd_grep_os__variable}=||" \
2024-05-04 11:35:35 +00:00
| sed "s|^\"\(.*\)\"$|\1|"
2024-05-03 10:42:35 +00:00
fi
2024-05-02 14:46:08 +00:00
}
2024-04-27 19:38:43 +00:00
cd_install_package () {
2024-06-08 11:21:17 +00:00
cd_install_package__name="${1}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_install_package__name}" ] ; then
2024-06-21 11:15:22 +00:00
${CIDD_PM_INSTALL} "${cd_install_package__name}" || exit
2024-04-27 19:38:43 +00:00
fi
}
2024-05-03 22:24:14 +00:00
cd_ln_python () {
2024-06-08 10:45:43 +00:00
cd_ln_python__command="${1}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_ln_python__command}" ] ; then
2024-06-21 11:15:22 +00:00
echo "${CIDD_PYTHON_ALIAS}${cd_ln_python__command}"
ln -f -s "${cd_ln_python__command}" "/usr/bin/${CIDD_PYTHON_ALIAS}" \
2024-06-08 10:45:43 +00:00
|| exit
2024-05-03 22:24:14 +00:00
fi
}
2024-05-04 08:30:33 +00:00
cd_ls () {
2024-06-08 10:42:10 +00:00
cd_ls__path="${1}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_ls__path}" ] ; then
2024-06-08 10:42:10 +00:00
cd_open "${cd_ls__path}"
ls -a -l "${cd_ls__path}" || exit
cd_shut "${cd_ls__path}"
2024-05-04 08:30:33 +00:00
fi
}
2024-04-29 18:16:14 +00:00
cd_mkdir () {
2024-06-08 10:37:06 +00:00
cd_mkdir__path="${1}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_mkdir__path}" ] ; then
2024-06-08 10:37:06 +00:00
echo "${cd_mkdir__path}"
mkdir --parents "${cd_mkdir__path}" || exit
2024-04-29 18:16:14 +00:00
fi
}
2024-06-04 21:18:25 +00:00
cd_open () {
2024-06-21 11:15:22 +00:00
echo "${CIDD_OPEN}${*}"
2024-06-04 21:18:25 +00:00
}
2024-05-04 07:50:13 +00:00
cd_openssl () {
2024-06-08 10:18:39 +00:00
cd_openssl__file="${1}"
if [ -f "${cd_openssl__file}" ] ; then
openssl x509 \
-in "${cd_openssl__file}" \
-noout -text \
|| exit
2024-05-04 07:50:13 +00:00
fi
}
2024-04-28 11:00:18 +00:00
cd_rm () {
2024-06-08 10:35:51 +00:00
cd_rm__path="${1}"
if [ -e "${cd_rm__path}" ] ; then
echo "${cd_rm__path}"
rm -r "${cd_rm__path}" || exit
2024-04-28 11:00:18 +00:00
fi
}
2024-04-29 21:07:52 +00:00
cd_sed () {
2024-06-08 10:32:21 +00:00
cd_sed__file="${1}"
shift
if [ -f "${cd_sed__file}" ] ; then
cd_cat "${cd_sed__file}"
for cd_sed__regex in "${@}" ; do
sed --in-place "s${cd_sed__regex}g" "${cd_sed__file}" \
&& cd_cat "${cd_sed__file}" \
2024-05-23 13:47:50 +00:00
|| exit
2024-04-29 21:07:52 +00:00
done
fi
}
2024-06-04 21:18:25 +00:00
cd_shut () {
2024-06-21 11:15:22 +00:00
echo "${CIDD_SHUT}${*}"
2024-06-04 21:18:25 +00:00
}
2024-04-30 10:36:33 +00:00
cd_split () {
2024-06-21 11:15:22 +00:00
echo "${CIDD_SPLT}"
2024-04-30 10:36:33 +00:00
}
2024-04-27 19:24:59 +00:00
cd_step () {
2024-06-21 11:15:22 +00:00
CIDD_STEP=$((CIDD_STEP+1))
2024-06-08 09:56:38 +00:00
echo "\
2024-06-21 11:15:22 +00:00
${CIDD_DOWN}
${CIDD_VERT} ${CIDD_STEP} ${*}
${CIDD___UP}"
2024-04-27 19:24:59 +00:00
}
cd_write () {
2024-06-08 10:05:37 +00:00
cd_write__file="${1}"
cd_write__text="${2}"
2024-06-08 16:11:41 +00:00
if [ -n "${cd_write__file}" ] ; then
2024-06-08 10:05:37 +00:00
[ -f "${cd_write__file}" ] && cd_cat "${cd_write__file}"
echo "${cd_write__file}"
printf "%s" "${cd_write__text}" > "${cd_write__file}" || exit
cd_cat "${cd_write__file}"
2024-04-27 19:24:59 +00:00
fi
}
2024-05-02 09:10:54 +00:00
# constants
2024-06-21 11:15:22 +00:00
CIDD_BOX_DOWN="╭"
CIDD_BOX_LEFT="╴"
CIDD_BOX_RIGHT="╶"
CIDD_BOX_UP="╰"
CIDD_BOX_VERTICAL="│"
CIDD_ERROR_CI=2
CIDD_ERROR_OS=1
CIDD_OS_ALMA="alma"
CIDD_OS_ALPINE="alpine"
CIDD_OS_ARCH="arch"
CIDD_OS_DEBIAN="debian"
CIDD_OS_FEDORA="fedora"
CIDD_OS_ROCKY="rocky"
CIDD_OS_UBUNTU="ubuntu"
CIDD_PM_APK="apk"
CIDD_PM_APT="apt"
CIDD_PM_DNF="dnf"
CIDD_PM_PACMAN="pacman"
CIDD_HORIZONTAL="────╌╌╌╌┄┄┄┄┈┈┈┈"
CIDD_OPEN="${CIDD_BOX_DOWN}${CIDD_BOX_LEFT}"
CIDD_DOWN="${CIDD_BOX_DOWN}${CIDD_HORIZONTAL}"
CIDD_VERT="${CIDD_BOX_VERTICAL}"
CIDD_SPLT="${CIDD_BOX_RIGHT}${CIDD_HORIZONTAL}"
CIDD___UP="${CIDD_BOX_UP}${CIDD_HORIZONTAL}"
CIDD_SHUT="${CIDD_BOX_UP}${CIDD_BOX_LEFT}"
2024-06-04 18:10:29 +00:00
2024-05-02 08:19:18 +00:00
# run
2024-06-01 20:26:36 +00:00
cd_main "${@}"