Compare commits

..

30 commits

Author SHA1 Message Date
8e50cb2e15
typo
Some checks failed
/ job (push) Failing after 8m53s
2024-06-24 13:05:27 +02:00
7fc3f088cc
split 2024-06-24 13:03:46 +02:00
d3d54bd2be
unsplit 2024-06-24 12:21:45 +02:00
87feb55792
indents 2024-06-24 12:20:16 +02:00
c197081d8e
indents 2024-06-24 12:17:39 +02:00
f50afa916f
indents 2024-06-24 12:15:09 +02:00
d5468ffde6
indent 2024-06-24 12:13:33 +02:00
db2092a251
indents 2024-06-24 12:10:28 +02:00
bc7498fba2
indents 2024-06-24 12:09:07 +02:00
7a9ed2ee10
pidd_sed 2024-06-24 12:04:00 +02:00
3df6f15f0e
seds 2024-06-24 12:01:44 +02:00
6e4692cb37
cases 2024-06-24 11:53:40 +02:00
736a0174ed
cases 2024-06-24 11:44:21 +02:00
3a5a670311
unindent 2024-06-24 11:35:40 +02:00
57a54c31d5
>" 2024-06-24 11:32:47 +02:00
ffcbe5afe0
+ 1 2024-06-24 11:28:36 +02:00
94087de223
; 2024-06-24 11:22:38 +02:00
1bbfa13c10
\t 2024-06-24 11:19:15 +02:00
3a8c567beb
" | " 2024-06-24 11:06:19 +02:00
61f61b08f2
]; 2024-06-24 11:04:10 +02:00
de370d346d
*) ;; 2024-06-24 10:59:41 +02:00
0dbbaaab69
() 2024-06-24 10:48:26 +02:00
81bcc37d25
stp 2024-06-24 09:51:01 +02:00
e7f64392fc
wpm 2024-06-24 08:43:07 +02:00
10b499d979
ipm 2024-06-24 08:39:21 +02:00
b1579d654f
wcc 2024-06-24 08:30:54 +02:00
dfef8ba5a6
sdr 2024-06-24 08:25:38 +02:00
0ee67f04c1
spr 2024-06-24 08:21:45 +02:00
24312b41c5
lwd 2024-06-24 08:16:50 +02:00
bf521a7200
mv 2024-06-24 08:10:47 +02:00

396
pidd.sh
View file

@ -8,7 +8,7 @@
[ -n "${PIDD_GIT_ROOT}" ] || PIDD_GIT_ROOT="rwx" [ -n "${PIDD_GIT_ROOT}" ] || PIDD_GIT_ROOT="rwx"
# main # main
pidd_main () { pidd_main() {
pidd_list_environment_variables pidd_list_environment_variables
pidd_list_working_directory pidd_list_working_directory
# #
@ -38,9 +38,22 @@ pidd_main () {
pidd_switch_to_python "${@}" pidd_switch_to_python "${@}"
} }
# context
pidd_list_environment_variables() {
pidd_step "List environment variables"
env | sort
}
pidd_list_working_directory() {
pidd_step "List working directory"
pidd_lwd__path="$(realpath .)"
pidd_ls "${pidd_lwd__path}"
}
# steps # steps
pidd_set_environment_variables () { pidd_set_environment_variables() {
pidd_step "Set environment variables" pidd_step "Set environment variables"
# set path # set path
PIDD_PATH="$(realpath "${0}")" PIDD_PATH="$(realpath "${0}")"
@ -59,58 +72,59 @@ pidd_set_environment_variables () {
esac esac
# set operating system version # set operating system version
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_ARCH}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}") "${PIDD_OS_ALMA}" | "${PIDD_OS_FEDORA}" | "${PIDD_OS_ROCKY}" | \
PIDD_OS_VERSION=$(pidd_grep_os VERSION_ID \ "${PIDD_OS_ARCH}")
| sed "s|^\([0-9]\+\)\..*|\1|") PIDD_OS_VERSION=$(pidd_grep_os VERSION_ID |
sed "s|^\([0-9]\+\)\..*|\1|")
;; ;;
"${PIDD_OS_ALPINE}") "${PIDD_OS_ALPINE}")
PIDD_OS_VERSION=$(pidd_grep_os VERSION_ID \ PIDD_OS_VERSION=$(pidd_grep_os VERSION_ID |
| sed "s|^\([0-9]\+\.[0-9]\+\)\..*|\1|") sed "s|^\([0-9]\+\.[0-9]\+\)\..*|\1|")
;; ;;
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}") "${PIDD_OS_DEBIAN}" | "${PIDD_OS_UBUNTU}")
PIDD_OS_VERSION="$(pidd_grep_os VERSION_CODENAME)" PIDD_OS_VERSION="$(pidd_grep_os VERSION_CODENAME)"
;; ;;
*) *) ;;
esac esac
# check operating system version # check operating system version
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_ROCKY}") "${PIDD_OS_ALMA}" | "${PIDD_OS_ROCKY}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"8"|"9") ;; "8" | "9") ;;
*) pidd_error_os "PIDD_OS_VERSION" ;; *) pidd_error_os "PIDD_OS_VERSION" ;;
esac esac
;; ;;
"${PIDD_OS_ALPINE}") "${PIDD_OS_ALPINE}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"3.18"|"3.19") ;; "3.18" | "3.19") ;;
*) pidd_error_os "PIDD_OS_VERSION" ;; *) pidd_error_os "PIDD_OS_VERSION" ;;
esac esac
;; ;;
"${PIDD_OS_ARCH}") "${PIDD_OS_ARCH}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"20231112"|"20240101") ;; "20231112" | "20240101") ;;
*) pidd_error_os "PIDD_OS_VERSION" ;; *) pidd_error_os "PIDD_OS_VERSION" ;;
esac esac
;; ;;
"${PIDD_OS_DEBIAN}") "${PIDD_OS_DEBIAN}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"bookworm"|"bullseye") ;; "bookworm" | "bullseye") ;;
*) pidd_error_os "PIDD_OS_VERSION" ;; *) pidd_error_os "PIDD_OS_VERSION" ;;
esac esac
;; ;;
"${PIDD_OS_FEDORA}") "${PIDD_OS_FEDORA}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"39"|"40") ;; "39" | "40") ;;
*) pidd_error_os "PIDD_OS_VERSION" ;; *) pidd_error_os "PIDD_OS_VERSION" ;;
esac esac
;; ;;
"${PIDD_OS_UBUNTU}") "${PIDD_OS_UBUNTU}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"jammy"|"noble") ;; "jammy" | "noble") ;;
*) pidd_error_os "PIDD_OS_VERSION" ;; *) pidd_error_os "PIDD_OS_VERSION" ;;
esac esac
;; ;;
*) *) ;;
esac esac
pidd_split pidd_split
pidd_echo "PIDD_OS_ID" "PIDD_OS_VERSION" pidd_echo "PIDD_OS_ID" "PIDD_OS_VERSION"
@ -125,7 +139,7 @@ pidd_set_environment_variables () {
pidd_echo "PIDD_DNS_FILE" "PIDD_PKG_CA" "PIDD_PKG_GIT" "PIDD_PYTHON_ALIAS" pidd_echo "PIDD_DNS_FILE" "PIDD_PKG_CA" "PIDD_PKG_GIT" "PIDD_PYTHON_ALIAS"
# set ca command & root # set ca command & root
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}") "${PIDD_OS_ALMA}" | "${PIDD_OS_FEDORA}" | "${PIDD_OS_ROCKY}")
PIDD_CA_ROOT="/etc/pki/ca-trust/source/anchors" PIDD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
PIDD_CMD_CA="update-ca-trust" PIDD_CMD_CA="update-ca-trust"
;; ;;
@ -137,11 +151,11 @@ pidd_set_environment_variables () {
PIDD_CA_ROOT="/etc/ca-certificates/trust-source/anchors" PIDD_CA_ROOT="/etc/ca-certificates/trust-source/anchors"
PIDD_CMD_CA="update-ca-trust" PIDD_CMD_CA="update-ca-trust"
;; ;;
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}") "${PIDD_OS_DEBIAN}" | "${PIDD_OS_UBUNTU}")
PIDD_CA_ROOT="/usr/local/share/ca-certificates" PIDD_CA_ROOT="/usr/local/share/ca-certificates"
PIDD_CMD_CA="update-ca-certificates" PIDD_CMD_CA="update-ca-certificates"
;; ;;
*) *) ;;
esac esac
pidd_split pidd_split
pidd_echo "PIDD_CA_ROOT" "PIDD_CMD_CA" pidd_echo "PIDD_CA_ROOT" "PIDD_CMD_CA"
@ -150,16 +164,16 @@ pidd_set_environment_variables () {
"${PIDD_OS_ALPINE}") "${PIDD_OS_ALPINE}")
PIDD_PM="${PIDD_PM_APK}" PIDD_PM="${PIDD_PM_APK}"
;; ;;
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}") "${PIDD_OS_DEBIAN}" | "${PIDD_OS_UBUNTU}")
PIDD_PM="${PIDD_PM_APT}" PIDD_PM="${PIDD_PM_APT}"
;; ;;
"${PIDD_OS_ALMA}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}") "${PIDD_OS_ALMA}" | "${PIDD_OS_FEDORA}" | "${PIDD_OS_ROCKY}")
PIDD_PM="${PIDD_PM_DNF}" PIDD_PM="${PIDD_PM_DNF}"
;; ;;
"${PIDD_OS_ARCH}") "${PIDD_OS_ARCH}")
PIDD_PM="${PIDD_PM_PACMAN}" PIDD_PM="${PIDD_PM_PACMAN}"
;; ;;
*) *) ;;
esac esac
pidd_split pidd_split
pidd_echo "PIDD_PM" pidd_echo "PIDD_PM"
@ -233,7 +247,7 @@ Dir::Etc::SourceParts \"\";
Acquire::https::Verify-Peer False; Acquire::https::Verify-Peer False;
" "
;; ;;
*) *) ;;
esac esac
pidd_split pidd_split
pidd_echo "PIDD_PM_CLEAN" \ pidd_echo "PIDD_PM_CLEAN" \
@ -263,7 +277,7 @@ Acquire::https::Verify-Peer False;
"${PIDD_OS_UBUNTU}") "${PIDD_OS_UBUNTU}")
PIDD_URL_DEFAULT="http://archive.ubuntu.com/ubuntu" PIDD_URL_DEFAULT="http://archive.ubuntu.com/ubuntu"
;; ;;
*) *) ;;
esac esac
PIDD_URL_CHOSEN="${PIDD_URL_DEFAULT}" PIDD_URL_CHOSEN="${PIDD_URL_DEFAULT}"
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
@ -277,28 +291,28 @@ Acquire::https::Verify-Peer False;
[ -n "${PIDD_URL_ARCH}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ARCH}" [ -n "${PIDD_URL_ARCH}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ARCH}"
;; ;;
"${PIDD_OS_DEBIAN}") "${PIDD_OS_DEBIAN}")
[ -n "${PIDD_URL_DEBIAN}" ] && PIDD_URL_CHOSEN="${PIDD_URL_DEBIAN}" \ [ -n "${PIDD_URL_DEBIAN}" ] && PIDD_URL_CHOSEN="${PIDD_URL_DEBIAN}" ||
|| PIDD_URL_CHOSEN="https://deb.debian.org/debian" PIDD_URL_CHOSEN="https://deb.debian.org/debian"
;; ;;
"${PIDD_OS_FEDORA}") "${PIDD_OS_FEDORA}")
[ -n "${PIDD_URL_FEDORA}" ] && PIDD_URL_CHOSEN="${PIDD_URL_FEDORA}" \ [ -n "${PIDD_URL_FEDORA}" ] && PIDD_URL_CHOSEN="${PIDD_URL_FEDORA}" ||
|| PIDD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases" PIDD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases"
;; ;;
"${PIDD_OS_ROCKY}") "${PIDD_OS_ROCKY}")
[ -n "${PIDD_URL_ROCKY}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ROCKY}" \ [ -n "${PIDD_URL_ROCKY}" ] && PIDD_URL_CHOSEN="${PIDD_URL_ROCKY}" ||
|| PIDD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir" PIDD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir"
;; ;;
"${PIDD_OS_UBUNTU}") "${PIDD_OS_UBUNTU}")
[ -n "${PIDD_URL_UBUNTU}" ] && PIDD_URL_CHOSEN="${PIDD_URL_UBUNTU}" \ [ -n "${PIDD_URL_UBUNTU}" ] && PIDD_URL_CHOSEN="${PIDD_URL_UBUNTU}" ||
|| PIDD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu" PIDD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu"
;; ;;
*) *) ;;
esac esac
pidd_split pidd_split
pidd_echo "PIDD_URL_DEFAULT" "PIDD_URL_CHOSEN" pidd_echo "PIDD_URL_DEFAULT" "PIDD_URL_CHOSEN"
# set python command & package # set python command & package
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_ROCKY}") "${PIDD_OS_ALMA}" | "${PIDD_OS_ROCKY}")
PIDD_PYTHON_COMMAND="python3.11" PIDD_PYTHON_COMMAND="python3.11"
PIDD_PYTHON_PACKAGE="python3.11" PIDD_PYTHON_PACKAGE="python3.11"
;; ;;
@ -314,7 +328,7 @@ Acquire::https::Verify-Peer False;
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"bookworm") PIDD_PYTHON_COMMAND="python3.11" ;; "bookworm") PIDD_PYTHON_COMMAND="python3.11" ;;
"bullseye") PIDD_PYTHON_COMMAND="python3.9" ;; "bullseye") PIDD_PYTHON_COMMAND="python3.9" ;;
*) *) ;;
esac esac
PIDD_PYTHON_PACKAGE="python3" PIDD_PYTHON_PACKAGE="python3"
;; ;;
@ -326,63 +340,63 @@ Acquire::https::Verify-Peer False;
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"noble") PIDD_PYTHON_COMMAND="python3.12" ;; "noble") PIDD_PYTHON_COMMAND="python3.12" ;;
"jammy") PIDD_PYTHON_COMMAND="python3.10" ;; "jammy") PIDD_PYTHON_COMMAND="python3.10" ;;
*) *) ;;
esac esac
PIDD_PYTHON_PACKAGE="python3" PIDD_PYTHON_PACKAGE="python3"
;; ;;
*) *) ;;
esac esac
# set python packages # set python packages
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}"|"${PIDD_OS_FEDORA}"|"${PIDD_OS_ROCKY}") "${PIDD_OS_ALMA}" | "${PIDD_OS_FEDORA}" | "${PIDD_OS_ROCKY}")
PIDD_PYTHON_PACKAGES="/usr/lib64/${PIDD_PYTHON_COMMAND}/site-packages" PIDD_PYTHON_PACKAGES="/usr/lib64/${PIDD_PYTHON_COMMAND}/site-packages"
;; ;;
"${PIDD_OS_ALPINE}"|"${PIDD_OS_ARCH}") "${PIDD_OS_ALPINE}" | "${PIDD_OS_ARCH}")
PIDD_PYTHON_PACKAGES="/usr/lib/${PIDD_PYTHON_COMMAND}/site-packages" PIDD_PYTHON_PACKAGES="/usr/lib/${PIDD_PYTHON_COMMAND}/site-packages"
;; ;;
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}") "${PIDD_OS_DEBIAN}" | "${PIDD_OS_UBUNTU}")
PIDD_PYTHON_PACKAGES="/usr/lib/${PIDD_PYTHON_ALIAS}/dist-packages" PIDD_PYTHON_PACKAGES="/usr/lib/${PIDD_PYTHON_ALIAS}/dist-packages"
;; ;;
*) *) ;;
esac esac
pidd_split pidd_split
pidd_echo "PIDD_PYTHON_COMMAND" "PIDD_PYTHON_PACKAGE" "PIDD_PYTHON_PACKAGES" pidd_echo "PIDD_PYTHON_COMMAND" "PIDD_PYTHON_PACKAGE" "PIDD_PYTHON_PACKAGES"
# variables # variables
[ -n "${PIDD_CA_1}" ] && PIDD_CA=true [ -n "${PIDD_CA_1}" ] && PIDD_CA=true
# continuous integration platform # continuous integration platform
if [ -n "${GITHUB_ACTIONS}" ] ; then if [ -n "${GITHUB_ACTIONS}" ]; then
# github → gitea → forgejo # github → gitea → forgejo
if [ -n "${GITHUB_SERVER_URL}" ] ; then if [ -n "${GITHUB_SERVER_URL}" ]; then
PIDD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//" PIDD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//"
if [ -n "${GITHUB_TOKEN}" ] ; then if [ -n "${GITHUB_TOKEN}" ]; then
PIDD_PROJECT_ROOT="${PIDD_PROJECT_ROOT}${GITHUB_TOKEN}@" PIDD_PROJECT_ROOT="${PIDD_PROJECT_ROOT}${GITHUB_TOKEN}@"
fi fi
PIDD_PROJECT_ROOT="${PIDD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")" PIDD_PROJECT_ROOT="${PIDD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
else else
pidd_error_ci "GITHUB_SERVER_URL" pidd_error_ci "GITHUB_SERVER_URL"
fi fi
if [ -n "${GITHUB_REPOSITORY}" ] ; then if [ -n "${GITHUB_REPOSITORY}" ]; then
PIDD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")" PIDD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")"
PIDD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" PIDD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
else else
pidd_error_ci "GITHUB_REPOSITORY" pidd_error_ci "GITHUB_REPOSITORY"
fi fi
if [ -n "${GITHUB_REF_NAME}" ] ; then if [ -n "${GITHUB_REF_NAME}" ]; then
PIDD_PROJECT_BRANCH="${GITHUB_REF_NAME}" PIDD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
else else
pidd_error_ci "GITHUB_REF_NAME" pidd_error_ci "GITHUB_REF_NAME"
fi fi
elif [ -n "${GITLAB_CI}" ] ; then elif [ -n "${GITLAB_CI}" ]; then
# gitlab # gitlab
if [ -n "${CI_SERVER_PROTOCOL}" ] ; then if [ -n "${CI_SERVER_PROTOCOL}" ]; then
if [ -n "${CI_REGISTRY_USER}" ] ; then if [ -n "${CI_REGISTRY_USER}" ]; then
if [ -n "${CI_REGISTRY_PASSWORD}" ] ; then if [ -n "${CI_REGISTRY_PASSWORD}" ]; then
if [ -n "${CI_SERVER_FQDN}" ] ; then if [ -n "${CI_SERVER_FQDN}" ]; then
PIDD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\ PIDD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}" ://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
if [ -n "${CI_PROJECT_NAMESPACE}" ] ; then if [ -n "${CI_PROJECT_NAMESPACE}" ]; then
PIDD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}" PIDD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}"
if [ -n "${CI_PROJECT_NAME}" ] ; then if [ -n "${CI_PROJECT_NAME}" ]; then
PIDD_PROJECT_NAME="${CI_PROJECT_NAME}" PIDD_PROJECT_NAME="${CI_PROJECT_NAME}"
else else
pidd_error_ci "CI_PROJECT_NAME" pidd_error_ci "CI_PROJECT_NAME"
@ -402,7 +416,7 @@ Acquire::https::Verify-Peer False;
else else
pidd_error_ci "CI_SERVER_PROTOCOL" pidd_error_ci "CI_SERVER_PROTOCOL"
fi fi
if [ -n "${CI_COMMIT_BRANCH}" ] ; then if [ -n "${CI_COMMIT_BRANCH}" ]; then
PIDD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}" PIDD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
else else
pidd_error_ci "CI_COMMIT_BRANCH" pidd_error_ci "CI_COMMIT_BRANCH"
@ -423,39 +437,37 @@ Acquire::https::Verify-Peer False;
"PIDD_PROJECT_PATH" "PIDD_PROJECT_NAME" "PIDD_PROJECT_BRANCH" "PIDD_PROJECT_PATH" "PIDD_PROJECT_NAME" "PIDD_PROJECT_BRANCH"
# TODO move to Python # TODO move to Python
case "${PIDD_PM}" in case "${PIDD_PM}" in
"${PIDD_PM_APK}"|"${PIDD_PM_APT}") PIDD_PKG_SSH="openssh-client" ;; "${PIDD_PM_APK}" | "${PIDD_PM_APT}") PIDD_PKG_SSH="openssh-client" ;;
"${PIDD_PM_DNF}") PIDD_PKG_SSH="openssh-clients" ;; "${PIDD_PM_DNF}") PIDD_PKG_SSH="openssh-clients" ;;
"${PIDD_PM_PACMAN}") PIDD_PKG_SSH="openssh" ;; "${PIDD_PM_PACMAN}") PIDD_PKG_SSH="openssh" ;;
*) *) ;;
esac esac
} }
pidd_set_packages_repositories () { pidd_set_packages_repositories() {
pidd_step "Set packages repositories" pidd_step "Set packages repositories"
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_ALMA}") "${PIDD_OS_ALMA}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"8") \ "8") pidd_spr__file="/etc/yum.repos.d/almalinux.repo" ;;
pidd_set_packages_repositories__file="/etc/yum.repos.d/almalinux.repo" ;; "9") pidd_spr__file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
"9") \ *) ;;
pidd_set_packages_repositories__file="/etc/yum.repos.d/almalinux-baseos.repo" ;;
*)
esac esac
pidd_sed "${pidd_set_packages_repositories__file}" \ pidd_sed "${pidd_spr__file}" \
"|^mirrorlist|# mirrorlist|" \ "|^mirrorlist|# mirrorlist|" \
"|${PIDD_URL_DEFAULT}|${PIDD_URL_CHOSEN}|" \ "|${PIDD_URL_DEFAULT}|${PIDD_URL_CHOSEN}|" \
"|^# baseurl|baseurl|" "|^# baseurl|baseurl|"
;; ;;
"${PIDD_OS_ALPINE}") "${PIDD_OS_ALPINE}")
pidd_set_packages_repositories__file="/etc/apk/repositories" pidd_spr__file="/etc/apk/repositories"
pidd_write "${pidd_set_packages_repositories__file}" "\ pidd_write "${pidd_spr__file}" "\
${PIDD_URL_CHOSEN}/v${PIDD_OS_VERSION}/main ${PIDD_URL_CHOSEN}/v${PIDD_OS_VERSION}/main
${PIDD_URL_CHOSEN}/v${PIDD_OS_VERSION}/community ${PIDD_URL_CHOSEN}/v${PIDD_OS_VERSION}/community
" "
;; ;;
"${PIDD_OS_DEBIAN}") "${PIDD_OS_DEBIAN}")
pidd_set_packages_repositories__file="/etc/apt/sources.list" pidd_spr__file="/etc/apt/sources.list"
pidd_write "${pidd_set_packages_repositories__file}" "\ pidd_write "${pidd_spr__file}" "\
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION} main deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION} main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-backports 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}-updates main
@ -464,128 +476,110 @@ deb ${PIDD_URL_CHOSEN}-security ${PIDD_OS_VERSION}-security main
;; ;;
"${PIDD_OS_ROCKY}") "${PIDD_OS_ROCKY}")
case "${PIDD_OS_VERSION}" in case "${PIDD_OS_VERSION}" in
"8") \ "8") pidd_spr__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;;
pidd_set_packages_repositories__file="/etc/yum.repos.d/Rocky-BaseOS.repo" ;; "9") pidd_spr__file="/etc/yum.repos.d/rocky.repo" ;;
"9") \ *) ;;
pidd_set_packages_repositories__file="/etc/yum.repos.d/rocky.repo" ;;
*)
esac esac
pidd_sed "${pidd_set_packages_repositories__file}" \ pidd_sed "${pidd_spr__file}" \
"|^mirrorlist|# mirrorlist|" \ "|^mirrorlist|# mirrorlist|" \
"|${PIDD_URL_DEFAULT}|${PIDD_URL_CHOSEN}|" \ "|${PIDD_URL_DEFAULT}|${PIDD_URL_CHOSEN}|" \
"|^#baseurl|baseurl|" "|^#baseurl|baseurl|"
;; ;;
"${PIDD_OS_UBUNTU}") "${PIDD_OS_UBUNTU}")
pidd_set_packages_repositories__file="/etc/apt/sources.list" pidd_spr__file="/etc/apt/sources.list"
pidd_write "${pidd_set_packages_repositories__file}" "\ pidd_write "${pidd_spr__file}" "\
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION} main deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION} main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-backports 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}-updates main
deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-security main deb ${PIDD_URL_CHOSEN} ${PIDD_OS_VERSION}-security main
" "
;; ;;
*) *) ;;
esac esac
} }
pidd_set_packages_configuration () { pidd_set_packages_configuration() {
pidd_step "Set packages configuration" pidd_step "Set packages configuration"
pidd_write "${PIDD_PM_CONF_PATH}" "${PIDD_PM_CONF_TEXT}" pidd_write "${PIDD_PM_CONF_PATH}" "${PIDD_PM_CONF_TEXT}"
case "${PIDD_OS_ID}" in case "${PIDD_OS_ID}" in
"${PIDD_OS_DEBIAN}"|"${PIDD_OS_UBUNTU}") "${PIDD_OS_DEBIAN}" | "${PIDD_OS_UBUNTU}")
export DEBIAN_FRONTEND="noninteractive" export DEBIAN_FRONTEND="noninteractive"
;; ;;
*) *) ;;
esac esac
} }
# agnostic steps # agnostic steps
pidd_list_environment_variables () { pidd_set_https_verification_off() {
pidd_step "List environment variables" if [ -n "${PIDD_CA}" ] || [ "${PIDD_PM}" = "${PIDD_PM_APT}" ]; then
env | sort
}
pidd_list_working_directory () {
pidd_step "List working directory"
pidd_list_working_directory__path="$(realpath .)"
pidd_ls "${pidd_list_working_directory__path}"
}
pidd_set_https_verification_off () {
if [ -n "${PIDD_CA}" ] || [ "${PIDD_PM}" = "${PIDD_PM_APT}" ] ; then
pidd_step "Set HTTPS verification off" pidd_step "Set HTTPS verification off"
pidd_mkdir "$(dirname "${PIDD_PM_HTTPS_PATH}")" pidd_mkdir "$(dirname "${PIDD_PM_HTTPS_PATH}")"
pidd_write "${PIDD_PM_HTTPS_PATH}" "${PIDD_PM_HTTPS_TEXT}" pidd_write "${PIDD_PM_HTTPS_PATH}" "${PIDD_PM_HTTPS_TEXT}"
fi fi
} }
pidd_set_dns_resolving () { pidd_set_dns_resolving() {
pidd_step "Set DNS resolving" pidd_step "Set DNS resolving"
for pidd_set_dns_resolving__server in ${PIDD_DNS} ; do for pidd_sdr__server in ${PIDD_DNS}; do
pidd_set_dns_resolving__text="${pidd_set_dns_resolving__text}\ pidd_sdr__text="${pidd_sdr__text}\
nameserver ${pidd_set_dns_resolving__server} nameserver ${pidd_sdr__server}
" "
done done
pidd_write "${PIDD_DNS_FILE}" "${pidd_set_dns_resolving__text}" pidd_write "${PIDD_DNS_FILE}" "${pidd_sdr__text}"
} }
pidd_update_packages_catalog () { pidd_update_packages_catalog() {
pidd_step "Update packages catalog" pidd_step "Update packages catalog"
${PIDD_PM_UPDATE} || exit ${PIDD_PM_UPDATE} || exit
} }
pidd_install_packages_tools () { pidd_install_packages_tools() {
pidd_step "Install packages tools" pidd_step "Install packages tools"
pidd_install_package "${PIDD_PKG_PKG}" pidd_install_package "${PIDD_PKG_PKG}"
} }
pidd_install_ca_certificates () { pidd_install_ca_certificates() {
pidd_step "Install CA" pidd_step "Install CA"
pidd_install_package "${PIDD_PKG_CA}" pidd_install_package "${PIDD_PKG_CA}"
} }
pidd_write_ca_certificates () { pidd_write_ca_certificates() {
pidd_step "Write CA certificates" pidd_step "Write CA certificates"
pidd_mkdir "${PIDD_CA_ROOT}" pidd_mkdir "${PIDD_CA_ROOT}"
pidd_write_ca_certificates__index=1 pidd_wcc__index=1
eval "pidd_write_ca_certificates__text=\ eval "pidd_wcc__text=\"\${PIDD_CA_${pidd_wcc__index}}\""
\"\${PIDD_CA_${pidd_write_ca_certificates__index}}\"" while [ -n "${pidd_wcc__text}" ]; do
while [ -n "${pidd_write_ca_certificates__text}" ] ; do pidd_wcc__path="${PIDD_CA_ROOT}/${pidd_wcc__index}.crt"
pidd_write_ca_certificates__path="\
${PIDD_CA_ROOT}/${pidd_write_ca_certificates__index}.crt"
pidd_split pidd_split
pidd_write \ pidd_write "${pidd_wcc__path}" "${pidd_wcc__text}"
"${pidd_write_ca_certificates__path}" \ pidd_openssl "${pidd_wcc__path}"
"${pidd_write_ca_certificates__text}" pidd_wcc__index=$((pidd_wcc__index + 1))
pidd_openssl "${pidd_write_ca_certificates__path}" eval "pidd_wcc__text=\"\${PIDD_CA_${pidd_wcc__index}}\""
pidd_write_ca_certificates__index=$((pidd_write_ca_certificates__index+1))
eval "pidd_write_ca_certificates__text=\
\"\${PIDD_CA_${pidd_write_ca_certificates__index}}\""
done done
} }
pidd_update_ca_certificates () { pidd_update_ca_certificates() {
pidd_step "Update CA certificates" pidd_step "Update CA certificates"
${PIDD_CMD_CA} || exit ${PIDD_CMD_CA} || exit
} }
pidd_set_https_verification_on () { pidd_set_https_verification_on() {
pidd_step "Set HTTPS verification on" pidd_step "Set HTTPS verification on"
pidd_rm "${PIDD_PM_HTTPS_PATH}" pidd_rm "${PIDD_PM_HTTPS_PATH}"
} }
pidd_upgrade_packages () { pidd_upgrade_packages() {
pidd_step "Upgrade packages" pidd_step "Upgrade packages"
${PIDD_PM_UPGRADE} || exit ${PIDD_PM_UPGRADE} || exit
} }
pidd_install_git () { pidd_install_git() {
pidd_step "Install Git" pidd_step "Install Git"
pidd_install_package "${PIDD_PKG_GIT}" pidd_install_package "${PIDD_PKG_GIT}"
} }
pidd_install_python () { pidd_install_python() {
pidd_step "Install Python" pidd_step "Install Python"
pidd_install_package "${PIDD_PYTHON_PACKAGE}" pidd_install_package "${PIDD_PYTHON_PACKAGE}"
pidd_split pidd_split
@ -593,107 +587,95 @@ pidd_install_python () {
} }
# TODO move to Python # TODO move to Python
pidd_install_rsync () { pidd_install_rsync() {
pidd_step "Install Rsync" pidd_step "Install Rsync"
pidd_install_package "${PIDD_PKG_RSYNC}" pidd_install_package "${PIDD_PKG_RSYNC}"
} }
# TODO move to Python # TODO move to Python
pidd_install_ssh () { pidd_install_ssh() {
pidd_step "Install SSH" pidd_step "Install SSH"
pidd_install_package "${PIDD_PKG_SSH}" pidd_install_package "${PIDD_PKG_SSH}"
} }
pidd_clean_packages_cache () { pidd_clean_packages_cache() {
pidd_step "Clean packages cache" pidd_step "Clean packages cache"
${PIDD_PM_CLEAN} || exit ${PIDD_PM_CLEAN} || exit
} }
pidd_install_python_modules () { pidd_install_python_modules() {
pidd_step "Install Python modules" pidd_step "Install Python modules"
pidd_install_python_modules__root="$(mktemp --directory)" || exit pidd_ipm__root="$(mktemp --directory)" || exit
echo "${pidd_install_python_modules__root}" echo "${pidd_ipm__root}"
for pidd_install_python_modules__repository \ for pidd_ipm__repository in "${PIDD_GIT_MAIN}" "${PIDD_GIT_ROOT}"; do
in "${PIDD_GIT_MAIN}" "${PIDD_GIT_ROOT}" ; do case "${pidd_ipm__repository}" in
case "${pidd_install_python_modules__repository}" in http*) pidd_ipm__url="${pidd_ipm__repository}" ;;
http*) pidd_install_python_modules__url="\ /*) pidd_ipm__url="${PIDD_PROJECT_ROOT}${pidd_ipm__repository}" ;;
${pidd_install_python_modules__repository}" ;; *) pidd_ipm__url="\
/*) pidd_install_python_modules__url="${PIDD_PROJECT_ROOT}\ ${PIDD_PROJECT_ROOT}/${PIDD_PROJECT_PATH}/${pidd_ipm__repository}" ;;
${pidd_install_python_modules__repository}" ;;
*) pidd_install_python_modules__url="${PIDD_PROJECT_ROOT}\
/${PIDD_PROJECT_PATH}/${pidd_install_python_modules__repository}" ;;
esac esac
pidd_install_python_modules__name="\ pidd_ipm__name="$(basename "${pidd_ipm__url}")"
$(basename "${pidd_install_python_modules__url}")"
pidd_split pidd_split
echo "\ echo "\
${pidd_install_python_modules__url} ${pidd_ipm__url}
" "
git clone \ git clone \
"${pidd_install_python_modules__url}" \ "${pidd_ipm__url}" \
"${pidd_install_python_modules__root}\ "${pidd_ipm__root}/${pidd_ipm__name}" ||
/${pidd_install_python_modules__name}" \ exit
|| exit pidd_ipm__path="${pidd_ipm__root}/${pidd_ipm__name}/${pidd_ipm__name}"
pidd_install_python_modules__path="\
${pidd_install_python_modules__root}\
/${pidd_install_python_modules__name}\
/${pidd_install_python_modules__name}"
echo "\ echo "\
${pidd_install_python_modules__path} ${pidd_ipm__path}
${PIDD_PYTHON_PACKAGES}" ${PIDD_PYTHON_PACKAGES}"
cp --recursive \ cp --recursive "${pidd_ipm__path}" "${PIDD_PYTHON_PACKAGES}" ||
"${pidd_install_python_modules__path}" "${PIDD_PYTHON_PACKAGES}" \ exit
|| exit
done done
pidd_split pidd_split
pidd_ls "${PIDD_PYTHON_PACKAGES}" pidd_ls "${PIDD_PYTHON_PACKAGES}"
pidd_split pidd_split
pidd_rm "${pidd_install_python_modules__root}" pidd_rm "${pidd_ipm__root}"
} }
pidd_write_python_module () { pidd_write_python_module() {
pidd_step "Write Python module" pidd_step "Write Python module"
for pidd_write_python_module__variable in \ for pidd_wpm__variable in \
OPEN DOWN VERT SPLT __UP SHUT \
OS_ID OS_VERSION \ OS_ID OS_VERSION \
PROJECT_ROOT PROJECT_PATH PROJECT_NAME \ PROJECT_ROOT PROJECT_PATH PROJECT_NAME \
; do OPEN DOWN VERT SPLT __UP SHUT; do
pidd_write_python_module__value="\ pidd_wpm__value="$(pidd_echo "PIDD_${pidd_wpm__variable}")"
$(pidd_echo "PIDD_${pidd_write_python_module__variable}")" pidd_wpm__text="${pidd_wpm__text}${pidd_wpm__value}
pidd_write_python_module__text="${pidd_write_python_module__text}\
${pidd_write_python_module__value}
" "
done done
pidd_write "${PIDD_PYTHON_PACKAGES}/env.py" "${pidd_write_python_module__text}\ pidd_write "${PIDD_PYTHON_PACKAGES}/env.py" "${pidd_wpm__text}
PIDD_STEP = $((PIDD_STEP+1)) PIDD_STEP = $((PIDD_STEP + 1))
" "
} }
pidd_switch_to_python () { pidd_switch_to_python() {
pidd_step "Switch to Python" pidd_step "Switch to Python"
pidd_switch_to_python__name="$(basename "${PIDD_GIT_MAIN}")" pidd_stp__name="$(basename "${PIDD_GIT_MAIN}")"
echo "\ echo "\
${PIDD_PATH} ${PIDD_PATH}
${PIDD_PYTHON_PACKAGES}/${pidd_switch_to_python__name}" ${PIDD_PYTHON_PACKAGES}/${pidd_stp__name}"
"${PIDD_PYTHON_ALIAS}" -m "${pidd_switch_to_python__name}" "${@}" "${PIDD_PYTHON_ALIAS}" -m "${pidd_stp__name}" "${@}"
} }
# functions # functions
pidd_cat () { pidd_cat() {
pidd_cat__file="${1}" pidd_cat__file="${1}"
if [ -n "${pidd_cat__file}" ] ; then if [ -n "${pidd_cat__file}" ]; then
pidd_open "${pidd_cat__file}" pidd_open "${pidd_cat__file}"
cat "${pidd_cat__file}" || exit cat "${pidd_cat__file}" || exit
pidd_shut "${pidd_cat__file}" pidd_shut "${pidd_cat__file}"
fi fi
} }
pidd_echo () { pidd_echo() {
if [ -n "${1}" ] ; then if [ -n "${1}" ]; then
for pidd_echo__name in "${@}" ; do for pidd_echo__name in "${@}"; do
pidd_echo__text="" pidd_echo__text=""
eval "pidd_echo__text=\"\${${pidd_echo__name}}\"" eval "pidd_echo__text=\"\${${pidd_echo__name}}\""
echo "${pidd_echo__name} = \"${pidd_echo__text}\"" echo "${pidd_echo__name} = \"${pidd_echo__text}\""
@ -701,118 +683,118 @@ pidd_echo () {
fi fi
} }
pidd_error_ci () { pidd_error_ci() {
echo "× CI: ${*}" echo "× CI: ${*}"
exit "${PIDD_ERROR_CI}" exit "${PIDD_ERROR_CI}"
} }
pidd_error_os () { pidd_error_os() {
pidd_error_os__variable="${1}" pidd_error_os__variable="${1}"
printf "× OS: " printf "× OS: "
pidd_echo "${pidd_error_os__variable}" pidd_echo "${pidd_error_os__variable}"
exit "${PIDD_ERROR_OS}" exit "${PIDD_ERROR_OS}"
} }
pidd_grep_os () { pidd_grep_os() {
pidd_grep_os__variable="${1}" pidd_grep_os__variable="${1}"
if [ -n "${pidd_grep_os__variable}" ] ; then if [ -n "${pidd_grep_os__variable}" ]; then
grep "^${pidd_grep_os__variable}=" "/etc/os-release" \ grep "^${pidd_grep_os__variable}=" "/etc/os-release" |
| sed "s|^${pidd_grep_os__variable}=||" \ sed "s|^${pidd_grep_os__variable}=||" |
| sed "s|^\"\(.*\)\"$|\1|" sed "s|^\"\(.*\)\"$|\1|"
fi fi
} }
pidd_install_package () { pidd_install_package() {
pidd_install_package__name="${1}" pidd_install_package__name="${1}"
if [ -n "${pidd_install_package__name}" ] ; then if [ -n "${pidd_install_package__name}" ]; then
${PIDD_PM_INSTALL} "${pidd_install_package__name}" || exit ${PIDD_PM_INSTALL} "${pidd_install_package__name}" || exit
fi fi
} }
pidd_ln_python () { pidd_ln_python() {
pidd_ln_python__command="${1}" pidd_ln_python__command="${1}"
if [ -n "${pidd_ln_python__command}" ] ; then if [ -n "${pidd_ln_python__command}" ]; then
echo "${PIDD_PYTHON_ALIAS}${pidd_ln_python__command}" echo "${PIDD_PYTHON_ALIAS}${pidd_ln_python__command}"
ln -f -s "${pidd_ln_python__command}" "/usr/bin/${PIDD_PYTHON_ALIAS}" \ ln -f -s "${pidd_ln_python__command}" "/usr/bin/${PIDD_PYTHON_ALIAS}" ||
|| exit exit
fi fi
} }
pidd_ls () { pidd_ls() {
pidd_ls__path="${1}" pidd_ls__path="${1}"
if [ -n "${pidd_ls__path}" ] ; then if [ -n "${pidd_ls__path}" ]; then
pidd_open "${pidd_ls__path}" pidd_open "${pidd_ls__path}"
ls -a -l "${pidd_ls__path}" || exit ls -a -l "${pidd_ls__path}" || exit
pidd_shut "${pidd_ls__path}" pidd_shut "${pidd_ls__path}"
fi fi
} }
pidd_mkdir () { pidd_mkdir() {
pidd_mkdir__path="${1}" pidd_mkdir__path="${1}"
if [ -n "${pidd_mkdir__path}" ] ; then if [ -n "${pidd_mkdir__path}" ]; then
echo "${pidd_mkdir__path}" echo "${pidd_mkdir__path}"
mkdir --parents "${pidd_mkdir__path}" || exit mkdir --parents "${pidd_mkdir__path}" || exit
fi fi
} }
pidd_open () { pidd_open() {
echo "${PIDD_OPEN}${*}" echo "${PIDD_OPEN}${*}"
} }
pidd_openssl () { pidd_openssl() {
pidd_openssl__file="${1}" pidd_openssl__file="${1}"
if [ -f "${pidd_openssl__file}" ] ; then if [ -f "${pidd_openssl__file}" ]; then
openssl x509 \ openssl x509 \
-in "${pidd_openssl__file}" \ -in "${pidd_openssl__file}" \
-noout -text \ -noout -text ||
|| exit exit
fi fi
} }
pidd_rm () { pidd_rm() {
pidd_rm__path="${1}" pidd_rm__path="${1}"
if [ -e "${pidd_rm__path}" ] ; then if [ -e "${pidd_rm__path}" ]; then
echo "${pidd_rm__path}" echo "${pidd_rm__path}"
rm -r "${pidd_rm__path}" || exit rm -r "${pidd_rm__path}" || exit
fi fi
} }
pidd_sed () { pidd_sed() {
pidd_sed__file="${1}" pidd_sed__file="${1}"
shift shift
if [ -f "${pidd_sed__file}" ] ; then if [ -f "${pidd_sed__file}" ]; then
pidd_cat "${pidd_sed__file}" pidd_cat "${pidd_sed__file}"
for pidd_sed__regex in "${@}" ; do for pidd_sed__regex in "${@}"; do
sed --in-place "s${pidd_sed__regex}g" "${pidd_sed__file}" \ sed --in-place "s${pidd_sed__regex}g" "${pidd_sed__file}" &&
&& pidd_cat "${pidd_sed__file}" \ pidd_cat "${pidd_sed__file}" ||
|| exit exit
done done
fi fi
} }
pidd_shut () { pidd_shut() {
echo "${PIDD_SHUT}${*}" echo "${PIDD_SHUT}${*}"
} }
pidd_split () { pidd_split() {
echo "${PIDD_SPLT}" echo "${PIDD_SPLT}"
} }
pidd_step () { pidd_step() {
PIDD_STEP=$((PIDD_STEP+1)) PIDD_STEP=$((PIDD_STEP + 1))
echo "\ echo "\
${PIDD_DOWN} ${PIDD_DOWN}
${PIDD_VERT} ${PIDD_STEP} ${*} ${PIDD_VERT} ${PIDD_STEP} ${*}
${PIDD___UP}" ${PIDD___UP}"
} }
pidd_write () { pidd_write() {
pidd_write__file="${1}" pidd_write__file="${1}"
pidd_write__text="${2}" pidd_write__text="${2}"
if [ -n "${pidd_write__file}" ] ; then if [ -n "${pidd_write__file}" ]; then
[ -f "${pidd_write__file}" ] && pidd_cat "${pidd_write__file}" [ -f "${pidd_write__file}" ] && pidd_cat "${pidd_write__file}"
echo "${pidd_write__file}" echo "${pidd_write__file}"
printf "%s" "${pidd_write__text}" > "${pidd_write__file}" || exit printf "%s" "${pidd_write__text}" >"${pidd_write__file}" || exit
pidd_cat "${pidd_write__file}" pidd_cat "${pidd_write__file}"
fi fi
} }