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