spcd/pidd.sh

839 lines
25 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 12:57:57 +00:00
[ -n "${PIDD_DNS}" ] || PIDD_DNS="\
2024-04-29 13:10:51 +00:00
9.9.9.9 \
"
2024-06-23 20:23:05 +00:00
[ -n "${PIDD_GIT_MAIN}" ] || PIDD_GIT_MAIN="pidd"
[ -n "${PIDD_GIT_ROOT}" ] || PIDD_GIT_ROOT="rwx"
2024-04-26 11:38:38 +00:00
2024-05-02 08:19:18 +00:00
# main
2024-06-24 08:48:26 +00:00
pidd_main() {
2024-06-23 20:53:19 +00:00
pidd_list_environment_variables
pidd_list_working_directory
#
2024-06-21 12:57:57 +00:00
pidd_set_environment_variables
pidd_set_packages_repositories
pidd_set_packages_configuration
2024-05-04 10:52:28 +00:00
#
2024-06-21 12:57:57 +00:00
pidd_set_https_verification_off
pidd_set_dns_resolving
pidd_update_packages_catalog
pidd_install_packages_tools
pidd_install_ca_certificates
pidd_write_ca_certificates
pidd_update_ca_certificates
pidd_set_https_verification_on
pidd_update_packages_catalog
pidd_upgrade_packages
pidd_install_git
pidd_install_python
2024-05-30 18:38:32 +00:00
# TODO move to Python
2024-06-21 12:57:57 +00:00
pidd_install_rsync
2024-05-30 19:29:06 +00:00
# TODO move to Python
2024-06-21 12:57:57 +00:00
pidd_install_ssh
pidd_clean_packages_cache
pidd_install_python_modules
pidd_write_python_module
pidd_switch_to_python "${@}"
2024-04-27 15:36:14 +00:00
}
2024-06-24 06:10:47 +00:00
# context
2024-06-24 08:48:26 +00:00
pidd_list_environment_variables() {
2024-06-24 06:10:47 +00:00
pidd_step "List environment variables"
env | sort
}
2024-06-24 08:48:26 +00:00
pidd_list_working_directory() {
2024-06-24 06:10:47 +00:00
pidd_step "List working directory"
2024-06-24 06:16:50 +00:00
pidd_lwd__path="$(realpath .)"
pidd_ls "${pidd_lwd__path}"
2024-06-24 06:10:47 +00:00
}
2024-05-02 08:19:18 +00:00
# steps
2024-04-27 19:47:02 +00:00
2024-06-24 08:48:26 +00:00
pidd_set_environment_variables() {
2024-06-21 12:57:57 +00:00
pidd_step "Set environment variables"
2024-06-08 14:21:46 +00:00
# set path
2024-06-21 12:57:57 +00:00
PIDD_PATH="$(realpath "${0}")"
pidd_echo "PIDD_PATH"
2024-05-23 13:20:25 +00:00
# set operating system id
2024-06-21 12:57:57 +00:00
PIDD_OS_ID="$(pidd_grep_os ID)"
case "${PIDD_OS_ID}" in
"almalinux") PIDD_OS_ID="${PIDD_OS_ALMA}" ;;
"alpine") PIDD_OS_ID="${PIDD_OS_ALPINE}" ;;
"arch") PIDD_OS_ID="${PIDD_OS_ARCH}" ;;
"debian") PIDD_OS_ID="${PIDD_OS_DEBIAN}" ;;
"fedora") PIDD_OS_ID="${PIDD_OS_FEDORA}" ;;
"rocky") PIDD_OS_ID="${PIDD_OS_ROCKY}" ;;
"ubuntu") PIDD_OS_ID="${PIDD_OS_UBUNTU}" ;;
*) pidd_error_os "PIDD_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 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_ARCH}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}")
PIDD_OS_VERSION=$(pidd_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 12:57:57 +00:00
"${PIDD_OS_ALPINE}")
PIDD_OS_VERSION=$(pidd_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 12:57:57 +00:00
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}")
PIDD_OS_VERSION="$(pidd_grep_os VERSION_CODENAME)"
2024-05-05 18:27:18 +00:00
;;
2024-06-24 08:59:41 +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 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_ROCKY}")
case "${PIDD_OS_VERSION}" in
2024-05-04 16:27:32 +00:00
"8"|"9") ;;
2024-06-21 12:57:57 +00:00
*) pidd_error_os "PIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALPINE}")
case "${PIDD_OS_VERSION}" in
2024-05-04 16:27:32 +00:00
"3.18"|"3.19") ;;
2024-06-21 12:57:57 +00:00
*) pidd_error_os "PIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ARCH}")
case "${PIDD_OS_VERSION}" in
2024-05-05 18:27:18 +00:00
"20231112"|"20240101") ;;
2024-06-21 12:57:57 +00:00
*) pidd_error_os "PIDD_OS_VERSION" ;;
2024-05-05 18:27:18 +00:00
esac
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}")
case "${PIDD_OS_VERSION}" in
2024-05-04 16:27:32 +00:00
"bookworm"|"bullseye") ;;
2024-06-21 12:57:57 +00:00
*) pidd_error_os "PIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_FEDORA}")
case "${PIDD_OS_VERSION}" in
2024-05-06 09:36:27 +00:00
"39"|"40") ;;
2024-06-21 12:57:57 +00:00
*) pidd_error_os "PIDD_OS_VERSION" ;;
2024-05-06 09:36:27 +00:00
esac
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_UBUNTU}")
case "${PIDD_OS_VERSION}" in
2024-05-06 09:56:45 +00:00
"jammy"|"noble") ;;
2024-06-21 12:57:57 +00:00
*) pidd_error_os "PIDD_OS_VERSION" ;;
2024-05-04 16:27:32 +00:00
esac
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 16:27:32 +00:00
esac
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_OS_ID" "PIDD_OS_VERSION"
2024-05-04 14:30:40 +00:00
# universal
2024-06-21 12:57:57 +00:00
PIDD_DNS_FILE="/etc/resolv.conf"
PIDD_PKG_CA="ca-certificates"
PIDD_PKG_GIT="git"
2024-05-30 18:38:32 +00:00
# TODO move to Python
2024-06-21 12:57:57 +00:00
PIDD_PKG_RSYNC="rsync"
PIDD_PYTHON_ALIAS="python3"
pidd_split
pidd_echo "PIDD_DNS_FILE" "PIDD_PKG_CA" "PIDD_PKG_GIT" "PIDD_PYTHON_ALIAS"
2024-05-23 13:20:25 +00:00
# set ca command & root
2024-06-21 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}")
PIDD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
PIDD_CMD_CA="update-ca-trust"
2024-05-10 20:40:01 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALPINE}")
PIDD_CA_ROOT="/usr/local/share/ca-certificates"
PIDD_CMD_CA="update-ca-certificates"
2024-05-04 15:47:07 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ARCH}")
PIDD_CA_ROOT="/etc/ca-certificates/trust-source/anchors"
PIDD_CMD_CA="update-ca-trust"
2024-05-05 20:06:09 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}")
PIDD_CA_ROOT="/usr/local/share/ca-certificates"
PIDD_CMD_CA="update-ca-certificates"
2024-05-04 15:12:08 +00:00
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 15:10:00 +00:00
esac
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_CA_ROOT" "PIDD_CMD_CA"
2024-05-23 13:20:25 +00:00
# set package manager
2024-06-21 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALPINE}")
PIDD_PM="${PIDD_PM_APK}"
2024-05-23 14:40:03 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}")
PIDD_PM="${PIDD_PM_APT}"
2024-05-23 14:40:03 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALMA}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}")
PIDD_PM="${PIDD_PM_DNF}"
2024-05-23 14:40:03 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ARCH}")
PIDD_PM="${PIDD_PM_PACMAN}"
2024-05-23 14:40:03 +00:00
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-23 14:40:03 +00:00
esac
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_PM"
case "${PIDD_PM}" in
"${PIDD_PM_DNF}")
PIDD_PM_CLEAN="dnf clean all"
PIDD_PM_INSTALL="dnf install --assumeyes"
PIDD_PM_QUERY="rpm --query"
PIDD_PM_UPDATE="dnf makecache"
PIDD_PM_UPGRADE="dnf upgrade --assumeyes"
PIDD_PKG_PKG=""
PIDD_PM_CONF_PATH="/etc/dnf/dnf.conf"
PIDD_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 12:57:57 +00:00
PIDD_PM_HTTPS_PATH="/etc/dnf/dnf.conf.d/https.conf"
PIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
sslverify=False
"
2024-05-04 15:50:43 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_PM_APK}")
PIDD_PM_CLEAN="apk cache purge"
PIDD_PM_INSTALL="apk add"
PIDD_PM_QUERY="apk info"
PIDD_PM_UPDATE="apk update"
PIDD_PM_UPGRADE="apk upgrade"
PIDD_PKG_PKG=""
PIDD_PM_CONF_PATH=""
PIDD_PM_CONF_TEXT=""
PIDD_PM_HTTPS_PATH="/etc/apk/repositories.d/https"
PIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
--no-verify
"
2024-05-04 15:50:43 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_PM_PACMAN}")
PIDD_PM_CLEAN="pacman --sync --clean --noconfirm"
PIDD_PM_INSTALL="pacman --sync --noconfirm"
PIDD_PM_QUERY="pacman --query"
PIDD_PM_UPDATE="pacman --sync --refresh"
PIDD_PM_UPGRADE="pacman --sync --sysupgrade --noconfirm"
PIDD_PKG_PKG=""
PIDD_PM_CONF_PATH=""
PIDD_PM_CONF_TEXT=""
PIDD_PM_HTTPS_PATH="/etc/pacman.d/https.conf"
PIDD_PM_HTTPS_TEXT="\
2024-06-03 19:00:28 +00:00
SSLVerify = No
"
2024-05-05 20:09:26 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_PM_APT}")
PIDD_PM_CLEAN="apt-get clean"
PIDD_PM_INSTALL="apt-get install --assume-yes"
PIDD_PM_QUERY="dpkg-query --show"
PIDD_PM_UPDATE="apt-get update"
PIDD_PM_UPGRADE="apt-get upgrade --assume-yes"
PIDD_PKG_PKG="apt-utils"
PIDD_PM_CONF_PATH="/etc/apt/apt.conf.d/apt.conf"
PIDD_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 12:57:57 +00:00
PIDD_PM_HTTPS_PATH="/etc/apt/apt.conf.d/https"
PIDD_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-24 08:59:41 +00:00
*) ;;
2024-05-04 15:50:43 +00:00
esac
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_PM_CLEAN" \
"PIDD_PM_INSTALL" "PIDD_PM_QUERY" "PIDD_PM_UPDATE" "PIDD_PM_UPGRADE"
pidd_split
pidd_echo "PIDD_PKG_PKG" "PIDD_PM_CONF_PATH" "PIDD_PM_HTTPS_PATH"
2024-05-04 17:33:07 +00:00
# specific
2024-06-21 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}")
PIDD_URL_DEFAULT="https://repo.almalinux.org/almalinux"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALPINE}")
PIDD_URL_DEFAULT="https://dl-cdn.alpinelinux.org/alpine"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ARCH}")
PIDD_URL_DEFAULT="https://geo.mirror.pkgbuild.com"
2024-05-06 11:42:33 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}")
PIDD_URL_DEFAULT="http://deb.debian.org/debian"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_FEDORA}")
PIDD_URL_DEFAULT="http://download.example/pub/fedora/linux/releases"
2024-05-06 09:36:27 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ROCKY}")
PIDD_URL_DEFAULT="http://dl.rockylinux.org/\$contentdir"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_UBUNTU}")
PIDD_URL_DEFAULT="http://archive.ubuntu.com/ubuntu"
2024-05-04 18:17:46 +00:00
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 18:17:46 +00:00
esac
2024-06-21 12:57:57 +00:00
PIDD_URL_CHOSEN="${PIDD_URL_DEFAULT}"
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}")
[ -n "${PIDD_URL_ALMA}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ALMA}"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALPINE}")
[ -n "${PIDD_URL_ALPINE}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ALPINE}"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ARCH}")
[ -n "${PIDD_URL_ARCH}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ARCH}"
2024-06-02 14:29:41 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}")
[ -n "${PIDD_URL_DEBIAN}" ] && PIDD_URL_CHOSEN="${PIDD_URL_DEBIAN}" \
|| PIDD_URL_CHOSEN="https://deb.debian.org/debian"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_FEDORA}")
[ -n "${PIDD_URL_FEDORA}" ] && PIDD_URL_CHOSEN="${PIDD_URL_FEDORA}" \
|| PIDD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases"
2024-05-06 09:36:27 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ROCKY}")
[ -n "${PIDD_URL_ROCKY}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ROCKY}" \
|| PIDD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir"
2024-05-04 18:17:46 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_UBUNTU}")
[ -n "${PIDD_URL_UBUNTU}" ] && PIDD_URL_CHOSEN="${PIDD_URL_UBUNTU}" \
|| PIDD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu"
2024-05-04 18:17:46 +00:00
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 17:33:07 +00:00
esac
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_URL_DEFAULT" "PIDD_URL_CHOSEN"
2024-05-23 13:20:25 +00:00
# set python command & package
2024-06-21 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_ROCKY}")
PIDD_PYTHON_COMMAND="python3.11"
PIDD_PYTHON_PACKAGE="python3.11"
;;
"${PIDD_OS_ALPINE}")
PIDD_PYTHON_COMMAND="python3.11"
PIDD_PYTHON_PACKAGE="python3"
;;
"${PIDD_OS_ARCH}")
PIDD_PYTHON_COMMAND="python3.12"
PIDD_PYTHON_PACKAGE="python"
;;
"${PIDD_OS_DEBIAN}")
case "${PIDD_OS_VERSION}" in
"bookworm") PIDD_PYTHON_COMMAND="python3.11" ;;
"bullseye") PIDD_PYTHON_COMMAND="python3.9" ;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-03 19:03:07 +00:00
esac
2024-06-21 12:57:57 +00:00
PIDD_PYTHON_PACKAGE="python3"
2024-05-03 19:03:07 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_FEDORA}")
PIDD_PYTHON_COMMAND="python3.12"
PIDD_PYTHON_PACKAGE="python3"
2024-05-06 09:36:27 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_UBUNTU}")
case "${PIDD_OS_VERSION}" in
"noble") PIDD_PYTHON_COMMAND="python3.12" ;;
"jammy") PIDD_PYTHON_COMMAND="python3.10" ;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 18:35:29 +00:00
esac
2024-06-21 12:57:57 +00:00
PIDD_PYTHON_PACKAGE="python3"
2024-05-06 09:45:21 +00:00
;;
2024-06-24 08:59:41 +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 12:57:57 +00:00
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}")
PIDD_PYTHON_PACKAGES="/usr/lib64/${PIDD_PYTHON_COMMAND}/site-packages"
2024-05-06 09:45:21 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALPINE}"|"${PIDD_OS_ARCH}")
PIDD_PYTHON_PACKAGES="/usr/lib/${PIDD_PYTHON_COMMAND}/site-packages"
2024-05-06 09:45:21 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}")
PIDD_PYTHON_PACKAGES="/usr/lib/${PIDD_PYTHON_ALIAS}/dist-packages"
2024-05-04 18:35:29 +00:00
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-04-27 09:59:30 +00:00
esac
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_PYTHON_COMMAND" "PIDD_PYTHON_PACKAGE" "PIDD_PYTHON_PACKAGES"
2024-05-04 14:23:02 +00:00
# variables
2024-06-21 12:57:57 +00:00
[ -n "${PIDD_CA_1}" ] && PIDD_CA=true
2024-05-03 11:06:52 +00:00
# continuous integration platform
2024-06-24 09:04:10 +00:00
if [ -n "${GITHUB_ACTIONS}" ]; then
2024-05-04 20:57:17 +00:00
# github → gitea → forgejo
2024-06-24 09:04:10 +00:00
if [ -n "${GITHUB_SERVER_URL}" ]; then
2024-06-23 21:11:51 +00:00
PIDD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//"
2024-06-24 09:04:10 +00:00
if [ -n "${GITHUB_TOKEN}" ]; then
2024-06-23 21:11:51 +00:00
PIDD_PROJECT_ROOT="${PIDD_PROJECT_ROOT}${GITHUB_TOKEN}@"
2024-06-23 18:48:37 +00:00
fi
2024-06-23 21:11:51 +00:00
PIDD_PROJECT_ROOT="${PIDD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
2024-06-08 21:14:27 +00:00
else
2024-06-21 12:57:57 +00:00
pidd_error_ci "GITHUB_SERVER_URL"
2024-06-08 21:14:27 +00:00
fi
2024-06-24 09:04:10 +00:00
if [ -n "${GITHUB_REPOSITORY}" ]; then
2024-06-23 18:48:37 +00:00
PIDD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")"
2024-06-21 12:57:57 +00:00
PIDD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
2024-06-08 21:14:27 +00:00
else
2024-06-21 12:57:57 +00:00
pidd_error_ci "GITHUB_REPOSITORY"
2024-06-08 21:14:27 +00:00
fi
2024-06-24 09:04:10 +00:00
if [ -n "${GITHUB_REF_NAME}" ]; then
2024-06-21 12:57:57 +00:00
PIDD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
2024-06-08 21:14:27 +00:00
else
2024-06-21 12:57:57 +00:00
pidd_error_ci "GITHUB_REF_NAME"
2024-06-08 21:14:27 +00:00
fi
2024-06-24 09:04:10 +00:00
elif [ -n "${GITLAB_CI}" ]; then
2024-05-03 11:06:52 +00:00
# gitlab
2024-06-24 09:04:10 +00:00
if [ -n "${CI_SERVER_PROTOCOL}" ]; then
if [ -n "${CI_REGISTRY_USER}" ]; then
if [ -n "${CI_REGISTRY_PASSWORD}" ]; then
if [ -n "${CI_SERVER_FQDN}" ]; then
2024-06-23 18:48:37 +00:00
PIDD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
2024-06-24 09:04:10 +00:00
if [ -n "${CI_PROJECT_NAMESPACE}" ]; then
2024-06-23 18:48:37 +00:00
PIDD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}"
2024-06-24 09:04:10 +00:00
if [ -n "${CI_PROJECT_NAME}" ]; then
2024-06-23 18:48:37 +00:00
PIDD_PROJECT_NAME="${CI_PROJECT_NAME}"
else
pidd_error_ci "CI_PROJECT_NAME"
fi
else
pidd_error_ci "CI_PROJECT_NAMESPACE"
fi
else
pidd_error_ci "CI_SERVER_FQDN"
fi
else
pidd_error_ci "CI_REGISTRY_PASSWORD"
fi
else
pidd_error_ci "CI_REGISTRY_USER"
fi
2024-06-08 21:14:27 +00:00
else
2024-06-23 18:48:37 +00:00
pidd_error_ci "CI_SERVER_PROTOCOL"
2024-06-08 21:14:27 +00:00
fi
2024-06-24 09:04:10 +00:00
if [ -n "${CI_COMMIT_BRANCH}" ]; then
2024-06-21 12:57:57 +00:00
PIDD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
2024-06-08 21:14:27 +00:00
else
2024-06-21 12:57:57 +00:00
pidd_error_ci "CI_COMMIT_BRANCH"
2024-06-08 21:14:27 +00:00
fi
2024-04-27 09:59:30 +00:00
else
2024-05-03 11:06:52 +00:00
# unsupported
2024-06-21 12:57:57 +00:00
pidd_error_ci "ø"
2024-04-27 09:59:30 +00:00
fi
2024-06-23 18:48:37 +00:00
[ -n "${PIDD_PROJECT_ROOT}" ] || pidd_error_ci "PIDD_PROJECT_ROOT"
[ -n "${PIDD_PROJECT_PATH}" ] || pidd_error_ci "PIDD_PROJECT_PATH"
2024-06-21 12:57:57 +00:00
[ -n "${PIDD_PROJECT_NAME}" ] || pidd_error_ci "PIDD_PROJECT_NAME"
[ -n "${PIDD_PROJECT_BRANCH}" ] || pidd_error_ci "PIDD_PROJECT_BRANCH"
2024-04-29 08:58:37 +00:00
#
2024-06-21 12:57:57 +00:00
pidd_split
pidd_echo "PIDD_CA"
pidd_split
2024-06-23 18:48:37 +00:00
pidd_echo "PIDD_PROJECT_ROOT" \
"PIDD_PROJECT_PATH" "PIDD_PROJECT_NAME" "PIDD_PROJECT_BRANCH"
2024-05-30 19:29:06 +00:00
# TODO move to Python
2024-06-21 12:57:57 +00:00
case "${PIDD_PM}" in
"${PIDD_PM_APK}"|"${PIDD_PM_APT}") PIDD_PKG_SSH="openssh-client" ;;
"${PIDD_PM_DNF}") PIDD_PKG_SSH="openssh-clients" ;;
"${PIDD_PM_PACMAN}") PIDD_PKG_SSH="openssh" ;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-30 19:29:06 +00:00
esac
2024-04-27 09:56:16 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_set_packages_repositories() {
2024-06-21 12:57:57 +00:00
pidd_step "Set packages repositories"
case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}")
case "${PIDD_OS_VERSION}" in
2024-06-24 06:21:45 +00:00
"8") pidd_spr__file="/etc/yum.repos.d/almalinux.repo" ;;
"9") pidd_spr_file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 20:51:23 +00:00
esac
2024-06-24 06:21:45 +00:00
pidd_sed "${pidd_spr__file}" \
2024-05-03 17:02:51 +00:00
"|^mirrorlist|# mirrorlist|" \
2024-06-21 12:57:57 +00:00
"|${PIDD_URL_DEFAULT}|${PIDD_URL_CHOSEN}|" \
2024-05-03 17:02:51 +00:00
"|^# baseurl|baseurl|"
2024-04-29 20:41:28 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ALPINE}")
2024-06-24 06:21:45 +00:00
pidd_spr__file="/etc/apk/repositories"
pidd_write "${pidd_spr__file}" "\
2024-06-21 12:57:57 +00:00
${PIDD_URL_CHOSEN}/v${PIDD_OS_VERSION}/main
${PIDD_URL_CHOSEN}/v${PIDD_OS_VERSION}/community
2024-05-04 10:50:20 +00:00
"
2024-05-04 10:41:08 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_DEBIAN}")
2024-06-24 06:21:45 +00:00
pidd_spr__file="/etc/apt/sources.list"
pidd_write "${pidd_spr__file}" "\
2024-06-21 12:57:57 +00:00
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION} main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-backports main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-updates main
deb ${PIDD_URL_CHOSEN}-security ${PIDD_OS_VERSION}-security main
2024-05-03 19:03:07 +00:00
"
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_ROCKY}")
case "${PIDD_OS_VERSION}" in
2024-06-24 06:21:45 +00:00
"8") pidd_spr__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;;
"9") pidd_spr__file="/etc/yum.repos.d/rocky.repo" ;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 20:51:23 +00:00
esac
2024-06-24 06:21:45 +00:00
pidd_sed "${pidd_spr__file}" \
2024-05-04 20:51:23 +00:00
"|^mirrorlist|# mirrorlist|" \
2024-06-21 12:57:57 +00:00
"|${PIDD_URL_DEFAULT}|${PIDD_URL_CHOSEN}|" \
2024-05-04 20:51:23 +00:00
"|^#baseurl|baseurl|"
2024-05-04 19:39:20 +00:00
;;
2024-06-21 12:57:57 +00:00
"${PIDD_OS_UBUNTU}")
2024-06-24 06:21:45 +00:00
pidd_spr__file="/etc/apt/sources.list"
pidd_write "${pidd_spr__file}" "\
2024-06-21 12:57:57 +00:00
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION} main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-backports main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-updates main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-security main
2024-05-04 21:47:31 +00:00
"
2024-05-04 19:39:20 +00:00
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-04-26 14:13:35 +00:00
esac
}
2024-06-24 08:48:26 +00:00
pidd_set_packages_configuration() {
2024-06-21 12:57:57 +00:00
pidd_step "Set packages configuration"
pidd_write "${PIDD_PM_CONF_PATH}" "${PIDD_PM_CONF_TEXT}"
case "${PIDD_OS_ID}" in
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}")
2024-05-04 20:36:30 +00:00
export DEBIAN_FRONTEND="noninteractive"
;;
2024-06-24 08:59:41 +00:00
*) ;;
2024-05-04 20:36:30 +00:00
esac
}
2024-05-03 21:19:30 +00:00
# agnostic steps
2024-06-24 08:48:26 +00:00
pidd_set_https_verification_off() {
2024-06-24 09:04:10 +00:00
if [ -n "${PIDD_CA}" ] || [ "${PIDD_PM}" = "${PIDD_PM_APT}" ]; then
2024-06-21 12:57:57 +00:00
pidd_step "Set HTTPS verification off"
pidd_mkdir "$(dirname "${PIDD_PM_HTTPS_PATH}")"
pidd_write "${PIDD_PM_HTTPS_PATH}" "${PIDD_PM_HTTPS_TEXT}"
2024-05-03 18:20:26 +00:00
fi
2024-04-26 14:23:30 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_set_dns_resolving() {
2024-06-21 12:57:57 +00:00
pidd_step "Set DNS resolving"
2024-06-24 06:25:38 +00:00
for pidd_sdr__server in ${PIDD_DNS} ; do
pidd_sdr__text="${pidd_sdr__text}\
nameserver ${pidd_sdr__server}
2024-05-04 10:14:30 +00:00
"
done
2024-06-24 06:25:38 +00:00
pidd_write "${PIDD_DNS_FILE}" "${pidd_sdr__text}"
2024-05-04 10:14:30 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_update_packages_catalog() {
2024-06-21 12:57:57 +00:00
pidd_step "Update packages catalog"
${PIDD_PM_UPDATE} || exit
2024-04-26 14:27:36 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_install_packages_tools() {
2024-06-21 12:57:57 +00:00
pidd_step "Install packages tools"
pidd_install_package "${PIDD_PKG_PKG}"
2024-06-21 11:20:20 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_install_ca_certificates() {
2024-06-21 12:57:57 +00:00
pidd_step "Install CA"
pidd_install_package "${PIDD_PKG_CA}"
2024-06-21 11:20:20 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_write_ca_certificates() {
2024-06-21 12:57:57 +00:00
pidd_step "Write CA certificates"
pidd_mkdir "${PIDD_CA_ROOT}"
2024-06-24 06:30:54 +00:00
pidd_wcc__index=1
eval "pidd_wcc__text=\"\${PIDD_CA_${pidd_wcc__index}}\""
while [ -n "${pidd_wcc__text}" ] ; do
pidd_wcc__path="${PIDD_CA_ROOT}/${pidd_wcc__index}.crt"
2024-06-21 12:57:57 +00:00
pidd_split
pidd_write \
2024-06-24 06:30:54 +00:00
"${pidd_wcc__path}" \
"${pidd_wcc__text}"
pidd_openssl "${pidd_wcc__path}"
pidd_wcc__index=$((pidd_wcc__index+1))
eval "pidd_wcc__text=\"\${PIDD_CA_${pidd_wcc__index}}\""
2024-05-03 15:20:44 +00:00
done
}
2024-06-24 08:48:26 +00:00
pidd_update_ca_certificates() {
2024-06-21 12:57:57 +00:00
pidd_step "Update CA certificates"
${PIDD_CMD_CA} || exit
2024-04-27 21:58:48 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_set_https_verification_on() {
2024-06-21 12:57:57 +00:00
pidd_step "Set HTTPS verification on"
pidd_rm "${PIDD_PM_HTTPS_PATH}"
2024-04-26 14:50:25 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_upgrade_packages() {
2024-06-21 12:57:57 +00:00
pidd_step "Upgrade packages"
${PIDD_PM_UPGRADE} || exit
2024-04-26 14:35:15 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_install_git() {
2024-06-21 12:57:57 +00:00
pidd_step "Install Git"
pidd_install_package "${PIDD_PKG_GIT}"
2024-04-26 14:35:15 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_install_python() {
2024-06-21 12:57:57 +00:00
pidd_step "Install Python"
pidd_install_package "${PIDD_PYTHON_PACKAGE}"
pidd_split
pidd_ln_python "${PIDD_PYTHON_COMMAND}"
2024-04-26 14:39:24 +00:00
}
2024-05-30 18:38:32 +00:00
# TODO move to Python
2024-06-24 08:48:26 +00:00
pidd_install_rsync() {
2024-06-21 12:57:57 +00:00
pidd_step "Install Rsync"
pidd_install_package "${PIDD_PKG_RSYNC}"
2024-05-30 18:38:32 +00:00
}
2024-05-30 19:29:06 +00:00
# TODO move to Python
2024-06-24 08:48:26 +00:00
pidd_install_ssh() {
2024-06-21 12:57:57 +00:00
pidd_step "Install SSH"
pidd_install_package "${PIDD_PKG_SSH}"
2024-05-30 19:29:06 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_clean_packages_cache() {
2024-06-21 12:57:57 +00:00
pidd_step "Clean packages cache"
${PIDD_PM_CLEAN} || exit
2024-04-26 14:53:41 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_install_python_modules() {
2024-06-21 12:57:57 +00:00
pidd_step "Install Python modules"
2024-06-24 06:39:21 +00:00
pidd_ipm__root="$(mktemp --directory)" || exit
echo "${pidd_ipm__root}"
for pidd_ipm__repository in "${PIDD_GIT_MAIN}" "${PIDD_GIT_ROOT}" ; do
case "${pidd_ipm__repository}" in
http*) pidd_ipm__url="${pidd_ipm__repository}" ;;
/*) pidd_ipm__url="${PIDD_PROJECT_ROOT}${pidd_ipm__repository}" ;;
*) pidd_ipm__url="\
${PIDD_PROJECT_ROOT}/${PIDD_PROJECT_PATH}/${pidd_ipm__repository}" ;;
2024-06-23 19:58:02 +00:00
esac
2024-06-24 06:39:21 +00:00
pidd_ipm__name="$(basename "${pidd_ipm__url}")"
2024-06-23 19:58:02 +00:00
pidd_split
2024-06-08 09:56:38 +00:00
echo "\
2024-06-24 06:39:21 +00:00
${pidd_ipm__url}
2024-06-08 09:56:38 +00:00
"
2024-04-26 18:09:11 +00:00
git clone \
2024-06-24 06:39:21 +00:00
"${pidd_ipm__url}" \
"${pidd_ipm__root}/${pidd_ipm__name}" \
2024-04-26 18:29:26 +00:00
|| exit
2024-06-24 06:39:21 +00:00
pidd_ipm__path="${pidd_ipm__root}/${pidd_ipm__name}/${pidd_ipm__name}"
2024-06-08 09:56:38 +00:00
echo "\
2024-06-24 06:39:21 +00:00
${pidd_ipm__path}
2024-04-28 21:29:31 +00:00
2024-06-21 12:57:57 +00:00
${PIDD_PYTHON_PACKAGES}"
2024-06-24 06:39:21 +00:00
cp --recursive "${pidd_ipm__path}" "${PIDD_PYTHON_PACKAGES}" \
2024-04-26 18:29:26 +00:00
|| exit
2024-04-26 18:09:11 +00:00
done
2024-06-21 12:57:57 +00:00
pidd_split
pidd_ls "${PIDD_PYTHON_PACKAGES}"
pidd_split
2024-06-24 06:39:21 +00:00
pidd_rm "${pidd_ipm__root}"
2024-04-26 16:54:09 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_write_python_module() {
2024-06-21 12:57:57 +00:00
pidd_step "Write Python module"
2024-06-24 06:43:07 +00:00
for pidd_wpm__variable in \
2024-06-23 18:55:37 +00:00
OPEN DOWN VERT SPLT __UP SHUT \
OS_ID OS_VERSION \
PROJECT_ROOT PROJECT_PATH PROJECT_NAME \
; do
2024-06-24 06:43:07 +00:00
pidd_wpm__value="$(pidd_echo "PIDD_${pidd_wpm__variable}")"
pidd_wpm__text="${pidd_wpm__text}${pidd_wpm__value}
2024-06-08 17:15:47 +00:00
"
done
2024-06-24 06:43:07 +00:00
pidd_write "${PIDD_PYTHON_PACKAGES}/env.py" "${pidd_wpm__text}
2024-06-21 12:57:57 +00:00
PIDD_STEP = $((PIDD_STEP+1))
2024-06-04 07:18:54 +00:00
"
2024-06-04 19:13:08 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_switch_to_python() {
2024-06-21 12:57:57 +00:00
pidd_step "Switch to Python"
2024-06-24 07:51:01 +00:00
pidd_stp__name="$(basename "${PIDD_GIT_MAIN}")"
2024-06-08 09:56:38 +00:00
echo "\
2024-06-21 12:57:57 +00:00
${PIDD_PATH}
2024-04-28 13:42:36 +00:00
2024-06-24 07:51:01 +00:00
${PIDD_PYTHON_PACKAGES}/${pidd_stp__name}"
"${PIDD_PYTHON_ALIAS}" -m "${pidd_stp__name}" "${@}"
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-06-24 08:48:26 +00:00
pidd_cat() {
2024-06-21 12:57:57 +00:00
pidd_cat__file="${1}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_cat__file}" ]; then
2024-06-21 12:57:57 +00:00
pidd_open "${pidd_cat__file}"
cat "${pidd_cat__file}" || exit
pidd_shut "${pidd_cat__file}"
2024-04-28 10:35:43 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_echo() {
2024-06-24 09:04:10 +00:00
if [ -n "${1}" ]; then
2024-06-21 12:57:57 +00:00
for pidd_echo__name in "${@}" ; do
2024-06-23 17:22:25 +00:00
pidd_echo__text=""
2024-06-21 12:57:57 +00:00
eval "pidd_echo__text=\"\${${pidd_echo__name}}\""
echo "${pidd_echo__name} = \"${pidd_echo__text}\""
2024-05-02 07:59:17 +00:00
done
fi
}
2024-06-24 08:48:26 +00:00
pidd_error_ci() {
2024-06-08 14:08:06 +00:00
echo "× CI: ${*}"
2024-06-21 12:57:57 +00:00
exit "${PIDD_ERROR_CI}"
2024-04-29 09:01:48 +00:00
}
2024-05-02 08:33:34 +00:00
2024-06-24 08:48:26 +00:00
pidd_error_os() {
2024-06-21 12:57:57 +00:00
pidd_error_os__variable="${1}"
2024-06-07 13:45:18 +00:00
printf "× OS: "
2024-06-21 12:57:57 +00:00
pidd_echo "${pidd_error_os__variable}"
exit "${PIDD_ERROR_OS}"
2024-04-29 09:01:48 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_grep_os() {
2024-06-21 12:57:57 +00:00
pidd_grep_os__variable="${1}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_grep_os__variable}" ]; then
2024-06-21 12:57:57 +00:00
grep "^${pidd_grep_os__variable}=" "/etc/os-release" \
| sed "s|^${pidd_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-06-24 08:48:26 +00:00
pidd_install_package() {
2024-06-21 12:57:57 +00:00
pidd_install_package__name="${1}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_install_package__name}" ]; then
2024-06-21 12:57:57 +00:00
${PIDD_PM_INSTALL} "${pidd_install_package__name}" || exit
2024-04-27 19:38:43 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_ln_python() {
2024-06-21 12:57:57 +00:00
pidd_ln_python__command="${1}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_ln_python__command}" ]; then
2024-06-21 12:57:57 +00:00
echo "${PIDD_PYTHON_ALIAS}${pidd_ln_python__command}"
ln -f -s "${pidd_ln_python__command}" "/usr/bin/${PIDD_PYTHON_ALIAS}" \
2024-06-08 10:45:43 +00:00
|| exit
2024-05-03 22:24:14 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_ls() {
2024-06-21 12:57:57 +00:00
pidd_ls__path="${1}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_ls__path}" ]; then
2024-06-21 12:57:57 +00:00
pidd_open "${pidd_ls__path}"
ls -a -l "${pidd_ls__path}" || exit
pidd_shut "${pidd_ls__path}"
2024-05-04 08:30:33 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_mkdir() {
2024-06-21 12:57:57 +00:00
pidd_mkdir__path="${1}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_mkdir__path}" ]; then
2024-06-21 12:57:57 +00:00
echo "${pidd_mkdir__path}"
mkdir --parents "${pidd_mkdir__path}" || exit
2024-04-29 18:16:14 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_open() {
2024-06-21 12:57:57 +00:00
echo "${PIDD_OPEN}${*}"
2024-06-04 21:18:25 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_openssl() {
2024-06-21 12:57:57 +00:00
pidd_openssl__file="${1}"
2024-06-24 09:04:10 +00:00
if [ -f "${pidd_openssl__file}" ]; then
2024-06-08 10:18:39 +00:00
openssl x509 \
2024-06-21 12:57:57 +00:00
-in "${pidd_openssl__file}" \
2024-06-08 10:18:39 +00:00
-noout -text \
|| exit
2024-05-04 07:50:13 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_rm() {
2024-06-21 12:57:57 +00:00
pidd_rm__path="${1}"
2024-06-24 09:04:10 +00:00
if [ -e "${pidd_rm__path}" ]; then
2024-06-21 12:57:57 +00:00
echo "${pidd_rm__path}"
rm -r "${pidd_rm__path}" || exit
2024-04-28 11:00:18 +00:00
fi
}
2024-06-24 08:48:26 +00:00
pidd_sed() {
2024-06-21 12:57:57 +00:00
pidd_sed__file="${1}"
2024-06-08 10:32:21 +00:00
shift
2024-06-24 09:04:10 +00:00
if [ -f "${pidd_sed__file}" ]; then
2024-06-21 12:57:57 +00:00
pidd_cat "${pidd_sed__file}"
for pidd_sed__regex in "${@}" ; do
sed --in-place "s${pidd_sed__regex}g" "${pidd_sed__file}" \
&& pidd_cat "${pidd_sed__file}" \
2024-05-23 13:47:50 +00:00
|| exit
2024-04-29 21:07:52 +00:00
done
fi
}
2024-06-24 08:48:26 +00:00
pidd_shut() {
2024-06-21 12:57:57 +00:00
echo "${PIDD_SHUT}${*}"
2024-06-04 21:18:25 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_split() {
2024-06-21 12:57:57 +00:00
echo "${PIDD_SPLT}"
2024-04-30 10:36:33 +00:00
}
2024-06-24 08:48:26 +00:00
pidd_step() {
2024-06-21 12:57:57 +00:00
PIDD_STEP=$((PIDD_STEP+1))
2024-06-08 09:56:38 +00:00
echo "\
2024-06-21 12:57:57 +00:00
${PIDD_DOWN}
${PIDD_VERT} ${PIDD_STEP} ${*}
${PIDD___UP}"
}
2024-06-24 08:48:26 +00:00
pidd_write() {
2024-06-21 12:57:57 +00:00
pidd_write__file="${1}"
pidd_write__text="${2}"
2024-06-24 09:04:10 +00:00
if [ -n "${pidd_write__file}" ]; then
2024-06-21 12:57:57 +00:00
[ -f "${pidd_write__file}" ] && pidd_cat "${pidd_write__file}"
echo "${pidd_write__file}"
printf "%s" "${pidd_write__text}" > "${pidd_write__file}" || exit
pidd_cat "${pidd_write__file}"
2024-04-27 19:24:59 +00:00
fi
}
2024-05-02 09:10:54 +00:00
# constants
2024-06-21 12:57:57 +00:00
PIDD_BOX_DOWN="╭"
PIDD_BOX_LEFT="╴"
PIDD_BOX_RIGHT="╶"
PIDD_BOX_UP="╰"
PIDD_BOX_VERTICAL="│"
PIDD_ERROR_CI=2
PIDD_ERROR_OS=1
PIDD_OS_ALMA="alma"
PIDD_OS_ALPINE="alpine"
PIDD_OS_ARCH="arch"
PIDD_OS_DEBIAN="debian"
PIDD_OS_FEDORA="fedora"
PIDD_OS_ROCKY="rocky"
PIDD_OS_UBUNTU="ubuntu"
PIDD_PM_APK="apk"
PIDD_PM_APT="apt"
PIDD_PM_DNF="dnf"
PIDD_PM_PACMAN="pacman"
PIDD_HORIZONTAL="────╌╌╌╌┄┄┄┄┈┈┈┈"
PIDD_OPEN="${PIDD_BOX_DOWN}${PIDD_BOX_LEFT}"
PIDD_DOWN="${PIDD_BOX_DOWN}${PIDD_HORIZONTAL}"
PIDD_VERT="${PIDD_BOX_VERTICAL}"
PIDD_SPLT="${PIDD_BOX_RIGHT}${PIDD_HORIZONTAL}"
PIDD___UP="${PIDD_BOX_UP}${PIDD_HORIZONTAL}"
PIDD_SHUT="${PIDD_BOX_UP}${PIDD_BOX_LEFT}"
2024-06-04 18:10:29 +00:00
2024-05-02 08:19:18 +00:00
# run
2024-06-21 12:57:57 +00:00
pidd_main "${@}"