You've already forked Reprepro-Wrapper
254 lines
8.3 KiB
Bash
254 lines
8.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
|
|
###
|
|
#
|
|
# Options Section
|
|
#
|
|
###
|
|
|
|
set -e
|
|
set -o pipefail
|
|
|
|
|
|
###
|
|
#
|
|
# Function Section
|
|
#
|
|
###
|
|
|
|
function import_pve () {
|
|
local ARCHITECTURE
|
|
local VERSION_CODENAME
|
|
local COMPONENT
|
|
local TEMP
|
|
local REPOSITORY
|
|
local DEBS
|
|
local DEBSVERSIONS
|
|
local DEB
|
|
local BASENAME
|
|
local PKGNAME
|
|
|
|
ARCHITECTURE="${1}"
|
|
VERSION_CODENAME="${2}"
|
|
COMPONENT="${3}"
|
|
TEMP=$(/usr/bin/mktemp --directory --quiet)
|
|
REPOSITORY="https://download.lierfang.com/pxcloud/pxvirt/dists/${VERSION_CODENAME}/${COMPONENT}/binary-${ARCHITECTURE}/"
|
|
case "${COMPONENT}" in
|
|
main)
|
|
case "${VERSION_CODENAME}" in
|
|
bookworm)
|
|
COMPONENT='pve8'
|
|
;;
|
|
trixie)
|
|
COMPONENT='pve9'
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
ceph*)
|
|
case "${VERSION_CODENAME}" in
|
|
bookworm)
|
|
COMPONENT='pve8-ceph'
|
|
;;
|
|
trixie)
|
|
COMPONENT='pve9-ceph'
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
/usr/bin/wget --quiet --output-document="${TEMP}/repository.html" "${REPOSITORY}"
|
|
HTML=$(/usr/bin/grep --perl-regexp --only-matching 'href="\K[^"]*(amd64|arm64|all)[^"]*\.deb' "${TEMP}/repository.html")
|
|
/usr/bin/sleep '3s'
|
|
declare -A DEBS
|
|
declare -A VERSIONS
|
|
for DEB in ${HTML}; do
|
|
NAME=$(/bin/echo "${DEB}" | /usr/bin/sed -E 's/(_[0-9].*)//')
|
|
VERSION="${DEB#*_}"
|
|
VERSION="${VERSION%_*.deb}"
|
|
if [[ -z "${VERSIONS[$NAME]}" ]] || \
|
|
/usr/bin/dpkg --compare-versions "$VERSION" gt "${VERSIONS[$NAME]}" 2>/dev/null; then
|
|
DEBS[$NAME]="$DEB"
|
|
VERSIONS[$NAME]="$VERSION"
|
|
fi
|
|
done
|
|
for DEB in "${DEBS[@]}"; do
|
|
PKGNAME="${DEB%%_*}"
|
|
VERSION_A="${DEB#*_}"
|
|
VERSION_A="${VERSION_A%_*.deb}"
|
|
VERSION_B=$(/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component "${COMPONENT}" list "${VERSION_CODENAME}" "${PKGNAME}" | /usr/bin/mawk '{print $NF}' | /usr/bin/head --lines='1')
|
|
if /usr/bin/dpkg --compare-versions "$VERSION_A" gt "${VERSION_B}" 2>/dev/null; then
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
/usr/bin/echo "Download (lierfang/pxvirt): ${DEB}"
|
|
/usr/bin/wget --quiet --output-document="${TEMP}/${DEB}" "${REPOSITORY}${DEB}"
|
|
/usr/bin/echo "Repository (${VERSION_CODENAME}/${COMPONENT}): ${PKGNAME}"
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component "${COMPONENT}" includedeb "${VERSION_CODENAME}" "${TEMP}/${DEB}" &> '/dev/null'
|
|
/usr/bin/rm --force "${TEMP}/${DEB}"
|
|
fi
|
|
done
|
|
/bin/rm --force --recursive "${TEMP}"
|
|
}
|
|
|
|
function import_pbs () {
|
|
local VERSION_CODENAME
|
|
local TEMP
|
|
local REPOSITORY
|
|
local URLS
|
|
local URL
|
|
local DEB
|
|
local PKGNAME
|
|
|
|
VERSION_CODENAME="${1}"
|
|
TEMP=$(/usr/bin/mktemp --directory --quiet)
|
|
case "${VERSION_CODENAME}" in
|
|
bookworm)
|
|
REPOSITORY="https://api.github.com/repos/wofferl/proxmox-backup-arm64/releases/tags/3.4.6-1"
|
|
COMPONENT='pbs8'
|
|
;;
|
|
trixie)
|
|
REPOSITORY="https://api.github.com/repos/wofferl/proxmox-backup-arm64/releases/latest"
|
|
COMPONENT='pbs9'
|
|
;;
|
|
*)
|
|
exit 1
|
|
;;
|
|
esac
|
|
/usr/bin/wget --quiet --output-document="${TEMP}/gitapi.json" "${REPOSITORY}"
|
|
URLS=$(/usr/bin/grep 'browser_download_url' "${TEMP}/gitapi.json" | /usr/bin/cut --delimiter='"' --fields='4')
|
|
for URL in ${URLS}; do
|
|
DEB=$(/usr/bin/basename "${URL}")
|
|
PKGNAME=$(/usr/bin/basename "${URL%%_*}")
|
|
VERSION_A="${DEB#*_}"
|
|
VERSION_A="${VERSION_A%_*.deb}"
|
|
VERSION_B=$(/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component "${COMPONENT}" list "${VERSION_CODENAME}" "${PKGNAME}" | /usr/bin/mawk '{print $NF}' | /usr/bin/head --lines='1')
|
|
if [[ -z "${VERSION_B}" ]] || \
|
|
/usr/bin/dpkg --compare-versions "$VERSION_A" gt "${VERSION_B}" 2>/dev/null; then
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
/usr/bin/echo "Download (wofferl/proxmox-backup-arm64): ${DEB}"
|
|
/usr/bin/wget --quiet --output-document="${TEMP}/${DEB}" "${URL}"
|
|
/usr/bin/echo "Repository (${VERSION_CODENAME}/${COMPONENT}): ${PKGNAME}"
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component "${COMPONENT}" includedeb "${VERSION_CODENAME}" "${TEMP}/${DEB}" &> '/dev/null'
|
|
/usr/bin/rm --force "${TEMP}/${DEB}"
|
|
fi
|
|
done
|
|
/usr/bin/rm --force --recursive "${TEMP}"
|
|
}
|
|
|
|
|
|
###
|
|
#
|
|
# Runtime Environment
|
|
#
|
|
###
|
|
|
|
if [[ "${EUID}" -ne '0' ]]; then
|
|
/usr/bin/echo 'Error: Permission Denied'
|
|
exit 1
|
|
fi
|
|
if [[ -z "${1}" ]] || \
|
|
[[ "${1}" != @(add|remove|update) ]]; then
|
|
/usr/bin/echo 'Usage: repository [add|remove|update]'
|
|
exit 1
|
|
fi
|
|
|
|
OUTDIR=$(/usr/bin/grep 'outdir' '/etc/reprepro/options' | /usr/bin/sed --expression='s/outdir //')
|
|
ARGUMENT="${1}"
|
|
VERSION_CODENAME="${2}"
|
|
DEB_PATH="${3}"
|
|
DEB_NAME=$(/usr/bin/basename "${DEB_PATH}")
|
|
PKGNAME=$(/usr/bin/basename "${DEB_PATH%%_*}")
|
|
|
|
case "${ARGUMENT}" in
|
|
add)
|
|
if [[ -z "${VERSION_CODENAME}" ]] || \
|
|
[[ "${VERSION_CODENAME}" != @(all|bookworm|trixie|noble) ]] || \
|
|
[[ -z "${DEB_PATH}" ]]; then
|
|
/usr/bin/echo 'Usage: repository [add] (all|bookworm|trixie|noble) (DEB)'
|
|
exit 1
|
|
fi
|
|
if /usr/bin/dpkg-deb -W "${DEB_PATH}" &> '/dev/null'; then
|
|
if [[ -d "${OUTDIR}/pool/main/${DEB_NAME:0:1}/${PKGNAME}" ]]; then
|
|
/usr/bin/echo "Error: The Package '${PKGNAME}' already exist."
|
|
exit 1
|
|
fi
|
|
if [[ "${VERSION_CODENAME}" == 'all' ]]; then
|
|
for VERSION_CODENAME in bookworm trixie noble; do
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
/usr/bin/echo "Repository (${VERSION_CODENAME}/main) : ${PKGNAME}"
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component 'main' includedeb "${VERSION_CODENAME}" "${DEB_PATH}" &> '/dev/null'
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
done
|
|
elif [[ "${VERSION_CODENAME}" =~ ^(bookworm|trixie|noble)$ ]]; then
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
/usr/bin/echo "Repository (${VERSION_CODENAME}/main) : ${PKGNAME}"
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component 'main' remove "${VERSION_CODENAME}" "${PKGNAME}" &> '/dev/null'
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component 'main' includedeb "${VERSION_CODENAME}" "${DEB_PATH}" &> '/dev/null'
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
fi
|
|
fi
|
|
;;
|
|
remove)
|
|
if [[ -z "${VERSION_CODENAME}" ]] || \
|
|
[[ "${VERSION_CODENAME}" != @(all|bookworm|trixie|noble) ]] || \
|
|
[[ -z "${DEB_PATH}" ]]; then
|
|
/usr/bin/echo 'Usage: repository [remove] (all|bookworm|trixie|noble) (DEB)'
|
|
exit 1
|
|
fi
|
|
if [[ ! -d "${OUTDIR}/pool/main/${DEB_NAME:0:1}/${PKGNAME}" ]]; then
|
|
/usr/bin/echo "Error: The Package '${PKGNAME}' does not exist."
|
|
exit 1
|
|
fi
|
|
if [[ "${VERSION_CODENAME}" == 'all' ]]; then
|
|
for VERSION_CODENAME in bookworm trixie noble; do
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
/usr/bin/echo "Repository (${VERSION_CODENAME}/main) : ${PKGNAME}"
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component 'main' remove "${VERSION_CODENAME}" "${PKGNAME}" &> '/dev/null'
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
done
|
|
elif [[ "${VERSION_CODENAME}" =~ ^(bookworm|trixie|noble)$ ]]; then
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
/usr/bin/echo "Repository (${VERSION_CODENAME}/main) : ${PKGNAME}"
|
|
/usr/bin/reprepro --confdir '/etc/reprepro' --silent --component 'main' remove "${VERSION_CODENAME}" "${PKGNAME}" &> '/dev/null'
|
|
/usr/bin/echo '# --- --- --- --- --- #'
|
|
fi
|
|
;;
|
|
update)
|
|
if [[ -z "${VERSION_CODENAME}" ]] || \
|
|
[[ "${VERSION_CODENAME}" != @(all|bookworm|trixie|noble) ]]; then
|
|
/usr/bin/echo 'Usage: repository [update] (all|bookworm|trixie|noble)'
|
|
exit 1
|
|
fi
|
|
case "${VERSION_CODENAME}" in
|
|
all)
|
|
import_pve 'arm64' 'bookworm' 'main'
|
|
import_pve 'arm64' 'bookworm' 'ceph-squid'
|
|
import_pbs 'bookworm'
|
|
import_pve 'arm64' 'trixie' 'main'
|
|
import_pve 'arm64' 'trixie' 'ceph-squid'
|
|
import_pbs 'trixie'
|
|
;;
|
|
bookworm)
|
|
import_pve 'arm64' 'bookworm' 'main'
|
|
import_pve 'arm64' 'bookworm' 'ceph-squid'
|
|
import_pbs 'bookworm'
|
|
;;
|
|
trixie)
|
|
import_pve 'arm64' 'trixie' 'main'
|
|
import_pve 'arm64' 'trixie' 'ceph-squid'
|
|
import_pbs 'trixie'
|
|
;;
|
|
noble)
|
|
return 0
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|