From f1e8333af08142217e1a468790fd4e9922396b55 Mon Sep 17 00:00:00 2001 From: Joseph Graham Date: Sun, 28 May 2017 22:34:00 +0100 Subject: Made the cron job "make_repo_torrents" clean up old torrents. --- cron-jobs/make_repo_torrents | 55 ++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/cron-jobs/make_repo_torrents b/cron-jobs/make_repo_torrents index 2eb0978..b130de1 100755 --- a/cron-jobs/make_repo_torrents +++ b/cron-jobs/make_repo_torrents @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (C) 2014 Joseph Graham +# Copyright (C) 2014, 2017 Joseph Graham # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,32 +39,47 @@ torrent_location="$FTP_BASE/torrents/" cd "${torrent_location}" -# Find any directories that might have packages in then +pkgfilelist=$(mktemp) + +# Find any directories that might have packages in them find "${public_location}" -name 'os' -type 'd' | -while read dir -do - # Find any packages - find "${dir}" -name '*\.pkg\.tar\.xz' | - while read pkg + while read dir do - pkg_name="${pkg##*/}" + # Find any packages + find "${dir}" -name '*.pkg.tar.xz' -print0 + done > "${pkgfilelist}" + +while read pkg +do + pkg_name="${pkg##*/}" - if [[ -h "${pkg}" ]] # check if it's a symbolic link - then - # We get the target of the symlink - pkg=$( readlink -f "${pkg}" ) - fi + if [[ -h "${pkg}" ]] # check if it's a symbolic link + then + # We get the target of the symlink + pkg=$( readlink -f "${pkg}" ) + fi - # If a .torrent file does not already exist for this package, we call - # `make_individual_torrent' to make it. - if ! [[ -f "${torrent_location}${pkg_name}.torrent" ]] - then - "$script_directory/make_individual_torrent" "${pkg}" "${public_location}" - fi + # If a .torrent file does not already exist for this package, we call + # `make_individual_torrent' to make it. + if ! [[ -f "${torrent_location}${pkg_name}.torrent" ]] + then + "$script_directory/make_individual_torrent" "${pkg}" "${public_location}" + fi +done < "${pkgfilelist}" + +# For torrents older than 1 year, we check if it's package still exists, else clean it up +find -H "${torrent_location}" -mtime +365 -name '*.torrent' -type f | + while read oldtorrent + do + oldtorrentnm="${oldtorrent##*/}" + correspackagenm="${oldtorrentnm%.torrent}" + + grep "${correspackagenm}" "${pkgfilelist}" &> /dev/null || rm "${oldtorrent}" done -done if [[ "${username}" == root ]] then chown repo * fi + +rm -f "${pkgfilelist}" -- cgit v1.2.3-54-g00ecf