Compare commits

...

4 commits

Author SHA1 Message Date
4ed8c776d4
error_os
Some checks failed
/ job (push) Failing after 1m5s
2024-04-29 11:42:11 +02:00
de5f67bb9b
error_ci 2024-04-29 11:08:29 +02:00
c114dfae77
error_ci,error_os 2024-04-29 11:01:48 +02:00
64ed4186b3
refactor 2024-04-29 10:58:37 +02:00

103
cd.sh
View file

@ -38,52 +38,34 @@ cd_set_environment () {
"bookworm") "bookworm")
echo "TODO" echo "TODO"
;; ;;
*) *) cd_error_os "CD_OS_VERSION=" ;;
echo "CD_OS_VERSION"
exit 2
;;
esac esac
;; ;;
*) *) cd_error_os "CD_OS_NAME=" ;;
echo "CD_OS_NAME"
exit 1
;;
esac esac
# project / branch # ci / github
[ "${CI_COMMIT_BRANCH}" ] && CD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}" if [ "${GITHUB_ACTIONS}" ] ; then
[ "${GITHUB_REF_NAME}" ] && CD_PROJECT_BRANCH="${GITHUB_REF_NAME}" CD_SERVER_URL="${GITHUB_SERVER_URL}"
if [ ! "${CD_PROJECT_BRANCH}" ] ; then CD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
echo "CD_PROJECT_BRANCH" CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
exit 3 CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
fi # ci / gitlab
# project / name elif [ "${GITLAB_CI}" ] ; then
[ "${CI_PROJECT_PATH}" ] \ CD_SERVER_URL="${CI_SERVER_URL}"
&& CD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")" CD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
[ "${GITHUB_REPOSITORY}" ] \ CD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")"
&& CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
if [ ! "${CD_PROJECT_NAME}" ] ; then # ci / none
echo "CD_PROJECT_NAME"
exit 3
fi
# projects / group
[ "${CI_PROJECT_PATH}" ] \
&& CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")"
[ "${GITHUB_REPOSITORY}" ] \
&& CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")"
if [ ! "${CD_PROJECTS_GROUP}" ] ; then
echo "CD_PROJECTS_GROUP"
exit 3
fi
# projects / url
[ "${CI_SERVER_URL}" ] && CD_PROJECTS_URL="${CI_SERVER_URL}"
[ "${GITHUB_SERVER_URL}" ] && CD_PROJECTS_URL="${GITHUB_SERVER_URL}"
if [ "${CD_PROJECTS_URL}" ] ; then
CD_PROJECTS_URL="${CD_PROJECTS_URL}/${CD_PROJECTS_GROUP}"
else else
echo "CD_PROJECTS_URL" cd_error_ci "ø"
exit 3
fi fi
# project / url #
[ "${CD_SERVER_URL}" ] || cd_error_ci "CD_SERVER_URL"
[ "${CD_PROJECT_BRANCH}" ] || cd_error_ci "CD_PROJECT_BRANCH"
[ "${CD_PROJECT_NAME}" ] || cd_error_ci "CD_PROJECT_NAME"
[ "${CD_PROJECTS_GROUP}" ] || cd_error_ci "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}"
# #
echo -n "\ echo -n "\
@ -95,11 +77,13 @@ CD_DNS_FILE=${CD_DNS_FILE}
CD_PYTHON_COMMAND=${CD_PYTHON_COMMAND} CD_PYTHON_COMMAND=${CD_PYTHON_COMMAND}
CD_PYTHON_PACKAGES=${CD_PYTHON_PACKAGES} CD_PYTHON_PACKAGES=${CD_PYTHON_PACKAGES}
# #
CD_SERVER_URL=${CD_SERVER_URL}
CD_PROJECT_BRANCH=${CD_PROJECT_BRANCH} CD_PROJECT_BRANCH=${CD_PROJECT_BRANCH}
CD_PROJECT_NAME=${CD_PROJECT_NAME} CD_PROJECT_NAME=${CD_PROJECT_NAME}
CD_PROJECT_URL=${CD_PROJECT_URL}
CD_PROJECTS_GROUP=${CD_PROJECTS_GROUP} CD_PROJECTS_GROUP=${CD_PROJECTS_GROUP}
#
CD_PROJECTS_URL=${CD_PROJECTS_URL} CD_PROJECTS_URL=${CD_PROJECTS_URL}
CD_PROJECT_URL=${CD_PROJECT_URL}
" "
} }
@ -127,7 +111,7 @@ deb https://deb.debian.org/debian-security bookworm-security main
" "
cd_cat "/etc/apt/sources.list" cd_cat "/etc/apt/sources.list"
;; ;;
*) exit 1 ;; *) cd_error_os "cd_set_packages_repositories" ;;
esac esac
} }
@ -145,7 +129,7 @@ Dir::Etc::SourceParts \"\";
" "
cd_cat "/etc/apt/apt.conf.d/apt.conf" cd_cat "/etc/apt/apt.conf.d/apt.conf"
;; ;;
*) exit 1 ;; *) cd_error_os "cd_set_packages_configuration" ;;
esac esac
} }
@ -158,7 +142,7 @@ Acquire::https::Verify-Peer False;
" "
cd_cat "/etc/apt/apt.conf.d/https" cd_cat "/etc/apt/apt.conf.d/https"
;; ;;
*) exit 1 ;; *) cd_error_os "cd_set_https_verification_off" ;;
esac esac
} }
@ -166,7 +150,7 @@ cd_update_packages_catalog () {
cd_step "Update packages catalog" cd_step "Update packages catalog"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get update || exit ;; "debian") apt-get update || exit ;;
*) exit 1 ;; *) cd_error_os "cd_update_packages_catalog" ;;
esac esac
} }
@ -174,7 +158,7 @@ cd_install_packages_tools () {
cd_step "Install packages tools" cd_step "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" ;;
*) exit 1 ;; *) cd_error_os "cd_install_packages_tools" ;;
esac esac
} }
@ -182,7 +166,7 @@ cd_install_ca () {
cd_step "Install CA" cd_step "Install CA"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") cd_install_package "ca-certificates" ;; "debian") cd_install_package "ca-certificates" ;;
*) exit 1 ;; *) cd_error_os "cd_install_ca" ;;
esac esac
} }
@ -191,7 +175,7 @@ local target
cd_step "Copy CA" cd_step "Copy CA"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") target="/usr/local/share/ca-certificates" ;; "debian") target="/usr/local/share/ca-certificates" ;;
*) exit 1 ;; *) cd_error_os "cd_copy_ca" ;;
esac esac
# TODO copy # TODO copy
} }
@ -200,7 +184,7 @@ cd_update_ca () {
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 ;;
*) exit 1 ;; *) cd_error_os "cd_update_ca" ;;
esac esac
} }
@ -208,7 +192,7 @@ cd_set_https_verification_on () {
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" ;;
*) exit 1 ;; *) cd_error_os "cd_set_https_verification_on" ;;
esac esac
} }
@ -216,7 +200,7 @@ cd_upgrade_packages () {
cd_step "Upgrade packages" cd_step "Upgrade packages"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get upgrade --yes || exit ;; "debian") apt-get upgrade --yes || exit ;;
*) exit 1 ;; *) cd_error_os "cd_upgrade_packages" ;;
esac esac
} }
@ -224,7 +208,7 @@ cd_install_git () {
cd_step "Install Git" cd_step "Install Git"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") cd_install_package "git" ;; "debian") cd_install_package "git" ;;
*) exit 1 ;; *) cd_error_os "cd_install_git" ;;
esac esac
} }
@ -232,7 +216,7 @@ cd_install_python () {
cd_step "Install Python" cd_step "Install Python"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") cd_install_package "python3" ;; "debian") cd_install_package "python3" ;;
*) exit 1 ;; *) cd_error_os "cd_install_python" ;;
esac esac
} }
@ -240,7 +224,7 @@ cd_clean_packages_cache () {
cd_step "Clean packages cache" cd_step "Clean packages cache"
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in
"debian") apt-get clean || exit ;; "debian") apt-get clean || exit ;;
*) exit 1 ;; *) cd_error_os "cd_clean_packages_cache" ;;
esac esac
} }
@ -295,6 +279,15 @@ cd_cat () {
fi fi
} }
cd_error_ci () {
echo "× CI: ${1}"
exit 1
}
cd_error_os () {
echo "× OS: ${1}"
exit 2
}
cd_install_package () { cd_install_package () {
if [ "${1}" ] ; then if [ "${1}" ] ; then
case "${CD_OS_NAME}" in case "${CD_OS_NAME}" in