diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2018-09-25 02:06:24 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2018-09-25 02:06:24 -0400 |
commit | 114225c19aa1dfe427527acf71b7479cdff1e186 (patch) | |
tree | 9ebcd88d3c7c7063709d52074c72d26972a5c9d9 | |
parent | fe27caea29421b01e502a6b99cb59707bfe467be (diff) |
make_repo_torrents: Clean up, add config
- Don't bother checking which user is running it, that's hacky
- set -e
* actually bail if we get an error
- Make the torrent directory configurable as TORRENTPOOL
-rwxr-xr-x | cron-jobs/make_repo_torrents | 80 | ||||
-rw-r--r-- | torrent.conf | 3 |
2 files changed, 27 insertions, 56 deletions
diff --git a/cron-jobs/make_repo_torrents b/cron-jobs/make_repo_torrents index 86fcaba..dd14b22 100755 --- a/cron-jobs/make_repo_torrents +++ b/cron-jobs/make_repo_torrents @@ -1,5 +1,6 @@ #!/bin/bash # Copyright (C) 2014, 2017 Joseph Graham <joseph@xylon.me.uk> +# Copyright (C) 2018 Luke Shumaker <lukeshu@parabola.nu> # # 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 @@ -17,76 +18,43 @@ # This script finds any updated packages and calls # `make_indivudual_torrent' for each of them. Run every hour from cron. -username=$( id -un ) - -case "${username}" in - repo | root ) - true - ;; - * ) - echo "This script must be run as repo user or root user." - echo "ByeBye!" - exit 1 - ;; -esac - # pacman doesn't support multiple different packages of the same name, # so it's OK to just stuff all the torrents into a single directory. + +set -eE script_directory="$(dirname "$(readlink -e "$0")")/.." . "$(dirname "$(readlink -e "$0")")/../config" -public_location="$FTP_BASE/" -torrent_location="$FTP_BASE/torrents/" +. "$(dirname "$(readlink -e "$0")")/../torrent.conf" +. "$(dirname "$(readlink -e "$0")")/../db-functions" -cd "${torrent_location}" +mkdir -p -- "${FTP_BASE}/${TORRENTPOOL}" +cd "${FTP_BASE}/${TORRENTPOOL}" -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}" -regex '[^ ]+\.pkg\.tar\.xz' - 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 +# Find any packages +for pkgpath in "$FTP_BASE"/*/os/*/*${PKGEXTS}; do + # Resolve any symlinks + pkgpath=$(readlink -f -- "$pkgpath") + pkgfile="${pkgpath##*/}" # 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}" + if ! [[ -f ${pkgfile}.torrent ]]; then + "$script_directory/make_individual_torrent" "$pkgpath" fi -done < "${pkgfilelist}" +done # For torrents older than 1 year, we check if it's package still # exists, else clean it up. This shouldn't be done every hour, but it # is good for it to be in this cronjob so it can re-use the # $pkgfilelist we made earlier. So we do it with a 1-in-30 # probability. -if ! (( $(shuf -e {0..29} | head -1) )) -then - 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 +if ! (( $(shuf -e {0..29} | head -1) )); then + while read -r torrent; do + pkgfile="${torrent##*/}" + pkgfile="${torrent%.torrent}" + + if ! is_globfile "$FTP_BASE"/*/os/*/"$pkgfile"; then + rm -f -- "$torrent" + fi + done < <(find -H . -mtime +365 -name '*.torrent' -type f) fi - -if [[ "${username}" == root ]] -then - chown repo * -fi - -rm -f "${pkgfilelist}" diff --git a/torrent.conf b/torrent.conf index cbc42a4..bd09aed 100644 --- a/torrent.conf +++ b/torrent.conf @@ -10,3 +10,6 @@ TRACKERS=( # doesn't really matter since it's re-written on the client machine by # pacman2pacman so it won't normally be used anyway. WEBSEED_MIRROR='https://repomirror.parabola.nu/' + +# Where under $FTP_BASE/ to put the torrents +TORRENTPOOL=torrents |