Compare commits

..

No commits in common. "b2a882079accf6142e8c139f63dd09261ee3b773" and "4a2560d3958044be68e8fa9be8e4c99b1c3351a4" have entirely different histories.

178
spcd.sh
View file

@ -1,8 +1,6 @@
#! /usr/bin/env sh
# defaults
[ -n "${SPCD_BRANCH_RELEASE}" ] || SPCD_BRANCH_RELEASE="main"
[ -n "${SPCD_BRANCH_STAGING}" ] || SPCD_BRANCH_STAGING="dev"
[ -n "${SPCD_DNS}" ] || SPCD_DNS="\
9.9.9.9 \
"
@ -12,10 +10,9 @@
# main
spcd_main() {
spcd_list_environment_variables
spcd_set_environment_variables
#
spcd_list_working_directory
#
spcd_set_environment_variables
spcd_set_packages_repositories
spcd_set_packages_configuration
#
@ -41,7 +38,7 @@ spcd_main() {
spcd_switch_to_python "${@}"
}
# steps
# context
spcd_list_environment_variables() {
spcd_step "List environment variables"
@ -52,93 +49,16 @@ spcd_list_environment_variables() {
done
}
spcd_list_working_directory() {
spcd_step "List working directory"
spcd_lwd__path="$(realpath .)"
spcd_ls "${spcd_lwd__path}"
}
# steps
spcd_set_environment_variables() {
spcd_step "Set environment variables"
# continuous integration / github → gitea → forgejo
if [ -n "${GITHUB_ACTIONS}" ]; then
# project branch
if [ -n "${GITHUB_REF_NAME}" ]; then
SPCD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
else
spcd_error_ci "GITHUB_REF_NAME"
fi
# project root
if [ -n "${GITHUB_SERVER_URL}" ]; then
SPCD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//"
[ -n "${GITHUB_TOKEN}" ] &&
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}${GITHUB_TOKEN}@"
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
else
spcd_error_ci "GITHUB_SERVER_URL"
fi
# project path & name
if [ -n "${GITHUB_REPOSITORY}" ]; then
# project path
SPCD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")"
# project name
SPCD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
else
spcd_error_ci "GITHUB_REPOSITORY"
fi
# continuous integration / gitlab
elif [ -n "${GITLAB_CI}" ]; then
# project branch
if [ -n "${CI_COMMIT_BRANCH}" ]; then
SPCD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
else
spcd_error_ci "CI_COMMIT_BRANCH"
fi
# project root / protocol
if [ -n "${CI_SERVER_PROTOCOL}" ]; then
# project root / login
if [ -n "${CI_REGISTRY_USER}" ]; then
# project root / password
if [ -n "${CI_REGISTRY_PASSWORD}" ]; then
# project root / host
if [ -n "${CI_SERVER_FQDN}" ]; then
# project root
SPCD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
# project path
if [ -n "${CI_PROJECT_NAMESPACE}" ]; then
SPCD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}"
# project name
if [ -n "${CI_PROJECT_NAME}" ]; then
SPCD_PROJECT_NAME="${CI_PROJECT_NAME}"
else
spcd_error_ci "CI_PROJECT_NAME"
fi
else
spcd_error_ci "CI_PROJECT_NAMESPACE"
fi
else
spcd_error_ci "CI_SERVER_FQDN"
fi
else
spcd_error_ci "CI_REGISTRY_PASSWORD"
fi
else
spcd_error_ci "CI_REGISTRY_USER"
fi
else
spcd_error_ci "CI_SERVER_PROTOCOL"
fi
# continuous integration / unsupported
else
spcd_error_ci "ø"
fi
# check project variables
case "${SPCD_PROJECT_BRANCH}" in
"${SPCD_BRANCH_RELEASE}" | "${SPCD_BRANCH_STAGING}") ;;
*) spcd_error_ci "SPCD_PROJECT_BRANCH" ;;
esac
[ -n "${SPCD_PROJECT_ROOT}" ] || spcd_error_ci "SPCD_PROJECT_ROOT"
[ -n "${SPCD_PROJECT_PATH}" ] || spcd_error_ci "SPCD_PROJECT_PATH"
[ -n "${SPCD_PROJECT_NAME}" ] || spcd_error_ci "SPCD_PROJECT_NAME"
#
spcd_split
spcd_echo "SPCD_PROJECT_BRANCH" \
"SPCD_PROJECT_ROOT" "SPCD_PROJECT_PATH" "SPCD_PROJECT_NAME"
# set path
SPCD_PATH="$(realpath "${0}")"
spcd_echo "SPCD_PATH"
@ -447,9 +367,77 @@ Acquire::https::Verify-Peer False;
spcd_echo "SPCD_PYTHON_COMMAND" "SPCD_PYTHON_PACKAGE" "SPCD_PYTHON_PACKAGES"
# variables
[ -n "${SPCD_CA_1}" ] && SPCD_CA=true
# continuous integration platform
if [ -n "${GITHUB_ACTIONS}" ]; then
# github → gitea → forgejo
if [ -n "${GITHUB_SERVER_URL}" ]; then
SPCD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//"
[ -n "${GITHUB_TOKEN}" ] &&
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}${GITHUB_TOKEN}@"
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
else
spcd_error_ci "GITHUB_SERVER_URL"
fi
if [ -n "${GITHUB_REPOSITORY}" ]; then
SPCD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")"
SPCD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
else
spcd_error_ci "GITHUB_REPOSITORY"
fi
if [ -n "${GITHUB_REF_NAME}" ]; then
SPCD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
else
spcd_error_ci "GITHUB_REF_NAME"
fi
elif [ -n "${GITLAB_CI}" ]; then
# gitlab
if [ -n "${CI_SERVER_PROTOCOL}" ]; then
if [ -n "${CI_REGISTRY_USER}" ]; then
if [ -n "${CI_REGISTRY_PASSWORD}" ]; then
if [ -n "${CI_SERVER_FQDN}" ]; then
SPCD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
if [ -n "${CI_PROJECT_NAMESPACE}" ]; then
SPCD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}"
if [ -n "${CI_PROJECT_NAME}" ]; then
SPCD_PROJECT_NAME="${CI_PROJECT_NAME}"
else
spcd_error_ci "CI_PROJECT_NAME"
fi
else
spcd_error_ci "CI_PROJECT_NAMESPACE"
fi
else
spcd_error_ci "CI_SERVER_FQDN"
fi
else
spcd_error_ci "CI_REGISTRY_PASSWORD"
fi
else
spcd_error_ci "CI_REGISTRY_USER"
fi
else
spcd_error_ci "CI_SERVER_PROTOCOL"
fi
if [ -n "${CI_COMMIT_BRANCH}" ]; then
SPCD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
else
spcd_error_ci "CI_COMMIT_BRANCH"
fi
else
# unsupported
spcd_error_ci "ø"
fi
[ -n "${SPCD_PROJECT_ROOT}" ] || spcd_error_ci "SPCD_PROJECT_ROOT"
[ -n "${SPCD_PROJECT_PATH}" ] || spcd_error_ci "SPCD_PROJECT_PATH"
[ -n "${SPCD_PROJECT_NAME}" ] || spcd_error_ci "SPCD_PROJECT_NAME"
[ -n "${SPCD_PROJECT_BRANCH}" ] || spcd_error_ci "SPCD_PROJECT_BRANCH"
#
spcd_split
spcd_echo "SPCD_CA"
spcd_split
spcd_echo "SPCD_PROJECT_ROOT" \
"SPCD_PROJECT_PATH" "SPCD_PROJECT_NAME" "SPCD_PROJECT_BRANCH"
# TODO move to Python
case "${SPCD_PM}" in
"${SPCD_PM_APK}" | "${SPCD_PM_APT}") SPCD_PKG_SSH="openssh-client" ;;
@ -459,12 +447,6 @@ Acquire::https::Verify-Peer False;
esac
}
spcd_list_working_directory() {
spcd_step "List working directory"
spcd_lwd__path="$(realpath .)"
spcd_ls "${spcd_lwd__path}"
}
spcd_set_packages_repositories() {
spcd_step "Set packages repositories"
case "${SPCD_OS_ID}" in
@ -826,8 +808,8 @@ SPCD_BOX_RIGHT="╶"
SPCD_BOX_UP="╰"
SPCD_BOX_VERTICAL="│"
SPCD_ERROR_CI=1
SPCD_ERROR_OS=2
SPCD_ERROR_CI=2
SPCD_ERROR_OS=1
SPCD_OS_ALMA="alma"
SPCD_OS_ALPINE="alpine"