This commit is contained in:
Marc Beninca 2024-06-08 18:11:41 +02:00
parent d73dd66251
commit c5852824a3
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

54
cd.sh
View file

@ -1,11 +1,11 @@
#! /usr/bin/env sh #! /usr/bin/env sh
# defaults # defaults
[ "${CD_DNS}" ] || CD_DNS="\ [ -n "${CD_DNS}" ] || CD_DNS="\
9.9.9.9 \ 9.9.9.9 \
" "
[ "${CD_GIT_CHILD}" ] || CD_GIT_CHILD="cd" [ -n "${CD_GIT_CHILD}" ] || CD_GIT_CHILD="cd"
[ "${CD_GIT_PARENT}" ] || CD_GIT_PARENT="rwx" [ -n "${CD_GIT_PARENT}" ] || CD_GIT_PARENT="rwx"
# main # main
cd_main () { cd_main () {
@ -260,28 +260,28 @@ Acquire::https::Verify-Peer False;
CD_URL_CHOSEN="${CD_URL_DEFAULT}" CD_URL_CHOSEN="${CD_URL_DEFAULT}"
case "${CD_OS_ID}" in case "${CD_OS_ID}" in
"${CD_OS_ALMA}") "${CD_OS_ALMA}")
[ "${CD_URL_ALMA}" ] && CD_URL_CHOSEN="${CD_URL_ALMA}" [ -n "${CD_URL_ALMA}" ] && CD_URL_CHOSEN="${CD_URL_ALMA}"
;; ;;
"${CD_OS_ALPINE}") "${CD_OS_ALPINE}")
[ "${CD_URL_ALPINE}" ] && CD_URL_CHOSEN="${CD_URL_ALPINE}" [ -n "${CD_URL_ALPINE}" ] && CD_URL_CHOSEN="${CD_URL_ALPINE}"
;; ;;
"${CD_OS_ARCH}") "${CD_OS_ARCH}")
[ "${CD_URL_ARCH}" ] && CD_URL_CHOSEN="${CD_URL_ARCH}" [ -n "${CD_URL_ARCH}" ] && CD_URL_CHOSEN="${CD_URL_ARCH}"
;; ;;
"${CD_OS_DEBIAN}") "${CD_OS_DEBIAN}")
[ "${CD_URL_DEBIAN}" ] && CD_URL_CHOSEN="${CD_URL_DEBIAN}" \ [ -n "${CD_URL_DEBIAN}" ] && CD_URL_CHOSEN="${CD_URL_DEBIAN}" \
|| CD_URL_CHOSEN="https://deb.debian.org/debian" || CD_URL_CHOSEN="https://deb.debian.org/debian"
;; ;;
"${CD_OS_FEDORA}") "${CD_OS_FEDORA}")
[ "${CD_URL_FEDORA}" ] && CD_URL_CHOSEN="${CD_URL_FEDORA}" \ [ -n "${CD_URL_FEDORA}" ] && CD_URL_CHOSEN="${CD_URL_FEDORA}" \
|| CD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases" || CD_URL_CHOSEN="https://rpmfind.net/linux/fedora/linux/releases"
;; ;;
"${CD_OS_ROCKY}") "${CD_OS_ROCKY}")
[ "${CD_URL_ROCKY}" ] && CD_URL_CHOSEN="${CD_URL_ROCKY}" \ [ -n "${CD_URL_ROCKY}" ] && CD_URL_CHOSEN="${CD_URL_ROCKY}" \
|| CD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir" || CD_URL_CHOSEN="https://dl.rockylinux.org/\$contentdir"
;; ;;
"${CD_OS_UBUNTU}") "${CD_OS_UBUNTU}")
[ "${CD_URL_UBUNTU}" ] && CD_URL_CHOSEN="${CD_URL_UBUNTU}" \ [ -n "${CD_URL_UBUNTU}" ] && CD_URL_CHOSEN="${CD_URL_UBUNTU}" \
|| CD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu" || CD_URL_CHOSEN="https://ubuntu.mirrors.ovh.net/ubuntu"
;; ;;
esac esac
@ -335,15 +335,15 @@ Acquire::https::Verify-Peer False;
cd_split cd_split
cd_echo "CD_PYTHON_COMMAND" "CD_PYTHON_PACKAGE" "CD_PYTHON_PACKAGES" cd_echo "CD_PYTHON_COMMAND" "CD_PYTHON_PACKAGE" "CD_PYTHON_PACKAGES"
# variables # variables
[ "${CD_CA_1}" ] && CD_CA=true [ -n "${CD_CA_1}" ] && CD_CA=true
# continuous integration platform # continuous integration platform
if [ "${GITHUB_ACTIONS}" ] ; then if [ -n "${GITHUB_ACTIONS}" ] ; then
# github → gitea → forgejo # github → gitea → forgejo
CD_SERVER_URL="${GITHUB_SERVER_URL}" CD_SERVER_URL="${GITHUB_SERVER_URL}"
CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")" CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
CD_PROJECT_BRANCH="${GITHUB_REF_NAME}" CD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
elif [ "${GITLAB_CI}" ] ; then elif [ -n "${GITLAB_CI}" ] ; then
# gitlab # gitlab
CD_SERVER_URL="${CI_SERVER_URL}" CD_SERVER_URL="${CI_SERVER_URL}"
CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")" CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
@ -353,10 +353,10 @@ Acquire::https::Verify-Peer False;
# unsupported # unsupported
cd_error_ci "ø" cd_error_ci "ø"
fi fi
[ "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL" [ -n "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL"
[ "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP" [ -n "${CD_PROJECTS_GROUP}" ] || cd_error_ci "CD_PROJECTS_GROUP"
[ "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME" [ -n "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME"
[ "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH" [ -n "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH"
# #
CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}" CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}"
# #
@ -448,7 +448,7 @@ cd_list_working_directory () {
} }
cd_set_https_verification_off () { cd_set_https_verification_off () {
if [ "${CD_CA}" ] || [ "${CD_PM}" = "${CD_PM_APT}" ] ; then if [ -n "${CD_CA}" ] || [ "${CD_PM}" = "${CD_PM_APT}" ] ; then
cd_step "Set HTTPS verification off" cd_step "Set HTTPS verification off"
cd_mkdir "$(dirname "${CD_PM_HTTPS_PATH}")" cd_mkdir "$(dirname "${CD_PM_HTTPS_PATH}")"
cd_write "${CD_PM_HTTPS_PATH}" "${CD_PM_HTTPS_TEXT}" cd_write "${CD_PM_HTTPS_PATH}" "${CD_PM_HTTPS_TEXT}"
@ -486,7 +486,7 @@ cd_write_ca_certificates () {
cd_write_ca_certificates__index=1 cd_write_ca_certificates__index=1
eval "cd_write_ca_certificates__text=\ eval "cd_write_ca_certificates__text=\
\"\${CD_CA_${cd_write_ca_certificates__index}}\"" \"\${CD_CA_${cd_write_ca_certificates__index}}\""
while [ "${cd_write_ca_certificates__text}" ] ; do while [ -n "${cd_write_ca_certificates__text}" ] ; do
cd_write_ca_certificates__path="\ cd_write_ca_certificates__path="\
${CD_CA_ROOT}/${cd_write_ca_certificates__index}.crt" ${CD_CA_ROOT}/${cd_write_ca_certificates__index}.crt"
cd_split cd_split
@ -605,7 +605,7 @@ ${CD_PYTHON_PACKAGES}/${CD_GIT_CHILD}"
cd_cat () { cd_cat () {
cd_cat__file="${1}" cd_cat__file="${1}"
if [ "${cd_cat__file}" ] ; then if [ -n "${cd_cat__file}" ] ; then
cd_open "${cd_cat__file}" cd_open "${cd_cat__file}"
cat "${cd_cat__file}" || exit cat "${cd_cat__file}" || exit
cd_shut "${cd_cat__file}" cd_shut "${cd_cat__file}"
@ -613,7 +613,7 @@ cd_cat () {
} }
cd_echo () { cd_echo () {
if [ "${1}" ] ; then if [ -n "${1}" ] ; then
for cd_echo__name in "${@}" ; do for cd_echo__name in "${@}" ; do
eval "echo ${cd_echo__name} = \\\"\${${cd_echo__name}}\\\"" eval "echo ${cd_echo__name} = \\\"\${${cd_echo__name}}\\\""
done done
@ -634,7 +634,7 @@ cd_error_os () {
cd_grep_os () { cd_grep_os () {
cd_grep_os__variable="${1}" cd_grep_os__variable="${1}"
if [ "${cd_grep_os__variable}" ] ; then if [ -n "${cd_grep_os__variable}" ] ; then
grep "^${cd_grep_os__variable}=" "/etc/os-release" \ grep "^${cd_grep_os__variable}=" "/etc/os-release" \
| sed "s|^${cd_grep_os__variable}=||" \ | sed "s|^${cd_grep_os__variable}=||" \
| sed "s|^\"\(.*\)\"$|\1|" | sed "s|^\"\(.*\)\"$|\1|"
@ -643,14 +643,14 @@ cd_grep_os () {
cd_install_package () { cd_install_package () {
cd_install_package__name="${1}" cd_install_package__name="${1}"
if [ "${cd_install_package__name}" ] ; then if [ -n "${cd_install_package__name}" ] ; then
${CD_PM_INSTALL} "${cd_install_package__name}" || exit ${CD_PM_INSTALL} "${cd_install_package__name}" || exit
fi fi
} }
cd_ln_python () { cd_ln_python () {
cd_ln_python__command="${1}" cd_ln_python__command="${1}"
if [ "${cd_ln_python__command}" ] ; then if [ -n "${cd_ln_python__command}" ] ; then
echo "${CD_PYTHON_ALIAS}${cd_ln_python__command}" echo "${CD_PYTHON_ALIAS}${cd_ln_python__command}"
ln -f -s "${cd_ln_python__command}" "/usr/bin/${CD_PYTHON_ALIAS}" \ ln -f -s "${cd_ln_python__command}" "/usr/bin/${CD_PYTHON_ALIAS}" \
|| exit || exit
@ -659,7 +659,7 @@ cd_ln_python () {
cd_ls () { cd_ls () {
cd_ls__path="${1}" cd_ls__path="${1}"
if [ "${cd_ls__path}" ] ; then if [ -n "${cd_ls__path}" ] ; then
cd_open "${cd_ls__path}" cd_open "${cd_ls__path}"
ls -a -l "${cd_ls__path}" || exit ls -a -l "${cd_ls__path}" || exit
cd_shut "${cd_ls__path}" cd_shut "${cd_ls__path}"
@ -668,7 +668,7 @@ cd_ls () {
cd_mkdir () { cd_mkdir () {
cd_mkdir__path="${1}" cd_mkdir__path="${1}"
if [ "${cd_mkdir__path}" ] ; then if [ -n "${cd_mkdir__path}" ] ; then
echo "${cd_mkdir__path}" echo "${cd_mkdir__path}"
mkdir --parents "${cd_mkdir__path}" || exit mkdir --parents "${cd_mkdir__path}" || exit
fi fi
@ -728,7 +728,7 @@ ${CD___UP}"
cd_write () { cd_write () {
cd_write__file="${1}" cd_write__file="${1}"
cd_write__text="${2}" cd_write__text="${2}"
if [ "${cd_write__file}" ] ; then if [ -n "${cd_write__file}" ] ; then
[ -f "${cd_write__file}" ] && cd_cat "${cd_write__file}" [ -f "${cd_write__file}" ] && cd_cat "${cd_write__file}"
echo "${cd_write__file}" echo "${cd_write__file}"
printf "%s" "${cd_write__text}" > "${cd_write__file}" || exit printf "%s" "${cd_write__text}" > "${cd_write__file}" || exit