spcd/cd.sh

155 lines
3 KiB
Bash
Raw Normal View History

2024-04-26 13:38:22 +00:00
#! /usr/bin/env bash
2024-04-26 11:38:38 +00:00
CD_DNS_SERVERS=(
2024-03-25 11:26:38 +00:00
'9.9.9.9'
)
2024-04-26 11:38:38 +00:00
CD_REPOSITORY='rwx.work/cd'
CD_DNS_FILE='/etc/resolv.conf'
case "${CD_OS_NAME}" in
'debian')
case "${CD_OS_VERSION}" in
'bookworm')
echo 'bookworm!'
;;
*)
echo 'CD_OS_VERSION'
exit 2
;;
esac
;;
*)
echo 'CD_OS_NAME'
exit 1
;;
esac
2024-04-26 11:59:41 +00:00
CD_STEP=0
2024-03-25 11:26:38 +00:00
2024-04-26 12:18:44 +00:00
function cd_step {
2024-04-26 11:59:41 +00:00
if [ "${1}" ] ; then
2024-04-26 13:38:22 +00:00
((CD_STEP++))
2024-04-26 11:59:41 +00:00
echo "
${CD_STEP}${1}
2024-04-25 14:01:18 +00:00
"
2024-04-26 11:59:41 +00:00
fi
2024-04-26 11:44:31 +00:00
}
2024-04-26 12:18:44 +00:00
function cd_write {
2024-04-26 12:07:46 +00:00
local file="${1}"
local text="${2}"
if [ "${file}" ] ; then
echo -n "${text}" \
> "${file}" \
|| exit
fi
}
2024-04-26 13:54:37 +00:00
function cd_set_dns_resolving {
2024-04-26 12:18:44 +00:00
local server
local text=''
2024-04-26 14:17:49 +00:00
cd_step "${FUNCNAME}"
2024-04-26 12:18:44 +00:00
for server in "${CD_DNS_SERVERS[@]}" ; do
text+="nameserver ${server}
"
done
cd_write "${CD_DNS_FILE}" "${text}" \
2024-03-25 11:26:38 +00:00
|| exit
2024-04-26 12:18:44 +00:00
}
2024-03-25 11:26:38 +00:00
2024-04-26 14:13:35 +00:00
function cd_set_packages_repositories {
2024-04-26 14:17:49 +00:00
cd_step "${FUNCNAME}"
2024-04-26 14:13:35 +00:00
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
"
;;
*) exit 1 ;;
esac
}
2024-04-26 13:54:37 +00:00
function cd_set_packages_configuration {
2024-04-26 14:17:49 +00:00
cd_step "${FUNCNAME}"
2024-04-26 13:54:37 +00:00
case "${CD_OS_NAME}" in
'debian')
2024-04-26 14:13:35 +00:00
cd_write '/etc/apt/apt.conf.d/apt.conf' "\
2024-04-25 13:33:58 +00:00
Acquire::Check-Valid-Until True;
2024-04-05 15:49:25 +00:00
APT::Get::Show-Versions True;
2024-04-08 08:07:37 +00:00
APT::Install-Recommends False;
APT::Install-Suggests False;
2024-04-26 14:03:17 +00:00
Dir::Etc::SourceParts \"\";
2024-04-26 13:54:37 +00:00
"
;;
2024-04-26 13:57:23 +00:00
*) exit 1 ;;
2024-04-26 13:54:37 +00:00
esac
}
2024-04-26 14:23:30 +00:00
function cd_set_https_verification_off {
cd_step "${FUNCNAME}"
case "${CD_OS_NAME}" in
'debian')
cd_write '/etc/apt/apt.conf.d/https' "\
Acquire::https::Verify-Peer False;
"
;;
*) exit 1 ;;
esac
}
2024-04-26 14:27:36 +00:00
function cd_update_packages_catalog {
cd_step "${FUNCNAME}"
case "${CD_OS_NAME}" in
'debian') apt-get update ;;
*) exit 1 ;;
esac
}
2024-04-26 13:54:37 +00:00
function cd_main {
cd_set_dns_resolving
2024-04-26 14:13:35 +00:00
cd_set_packages_repositories
2024-04-26 13:54:37 +00:00
cd_set_packages_configuration
2024-04-26 14:27:36 +00:00
cd_set_https_verification_off
cd_update_packages_catalog
2024-04-26 13:54:37 +00:00
2024-04-26 12:18:44 +00:00
cd_step "install CA certificates package"
2024-04-25 13:30:32 +00:00
apt-get install --yes 'ca-certificates' \
|| exit
2024-04-26 12:18:44 +00:00
cd_step "enable package verification"
2024-04-25 14:10:57 +00:00
rm '/etc/apt/apt.conf.d/https' \
|| exit
2024-04-26 12:18:44 +00:00
cd_step "update package catalog"
2024-03-25 08:02:43 +00:00
apt-get update \
2024-03-25 11:26:38 +00:00
|| exit
2024-04-26 12:18:44 +00:00
cd_step "upgrade packages"
2024-04-25 13:30:32 +00:00
apt-get upgrade --yes \
|| exit
2024-04-26 12:18:44 +00:00
cd_step "install Git"
2024-04-25 13:30:32 +00:00
apt-get install --yes 'git' \
2024-03-25 11:26:38 +00:00
|| exit
2024-03-25 19:09:04 +00:00
DIRECTORY="$(mktemp --directory)" \
|| exit
2024-04-26 12:18:44 +00:00
cd_step "clone Continuous Delivery"
2024-03-25 08:02:43 +00:00
git clone \
2024-04-26 11:38:38 +00:00
"${GITHUB_SERVER_URL}/${CD_REPOSITORY}" \
2024-03-25 19:09:04 +00:00
"${DIRECTORY}" \
2024-03-25 11:26:38 +00:00
|| exit
2024-04-25 13:30:32 +00:00
2024-04-26 12:18:44 +00:00
cd_step "install Python"
2024-04-25 13:30:32 +00:00
apt-get install --yes 'python3' \
|| exit
2024-04-26 12:18:44 +00:00
cd_step "clean package cache"
2024-04-25 13:38:28 +00:00
apt-get clean \
|| exit
2024-04-26 12:18:44 +00:00
cd_step "bootstrap"
2024-03-25 19:09:04 +00:00
"${DIRECTORY}/bootstrap.sh"
2024-04-26 12:18:44 +00:00
}
cd_main