Skip to content

Commit

Permalink
Remove old packages based on time
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Apr 7, 2021
1 parent f4be53a commit 6cd95cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions packaging/bin/create-deb-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ _usage="Usage: $0 <pkgdir> <repodir> [s3bucket=${_s3bucket}]"
PKGDIR="${1?${_usage}}" # The directory where .deb files are located
REPODIR="${2?${_usage}}" # The package repository working directory
S3PATH="${3-${_s3bucket}}/deb"
# Number of packages to keep for each architecture, older packages will be deleted.
RETAIN_PKG_COUNT=25
# Remove packages older than N number of days (730 is roughly ~2 years).
REMOVE_PKG_DAYS=730

log() {
echo "$(date -Iseconds) $*"
echo "$(date -Iseconds) $*"
}

delete_old_pkgs() {
find "$1" -name '*.deb' -type f | sort -r | tail -n "+$((RETAIN_PKG_COUNT+1))" | xargs -r rm -v
find "$1" -name '*.deb' -type f -daystart -mtime "+${REMOVE_PKG_DAYS}" -print0 | xargs -r0 rm -v

# Remove any dangling .asc files
find "$1" -name '*.asc' -type f -print0 | while read -r -d $'\0' f; do
if ! [ -r "${f%.*}" ]; then
Expand Down
8 changes: 4 additions & 4 deletions packaging/bin/create-msi-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ _usage="Usage: $0 <pkgdir> <repodir> [s3bucket=${_s3bucket}]"
PKGDIR="${1?${_usage}}" # The directory where .msi files are located
REPODIR="${2?${_usage}}" # The package repository working directory
S3PATH="${3-${_s3bucket}}/msi"
# Number of packages to keep, older packages will be deleted.
RETAIN_PKG_COUNT=25
# Remove packages older than N number of days (730 is roughly ~2 years).
REMOVE_PKG_DAYS=730

log() {
echo "$(date -Iseconds) $*"
echo "$(date -Iseconds) $*"
}

delete_old_pkgs() {
find "$1" -name '*.msi' -type f | sort -r | tail -n "+$((RETAIN_PKG_COUNT+1))" | xargs -r rm -v
find "$1" -name '*.msi' -type f -daystart -mtime "+${REMOVE_PKG_DAYS}" -print0 | xargs -r0 rm -v
}

sync_to_s3() {
Expand Down
6 changes: 3 additions & 3 deletions packaging/bin/create-rpm-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ _usage="Usage: $0 <pkgdir> <repodir> [s3bucket=${_s3bucket}]"
PKGDIR="${1?${_usage}}" # The directory where .rpm files are located
REPODIR="${2?${_usage}}" # The package repository working directory
S3PATH="${3-${_s3bucket}}/rpm"
# Number of packages to keep for each architecture, older packages will be deleted.
RETAIN_PKG_COUNT=25
# Remove packages older than N number of days (730 is roughly ~2 years).
REMOVE_PKG_DAYS=730

log() {
echo "$(date -Iseconds) $*"
}

delete_old_pkgs() {
find "$1" -name '*.rpm' -type f | sort -r | tail -n "+$((RETAIN_PKG_COUNT+1))" | xargs -r rm -v
find "$1" -name '*.rpm' -type f -daystart -mtime "+${REMOVE_PKG_DAYS}" -print0 | xargs -r0 rm -v
}

sync_to_s3() {
Expand Down

0 comments on commit 6cd95cd

Please sign in to comment.