From 84ca39c83c3fc514dfcd265cf2767cb0b8e4faaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Pe=C4=8Dovnik?= Date: Fri, 23 Dec 2022 21:58:06 +0100 Subject: [PATCH] Moving repository handling from main script (#4600) * Moving repository handling from main script - cleaning - working TBD: handling of parameters * Not needed anymore * Paramter handling, edit config in mktemp * Typo * Improve string handling * Cleanining * Compacting * Change to backslash compatible sed replacement * Publish all, update selected to avoid having erros at update * Add support for html index generation * Bugfix * More arch * Don't run publish if there is nothing in the incoming * Add repo sync control file creation * Fix hardcoded value --- config/aptly-beta.conf | 18 -- lib/functions/general/repo.sh | 300 --------------------- lib/functions/main/config-prepare.sh | 24 -- {config => tools/repository}/aptly.conf | 2 +- tools/repository/armbian.key | 52 ++++ tools/repository/example.deb | Bin 0 -> 740 bytes tools/repository/footer.html | 1 + tools/repository/header.html | 24 ++ tools/repository/repo | 332 ++++++++++++++++++++++++ 9 files changed, 410 insertions(+), 343 deletions(-) delete mode 100644 config/aptly-beta.conf delete mode 100644 lib/functions/general/repo.sh rename {config => tools/repository}/aptly.conf (93%) create mode 100644 tools/repository/armbian.key create mode 100644 tools/repository/example.deb create mode 100644 tools/repository/footer.html create mode 100644 tools/repository/header.html create mode 100755 tools/repository/repo diff --git a/config/aptly-beta.conf b/config/aptly-beta.conf deleted file mode 100644 index 6492b15e0..000000000 --- a/config/aptly-beta.conf +++ /dev/null @@ -1,18 +0,0 @@ -{ - "rootDir": "output/repository-beta", - "downloadConcurrency": 4, - "downloadSpeedLimit": 0, - "architectures": [], - "dependencyFollowSuggests": false, - "dependencyFollowRecommends": false, - "dependencyFollowAllVariants": false, - "dependencyFollowSource": false, - "gpgDisableSign": false, - "gpgDisableVerify": false, - "gpgProvider": "internal", - "downloadSourcePackages": false, - "ppaDistributorID": "ubuntu", - "ppaCodename": "", - "S3PublishEndpoints": {}, - "SwiftPublishEndpoints": {} -} diff --git a/lib/functions/general/repo.sh b/lib/functions/general/repo.sh deleted file mode 100644 index 1fcd1cdf4..000000000 --- a/lib/functions/general/repo.sh +++ /dev/null @@ -1,300 +0,0 @@ -#!/usr/bin/env bash -adding_packages() { - # add deb files to repository if they are not already there - - display_alert "Checking and adding to repository $release" "$3" "ext" - for f in "${DEB_STORAGE}${2}"/*.deb; do - local name version arch - name=$(dpkg-deb -I "${f}" | grep Package | awk '{print $2}') - version=$(dpkg-deb -I "${f}" | grep Version | awk '{print $2}') - arch=$(dpkg-deb -I "${f}" | grep Architecture | awk '{print $2}') - # add if not already there - aptly repo search -architectures="${arch}" -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${1}" 'Name (% '${name}'), $Version (='${version}'), $Architecture (='${arch}')' &> /dev/null - if [[ $? -ne 0 ]]; then - display_alert "Adding ${1}" "$name" "info" - aptly repo add -force-replace=true -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${1}" "${f}" &> /dev/null - fi - done - -} - -addtorepo() { - # create repository - # parameter "remove" dumps all and creates new - # parameter "delete" remove incoming directory if publishing is succesful - # function: cycle trough distributions - - local distributions=("stretch" "bionic" "buster" "bullseye" "focal" "hirsute" "impish" "jammy" "kinetic" "sid") - #local distributions=($(grep -rw config/distributions/*/ -e 'supported' | cut -d"/" -f3)) - local errors=0 - - for release in "${distributions[@]}"; do - - ADDING_PACKAGES="false" - if [[ -d "config/distributions/${release}/" ]]; then - [[ -n "$(cat config/distributions/${release}/support | grep "csc\|supported" 2> /dev/null)" ]] && ADDING_PACKAGES="true" - else - display_alert "Skipping adding packages (not supported)" "$release" "wrn" - continue - fi - - local forceoverwrite="" - - # let's drop from publish if exits - if [[ -n $(aptly publish list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}") ]]; then - aptly publish drop -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" > /dev/null 2>&1 - fi - - # create local repository if not exist - if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}") ]]; then - display_alert "Creating section" "main" "info" - aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="main" \ - -comment="Armbian main repository" "${release}" > /dev/null - fi - - if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "^utils") ]]; then - aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="utils" \ - -comment="Armbian utilities (backwards compatibility)" utils > /dev/null - fi - if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}-utils") ]]; then - aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="${release}-utils" \ - -comment="Armbian ${release} utilities" "${release}-utils" > /dev/null - fi - if [[ -z $(aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}" -raw | awk '{print $(NF)}' | grep "${release}-desktop") ]]; then - aptly repo create -config="${SCRIPTPATH}config/${REPO_CONFIG}" -distribution="${release}" -component="${release}-desktop" \ - -comment="Armbian ${release} desktop" "${release}-desktop" > /dev/null - fi - - # adding main - if find "${DEB_STORAGE}"/ -maxdepth 1 -type f -name "*.deb" 2> /dev/null | grep -q .; then - [[ "${ADDING_PACKAGES}" == true ]] && adding_packages "$release" "" "main" - else - aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" "${SCRIPTPATH}config/templates/example.deb" > /dev/null - fi - - local COMPONENTS="main" - - # adding main distribution packages - if find "${DEB_STORAGE}/${release}" -maxdepth 1 -type f -name "*.deb" 2> /dev/null | grep -q .; then - [[ "${ADDING_PACKAGES}" == true ]] && adding_packages "${release}-utils" "/${release}" "release packages" - else - # workaround - add dummy package to not trigger error - aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" "${SCRIPTPATH}config/templates/example.deb" > /dev/null - fi - - # adding release-specific utils - if find "${DEB_STORAGE}/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" - else - aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-utils" "${SCRIPTPATH}config/templates/example.deb" > /dev/null - fi - COMPONENTS="${COMPONENTS} ${release}-utils" - - # adding desktop - if find "${DEB_STORAGE}/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" - else - # workaround - add dummy package to not trigger error - aptly repo add -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" "${SCRIPTPATH}config/templates/example.deb" > /dev/null - fi - COMPONENTS="${COMPONENTS} ${release}-desktop" - - local mainnum utilnum desknum - mainnum=$(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" | grep "Number of packages" | awk '{print $NF}') - utilnum=$(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" | grep "Number of packages" | awk '{print $NF}') - desknum=$(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-utils" | grep "Number of packages" | awk '{print $NF}') - - if [ $mainnum -gt 0 ] && [ $utilnum -gt 0 ] && [ $desknum -gt 0 ]; then - - # publish - aptly publish \ - -acquire-by-hash \ - -passphrase="${GPG_PASS}" \ - -origin="Armbian" \ - -label="Armbian" \ - -config="${SCRIPTPATH}config/${REPO_CONFIG}" \ - -component="${COMPONENTS// /,}" \ - -distribution="${release}" repo "${release}" ${COMPONENTS//main/} > /dev/null - - if [[ $? -ne 0 ]]; then - display_alert "Publishing failed" "${release}" "err" - 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 - - done - - # cleanup - display_alert "Cleaning repository" "${DEB_STORAGE}" "info" - aptly db cleanup -config="${SCRIPTPATH}config/${REPO_CONFIG}" - - # display what we have - echo "" - display_alert "List of local repos" "local" "info" - (aptly repo list -config="${SCRIPTPATH}config/${REPO_CONFIG}") | grep -E packages - - # remove debs if no errors found - if [[ $errors -eq 0 ]]; then - if [[ "$2" == "delete" ]]; then - display_alert "Purging incoming debs" "all" "ext" - find "${DEB_STORAGE}" -name "*.deb" -type f -delete - fi - else - display_alert "There were some problems $err_txt" "leaving incoming directory intact" "err" - fi - -} - -repo-manipulate() { - # repository manipulation - # "show" displays packages in each repository - # "server" serve repository - useful for local diagnostics - # "unique" manually select which package should be removed from all repositories - # "update" search for new files in output/debs* to add them to repository - # "purge" leave only last 5 versions - - local DISTROS=("stretch" "bionic" "buster" "bullseye" "focal" "hirsute" "impish" "jammy" "sid") - #local DISTROS=($(grep -rw config/distributions/*/ -e 'supported' | cut -d"/" -f3)) - - case $@ in - - serve) - # display repository content - display_alert "Serving content" "common utils" "ext" - aptly serve -listen=$(ip -f inet addr | grep -Po 'inet \K[\d.]+' | grep -v 127.0.0.1 | head -1):80 -config="${SCRIPTPATH}config/${REPO_CONFIG}" - exit 0 - ;; - - show) - # display repository content - for release in "${DISTROS[@]}"; do - display_alert "Displaying repository contents for" "$release" "ext" - aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" | tail -n +7 - aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" | tail -n +7 - done - display_alert "Displaying repository contents for" "common utils" "ext" - aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" utils | tail -n +7 - echo "done." - exit 0 - ;; - - unique) - # which package should be removed from all repositories - IFS=$'\n' - while true; do - LIST=() - for release in "${DISTROS[@]}"; do - LIST+=($(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" | tail -n +7)) - LIST+=($(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" | tail -n +7)) - done - LIST+=($(aptly repo show -with-packages -config="${SCRIPTPATH}config/${REPO_CONFIG}" utils | tail -n +7)) - LIST=($(echo "${LIST[@]}" | tr ' ' '\n' | sort -u)) - new_list=() - # create a human readable menu - for ((n = 0; n < $((${#LIST[@]})); n++)); do - new_list+=("${LIST[$n]}") - new_list+=("") - done - LIST=("${new_list[@]}") - LIST_LENGTH=$((${#LIST[@]} / 2)) - exec 3>&1 - TARGET_VERSION=$(dialog --cancel-label "Cancel" --backtitle "BACKTITLE" --no-collapse --title "Remove packages from repositories" --clear --menu "Delete" $((9 + ${LIST_LENGTH})) 82 65 "${LIST[@]}" 2>&1 1>&3) - exitstatus=$? - exec 3>&- - if [[ $exitstatus -eq 0 ]]; then - for release in "${DISTROS[@]}"; do - aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" "$TARGET_VERSION" - aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}-desktop" "$TARGET_VERSION" - done - aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "utils" "$TARGET_VERSION" - else - exit 1 - fi - aptly db cleanup -config="${SCRIPTPATH}config/${REPO_CONFIG}" > /dev/null 2>&1 - done - ;; - - update) - # display full help test - # run repository update - addtorepo "update" "" - # add a key to repo - cp "${SCRIPTPATH}"config/armbian.key "${REPO_STORAGE}"/public/ - exit 0 - ;; - - purge) - for release in "${DISTROS[@]}"; do - repo-remove-old-packages "$release" "armhf" "5" - repo-remove-old-packages "$release" "arm64" "5" - repo-remove-old-packages "$release" "amd64" "5" - repo-remove-old-packages "$release" "all" "5" - aptly -config="${SCRIPTPATH}config/${REPO_CONFIG}" -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 - done - exit 0 - ;; - - purgeedge) - for release in "${DISTROS[@]}"; do - repo-remove-old-packages "$release" "armhf" "3" "edge" - repo-remove-old-packages "$release" "arm64" "3" "edge" - repo-remove-old-packages "$release" "amd64" "3" "edge" - repo-remove-old-packages "$release" "all" "3" "edge" - aptly -config="${SCRIPTPATH}config/${REPO_CONFIG}" -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 - done - exit 0 - ;; - - \ - purgesource) - for release in "${DISTROS[@]}"; do - aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${release}" 'Name (% *-source*)' - aptly -config="${SCRIPTPATH}config/${REPO_CONFIG}" -passphrase="${GPG_PASS}" publish update "${release}" > /dev/null 2>&1 - done - aptly db cleanup -config="${SCRIPTPATH}config/${REPO_CONFIG}" > /dev/null 2>&1 - exit 0 - ;; - *) - - echo -e "Usage: repository show | serve | unique | create | update | purge | purgesource\n" - echo -e "\n show = display repository content" - echo -e "\n serve = publish your repositories on current server over HTTP" - echo -e "\n unique = manually select which package should be removed from all repositories" - echo -e "\n update = updating repository" - echo -e "\n purge = removes all but last 5 versions" - echo -e "\n purgeedge = removes all but last 3 edge versions" - echo -e "\n purgesource = removes all sources\n\n" - exit 0 - ;; - - esac - -} - -# Removes old packages in the received repo -# -# $1: Repository -# $2: Architecture -# $3: Amount of packages to keep -# $4: Additional search pattern -repo-remove-old-packages() { - local repo=$1 - local arch=$2 - local keep=$3 - for pkg in $(aptly repo search -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${repo}" "Architecture ($arch)" | grep -v "ERROR: no results" | sort -t '.' -nk4 | grep -e "$4"); do - local pkg_name - count=0 - pkg_name=$(echo "${pkg}" | cut -d_ -f1) - for subpkg in $(aptly repo search -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${repo}" "Name ($pkg_name)" | grep -v "ERROR: no results" | sort -rt '.' -nk4); do - ((count += 1)) - if [[ $count -gt $keep ]]; then - pkg_version=$(echo "${subpkg}" | cut -d_ -f2) - aptly repo remove -config="${SCRIPTPATH}config/${REPO_CONFIG}" "${repo}" "Name ($pkg_name), Version (= $pkg_version)" - fi - done - done -} diff --git a/lib/functions/main/config-prepare.sh b/lib/functions/main/config-prepare.sh index 4912f6974..d8595ffb7 100644 --- a/lib/functions/main/config-prepare.sh +++ b/lib/functions/main/config-prepare.sh @@ -61,30 +61,6 @@ function prepare_and_config_main_build_single() { fi - if [[ -n $REPOSITORY_UPDATE ]]; then - - # select stable/beta configuration - if [[ $BETA == yes ]]; then - DEB_STORAGE=$DEST/debs-beta - REPO_STORAGE=$DEST/repository-beta - REPO_CONFIG="aptly-beta.conf" - else - DEB_STORAGE=$DEST/debs - REPO_STORAGE=$DEST/repository - REPO_CONFIG="aptly.conf" - fi - - # For user override - if [[ -f "${USERPATCHES_PATH}"/lib.config ]]; then - display_alert "Using user configuration override" "userpatches/lib.config" "info" - source "${USERPATCHES_PATH}"/lib.config - fi - - repo-manipulate "$REPOSITORY_UPDATE" - exit - - fi - # if KERNEL_ONLY, KERNEL_CONFIGURE, BOARD, BRANCH or RELEASE are not set, display selection menu backward_compatibility_build_only diff --git a/config/aptly.conf b/tools/repository/aptly.conf similarity index 93% rename from config/aptly.conf rename to tools/repository/aptly.conf index 764310e0d..abcd3bd00 100644 --- a/config/aptly.conf +++ b/tools/repository/aptly.conf @@ -1,5 +1,5 @@ { - "rootDir": "output/repository", + "rootDir": "output", "downloadConcurrency": 4, "downloadSpeedLimit": 0, "architectures": [], diff --git a/tools/repository/armbian.key b/tools/repository/armbian.key new file mode 100644 index 000000000..c5b7a796b --- /dev/null +++ b/tools/repository/armbian.key @@ -0,0 +1,52 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1 + +mQINBFUG8p4BEADGlseGFmdjjfmoXtHpZxqgYHGweCnGZ05LiGgEVgbv5SrTsJsy +O8H8RyBPxgbpKEY+JCV1IlYQPaE3Til1+kqmR4XNKbufjEuqAV4VJW3267tYRuJ3 +08E70q7kpQSsEAWLVY+xV/l5stAupp4/wF5BPdAjW7gLuicPnqoKK0jcfrjuvd45 +WFhpjL1Sdd0PnILehz0to6R2H9MsW+VYYPFztdjBM/78UD8grMcCm/7Mz8ENRKCn +TKrgj4bpWA0kPEHN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0dU/+M3sVidkJ5mv4LW6CJaaY3 +rsom0TIjaxBvXqSeadJF4WGUHzg3ew+8ah0ZG8SDZu19ketN2cnTMAtgO+53Epjq +pk3uMF5hNaEHt9wVj2tq/anLEsl4T5U/ekQndxcTEsV2KIVSoye35ye4aam1gWhW +9JIFtShhEtXD/5Ovtj706YLTP84U8yHStzM6LLGpqM8bb1QsBUWRUhIKidltmO9K +jX6rJZuhwkcVJJYRdbetEXbiSIyeNZy7bBe4En+fVcN0ekBD36LhMcVL8F1Mntr1 +L5xf0cFEpFpEodQUvcayNgpI2y7EIPjKmKhVwW5dx36Q0CsCnwcC+Kg6BNzliI9I +s+oA2AVIanFPvjvSwfG9pH+2/u+KB4HT2Ux1FBbBi5GAwo+cu1d4XAc5bZHdPnAV +tnIN9dKRusZ8IGHWEd8Pw0kRepuNhSmSNALQkS6B+ppQZtmoGsBCqJeMPxQxj+yI +/bL3dmA2UXxnGJ3vs2ybFyHG3aoovKJfWVytxOJfG7qj1ACrOYOXekWlcw5lEiYF +cckukNqqFv/CXh+BZFlQT4DDvJlY0/KQFFKogQ== +=I/P8 +-----END PGP PUBLIC KEY BLOCK----- diff --git a/tools/repository/example.deb b/tools/repository/example.deb new file mode 100644 index 0000000000000000000000000000000000000000..da97d98ed6f7e0e1f5e892d4e7a18cb2df1ec158 GIT binary patch literal 740 zcmY$iNi0gvu;WTeP0CEn(@o0EODw8XP*5;5H8V3bHZd?ZRZuVh@?oT*fq|KciGl(U zK|unSk)8opa(-S(QGSkINn(*+MHONF#zrs`61e`FS4BiIFt9wkw#AL*Kr>TAfFh$9 z0|YE){b=?;{XfI+SO#(KJunt znN-1$#-b?pg!fbOA@$R;r=CTcZK*i2ebe1d&#xraEPK9miT93u4nndDt^%#_Nr+1)NTA*m{`}H{Ws zIiCw{ocZdtWBa=$l{ai_o&$rz^wR8g7sD67VPKpO3?BxD1-l)tY&??wn+X(5ERj(u zi6x2fzz4<*q4+bx8UAw_k;A`{K}Zc0{!?*>zkRss<(8w}Td%)Z#?!l+b773X!51&5 zz?rlDtu_u+@`kYhDJu71{KNp?St diff --git a/tools/repository/header.html b/tools/repository/header.html new file mode 100644 index 000000000..a77c2d3ec --- /dev/null +++ b/tools/repository/header.html @@ -0,0 +1,24 @@ + + + + + + diff --git a/tools/repository/repo b/tools/repository/repo new file mode 100755 index 000000000..23fea3a7a --- /dev/null +++ b/tools/repository/repo @@ -0,0 +1,332 @@ +#!/usr/bin/env bash + +# Adding package +# +# @arg $1 string component +# @arg $2 string incoming folder +# @arg $3 string description +# @arg $4 input folder +# +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}") + name=$(echo "${package}" | awk /Package/'{print $2}') + version=$(echo "${package}" | awk /Version/'{print $2}') + arch=$(echo "${package}" | awk /Architecture/'{print $2}') + # add if not already there + aptly repo search -architectures="${arch}" -config="${CONFIG}" "${1}" \ + 'Name (% '${name}'), $Version (='${version}'), $Architecture (='${arch}')' &> /dev/null + if [[ $? -ne 0 ]]; then + 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 +} + + +# publishing repository +# +# $1: Input folder +# $2: Output folder +# $3: Command +# $4: GPG password +# $5: jammy,sid +# +publishing() { +# read comma delimited distros into array +IFS=', ' read -r -a DISTROS <<< "$5" +local errors=0 +# publish all, update selected +local distributions=("jessy" "xenial" "stretch" "bionic" "buster" "bullseye" "focal" "hirsute" "impish" "jammy" "kinetic" "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 + fi + # create local repository if not exist + 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 + 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 + 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 + 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 + # write repo sync control file + sudo date +%s > ${2}/public/.control + # publish + echo "Publishing ${release}" + aptly publish \ + -acquire-by-hash \ + -architectures="armhf,arm64,amd64,riscv64,i386,all" \ + -passphrase="${4}" \ + -origin="Armbian" \ + -label="Armbian" \ + -config="${CONFIG}" \ + -component="${COMPONENTS// /,}" \ + -distribution="${release}" repo "${release}" ${COMPONENTS//main/} > /dev/null + if [[ $? -ne 0 ]]; then + echo "Publishing failed ${release}" + 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 +done +# cleanup +aptly db cleanup -config="${CONFIG}" > /dev/null +# key +cp armbian.key "${2}"/public/ +# display what we have +(aptly repo list -config="${CONFIG}") | grep -E packages +# remove debs if no errors found +if [[ $errors -eq 0 ]]; then + echo "Purging incoming debs" + find "${1}" -name "*.deb" -type f -delete +else + display_alert "There were some problems $err_txt" "leaving incoming directory intact" "err" +fi +} + + +# +# $1: Input folder +# $2: Output folder +# $3: Command +# $4: GPG password +# $5: jammy,sid +# +repo-manipulate() { + +# read comma delimited distros into array +IFS=', ' read -r -a DISTROS <<< "$5" + +case $3 in + + serve) + + sudo aptly serve -listen=$(ip -f inet addr | grep -Po 'inet \K[\d.]+' | grep -v 127.0.0.1 | head -1):80 -config="${CONFIG}" + return 0 + ;; + + html) + cat header.html + for release in "${DISTROS[@]}"; do + echo "" + echo "" + done + cat footer.html + return 0 + ;; + + show) + + for release in "${DISTROS[@]}"; do + echo "Displaying repository contents for $release" + aptly repo show -with-packages -config="${CONFIG}" "${release}" | tail -n +7 + echo "Displaying repository contents for $release-utils" + aptly repo show -with-packages -config="${CONFIG}" "${release}-utils" | tail -n +7 + echo "Displaying repository contents for $release-desktop" + aptly repo show -with-packages -config="${CONFIG}" "${release}-desktop" | tail -n +7 + done + return 0 + ;; + + unique) + # which package should be removed from all repositories + IFS=$'\n' + while true; do + LIST=() + for release in "${DISTROS[@]}"; do + LIST+=($(aptly repo show -with-packages -config="${CONFIG}" "${release}" | tail -n +7)) + LIST+=($(aptly repo show -with-packages -config="${CONFIG}" "${release}-utils" | tail -n +7)) + LIST+=($(aptly repo show -with-packages -config="${CONFIG}" "${release}-desktop" | tail -n +7)) + done + LIST=($(echo "${LIST[@]}" | tr ' ' '\n' | sort -u)) + new_list=() + # create a human readable menu + for ((n = 0; n < $((${#LIST[@]})); n++)); do + new_list+=("${LIST[$n]}") + new_list+=("") + done + LIST=("${new_list[@]}") + LIST_LENGTH=$((${#LIST[@]} / 2)) + exec 3>&1 + TARGET_VERSION=$(dialog --cancel-label "Cancel" --backtitle "BACKTITLE" --no-collapse --title \ + "Remove packages from repositories" --clear --menu "Delete" $((9 + LIST_LENGTH)) 82 65 "${LIST[@]}" 2>&1 1>&3) + exitstatus=$? + exec 3>&- + if [[ $exitstatus -eq 0 ]]; then + for release in "${DISTROS[@]}"; do + aptly repo remove -config="${CONFIG}" "${release}" "$TARGET_VERSION" + aptly repo remove -config="${CONFIG}" "${release}-utils" "$TARGET_VERSION" + aptly repo remove -config="${CONFIG}" "${release}-desktop" "$TARGET_VERSION" + done + else + return 1 + fi + aptly db cleanup -config="${CONFIG}" > /dev/null 2>&1 + # remove empty folders + find $2/public -type d -empty -print -exec rm -rf {} \; + done + ;; + + update) + publishing "$1" "$2" "$3" "$4" "$5" + ;; + + *) + echo -e "Unknown command" + return 1 + ;; +esac +} + + +# defaults +input="input" +output="output" +command="show" +releases="jammy,sid" + +help() +{ +echo "Armbian wrapper for Aptly v1.0 + +(c) Igor Pecovnik, igor@armbian.com + +License: (MIT) + +Usage: $0 [ -short | --long ] + +-h --help displays this +-i --input [input folder] +-o --output [output folder] +-p --password [GPG password] +-r --repository [jammy,sid,bullseye,...] +-c --command + + [show] displays packages in each repository + [html] displays packages in each repository in html form + [serve] serve repository - useful for local diagnostics + [unique] manually select which package should be removed from all repositories + [update] search for packages in input folder + " + exit 2 +} + +SHORT=i:,o:,c:,p:,r:,h +LONG=input:,output:,command:,password:,releases:,help +OPTS=$(getopt -a -n repo --options $SHORT --longoptions $LONG -- "$@") + +VALID_ARGUMENTS=$# # Returns the count of arguments that are in short or long options + +eval set -- "$OPTS" + +while : +do + case "$1" in + -i | --input ) + input="$2" + shift 2 + ;; + -o | --output ) + output="$2" + shift 2 + ;; + -c | --command ) + command="$2" + shift 2 + ;; + -p | --password ) + password="$2" + shift 2 + ;; + -r | --releases ) + releases="$2" + shift 2 + ;; + -h | --help) + help + ;; + --) + shift; + break + ;; + *) + echo "Unexpected option: $1" + help + ;; + esac +done + +# define job name +[[ $(cat /var/run/repomanagement 2>/dev/null) == "$output" ]] && echo "Running. Try again later" && exit 0 +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 +CONFIG="${TempDir}/aptly.conf" + +# main +repo-manipulate "$input" "$output" "$command" "$password" "$releases" +RETURN=$? +sudo rm /var/run/repomanagement +exit $RETURN

$release

MainUtilsDesktop
" + aptly repo show -with-packages -config="${CONFIG}" "${release}" | tail -n +7 | sed 's/.*/&
/' + echo "
" | sudo tee -a ${filename} + aptly repo show -with-packages -config="${CONFIG}" "${release}-utils" | tail -n +7 | sed 's/.*/&
/' + echo "
" | sudo tee -a ${filename} + aptly repo show -with-packages -config="${CONFIG}" "${release}-desktop" | tail -n +7 | sed 's/.*/&
/' + echo "