summaryrefslogtreecommitdiff
path: root/bin/delete-packages
diff options
context:
space:
mode:
Diffstat (limited to 'bin/delete-packages')
-rwxr-xr-xbin/delete-packages109
1 files changed, 73 insertions, 36 deletions
diff --git a/bin/delete-packages b/bin/delete-packages
index 2377f75..dddd5fa 100755
--- a/bin/delete-packages
+++ b/bin/delete-packages
@@ -11,8 +11,6 @@
# shellcheck disable=SC2039,SC2119,SC2120
-# TODO: use the intention-queue
-
# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"
@@ -360,42 +358,68 @@ fi
mkdir "${tmp_dir}/repos"
-while read -r arch repo; do
- mkdir -p "${tmp_dir}/repos/${arch}"
- failsafe_rsync \
- "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.db.tar.gz" \
- "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.files.tar.gz" \
- "${tmp_dir}/repos/${arch}"
-
- # shellcheck disable=SC2046
- repo-remove "${tmp_dir}/repos/${arch}/${repo}.db.tar.gz" \
- $(
- grep "^$(str_to_regex "${arch} ${repo}") " "${tmp_dir}/packages" | \
- cut -d' ' -f3
- )
- if ! ${no_action}; then
- recompress_gz \
- "${tmp_dir}" \
- "${tmp_dir}/repos/${arch}/${repo}."*".tar.gz" \
- "${tmp_dir}/repos/${arch}/${repo}."*".tar.gz.old"
- failsafe_rsync \
- "${tmp_dir}/repos/${arch}/${repo}.db."* \
- "${tmp_dir}/repos/${arch}/${repo}.files."* \
- "${master_mirror_rsync_directory}/${arch}/${repo}/"
- fi
-done < \
- "${tmp_dir}/repositories"
-
if ${no_action}; then
- printf 'Now, I would remove the packages from the database and delete the following files from the master mirror:\n'
+ printf 'I would delete the following files from the master mirror:\n'
sed '
s,^, ,
' "${tmp_dir}/package-files"
exit
fi
+while read -r arch repo; do
+ {
+ printf 'mkdir -p "%s/repos/%s"\n' "${tmp_dir}" "${arch}"
+ printf 'failsafe_rsync'
+ for suffix in 'db' 'files'; do
+ printf ' "%s/%s/%s/%s.%s.tar.gz"' \
+ "${master_mirror_rsync_directory}" \
+ "${arch}" \
+ "${repo}" \
+ "${repo}" \
+ "${suffix}"
+ done
+ printf ' "%s/repos/%s"\n' "${tmp_dir}" "${arch}"
+ } \
+ | intent_something
+ {
+ printf 'repo-remove "%s/repos/%s/%s.db.tar.gz" ' \
+ "${tmp_dir}" \
+ "${arch}" \
+ "${repo}"
+ grep "^$(str_to_regex "${arch} ${repo}") " "${tmp_dir}/packages" \
+ | cut -d' ' -f3 \
+ | tr '\n' ' '
+ printf '\n'
+ printf 'recompress_gz "%s"' \
+ "${tmp_dir}"
+ for suffix in '' '.old'; do
+ printf ' "%s/repos/%s/%s."*".tar.gz%s"' \
+ "${tmp_dir}" "${arch}" "${repo}" "${suffix}"
+ done
+ printf '\n'
+ } \
+ | intent_something
+ {
+ printf 'failsafe_rsync'
+ for suffix in 'db' 'files'; do
+ printf ' "%s/repos/%s/%s.%s."*' \
+ "${tmp_dir}" \
+ "${arch}" \
+ "${repo}" \
+ "${suffix}"
+ done
+ printf ' "%s/%s/%s/"\n' \
+ "${master_mirror_rsync_directory}" \
+ "${arch}" \
+ "${repo}"
+ } \
+ | intent_something
+done \
+<"${tmp_dir}/repositories"
+
# shellcheck disable=SC2016
{
+ printf 'mysql_run_query <<END_OF_MYSQL_QUERY\n'
printf 'CREATE TEMPORARY TABLE `bpir_to_delete` (`id` BIGINT, UNIQUE KEY (`id`));\n'
printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `bpir_to_delete`;\n' \
"${tmp_dir}/package-in-repository-ids"
@@ -428,11 +452,24 @@ fi
printf ' FROM `binary_packages_in_repositories`'
printf ' WHERE `binary_packages_in_repositories`.`package`=`binary_packages`.`id`'
printf ');\n'
-} | \
- mysql_run_query
+ printf 'END_OF_MYSQL_QUERY\n'
+} \
+| sed 's/`/\\`/g' \
+| intent_something
+
+{
+ printf 'failsafe_sftp <<END_OF_SFTP_COMMANDS\n'
+ sed '
+ s/^/rm "/
+ s/$/"/
+ ' "${tmp_dir}/package-files"
+ printf 'END_OF_SFTP_COMMANDS\n'
+} \
+| intent_something
+
+# cleanup is now handled by the intentions-queue
+printf 'rm -rf --one-file-system "%s"\n' "${tmp_dir}" \
+| intent_something
+trap - EXIT
-sed '
- s/^/rm "/
- s/$/"/
-' "${tmp_dir}/package-files" | \
- failsafe_sftp
+execute_all_intentions