Compare commits

..

No commits in common. "15bd46e9aad2db8cd9a63d6210a0ab4973be4dc9" and "8739a7be34a4a741087bcf495edb9c53cbf76f62" have entirely different histories.

2 changed files with 78 additions and 92 deletions

164
cd.sh
View file

@ -1,26 +1,24 @@
#! /usr/bin/env sh #! /usr/bin/env sh
# defaults [ "${CD_DNS}" ] || CD_DNS="\
CD_DEFAULT_DNS="\
9.9.9.9 \ 9.9.9.9 \
" "
CD_PYTHON_MODULES="\ CD_PYTHON_MODULES="\
cd \ cd \
rwx \ rwx \
" "
# main # steps
cd_main () { cd_main () {
cd_set_environment cd_set_environment
cd_set_dns_resolving cd_set_dns_resolving ${CD_DNS}
cd_set_packages_repositories cd_set_packages_repositories
cd_set_packages_configuration cd_set_packages_configuration
cd_write_ca_certificates
cd_set_https_verification_off cd_set_https_verification_off
cd_update_packages_catalog cd_update_packages_catalog
cd_install_packages_tools cd_install_packages_tools
cd_install_ca_certificates cd_install_ca_certificates
cd_write_ca_certificates
cd_update_ca_certificates cd_update_ca_certificates
cd_set_https_verification_on cd_set_https_verification_on
cd_update_packages_catalog cd_update_packages_catalog
@ -32,10 +30,9 @@ cd_main () {
cd_execute_python_module ${CD_PYTHON_MODULES} cd_execute_python_module ${CD_PYTHON_MODULES}
} }
# steps # functions
cd_set_environment () { cd_set_environment () {
local variable
cd_step "Set environment" cd_step "Set environment"
# #
CD_CA_PACKAGE="ca-certificates" CD_CA_PACKAGE="ca-certificates"
@ -45,13 +42,8 @@ local variable
# #
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") "debian")
case "${CD_OS_VERSION}" in
"bookworm"|"bullseye") cd_nop ;;
*) cd_error_os "CD_OS_VERSION" ;;
esac
CD_PYTHON_PACKAGE="python3" CD_PYTHON_PACKAGE="python3"
CD_PYTHON_PACKAGES="/usr/lib/python3/dist-packages" CD_PYTHON_PACKAGES="/usr/lib/python3/dist-packages"
CD_CA_ROOT="/usr/local/share/ca-certificates"
;; ;;
"alma") "alma")
case "${CD_OS_VERSION}" in case "${CD_OS_VERSION}" in
@ -61,7 +53,6 @@ local variable
;; ;;
*) cd_error_os "CD_OS_VERSION" ;; *) cd_error_os "CD_OS_VERSION" ;;
esac esac
CD_CA_ROOT="/etc/pki/ca-trust/source/anchors"
;; ;;
*) cd_error_os "CD_OS_NAME" ;; *) cd_error_os "CD_OS_NAME" ;;
esac esac
@ -90,25 +81,30 @@ local variable
CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}" CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}"
CD_PROJECT_URL="${CD_PROJECTS_URL}/${CD_PROJECT_NAME}" CD_PROJECT_URL="${CD_PROJECTS_URL}/${CD_PROJECT_NAME}"
# #
cd_echo "CD_OS_NAME" "CD_OS_VERSION" echo -n "\
cd_split CD_OS_NAME=${CD_OS_NAME}
cd_echo "CD_DNS_FILE" CD_OS_VERSION=${CD_OS_VERSION}
cd_split #
cd_echo "CD_PYTHON_PACKAGE" "CD_PYTHON_PACKAGES" "CD_CA_ROOT" CD_DNS_FILE=${CD_DNS_FILE}
cd_split #
cd_echo "CD_SERVER_URL" \ CD_PYTHON_COMMAND=${CD_PYTHON_COMMAND}
"CD_PROJECTS_GROUP" "CD_PROJECT_NAME" "CD_PROJECT_BRANCH" CD_PYTHON_PACKAGES=${CD_PYTHON_PACKAGES}
cd_split #
cd_echo "CD_PROJECTS_URL" "CD_PROJECT_URL" CD_SERVER_URL=${CD_SERVER_URL}
CD_PROJECTS_GROUP=${CD_PROJECTS_GROUP}
CD_PROJECT_NAME=${CD_PROJECT_NAME}
CD_PROJECT_BRANCH=${CD_PROJECT_BRANCH}
#
CD_PROJECTS_URL=${CD_PROJECTS_URL}
CD_PROJECT_URL=${CD_PROJECT_URL}
"
} }
cd_set_dns_resolving () { cd_set_dns_resolving () {
local server local server
local servers
local text="" local text=""
cd_step "Set DNS resolving" cd_step "Set DNS resolving"
[ "${CD_DNS}" ] && servers="${CD_DNS}" || servers="${CD_DEFAULT_DNS}" for server in "${@}" ; do
for server in ${servers} ; do
text="${text}nameserver ${server} text="${text}nameserver ${server}
" "
done done
@ -122,10 +118,10 @@ local file
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") "debian")
cd_write "/etc/apt/sources.list" "\ cd_write "/etc/apt/sources.list" "\
deb https://deb.debian.org/debian ${CD_OS_VERSION} main deb https://deb.debian.org/debian bookworm main
deb https://deb.debian.org/debian ${CD_OS_VERSION}-backports main deb https://deb.debian.org/debian bookworm-backports main
deb https://deb.debian.org/debian ${CD_OS_VERSION}-updates main deb https://deb.debian.org/debian bookworm-updates main
deb https://deb.debian.org/debian-security ${CD_OS_VERSION}-security main deb https://deb.debian.org/debian-security bookworm-security main
" "
;; ;;
"alma") "alma")
@ -133,6 +129,7 @@ deb https://deb.debian.org/debian-security ${CD_OS_VERSION}-security main
cd_sed "${file}" "|^m|# m|" "|^# b|b|" cd_sed "${file}" "|^m|# m|" "|^# b|b|"
cd_cat "${file}" cd_cat "${file}"
;; ;;
*) cd_error_os "cd_set_packages_repositories" ;;
esac esac
} }
@ -150,40 +147,25 @@ Dir::Etc::SourceParts \"\";
" "
;; ;;
"alma") cd_mkdir "/etc/dnf/dnf.conf.d" ;; "alma") cd_mkdir "/etc/dnf/dnf.conf.d" ;;
*) cd_error_os "cd_set_packages_configuration" ;;
esac esac
} }
cd_write_ca_certificates () {
local index
local text
cd_step "Copy CA"
cd_mkdir "${CD_CA_ROOT}"
index=1
eval "text=\${CD_CA_${index}}"
while [ "${text}" ] ; do
cd_write "${CD_CA_ROOT}/${index}.crt" "${text}"
CD_CA=$((CD_CA+1))
index=$((index+1))
eval "text=\${CD_CA_${index}}"
done
}
cd_set_https_verification_off () { cd_set_https_verification_off () {
if [ "${CD_CA}" ] ; then cd_step "Set HTTPS verification off"
cd_step "Set HTTPS verification off" case "${CD_OS_NAME}" in
case "${CD_OS_NAME}" in "debian")
"debian") cd_write "/etc/apt/apt.conf.d/https" "\
cd_write "/etc/apt/apt.conf.d/https" "\
Acquire::https::Verify-Peer False; Acquire::https::Verify-Peer False;
" "
;; ;;
"alma") "alma")
cd_write "/etc/dnf/dnf.conf.d/https.conf" "\ cd_write "/etc/dnf/dnf.conf.d/https.conf" "\
sslverify=False sslverify=False
" "
;; ;;
esac *) cd_error_os "cd_set_https_verification_off" ;;
fi esac
} }
cd_update_packages_catalog () { cd_update_packages_catalog () {
@ -191,6 +173,7 @@ cd_update_packages_catalog () {
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get update || exit ;; "debian") apt-get update || exit ;;
"alma") dnf makecache || exit ;; "alma") dnf makecache || exit ;;
*) cd_error_os "cd_update_packages_catalog" ;;
esac esac
} }
@ -199,6 +182,7 @@ cd_install_packages_tools () {
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") cd_install_package "apt-utils" ;; "debian") cd_install_package "apt-utils" ;;
"alma") echo "TODO" ;; "alma") echo "TODO" ;;
*) cd_error_os "cd_install_packages_tools" ;;
esac esac
} }
@ -207,22 +191,41 @@ cd_install_ca_certificates () {
cd_install_package "${CD_CA_PACKAGE}" cd_install_package "${CD_CA_PACKAGE}"
} }
cd_write_ca_certificates () {
local index
local target
local text
cd_step "Copy CA"
case "${CD_OS_NAME}" in
"debian") target="/usr/local/share/ca-certificates" ;;
"alma") target="/etc/pki/ca-trust/source/anchors" ;;
*) cd_error_os "cd_copy_ca" ;;
esac
index=1
eval "text=\${CD_CA_${index}}"
while [ "${text}" ] ; do
cd_write "${target}/${index}.crt" "${text}"
index=$((index+1))
eval "text=\${CD_CA_${index}}"
done
}
cd_update_ca_certificates () { cd_update_ca_certificates () {
cd_step "Update CA" cd_step "Update CA"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") update-ca-certificates || exit ;; "debian") update-ca-certificates || exit ;;
"alma") update-ca-trust || exit ;; "alma") update-ca-trust || exit ;;
*) cd_error_os "cd_update_ca" ;;
esac esac
} }
cd_set_https_verification_on () { cd_set_https_verification_on () {
if [ "${CD_CA}" ] ; then cd_step "Set HTTPS verification on"
cd_step "Set HTTPS verification on" case "${CD_OS_NAME}" in
case "${CD_OS_NAME}" in "debian") cd_rm "/etc/apt/apt.conf.d/https" ;;
"debian") cd_rm "/etc/apt/apt.conf.d/https" ;; "alma") cd_rm "/etc/dnf/dnf.conf.d/https.conf" ;;
"alma") cd_rm "/etc/dnf/dnf.conf.d/https.conf" ;; *) cd_error_os "cd_set_https_verification_on" ;;
esac esac
fi
} }
cd_upgrade_packages () { cd_upgrade_packages () {
@ -230,6 +233,7 @@ cd_upgrade_packages () {
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get upgrade --assume-yes || exit ;; "debian") apt-get upgrade --assume-yes || exit ;;
"alma") dnf upgrade --assumeyes || exit ;; "alma") dnf upgrade --assumeyes || exit ;;
*) cd_error_os "cd_upgrade_packages" ;;
esac esac
} }
@ -248,6 +252,7 @@ cd_clean_packages_cache () {
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get clean || exit ;; "debian") apt-get clean || exit ;;
"alma") dnf clean all || exit ;; "alma") dnf clean all || exit ;;
*) cd_error_os "cd_clean_packages_cache" ;;
esac esac
} }
@ -260,9 +265,8 @@ local url
root="$(mktemp --directory)" || exit root="$(mktemp --directory)" || exit
echo "${root}" echo "${root}"
for repository in "${@}" ; do for repository in "${@}" ; do
cd_split
url="${CD_PROJECTS_URL}/${repository}" url="${CD_PROJECTS_URL}/${repository}"
echo -n "\ echo -n "
${url} ${url}
" "
@ -279,7 +283,6 @@ ${CD_PYTHON_PACKAGES}
"${path}" "${CD_PYTHON_PACKAGES}" \ "${path}" "${CD_PYTHON_PACKAGES}" \
|| exit || exit
done done
cd_split
cd_rm "${root}" cd_rm "${root}"
} }
@ -295,33 +298,21 @@ ${1}
"${CD_PYTHON_COMMAND}" -m "${1}" "${CD_STEP}" "${self}" "${CD_PYTHON_COMMAND}" -m "${1}" "${CD_STEP}" "${self}"
} }
# functions # tools
cd_cat () { cd_cat () {
if [ -f "${1}" ] ; then if [ -f "${1}" ] ; then
echo "╭╴$(realpath "${1}")" echo "$(realpath "${1}")"
cat "${1}" || exit cat "${1}" || exit
fi fi
} }
cd_echo () {
local name
if [ "${1}" ] ; then
for name in "${@}" ; do
eval "echo ${name}=\${${name}}"
done
fi
}
cd_error_ci () { cd_error_ci () {
echo "× CI: ${1}" echo "× CI: ${1}"
exit 1 exit 1
} }
cd_error_os () { cd_error_os () {
local variable="${1}" echo "× OS: ${1}"
echo -n "× OS: "
cd_echo "${variable}"
exit 2 exit 2
} }
@ -330,6 +321,7 @@ cd_install_package () {
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get install --assume-yes "${1}" || exit ;; "debian") apt-get install --assume-yes "${1}" || exit ;;
"alma") dnf install --assumeyes "${1}" || exit ;; "alma") dnf install --assumeyes "${1}" || exit ;;
*) exit 1 ;;
esac esac
fi fi
} }
@ -341,8 +333,6 @@ cd_mkdir () {
fi fi
} }
cd_nop () { true ; }
cd_rm () { cd_rm () {
if [ -e "${1}" ] ; then if [ -e "${1}" ] ; then
echo "$(realpath "${1}")" echo "$(realpath "${1}")"
@ -383,10 +373,12 @@ cd_write () {
local file="${1}" local file="${1}"
local text="${2}" local text="${2}"
if [ "${file}" ] ; then if [ "${file}" ] ; then
echo -n "${text}" > "${file}" || exit echo -n "${text}" \
> "${file}" \
|| exit
cd_cat "${file}" cd_cat "${file}"
fi fi
} }
# run # main
cd_main cd_main

View file

@ -9,12 +9,6 @@
* [X] ForgeJo / Gitea / GitHub * [X] ForgeJo / Gitea / GitHub
* [X] GitLab * [X] GitLab
## How
### Variables
| CD_DNS | Space separated servers |
## Tasks ## Tasks
* use constants for OS names * use constants for OS names