Compare commits

..

18 commits

Author SHA1 Message Date
15bd46e9aa
variables
Some checks failed
/ job (push) Failing after 11s
2024-05-02 10:58:02 +02:00
082f231b60
fix 2024-05-02 10:57:24 +02:00
82e2249bbf
cd_error_os 2024-05-02 10:33:34 +02:00
efac9b8463
cd_write 2024-05-02 10:29:43 +02:00
e891d90b43
nop 2024-05-02 10:28:34 +02:00
c356baee6d
dns 2024-05-02 10:27:18 +02:00
0cb9952b32
cd_nop 2024-05-02 10:19:18 +02:00
b3adfe3182
cd_echo 2024-05-02 09:59:17 +02:00
e745890b33
shrink 2024-05-02 09:39:17 +02:00
38d2138950
cd_ca_root 2024-05-02 09:33:50 +02:00
5787bf6fca
if inside https functions 2024-05-02 08:38:49 +02:00
1b1d94724b
splits 2024-05-01 20:33:24 +02:00
f4b875930e
cd_ca/https 2024-05-01 20:26:11 +02:00
a5177e565b
count ca 2024-05-01 20:23:33 +02:00
338f437861
mv 2024-04-30 13:46:23 +02:00
dc52d4f73d
split 2024-04-30 13:45:05 +02:00
179f234401
cat/corner 2024-04-30 13:44:12 +02:00
3349f51a23
ca/deb/mkdir 2024-04-30 13:40:11 +02:00
2 changed files with 92 additions and 78 deletions

136
cd.sh
View file

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

View file

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