Improve repository management

Signed-off-by: Igor <igor@armbian.com>
This commit is contained in:
Igor
2023-08-10 13:53:45 +02:00
parent 35feddc350
commit e492d3eeed

View File

@@ -10,6 +10,7 @@
adding_packages() {
# add deb files to repository if they are not already there
for f in "${4}${2}"/*.deb; do
local package name version arch
# read package
package=$(dpkg-deb -I "${f}")
@@ -23,10 +24,30 @@ for f in "${4}${2}"/*.deb; do
echo -e "Checking and adding \x1B[92m$name\x1B[0m to repository \x1B[92m$release $3\x1B[0m"
aptly repo add -force-replace=true -config="${CONFIG}" "${1}" "${f}" &> /dev/null
fi
done
}
fake_package()
{
fake_package_dir=$2
tmp_dir=$(mktemp -d)
mkdir -p "${tmp_dir}/${fake_package_dir}"/DEBIAN/
# set up control file
cat <<- END > "${tmp_dir}/${fake_package_dir}"/DEBIAN/control
Package: empty
Version: $3
Architecture: all
Description: Fake pacakge
Maintainer: Armbian
END
dpkg-deb --build "${tmp_dir}/${fake_package_dir}" &> /dev/null
aptly repo add -force-replace=true -config="${CONFIG}" "${1}" "${tmp_dir}/${fake_package_dir}" &> /dev/null
}
# publishing repository
#
# $1: Input folder
@@ -40,15 +61,14 @@ publishing() {
IFS=', ' read -r -a DISTROS <<< "$5"
local errors=0
# publish all, update selected
local distributions=("jessy" "xenial" "stretch" "bionic" "focal" "hirsute" "impish" "jammy" "lunar" "kinetic" "buster" "bullseye" "bookworm" "sid")
local distributions=($(grep -rw config/distributions/*/support -ve 'eos' | cut -d"/" -f3))
#local distributions=("jessy" "xenial" "stretch" "bionic" "focal" "hirsute" "impish" "jammy" "lunar" "kinetic" "buster" "bullseye" "bookworm" "sid")
for release in "${distributions[@]}"; do
local forceoverwrite=""
ADDING_PACKAGES="false"
[[ " ${DISTROS[@]} " =~ " ${release} " ]] && ADDING_PACKAGES="true"
[[ $(find ${1} -type f -name "*.deb" 2> /dev/null | wc -l) -eq 0 ]] && continue
# let's drop from publish if exits
if [[ -n $(aptly publish list -config="${CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}") ]]; then
aptly publish drop -config="${CONFIG}" "${release}" > /dev/null 2>&1
@@ -57,50 +77,47 @@ for release in "${distributions[@]}"; do
if [[ -z $(aptly repo list -config="${CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}") ]]; then
aptly repo create -config="${CONFIG}" -distribution="${release}" \
-component="main,${release}-utils,${release}-desktop" -comment="Armbian main repository" "${release}" > /dev/null 2>&1
fake_package "${release}" test 1234
fi
if [[ -z $(aptly repo list -config="${CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}-utils") ]]; then
aptly repo create -config="${CONFIG}" -distribution="${release}" \
-component="${release}-utils" -comment="Armbian ${release} utilities" "${release}-utils" > /dev/null 2>&1
fake_package "${release}" test 1234
fi
if [[ -z $(aptly repo list -config="${CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}-desktop") ]]; then
aptly repo create -config="${CONFIG}" -distribution="${release}" \
-component="${release}-desktop" -comment="Armbian ${release} desktop" "${release}-desktop" > /dev/null 2>&1
fake_package "${release}" test 1234
fi
# adding main
if find "$1"/ -maxdepth 1 -type f -name "*.deb" 2> /dev/null | grep -q .; then
[[ "${ADDING_PACKAGES}" == true ]] && adding_packages "$release" "" "main" "$1"
else
aptly repo add -config="${CONFIG}" "${release}" "example.deb" > /dev/null
fi
local COMPONENTS="main"
# adding release-specific main
if find "${1}/${release}" -maxdepth 1 -type f -name "*.deb" 2> /dev/null | grep -q .; then
[[ "${ADDING_PACKAGES}" == true ]] && adding_packages "${release}" "/${release}" "release packages" "$1"
else
# workaround - add dummy package to not trigger error
aptly repo add -config="${CONFIG}" "${release}" "example.deb" > /dev/null
fi
# adding release-specific utils
if find "${1}/extra/${release}-utils" -maxdepth 1 -type f -name "*.deb" 2> /dev/null | grep -q .; then
[[ "${ADDING_PACKAGES}" == true ]] && adding_packages "${release}-utils" "/extra/${release}-utils" "release utils" "$1"
else
aptly repo add -config="${CONFIG}" "${release}-utils" "example.deb" > /dev/null
fi
COMPONENTS="${COMPONENTS} ${release}-utils"
# adding release-specific desktop
if find "${1}/extra/${release}-desktop" -maxdepth 1 -type f -name "*.deb" 2> /dev/null | grep -q .; then
[[ "${ADDING_PACKAGES}" == true ]] && adding_packages "${release}-desktop" "/extra/${release}-desktop" "desktop" "$1"
else
# workaround - add dummy package to not trigger error
aptly repo add -config="${CONFIG}" "${release}-desktop" "example.deb" > /dev/null
fi
COMPONENTS="${COMPONENTS} ${release}-desktop"
local mainnum utilnum desknum
mainnum=$(aptly repo show -with-packages -config="${CONFIG}" "${release}" | grep "Number of packages" | awk '{print $NF}')
utilnum=$(aptly repo show -with-packages -config="${CONFIG}" "${release}-desktop" | grep "Number of packages" | awk '{print $NF}')
desknum=$(aptly repo show -with-packages -config="${CONFIG}" "${release}-utils" | grep "Number of packages" | awk '{print $NF}')
if [ $mainnum -gt 0 ] && [ $utilnum -gt 0 ] && [ $desknum -gt 0 ]; then
#if [ $mainnum -gt 0 ] && [ $utilnum -gt 0 ] && [ $desknum -gt 0 ]; then
# write repo sync control file
mkdir -p ${2}/public/
sudo date +%s > ${2}/public/.control
# publish
echo "Publishing ${release}"
@@ -118,15 +135,16 @@ for release in "${distributions[@]}"; do
errors=$((errors + 1))
exit 0
fi
else
errors=$((errors + 1))
local err_txt=": All components must be present: main, utils and desktop for first build"
fi
#else
# errors=$((errors + 1))
# local err_txt=": All components must be present: main, utils and desktop for first build"
#fi
done
# cleanup
aptly db cleanup -config="${CONFIG}" > /dev/null
# key
cp armbian.key "${2}"/public/
mkdir -p "${2}"/public/
cp config/armbian.key "${2}"/public/
# display what we have
(aptly repo list -config="${CONFIG}") | grep -E packages
# remove debs if no errors found
@@ -134,7 +152,7 @@ if [[ $errors -eq 0 ]]; then
echo "Purging incoming debs"
sudo find "${1}" -name "*.deb" -type f -delete
else
display_alert "There were some problems $err_txt" "leaving incoming directory intact" "err"
echo "There were some problems $err_txt - leaving incoming directory intact" "err"
fi
}
@@ -160,7 +178,7 @@ case $3 in
;;
html)
cat header.html
cat tools/repository/header.html
for release in "${DISTROS[@]}"; do
echo "<thead><tr><td colspan=3><h2>$release</h2></tr><tr><th>Main</th><th>Utils</th><th>Desktop</th></tr></thead>"
echo "<tbody><tr><td width=33% valing=top>"
@@ -171,7 +189,7 @@ case $3 in
aptly repo show -with-packages -config="${CONFIG}" "${release}-desktop" | tail -n +7 | sed 's/.*/&<br>/'
echo "</td></tr></tbody>"
done
cat footer.html
cat tools/repository/footer.html
return 0
;;
@@ -240,8 +258,8 @@ esac
# defaults
input="input"
output="output"
input="output/debs-beta"
output="output/repository"
command="show"
releases="jammy,sid"
@@ -322,7 +340,7 @@ echo "${output}" | sudo tee /var/run/repomanagement &>/dev/null
# redefine output folder in Aptly
TempDir="$(mktemp -d || exit 1)"
sed 's|"rootDir": ".*"|"rootDir": "'$output'"|g' aptly.conf > "${TempDir}"/aptly.conf
sed 's|"rootDir": ".*"|"rootDir": "'$output'"|g' tools/repository/aptly.conf > "${TempDir}"/aptly.conf
CONFIG="${TempDir}/aptly.conf"
# main