spcd/spcd/bootstrap.sh

1260 lines
36 KiB
Bash
Raw Normal View History

2024-04-27 15:47:23 +00:00
#! /usr/bin/env sh
2024-04-26 13:38:22 +00:00
2024-08-25 19:12:08 +00:00
# ╭──────────╮
# │ defaults │
# ╰──────────╯
2024-08-19 12:27:10 +00:00
[ -n "${SPCD_CMD_SUM}" ] || SPCD_CMD_SUM="sha512sum"
2024-08-26 12:42:24 +00:00
2024-08-06 10:53:23 +00:00
[ -n "${SPCD_DNS_1}" ] || SPCD_DNS_1="9.9.9.9"
2024-08-26 12:42:24 +00:00
2024-06-27 11:58:43 +00:00
[ -n "${SPCD_GIT_MAIN}" ] || SPCD_GIT_MAIN="spcd"
[ -n "${SPCD_GIT_ROOT}" ] || SPCD_GIT_ROOT="rwx"
2024-08-26 12:47:50 +00:00
2024-08-21 14:46:48 +00:00
[ -n "${SPCD_GIT_SHUNIT}" ] || SPCD_GIT_SHUNIT="shunit2"
2024-08-26 12:42:24 +00:00
2024-08-24 13:12:13 +00:00
[ -n "${SPCD_REF_FEATURE}" ] || SPCD_REF_FEATURE="f"
[ -n "${SPCD_REF_RELEASE}" ] || SPCD_REF_RELEASE="main"
[ -n "${SPCD_REF_STAGING}" ] || SPCD_REF_STAGING="dev"
2024-08-26 12:42:24 +00:00
2024-08-27 13:21:50 +00:00
[ -n "${SPCD_URL_ALMA}" ] ||
2024-08-27 14:53:05 +00:00
SPCD_URL_ALMA="https://repo.almalinux.org"
2024-08-24 14:11:41 +00:00
[ -n "${SPCD_URL_ALPINE}" ] ||
2024-08-26 18:55:54 +00:00
SPCD_URL_ALPINE="https://dl-cdn.alpinelinux.org/alpine"
2024-08-24 14:11:41 +00:00
[ -n "${SPCD_URL_ARCH}" ] ||
2024-08-27 14:08:00 +00:00
SPCD_URL_ARCH="https://geo.mirror.pkgbuild.com/\$repo/os/\$arch"
2024-08-24 14:11:41 +00:00
[ -n "${SPCD_URL_DEBIAN}" ] ||
2024-08-26 20:06:00 +00:00
SPCD_URL_DEBIAN="https://deb.debian.org/debian"
2024-08-24 14:11:41 +00:00
[ -n "${SPCD_URL_EPEL}" ] ||
SPCD_URL_EPEL="https://dl.fedoraproject.org"
[ -n "${SPCD_URL_FEDORA}" ] ||
2024-08-27 16:35:21 +00:00
SPCD_URL_FEDORA="https://rpmfind.net/linux/fedora/linux"
2024-08-24 14:11:41 +00:00
[ -n "${SPCD_URL_OPENSUSE}" ] ||
SPCD_URL_OPENSUSE="https://download.opensuse.org"
[ -n "${SPCD_URL_PYTHON}" ] ||
SPCD_URL_PYTHON="https://pypi.org/simple"
[ -n "${SPCD_URL_ROCKY}" ] ||
2024-08-27 15:44:44 +00:00
SPCD_URL_ROCKY="https://dl.rockylinux.org"
2024-08-24 14:11:41 +00:00
[ -n "${SPCD_URL_UBUNTU}" ] ||
2024-08-26 21:15:44 +00:00
SPCD_URL_UBUNTU="https://ubuntu.mirrors.ovh.net/ubuntu"
2024-04-26 11:38:38 +00:00
2024-08-27 10:26:10 +00:00
# ╭───╮
# │ _ │
# ╰───╯
2024-08-25 19:17:31 +00:00
2024-08-26 12:47:50 +00:00
_spcd_fill() {
_spcd_fill__index=${1}
while [ "${_spcd_fill__index}" -gt 0 ]; do
2024-08-25 19:17:31 +00:00
printf "%s" "${2}"
2024-08-26 12:47:50 +00:00
_spcd_fill__index=$((_spcd_fill__index - 1))
2024-08-25 19:17:31 +00:00
done
2024-08-26 12:48:36 +00:00
unset _spcd_fill__index
2024-08-25 19:17:31 +00:00
}
2024-08-27 10:26:10 +00:00
# ╭───┬────────╮
# │ _ │ banner │
# ╰───┴────────╯
2024-08-25 19:17:31 +00:00
2024-08-26 14:06:14 +00:00
_SPCD_BANNER_DOWN_AND_HORIZONTAL="┬"
_SPCD_BANNER_DOWN_AND_LEFT="╮"
_SPCD_BANNER_DOWN_AND_RIGHT="╭"
_SPCD_BANNER_HORIZONTAL="─"
_SPCD_BANNER_UP_AND_HORIZONTAL="┴"
_SPCD_BANNER_UP_AND_LEFT="╯"
_SPCD_BANNER_UP_AND_RIGHT="╰"
_SPCD_BANNER_VERTICAL="│"
2024-08-25 19:17:31 +00:00
2024-08-26 12:51:20 +00:00
_spcd_banner_add() {
2024-08-25 19:17:31 +00:00
if [ -n "${1}" ]; then
spcd_ba__text=" ${1} "
spcd_ba__length=${#spcd_ba__text}
spcd_ba__filler="$(
2024-08-26 14:06:14 +00:00
_spcd_fill "${spcd_ba__length}" "${_SPCD_BANNER_HORIZONTAL}"
2024-08-25 19:17:31 +00:00
)"
2024-08-26 14:38:46 +00:00
if [ -n "${__SPCD_BANNER_MIDDLE}" ]; then
2024-08-26 13:01:45 +00:00
_spcd_banner_split
2024-08-25 19:17:31 +00:00
else
2024-08-26 13:07:53 +00:00
_spcd_banner_open
2024-08-25 19:17:31 +00:00
fi
2024-08-26 12:58:34 +00:00
_spcd_banner_append \
2024-08-25 19:17:31 +00:00
"${spcd_ba__filler}" "${spcd_ba__text}" "${spcd_ba__filler}"
fi
}
2024-08-26 12:56:40 +00:00
_spcd_banner_add_index() {
2024-08-25 19:17:31 +00:00
unset spcd_bai__label
unset spcd_bai__level
while true; do
spcd_bai__level=$((spcd_bai__level + 1))
2024-08-26 14:19:21 +00:00
eval "spcd_bai__value=\"\${__SPCD_STEP_${spcd_bai__level}_INDEX}\""
2024-08-25 19:17:31 +00:00
[ -n "${spcd_bai__value}" ] || break
if [ -n "${spcd_bai__label}" ]; then
spcd_bai__label="${spcd_bai__label}.${spcd_bai__value}"
else
spcd_bai__label="${spcd_bai__value}"
fi
done
2024-08-26 12:51:20 +00:00
_spcd_banner_add "${spcd_bai__label}"
2024-08-25 19:17:31 +00:00
}
2024-08-26 12:58:34 +00:00
_spcd_banner_append() {
2024-08-25 19:17:31 +00:00
if [ -n "${3}" ]; then
2024-08-26 14:38:46 +00:00
__SPCD_BANNER_TOP="${__SPCD_BANNER_TOP}${1}"
__SPCD_BANNER_MIDDLE="${__SPCD_BANNER_MIDDLE}${2}"
__SPCD_BANNER_BOTTOM="${__SPCD_BANNER_BOTTOM}${3}"
2024-08-25 19:17:31 +00:00
fi
}
2024-08-26 13:09:16 +00:00
_spcd_banner_echo() {
2024-08-25 19:17:31 +00:00
echo "\
2024-08-26 14:38:46 +00:00
${__SPCD_BANNER_TOP}
${__SPCD_BANNER_MIDDLE}
${__SPCD_BANNER_BOTTOM}"
2024-08-25 19:17:31 +00:00
}
2024-08-26 13:07:53 +00:00
_spcd_banner_open() {
2024-08-26 12:58:34 +00:00
_spcd_banner_append \
2024-08-26 14:06:14 +00:00
"${_SPCD_BANNER_DOWN_AND_RIGHT}" \
"${_SPCD_BANNER_VERTICAL}" \
"${_SPCD_BANNER_UP_AND_RIGHT}"
2024-08-25 19:17:31 +00:00
}
2024-08-26 13:13:28 +00:00
_spcd_banner_render() {
2024-08-26 13:17:58 +00:00
_spcd_banner_wipe
2024-08-26 12:51:20 +00:00
_spcd_banner_add "S"
2024-08-26 12:56:40 +00:00
_spcd_banner_add_index
2024-08-25 19:17:31 +00:00
#
unset spcd_br__level
while true; do
spcd_br__level=$((spcd_br__level + 1))
2024-08-26 14:19:21 +00:00
eval "spcd_br__value=\"\${__SPCD_STEP_${spcd_br__level}_LABEL}\""
2024-08-25 19:17:31 +00:00
[ -n "${spcd_br__value}" ] || break
2024-08-26 12:51:20 +00:00
_spcd_banner_add "${spcd_br__value}"
2024-08-25 19:17:31 +00:00
done
#
2024-08-26 12:59:46 +00:00
_spcd_banner_shut
2024-08-26 13:09:16 +00:00
_spcd_banner_echo
2024-08-26 13:17:58 +00:00
_spcd_banner_wipe
2024-08-25 19:17:31 +00:00
}
2024-08-26 13:00:11 +00:00
_spcd_banner_shut() {
_spcd_banner_append \
2024-08-26 14:06:14 +00:00
"${_SPCD_BANNER_DOWN_AND_LEFT}" \
"${_SPCD_BANNER_VERTICAL}" \
"${_SPCD_BANNER_UP_AND_LEFT}"
2024-08-26 13:00:11 +00:00
}
2024-08-26 13:01:45 +00:00
_spcd_banner_split() {
2024-08-26 12:58:34 +00:00
_spcd_banner_append \
2024-08-26 14:06:14 +00:00
"${_SPCD_BANNER_DOWN_AND_HORIZONTAL}" \
"${_SPCD_BANNER_VERTICAL}" \
"${_SPCD_BANNER_UP_AND_HORIZONTAL}"
2024-08-25 19:17:31 +00:00
}
2024-08-26 13:17:58 +00:00
_spcd_banner_wipe() {
2024-08-25 19:17:31 +00:00
unset \
2024-08-26 14:38:46 +00:00
__SPCD_BANNER_TOP \
__SPCD_BANNER_MIDDLE \
__SPCD_BANNER_BOTTOM
2024-08-25 19:17:31 +00:00
}
2024-08-27 10:26:10 +00:00
# ╭───┬───────╮
# │ _ │ error │
# ╰───┴───────╯
2024-08-25 19:17:31 +00:00
2024-08-26 13:19:31 +00:00
_SPCD_ERROR_CI=1
2024-08-26 13:20:30 +00:00
_SPCD_ERROR_OS=2
2024-08-25 19:17:31 +00:00
2024-08-27 10:26:10 +00:00
# ╭───┬───────╮
# │ _ │ frame │
# ╰───┴───────╯
2024-08-25 19:37:39 +00:00
2024-08-26 12:19:59 +00:00
_SPCD_FRAME_TOP="╭╴"
_SPCD_FRAME_BOTTOM="╰╴"
2024-08-25 19:37:39 +00:00
2024-08-26 12:19:59 +00:00
_spcd_frame_open() {
echo "${_SPCD_FRAME_TOP}${1}"
2024-08-25 19:37:39 +00:00
}
2024-08-26 12:19:59 +00:00
_spcd_frame_shut() {
echo "${_SPCD_FRAME_BOTTOM}${1}"
2024-08-25 19:37:39 +00:00
}
2024-08-27 10:26:10 +00:00
# ╭───┬────╮
# │ _ │ os │
# ╰───┴────╯
2024-08-25 20:42:37 +00:00
2024-08-26 12:22:25 +00:00
_spcd_os_cat() {
2024-08-26 13:59:25 +00:00
if [ -n "${1}" ]; then
_spcd_frame_open "${1}"
cat "${1}"
_spcd_frame_shut "${1}"
2024-08-25 20:43:08 +00:00
fi
}
2024-08-25 20:42:37 +00:00
2024-08-27 10:26:10 +00:00
# ╭───┬──────╮
# │ _ │ rule │
# ╰───┴──────╯
2024-08-25 20:19:00 +00:00
2024-08-26 12:25:48 +00:00
_SPCD_RULE_LEFT="╶"
_SPCD_RULE_MIDDLE="─"
_SPCD_RULE_RIGHT="╴"
2024-08-25 20:19:00 +00:00
2024-08-27 10:26:10 +00:00
# ╭───┬──────╮
# │ _ │ step │
# ╰───┴──────╯
2024-08-25 19:17:31 +00:00
2024-08-26 12:34:01 +00:00
_spcd_step_wipe() {
2024-08-25 19:17:31 +00:00
unset \
2024-08-26 14:27:44 +00:00
"__SPCD_STEP_${__SPCD_STEP_LEVEL}_INDEX" \
"__SPCD_STEP_${__SPCD_STEP_LEVEL}_LABEL"
2024-08-25 19:17:31 +00:00
}
2024-08-26 12:37:50 +00:00
# ╭───────────╮
# │ functions │
# ╰───────────╯
2024-08-25 20:56:22 +00:00
2024-08-25 19:21:09 +00:00
# ╭───────────┬───────╮
# │ functions │ error │
# ╰───────────┴───────╯
spcd_error_ci() {
echo "× CI: ${*}"
2024-08-26 13:19:31 +00:00
exit "${_SPCD_ERROR_CI}"
2024-08-25 19:21:09 +00:00
}
spcd_error_os() {
printf "× OS: "
2024-08-26 16:11:10 +00:00
spcd_os_printenv "${1}"
2024-08-26 13:20:30 +00:00
exit "${_SPCD_ERROR_OS}"
2024-08-25 19:21:09 +00:00
}
2024-08-25 21:37:06 +00:00
# ╭───────────┬─────────╮
# │ functions │ openssl │
# ╰───────────┴─────────╯
spcd_openssl_x509() {
2024-08-26 16:09:58 +00:00
if [ -f "${1}" ]; then
2024-08-25 21:37:06 +00:00
openssl x509 \
2024-08-26 16:09:58 +00:00
-in "${1}" \
2024-08-25 21:37:06 +00:00
-noout -text
fi
}
2024-08-25 19:21:09 +00:00
# ╭───────────┬────╮
# │ functions │ os │
# ╰───────────┴────╯
spcd_os_grep() {
spcd_os_grep__variable="${1}"
[ -n "${spcd_os_grep__variable}" ] &&
grep "^${spcd_os_grep__variable}=" "/etc/os-release" |
sed "s|^${spcd_os_grep__variable}=||" |
sed "s|^\"\(.*\)\"$|\1|"
}
2024-08-25 20:48:21 +00:00
spcd_os_ls() {
2024-08-26 16:12:55 +00:00
if [ -n "${1}" ]; then
_spcd_frame_open "${1}"
ls -a -l "${1}"
_spcd_frame_shut "${1}"
2024-08-25 20:48:21 +00:00
fi
}
2024-08-25 19:21:09 +00:00
spcd_os_mkdir() {
2024-08-26 16:14:26 +00:00
echo "${1}"
mkdir --parents "${1}"
2024-08-25 19:21:09 +00:00
}
2024-08-25 19:29:21 +00:00
spcd_os_printenv() {
if [ -n "${1}" ]; then
for spcd_os_printenv__name in "${@}"; do
spcd_os_printenv__text=""
eval "spcd_os_printenv__text=\"\${${spcd_os_printenv__name}}\""
echo "${spcd_os_printenv__name} = \"${spcd_os_printenv__text}\""
done
fi
}
2024-08-25 19:21:09 +00:00
spcd_os_rm() {
2024-08-26 14:33:15 +00:00
if [ -e "${1}" ]; then
echo "${1}"
rm -r "${1}"
2024-08-25 19:21:09 +00:00
fi
}
2024-08-25 21:17:10 +00:00
spcd_os_sed() {
spcd_os_sed__file="${1}"
shift
if [ -f "${spcd_os_sed__file}" ]; then
2024-08-26 12:22:25 +00:00
_spcd_os_cat "${spcd_os_sed__file}"
2024-08-25 21:17:10 +00:00
for spcd_os_sed__regex in "${@}"; do
sed --in-place "s${spcd_os_sed__regex}g" "${spcd_os_sed__file}" &&
2024-08-26 12:22:25 +00:00
_spcd_os_cat "${spcd_os_sed__file}"
2024-08-25 21:17:10 +00:00
done
fi
}
2024-08-25 21:12:52 +00:00
spcd_os_write() {
spcd_os_write__file="${1}"
spcd_os_write__text="${2}"
if [ -n "${spcd_os_write__file}" ]; then
[ -f "${spcd_os_write__file}" ] &&
2024-08-26 12:22:25 +00:00
_spcd_os_cat "${spcd_os_write__file}"
2024-08-25 21:12:52 +00:00
echo "${spcd_os_write__file}"
printf "%s" "${spcd_os_write__text}" >"${spcd_os_write__file}"
2024-08-26 12:22:25 +00:00
_spcd_os_cat "${spcd_os_write__file}"
2024-08-25 21:12:52 +00:00
fi
}
2024-08-25 20:19:00 +00:00
# ╭───────────┬───────╮
# │ functions │ split │
# ╰───────────┴───────╯
spcd_split() {
2024-08-26 12:25:48 +00:00
echo "${_SPCD_RULE_LEFT}${_SPCD_RULE_MIDDLE}${_SPCD_RULE_RIGHT}"
2024-08-25 20:19:00 +00:00
}
2024-08-25 19:21:09 +00:00
# ╭───────────┬──────╮
# │ functions │ step │
# ╰───────────┴──────╯
spcd_step() {
if [ -n "${1}" ]; then
2024-08-26 14:27:44 +00:00
[ -n "${__SPCD_STEP_LEVEL}" ] || __SPCD_STEP_LEVEL=1
spcd_step__prefix="__SPCD_STEP_${__SPCD_STEP_LEVEL}"
2024-08-25 19:21:09 +00:00
spcd_step__index="${spcd_step__prefix}_INDEX"
eval "${spcd_step__index}=\$((${spcd_step__index} + 1))"
eval "${spcd_step__prefix}_LABEL=\"${1}\""
2024-08-26 13:13:28 +00:00
_spcd_banner_render
2024-08-25 19:21:09 +00:00
fi
}
spcd_step_in() {
[ -n "${1}" ] && spcd_step "${1}"
2024-08-26 14:27:44 +00:00
__SPCD_STEP_LEVEL=$((__SPCD_STEP_LEVEL + 1))
2024-08-26 12:34:01 +00:00
_spcd_step_wipe
2024-08-25 19:21:09 +00:00
}
spcd_step_out() {
2024-08-26 12:34:01 +00:00
_spcd_step_wipe
2024-08-26 14:27:44 +00:00
__SPCD_STEP_LEVEL=$((__SPCD_STEP_LEVEL - 1))
2024-08-25 19:21:09 +00:00
}
2024-08-27 10:41:57 +00:00
# ╭──────╮
# │ step │
# ╰──────╯
2024-08-25 20:56:22 +00:00
2024-08-27 10:41:57 +00:00
# ╭──────┬───────────╮
# │ step │ constants │
# ╰──────┴───────────╯
2024-08-25 19:48:37 +00:00
SPCD_OS_ALMA="alma"
SPCD_OS_ALPINE="alpine"
SPCD_OS_ARCH="arch"
SPCD_OS_DEBIAN="debian"
SPCD_OS_FEDORA="fedora"
SPCD_OS_OPENSUSE="opensuse"
SPCD_OS_ROCKY="rocky"
SPCD_OS_UBUNTU="ubuntu"
2024-08-25 19:50:09 +00:00
SPCD_PM_APK="apk"
SPCD_PM_APT="apt"
SPCD_PM_DNF="dnf"
SPCD_PM_PACMAN="pacman"
SPCD_PM_ZYPPER="zypper"
2024-08-27 10:41:57 +00:00
# ╭──────┬─────────────╮
# │ step │ environment │
# ╰──────┴─────────────╯
2024-06-24 06:10:47 +00:00
2024-08-27 11:04:09 +00:00
spcd_step__environment_set_variables() {
2024-08-25 22:30:20 +00:00
spcd_step "Set variables"
2024-08-19 08:35:27 +00:00
# check script first
[ -n "${SPCD}" ] || spcd_error_ci "SPCD"
# 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="\
2024-07-22 09:58:37 +00:00
${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
2024-08-19 08:35:27 +00:00
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}\
2024-07-19 19:59:09 +00:00
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
2024-08-19 08:35:27 +00:00
# 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
2024-08-24 14:10:36 +00:00
"${SPCD_REF_RELEASE}" | \
"${SPCD_REF_STAGING}" | \
"${SPCD_REF_FEATURE}") ;;
2024-08-19 08:35:27 +00:00
*) 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"
#
2024-08-25 19:28:50 +00:00
spcd_os_printenv "SPCD_PROJECT_BRANCH" \
2024-08-19 08:35:27 +00:00
"SPCD_PROJECT_ROOT" "SPCD_PROJECT_PATH" "SPCD_PROJECT_NAME"
# set operating system id
2024-08-25 17:32:00 +00:00
SPCD_OS_ID="$(spcd_os_grep ID)"
2024-08-19 08:35:27 +00:00
case "${SPCD_OS_ID}" in
"almalinux") SPCD_OS_ID="${SPCD_OS_ALMA}" ;;
"alpine") SPCD_OS_ID="${SPCD_OS_ALPINE}" ;;
"arch") SPCD_OS_ID="${SPCD_OS_ARCH}" ;;
"debian") SPCD_OS_ID="${SPCD_OS_DEBIAN}" ;;
"fedora") SPCD_OS_ID="${SPCD_OS_FEDORA}" ;;
2024-08-20 06:27:15 +00:00
"opensuse-leap") SPCD_OS_ID="${SPCD_OS_OPENSUSE}" ;;
2024-08-19 08:35:27 +00:00
"rocky") SPCD_OS_ID="${SPCD_OS_ROCKY}" ;;
"ubuntu") SPCD_OS_ID="${SPCD_OS_UBUNTU}" ;;
*) spcd_error_os "SPCD_OS_ID" ;;
esac
# set operating system version
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}" | \
"${SPCD_OS_ARCH}")
2024-08-25 17:32:00 +00:00
SPCD_OS_VERSION=$(spcd_os_grep VERSION_ID |
2024-08-19 08:35:27 +00:00
sed "s|^\([0-9]\+\)\..*|\1|")
;;
2024-08-20 06:27:15 +00:00
"${SPCD_OS_ALPINE}" | "${SPCD_OS_OPENSUSE}")
2024-08-25 17:32:00 +00:00
SPCD_OS_VERSION=$(spcd_os_grep VERSION_ID |
2024-08-19 08:35:27 +00:00
sed "s|^\([0-9]\+\.[0-9]\+\)\..*|\1|")
;;
"${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
2024-08-25 17:32:00 +00:00
SPCD_OS_VERSION="$(spcd_os_grep VERSION_CODENAME)"
2024-08-19 08:35:27 +00:00
;;
*) ;;
esac
# check operating system version
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_ROCKY}")
case "${SPCD_OS_VERSION}" in
"9" | "8") ;;
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
"${SPCD_OS_ALPINE}")
case "${SPCD_OS_VERSION}" in
"3.20" | "3.19") ;;
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
"${SPCD_OS_ARCH}")
case "${SPCD_OS_VERSION}" in
2024-08-20 20:12:30 +00:00
"20240818" | "20240101") ;;
2024-08-19 08:35:27 +00:00
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
"${SPCD_OS_DEBIAN}")
case "${SPCD_OS_VERSION}" in
2024-08-20 20:12:30 +00:00
"bookworm" | "bullseye") ;;
2024-08-19 08:35:27 +00:00
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
"${SPCD_OS_FEDORA}")
case "${SPCD_OS_VERSION}" in
"40" | "39") ;;
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
2024-08-20 06:27:15 +00:00
"${SPCD_OS_OPENSUSE}")
case "${SPCD_OS_VERSION}" in
"15.6" | "15.5") ;;
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
2024-08-19 08:35:27 +00:00
"${SPCD_OS_UBUNTU}")
case "${SPCD_OS_VERSION}" in
"noble" | "jammy") ;;
*) spcd_error_os "SPCD_OS_VERSION" ;;
esac
;;
*) ;;
esac
spcd_split
2024-08-25 19:28:50 +00:00
spcd_os_printenv "SPCD_OS_ID" "SPCD_OS_VERSION"
2024-08-19 08:35:27 +00:00
# set package manager
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALPINE}")
SPCD_PM="${SPCD_PM_APK}"
;;
"${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
SPCD_PM="${SPCD_PM_APT}"
;;
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}")
SPCD_PM="${SPCD_PM_DNF}"
;;
"${SPCD_OS_ARCH}")
SPCD_PM="${SPCD_PM_PACMAN}"
;;
2024-08-20 06:36:22 +00:00
"${SPCD_OS_OPENSUSE}")
SPCD_PM="${SPCD_PM_ZYPPER}"
;;
2024-08-19 08:35:27 +00:00
*) ;;
esac
spcd_split
2024-08-26 09:36:34 +00:00
spcd_os_printenv "SPCD_PM"
2024-08-26 16:31:23 +00:00
# set python alias
SPCD_PYTHON_ALIAS="python3"
spcd_split
spcd_os_printenv "SPCD_PYTHON_ALIAS"
# set python command & package
2024-08-19 08:35:27 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_ROCKY}")
SPCD_PYTHON_COMMAND="python3.12"
SPCD_PYTHON_PACKAGE="python3.12"
;;
"${SPCD_OS_ALPINE}")
case "${SPCD_OS_VERSION}" in
"3.20") SPCD_PYTHON_COMMAND="python3.12" ;;
"3.19") SPCD_PYTHON_COMMAND="python3.11" ;;
*) ;;
esac
SPCD_PYTHON_PACKAGE="python3"
;;
"${SPCD_OS_ARCH}")
SPCD_PYTHON_COMMAND="python3.12"
SPCD_PYTHON_PACKAGE="python"
;;
"${SPCD_OS_DEBIAN}")
case "${SPCD_OS_VERSION}" in
"bookworm") SPCD_PYTHON_COMMAND="python3.11" ;;
"bullseye") SPCD_PYTHON_COMMAND="python3.9" ;;
*) ;;
esac
SPCD_PYTHON_PACKAGE="python3"
;;
"${SPCD_OS_FEDORA}")
2024-08-20 13:32:18 +00:00
SPCD_PYTHON_COMMAND="python3.12"
SPCD_PYTHON_PACKAGE="python3"
2024-08-19 08:35:27 +00:00
;;
2024-08-20 08:56:07 +00:00
"${SPCD_OS_OPENSUSE}")
case "${SPCD_OS_VERSION}" in
"15.6")
SPCD_PYTHON_COMMAND="python3.12"
SPCD_PYTHON_PACKAGE="python312"
;;
"15.5")
SPCD_PYTHON_COMMAND="python3.11"
SPCD_PYTHON_PACKAGE="python311"
;;
*) ;;
esac
;;
2024-08-19 08:35:27 +00:00
"${SPCD_OS_UBUNTU}")
case "${SPCD_OS_VERSION}" in
"noble") SPCD_PYTHON_COMMAND="python3.12" ;;
"jammy") SPCD_PYTHON_COMMAND="python3.10" ;;
*) ;;
esac
SPCD_PYTHON_PACKAGE="python3"
;;
*) ;;
esac
spcd_split
2024-08-26 16:31:23 +00:00
spcd_os_printenv "SPCD_PYTHON_COMMAND" "SPCD_PYTHON_PACKAGE"
2024-08-19 08:35:27 +00:00
# set python packages
case "${SPCD_OS_ID}" in
2024-08-20 09:17:06 +00:00
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}" | \
"${SPCD_OS_OPENSUSE}")
2024-08-19 08:35:27 +00:00
SPCD_PYTHON_PACKAGES="/usr/lib64/${SPCD_PYTHON_COMMAND}/site-packages"
;;
"${SPCD_OS_ALPINE}" | "${SPCD_OS_ARCH}")
SPCD_PYTHON_PACKAGES="/usr/lib/${SPCD_PYTHON_COMMAND}/site-packages"
;;
"${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
2024-08-26 16:31:23 +00:00
SPCD_PYTHON_PACKAGES="/usr/lib/${SPCD_PYTHON_ALIAS}/dist-packages"
2024-08-19 08:35:27 +00:00
;;
*) ;;
esac
2024-08-26 16:27:58 +00:00
# set python virtual environment
SPCD_PYTHON_VENV="/opt/venv"
SPCD_PYTHON_VENV_BINARIES="${SPCD_PYTHON_VENV}/bin"
2024-08-19 08:35:27 +00:00
SPCD_PYTHON_VENV_PACKAGES="\
2024-08-07 11:35:39 +00:00
${SPCD_PYTHON_VENV}/lib/${SPCD_PYTHON_COMMAND}/site-packages"
2024-08-19 08:35:27 +00:00
spcd_split
2024-08-25 19:28:50 +00:00
spcd_os_printenv "SPCD_PYTHON_PACKAGES" "SPCD_PYTHON_VENV_PACKAGES"
2024-08-23 14:13:32 +00:00
# downloads
SPCD_DL="$(mktemp --directory)"
2024-08-19 08:35:27 +00:00
spcd_split
2024-08-26 09:46:41 +00:00
spcd_os_printenv "SPCD_DL"
2024-04-27 09:56:16 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__environment_list_workspace() {
2024-08-25 22:30:20 +00:00
spcd_step "List workspace"
2024-08-19 08:35:27 +00:00
spcd_lwd__path="$(realpath .)"
2024-08-25 20:47:21 +00:00
spcd_os_ls "${spcd_lwd__path}"
2024-07-20 14:21:34 +00:00
}
2024-08-27 10:41:57 +00:00
# ╭──────┬───────────╮
# │ step │ functions │
# ╰──────┴───────────╯
2024-08-25 22:22:17 +00:00
2024-08-26 09:23:50 +00:00
spcd_clean_cache() {
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk cache purge ;;
"${SPCD_PM_APT}") apt-get clean ;;
"${SPCD_PM_DNF}") dnf clean all ;;
"${SPCD_PM_PACMAN}") pacman --sync --clean --noconfirm ;;
"${SPCD_PM_ZYPPER}") zypper clean ;;
*) ;;
esac
}
2024-08-27 10:34:01 +00:00
spcd_git_clone() {
if [ -n "${1}" ]; then
spcd_gc__name="$(basename "${1}")"
spcd_gc__path="${SPCD_DL}/${spcd_gc__name}"
spcd_gc__url="$(spcd_git_url "${1}")"
git clone "${spcd_gc__url}" "${spcd_gc__path}"
echo "${spcd_gc__path}"
fi
}
spcd_git_url() {
if [ -n "${1}" ]; then
case "${1}" in
http*) echo "${1}" ;;
*/*) echo "${SPCD_PROJECT_ROOT}/${1}" ;;
*) echo "${SPCD_PROJECT_ROOT}/${SPCD_PROJECT_PATH}/${1}" ;;
esac
fi
}
2024-08-27 09:59:38 +00:00
spcd_https_path() {
case "${SPCD_PM}" in
"${SPCD_PM_APK}") echo "/etc/apk/repositories.d/https" ;;
"${SPCD_PM_APT}") echo "/etc/apt/apt.conf.d/https" ;;
2024-08-27 10:00:06 +00:00
"${SPCD_PM_DNF}") echo "/etc/dnf/dnf.conf.d/https.conf" ;;
"${SPCD_PM_PACMAN}") echo "/etc/pacman.d/https.conf" ;;
2024-08-27 09:59:38 +00:00
"${SPCD_PM_ZYPPER}") ;;
*) ;;
esac
}
2024-08-25 22:22:17 +00:00
spcd_install_package() {
2024-08-26 09:58:06 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk add "${1}" ;;
"${SPCD_PM_APT}") apt-get install --assume-yes "${1}" ;;
"${SPCD_PM_DNF}") dnf install --assumeyes "${1}" ;;
"${SPCD_PM_PACMAN}") pacman --sync --noconfirm "${1}" ;;
"${SPCD_PM_ZYPPER}") zypper --non-interactive install "${1}" ;;
*) ;;
esac
spcd_clean_cache
2024-08-25 22:22:17 +00:00
}
2024-08-26 16:18:10 +00:00
spcd_python_ln() {
spcd_python_ln__command="${1}"
if [ -n "${spcd_python_ln__command}" ]; then
echo "${SPCD_PYTHON_ALIAS}${spcd_python_ln__command}"
ln -f -s "${spcd_python_ln__command}" \
"/usr/bin/${SPCD_PYTHON_ALIAS}"
fi
}
2024-08-26 16:03:06 +00:00
spcd_python_pip() {
if [ -n "${1}" ]; then
spcd_pp__name="$(basename "${1}")"
spcd_pp__path="$(spcd_git_clone "${1}")"
spcd_pp__path="${spcd_pp__path}/${spcd_pp__name}"
spcd_pp__target="${SPCD_PYTHON_VENV_PACKAGES}"
cp --recursive "${spcd_pp__path}" "${spcd_pp__target}"
echo "${spcd_pp__target}/${spcd_pp__name}"
fi
}
2024-08-26 10:04:01 +00:00
spcd_query_package() {
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk info "${1}" ;;
"${SPCD_PM_APT}") dpkg-query --show "${1}" ;;
"${SPCD_PM_DNF}") rpm --query "${1}" ;;
"${SPCD_PM_PACMAN}") pacman --query "${1}" ;;
"${SPCD_PM_ZYPPER}") rpm --query "${1}" ;;
*) ;;
esac
}
2024-08-27 10:41:57 +00:00
# ╭──────┬─────╮
# │ step │ dns │
# ╰──────┴─────╯
2024-08-25 23:10:56 +00:00
2024-08-27 11:04:09 +00:00
spcd_step__dns() {
2024-08-25 23:10:56 +00:00
spcd_step "DNS"
while true; do
spcd_sdr__index=$((spcd_sdr__index + 1))
eval "spcd_sdr__value=\"\${SPCD_DNS_${spcd_sdr__index}}\""
[ -n "${spcd_sdr__value}" ] || break
spcd_sdr__text="${spcd_sdr__text}\
nameserver ${spcd_sdr__value}
"
done
2024-08-26 15:14:50 +00:00
spcd_os_write "/etc/resolv.conf" "${spcd_sdr__text}"
2024-08-25 23:10:56 +00:00
}
2024-08-27 10:41:57 +00:00
# ╭──────┬──────────╮
# │ step │ packages │
# ╰──────┴──────────╯
2024-08-24 14:54:07 +00:00
2024-08-27 11:04:09 +00:00
spcd_step__packages_set_repositories() {
2024-08-25 23:22:38 +00:00
spcd_step "Set repositories"
2024-08-19 08:35:27 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}")
case "${SPCD_OS_VERSION}" in
2024-08-27 14:53:05 +00:00
"9")
set -- \
"-appstream" \
"-baseos" \
"-crb" \
"-extras" \
"-highavailability" \
"-nfv" \
"-plus" \
"-resilientstorage" \
"-rt" \
"-sap" \
"-saphana"
;;
"8")
set -- \
"" \
"-ha" \
"-nfv" \
"-plus" \
"-powertools" \
"-resilientstorage" \
"-rt" \
"-sap" \
"-saphana"
;;
2024-08-19 08:35:27 +00:00
*) ;;
esac
2024-08-27 14:53:05 +00:00
for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/yum.repos.d/almalinux${spcd_spr__file}.repo" \
"|^mirrorlist|# mirrorlist|" \
"|https://repo.almalinux.org|${SPCD_URL_ALMA}|" \
"|^# baseurl|baseurl|"
done
2024-08-19 08:35:27 +00:00
;;
"${SPCD_OS_ALPINE}")
2024-08-27 13:43:19 +00:00
spcd_os_write "/etc/apk/repositories" "\
${SPCD_URL_ALPINE}/v${SPCD_OS_VERSION}/main
${SPCD_URL_ALPINE}/v${SPCD_OS_VERSION}/community
2024-08-27 14:08:00 +00:00
"
;;
"${SPCD_OS_ARCH}")
spcd_os_write "/etc/pacman.d/mirrorlist" "\
Server = ${SPCD_URL_ARCH}
2024-05-04 10:50:20 +00:00
"
2024-08-19 08:35:27 +00:00
;;
"${SPCD_OS_DEBIAN}")
2024-08-27 13:43:19 +00:00
spcd_os_write "/etc/apt/sources.list" "\
deb ${SPCD_URL_DEBIAN} ${SPCD_OS_VERSION} main
deb ${SPCD_URL_DEBIAN} ${SPCD_OS_VERSION}-backports main
deb ${SPCD_URL_DEBIAN} ${SPCD_OS_VERSION}-updates main
deb ${SPCD_URL_DEBIAN}-security ${SPCD_OS_VERSION}-security main
2024-05-03 19:03:07 +00:00
"
2024-08-19 08:35:27 +00:00
;;
2024-08-27 14:08:00 +00:00
"${SPCD_OS_FEDORA}")
for spcd_spr__file in \
"fedora" \
"fedora-updates" \
"fedora-updates-testing"; do
spcd_os_sed "/etc/yum.repos.d/${spcd_spr__file}.repo" \
2024-08-27 16:35:21 +00:00
"|^metalink|# metalink|" "\
|http://download.example/pub/fedora/linux|${SPCD_URL_FEDORA}|" \
2024-08-27 14:08:00 +00:00
"|^#baseurl|baseurl|"
done
spcd_os_sed "/etc/yum.repos.d/fedora-cisco-openh264.repo" \
"|^enabled=1|# enabled=0|"
;;
2024-08-20 11:08:15 +00:00
"${SPCD_OS_OPENSUSE}")
for spcd_spr__file in \
"backports-update" \
"non-oss" \
"oss" \
"sle-update" \
"update-non-oss" \
"update" \
"openh264"; do
2024-08-25 21:16:19 +00:00
spcd_os_sed "/etc/zypp/repos.d/repo-${spcd_spr__file}.repo" \
2024-08-27 13:43:19 +00:00
"|http://download.opensuse.org|${SPCD_URL_OPENSUSE}|"
2024-08-20 11:08:15 +00:00
done
;;
2024-08-19 08:35:27 +00:00
"${SPCD_OS_ROCKY}")
case "${SPCD_OS_VERSION}" in
2024-08-27 15:44:44 +00:00
"9")
set -- \
"rocky" \
"rocky-addons" \
"rocky-devel" \
"rocky-extras"
;;
"8")
set -- \
"Rocky-AppStream" \
"Rocky-BaseOS" \
"Rocky-Debuginfo" \
"Rocky-Devel" \
"Rocky-Extras" \
"Rocky-HighAvailability" \
"Rocky-NFV" \
"Rocky-Plus" \
"Rocky-PowerTools" \
"Rocky-RT" \
"Rocky-ResilientStorage" \
"Rocky-Sources"
;;
2024-08-19 08:35:27 +00:00
*) ;;
esac
2024-08-27 15:44:44 +00:00
for spcd_spr__file in "${@}"; do
spcd_os_sed "/etc/yum.repos.d/${spcd_spr__file}.repo" \
"|^mirrorlist|# mirrorlist|" \
"|http://dl.rockylinux.org|${SPCD_URL_ROCKY}|" \
"|^#baseurl|baseurl|"
done
2024-08-19 08:35:27 +00:00
;;
"${SPCD_OS_UBUNTU}")
2024-08-27 13:43:19 +00:00
spcd_os_write "/etc/apt/sources.list" "\
deb ${SPCD_URL_UBUNTU} ${SPCD_OS_VERSION} main universe
deb ${SPCD_URL_UBUNTU} ${SPCD_OS_VERSION}-backports main universe
deb ${SPCD_URL_UBUNTU} ${SPCD_OS_VERSION}-updates main universe
deb ${SPCD_URL_UBUNTU} ${SPCD_OS_VERSION}-security main universe
2024-05-04 21:47:31 +00:00
"
2024-08-19 08:35:27 +00:00
;;
*) ;;
esac
2024-04-26 14:13:35 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_set_configuration() {
2024-08-25 23:22:38 +00:00
spcd_step "Set configuration"
2024-08-26 10:36:41 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_DNF}")
spcd_os_write "/etc/dnf/dnf.conf" "\
[main]
best=True
clean_requirements_on_remove=True
gpgcheck=1
installonly_limit=3
skip_if_unavailable=False
"
;;
2024-08-26 14:28:37 +00:00
"${SPCD_PM_APK}") ;;
"${SPCD_PM_PACMAN}") ;;
2024-08-26 10:36:41 +00:00
"${SPCD_PM_APT}")
spcd_os_write "/etc/apt/apt.conf.d/apt.conf" "\
Acquire::Check-Valid-Until True;
APT::Get::Show-Versions True;
APT::Install-Recommends False;
APT::Install-Suggests False;
Dir::Etc::SourceParts \"\";
"
;;
2024-08-26 14:28:37 +00:00
"${SPCD_PM_ZYPPER}") ;;
2024-08-26 10:36:41 +00:00
*) ;;
esac
2024-08-19 08:35:27 +00:00
case "${SPCD_OS_ID}" in
2024-08-19 20:13:59 +00:00
"${SPCD_OS_ARCH}")
pacman-key --init
;;
2024-08-19 08:35:27 +00:00
"${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
export DEBIAN_FRONTEND="noninteractive"
;;
*) ;;
esac
2024-05-04 20:36:30 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_trust_https() {
2024-08-25 23:33:33 +00:00
spcd_step "Trust HTTPS"
2024-08-26 09:46:41 +00:00
if [ -n "${SPCD_CA_1}" ] || [ "${SPCD_PM}" = "${SPCD_PM_APT}" ]; then
2024-08-27 10:20:35 +00:00
spcd_pth__path="$(spcd_https_path)"
if [ -n "${spcd_pth__path}" ]; then
spcd_os_mkdir "$(dirname "${spcd_pth__path}")"
case "${SPCD_PM}" in
"${SPCD_PM_APK}") spcd_pth__text="\
--no-verify
" ;;
"${SPCD_PM_APT}") spcd_pth__text="\
Acquire::https::Verify-Peer False;
" ;;
"${SPCD_PM_DNF}") spcd_pth__text="\
sslverify=False
" ;;
"${SPCD_PM_PACMAN}") spcd_pth__text="\
SSLVerify = No
" ;;
"${SPCD_PM_ZYPPER}") ;;
*) ;;
esac
[ -n "${spcd_pth__text}" ] &&
spcd_os_write "${spcd_pth__path}" "${spcd_pth__text}"
fi
2024-08-19 08:35:27 +00:00
fi
2024-04-26 14:23:30 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_update_catalog() {
2024-08-25 23:36:25 +00:00
spcd_step "Update catalog"
2024-08-26 08:49:12 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk update ;;
"${SPCD_PM_APT}") apt-get update ;;
"${SPCD_PM_DNF}") dnf makecache ;;
"${SPCD_PM_PACMAN}") pacman --sync --refresh ;;
"${SPCD_PM_ZYPPER}") zypper refresh ;;
*) ;;
esac
2024-04-26 14:27:36 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_install_tools() {
2024-08-25 23:39:55 +00:00
spcd_step "Install tools"
2024-08-26 09:29:30 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_APT}") spcd_install_package "apt-utils" ;;
*) ;;
esac
2024-06-21 11:20:20 +00:00
}
2024-08-27 10:41:57 +00:00
# ╭──────┬────╮
# │ step │ ca │
# ╰──────┴────╯
2024-08-24 15:11:03 +00:00
2024-08-27 11:04:09 +00:00
spcd_step__ca_install_package() {
2024-08-26 01:17:36 +00:00
spcd_step "Install package"
2024-08-26 09:42:43 +00:00
spcd_install_package "ca-certificates"
2024-06-21 11:20:20 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__ca_write_certificates() {
2024-08-26 01:17:36 +00:00
spcd_step "Write certificates"
2024-08-26 09:16:53 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_FEDORA}" | "${SPCD_OS_ROCKY}")
spcd_wcc__root="/etc/pki/ca-trust/source/anchors"
;;
"${SPCD_OS_ALPINE}" | "${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
spcd_wcc__root="/usr/local/share/ca-certificates"
;;
"${SPCD_OS_ARCH}")
spcd_wcc__root="/etc/ca-certificates/trust-source/anchors"
;;
"${SPCD_OS_OPENSUSE}")
spcd_wcc__root="/etc/pki/trust/anchors"
;;
*) ;;
esac
spcd_os_mkdir "${spcd_wcc__root}"
2024-08-19 08:35:27 +00:00
while true; do
spcd_wcc__index=$((spcd_wcc__index + 1))
eval "spcd_wcc__text=\"\${SPCD_CA_${spcd_wcc__index}}\""
[ -n "${spcd_wcc__text}" ] || break
2024-08-26 09:16:53 +00:00
spcd_wcc__path="${spcd_wcc__root}/${spcd_wcc__index}.crt"
2024-08-19 08:35:27 +00:00
spcd_split
2024-08-25 21:12:21 +00:00
spcd_os_write "${spcd_wcc__path}" "${spcd_wcc__text}"
2024-08-25 21:35:16 +00:00
spcd_openssl_x509 "${spcd_wcc__path}"
2024-08-19 08:35:27 +00:00
done
2024-05-03 15:20:44 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__ca_update_certificates() {
2024-08-26 01:17:36 +00:00
spcd_step "Update certificates"
2024-08-26 09:11:26 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_ARCH}" | \
"${SPCD_OS_ALMA}" | \
"${SPCD_OS_FEDORA}" | \
"${SPCD_OS_ROCKY}")
update-ca-trust
;;
"${SPCD_OS_ALPINE}" | \
"${SPCD_OS_DEBIAN}" | \
"${SPCD_OS_OPENSUSE}" | \
"${SPCD_OS_UBUNTU}")
update-ca-certificates
;;
*) ;;
esac
2024-04-27 21:58:48 +00:00
}
2024-08-27 10:41:57 +00:00
# ╭──────┬──────────╮
# │ step │ packages │
# ╰──────┴──────────╯
2024-08-24 15:11:03 +00:00
2024-08-27 11:04:09 +00:00
spcd_step__packages_verify_https() {
2024-08-25 23:44:43 +00:00
spcd_step "Verify HTTPS"
2024-08-27 10:02:59 +00:00
spcd_pvh__path="$(spcd_https_path)"
2024-08-27 12:12:57 +00:00
if [ -n "${spcd_pvh__path}" ]; then
spcd_os_rm "${spcd_pvh__path}"
fi
2024-04-26 14:50:25 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_upgrade_system() {
2024-08-25 23:48:01 +00:00
spcd_step "Upgrade system"
2024-08-26 08:43:39 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_APK}") apk upgrade ;;
"${SPCD_PM_APT}") apt-get upgrade --assume-yes ;;
"${SPCD_PM_DNF}") dnf upgrade --assumeyes ;;
"${SPCD_PM_PACMAN}") pacman --sync --sysupgrade --noconfirm ;;
"${SPCD_PM_ZYPPER}") zypper --non-interactive update ;;
*) ;;
esac
2024-04-26 14:35:15 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_install_dos2unix() {
2024-08-19 08:35:27 +00:00
spcd_step "Install dos2unix"
2024-08-26 08:34:34 +00:00
spcd_install_package "dos2unix"
2024-08-19 08:19:15 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__packages_install_git() {
2024-08-19 08:35:27 +00:00
spcd_step "Install Git"
2024-08-26 08:33:04 +00:00
spcd_install_package "git"
2024-04-26 14:35:15 +00:00
}
2024-08-27 10:41:57 +00:00
# ╭──────┬────────╮
# │ step │ python │
# ╰──────┴────────╯
2024-08-24 15:11:03 +00:00
2024-08-27 11:04:09 +00:00
spcd_step__python_install() {
2024-08-26 01:00:48 +00:00
spcd_step "Install package"
2024-08-19 08:35:27 +00:00
spcd_install_package "${SPCD_PYTHON_PACKAGE}"
2024-08-25 15:41:04 +00:00
spcd_step "Link alias to command"
2024-08-25 21:06:37 +00:00
spcd_python_ln "${SPCD_PYTHON_COMMAND}"
2024-08-19 12:38:39 +00:00
# venv
2024-08-25 16:40:05 +00:00
spcd_step_in "Virtual environment"
spcd_step "Install package"
2024-08-19 12:15:29 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_DEBIAN}" | "${SPCD_OS_UBUNTU}")
spcd_install_package "python3-venv"
;;
*) ;;
esac
2024-08-25 15:41:04 +00:00
spcd_step "Configure PIP"
2024-08-25 21:12:21 +00:00
spcd_os_write "/etc/pip.conf" "\
2024-08-19 12:15:29 +00:00
[global]
index-url = ${SPCD_URL_PYTHON}
"
2024-08-25 16:40:05 +00:00
spcd_step "Create"
2024-08-19 12:15:29 +00:00
"${SPCD_PYTHON_ALIAS}" -m "venv" "${SPCD_PYTHON_VENV}"
2024-08-25 16:40:05 +00:00
spcd_step "Activate"
2024-08-19 12:15:29 +00:00
export PATH="${SPCD_PYTHON_VENV_BINARIES}:${PATH}"
export VIRTUAL_ENV="${SPCD_PYTHON_VENV}"
2024-08-25 15:41:04 +00:00
spcd_step_out
2024-04-26 14:39:24 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__python_modules() {
2024-08-26 01:00:48 +00:00
spcd_step_in "Modules"
2024-08-19 08:35:27 +00:00
spcd_ipm__target="${SPCD_PYTHON_VENV_PACKAGES}"
2024-08-25 18:18:05 +00:00
spcd_step "List"
2024-08-25 20:47:21 +00:00
spcd_os_ls "${spcd_ipm__target}"
2024-08-25 18:18:05 +00:00
spcd_step "Main"
2024-08-25 21:03:21 +00:00
spcd_ipm__path="$(spcd_python_pip "${SPCD_GIT_MAIN}")"
2024-08-23 16:07:41 +00:00
# check matching of file and variable
2024-08-25 18:18:05 +00:00
spcd_step "Check"
2024-08-25 22:10:46 +00:00
spcd_ipm__script="${spcd_ipm__path}/bootstrap.sh"
2024-08-23 16:18:43 +00:00
ls -l "${spcd_ipm__script}"
spcd_ipm__check="${spcd_ipm__script}.${SPCD_CMD_SUM}"
"${SPCD_CMD_SUM}" "${spcd_ipm__script}" >"${spcd_ipm__check}"
printf "%s" "${SPCD}" >"${spcd_ipm__script}"
ls -l "${spcd_ipm__script}"
dos2unix "${spcd_ipm__script}"
ls -l "${spcd_ipm__script}"
"${SPCD_CMD_SUM}" -c "${spcd_ipm__check}" || spcd_error_ci "SPCD"
2024-08-25 18:18:05 +00:00
spcd_step "Root"
2024-08-25 21:03:21 +00:00
spcd_python_pip "${SPCD_GIT_ROOT}"
2024-08-25 18:18:05 +00:00
spcd_step "List"
2024-08-25 20:47:21 +00:00
spcd_os_ls "${spcd_ipm__target}"
2024-08-25 18:18:05 +00:00
spcd_step_out
2024-08-19 08:23:08 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__install_packages() {
2024-08-25 19:06:03 +00:00
spcd_step_in "OS packages"
2024-08-19 08:35:27 +00:00
# epel
2024-08-25 19:06:03 +00:00
spcd_step "EPEL"
2024-08-19 08:35:27 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_ROCKY}")
spcd_install_package "epel-release"
[ -n "${SPCD_URL_EPEL}" ] && spcd_ip__epel="${SPCD_URL_EPEL}" ||
spcd_ip__epel="https://dl.fedoraproject.org"
2024-08-25 21:16:19 +00:00
spcd_os_sed "/etc/yum.repos.d/epel.repo" \
2024-08-19 08:35:27 +00:00
"|^metalink|# metalink|" \
"|https://download.example|${spcd_ip__epel}|" \
"|^#baseurl|baseurl|"
;;
*) ;;
esac
# graphviz
2024-08-25 19:06:03 +00:00
spcd_step "GraphViz"
2024-08-19 08:35:27 +00:00
spcd_install_package "graphviz"
2024-08-21 09:53:09 +00:00
# openssh
2024-08-25 19:06:03 +00:00
spcd_step "OpenSSH"
2024-08-21 09:53:09 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_APK}" | "${SPCD_PM_APT}")
spcd_install_package "openssh-client"
;;
"${SPCD_PM_DNF}" | "${SPCD_PM_ZYPPER}")
spcd_install_package "openssh-clients"
;;
"${SPCD_PM_PACMAN}") spcd_install_package "openssh" ;;
*) ;;
esac
2024-08-19 08:35:27 +00:00
# plantuml
2024-08-25 19:06:03 +00:00
spcd_step "PlantUML"
2024-08-19 08:35:27 +00:00
spcd_install_package "plantuml"
# rsync
2024-08-25 19:06:03 +00:00
spcd_step "Rsync"
2024-08-19 08:35:27 +00:00
spcd_install_package "rsync"
# shell check
2024-08-25 19:06:03 +00:00
spcd_step "ShellCheck"
2024-08-26 09:36:34 +00:00
case "${SPCD_PM}" in
"${SPCD_PM_DNF}" | "${SPCD_PM_ZYPPER}")
2024-08-20 13:44:30 +00:00
spcd_install_package "ShellCheck"
;;
2024-08-19 08:35:27 +00:00
*) spcd_install_package "shellcheck" ;;
esac
# shfmt
2024-08-25 19:06:03 +00:00
spcd_step "ShellFormat"
2024-08-19 08:35:27 +00:00
case "${SPCD_OS_ID}" in
"${SPCD_OS_ALMA}" | "${SPCD_OS_ROCKY}") ;;
"${SPCD_OS_DEBIAN}")
2024-08-21 12:47:29 +00:00
case "${SPCD_OS_VERSION}" in
"bullseye") ;;
*) spcd_install_package "shfmt" ;;
esac
2024-08-19 08:35:27 +00:00
;;
*) spcd_install_package "shfmt" ;;
esac
2024-08-25 15:41:04 +00:00
spcd_step_out
2024-06-27 11:58:43 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__python_write_module() {
2024-08-26 01:00:48 +00:00
spcd_step "Write module"
2024-08-19 08:35:27 +00:00
for spcd_wpm__variable in \
OS_ID OS_VERSION \
PROJECT_ROOT PROJECT_PATH PROJECT_NAME \
PYTHON_VENV_BINARIES PYTHON_VENV_PACKAGES \
OPEN DOWN VERT SPLT __UP SHUT; do
2024-08-25 19:28:50 +00:00
spcd_wpm__value="$(spcd_os_printenv "SPCD_${spcd_wpm__variable}")"
2024-08-19 08:35:27 +00:00
spcd_wpm__text="${spcd_wpm__text}${spcd_wpm__value}
2024-06-08 17:15:47 +00:00
"
2024-08-19 08:35:27 +00:00
done
2024-08-26 14:19:21 +00:00
spcd_wpm__index=$((__SPCD_STEP_1_INDEX + 1))
2024-08-19 08:35:27 +00:00
for spcd_wpm__root in \
"${SPCD_PYTHON_PACKAGES}" "${SPCD_PYTHON_VENV_PACKAGES}"; do
2024-08-25 21:12:21 +00:00
spcd_os_write "${spcd_wpm__root}/env.py" "${spcd_wpm__text}
2024-08-26 07:19:25 +00:00
SPCD_STEP = ${spcd_wpm__index}
2024-06-04 07:18:54 +00:00
"
2024-08-19 08:35:27 +00:00
done
2024-06-04 19:13:08 +00:00
}
2024-08-27 11:04:09 +00:00
spcd_step__python_switch() {
2024-08-26 01:00:48 +00:00
spcd_step "Switch"
2024-08-19 08:35:27 +00:00
spcd_stp__name="$(basename "${SPCD_GIT_MAIN}")"
2024-08-26 15:02:59 +00:00
spcd_stp__path="$(realpath "${0}")"
2024-08-19 08:35:27 +00:00
echo "\
2024-08-26 15:02:59 +00:00
${spcd_stp__path}
2024-04-28 13:42:36 +00:00
2024-08-07 17:08:03 +00:00
${SPCD_PYTHON_ALIAS} / ${spcd_stp__name}"
2024-08-19 08:35:27 +00:00
"${SPCD_PYTHON_ALIAS}" -m "${spcd_stp__name}"
2024-04-26 17:00:43 +00:00
}
2024-08-25 19:13:49 +00:00
# ╭──────╮
# │ main │
# ╰──────╯
spcd_main() {
2024-08-25 23:22:38 +00:00
# environment
2024-08-25 22:30:20 +00:00
spcd_step_in "Environment"
2024-08-27 11:04:09 +00:00
spcd_step__environment_set_variables
spcd_step__environment_list_workspace
2024-08-25 22:30:20 +00:00
spcd_step_out
2024-08-25 23:10:56 +00:00
# dns
2024-08-27 11:04:09 +00:00
spcd_step__dns
2024-08-25 23:22:38 +00:00
# packages
spcd_step_in "Packages"
2024-08-27 11:04:09 +00:00
spcd_step__packages_set_repositories
spcd_step__packages_set_configuration
spcd_step__packages_trust_https
spcd_step__packages_update_catalog
spcd_step__packages_install_tools
2024-08-25 23:22:38 +00:00
spcd_step_out
2024-08-25 19:13:49 +00:00
# ca
2024-08-26 01:17:36 +00:00
spcd_step_in "CA"
2024-08-27 11:04:09 +00:00
spcd_step__ca_install_package
spcd_step__ca_write_certificates
spcd_step__ca_update_certificates
2024-08-26 01:17:36 +00:00
spcd_step_out
2024-08-25 23:44:43 +00:00
# packages
spcd_step_in "Packages"
2024-08-27 11:04:09 +00:00
spcd_step__packages_verify_https
spcd_step__packages_update_catalog
spcd_step__packages_upgrade_system
spcd_step__packages_install_dos2unix
spcd_step__packages_install_git
2024-08-25 23:48:01 +00:00
spcd_step_out
2024-08-25 19:13:49 +00:00
# python
2024-08-26 01:00:48 +00:00
spcd_step_in "Python"
2024-08-27 11:04:09 +00:00
spcd_step__python_install
spcd_step__python_modules
spcd_step__install_packages
spcd_step__python_write_module
spcd_step__python_switch
2024-08-25 19:13:49 +00:00
}
2024-08-24 11:00:25 +00:00
2024-07-29 18:56:28 +00:00
spcd_main