{"id":1752,"date":"2023-01-27T21:07:02","date_gmt":"2023-01-27T20:07:02","guid":{"rendered":"https:\/\/blogs.gentoo.org\/mgorny\/?p=1752"},"modified":"2023-01-27T21:07:02","modified_gmt":"2023-01-27T20:07:02","slug":"handy-commands-to-clean-up-old-arch-only-packages","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/mgorny\/2023\/01\/27\/handy-commands-to-clean-up-old-arch-only-packages\/","title":{"rendered":"Handy commands to clean up old ~arch-only packages"},"content":{"rendered":"<p>Here&#8217;s a bunch of handy commands that I&#8217;ve conceived to semi-automatically remove old versions of packages that do not have stable keywords (and therefore are not subject to post-stabilization cleanups that I do normally).<\/p>\n<p><!--more--><\/p>\n<h2>Requirements<\/h2>\n<p>The snippets below require the following packages:<\/p>\n<ul>\n<li>app-portage\/mgorny-dev-scripts<\/li>\n<li>dev-util\/pkgcheck<\/li>\n<li>dev-util\/pkgdev<\/li>\n<\/ul>\n<p>They should be run in top directory of a ::gentoo checkout, ideally with no other changes queued.<\/p>\n<h2>Remove redundant versions<\/h2>\n<p>First, a pipeline that finds all packages without stable amd64 keywords (note: this is making an assumption that there are no packages that are stable only on some other architecture), then scans these packages for redundant versions and removes them. The example command operates on <kbd>dev-python\/*<\/kbd>:<\/p>\n<pre><code>pkgcheck scan 'dev-python\/*' -c UnstableOnlyCheck -a amd64 \\\r\n    -R FormatReporter --format '{category}\/{package}' |\r\n  sort -u |\r\n  xargs pkgcheck scan -c RedundantVersionCheck \\\r\n    -R FormatReporter --format \\\r\n    '{category}\/{package}\/{package}-{version}.ebuild' |\r\n  xargs git rm<\/code><\/pre>\n<h2>Check for broken revdeps<\/h2>\n<p>The next step is to check for broken revdeps. Start with:<\/p>\n<pre><code>rdep-fetch-cache\r\ncheck-revdep $(\r\n  git diff --name-only --cached | cut -d'\/' -f1-2 | sort -u\r\n)<\/code><\/pre>\n<p>Use <code>git restore -WS ...<\/code> to restore versions as necessary and repeat until it comes out clean.<\/p>\n<h2>Check for stale files<\/h2>\n<p>Finally, iterate over packages with <kbd>files\/<\/kbd> to check for stale patches:<\/p>\n<pre><code>(\r\n  for x in $(\r\n    git diff --name-only --cached | cut -d'\/' -f1-2 | sort -u\r\n  ); do\r\n    [[ -d ${x}\/files ]] &amp;&amp; ( cd ${x}; bash )\r\n  done\r\n)<\/code><\/pre>\n<p>This will start bash inside every cleaned up package (note: I&#8217;m assuming that there are no other changes in the repo) that has a <kbd>files\/<\/kbd> directory.  Use a quick grep followed by FILESDIR lookup:<\/p>\n<pre><code>grep FILES *.ebuild\r\nls files\/<\/code><\/pre>\n<p>Remove the files that are no longer referenced.<\/p>\n<h2>Commit the removals<\/h2>\n<pre><code>for x in $(\r\n  git diff --name-only --cached | cut -d'\/' -f1-2 | sort -u\r\n); do\r\n  (\r\n    cd ${x} &amp;&amp; pkgdev manifest &amp;&amp;\r\n    pkgcommit . -sS -m 'Remove old'\r\n  )\r\ndone\r\npkgcheck scan --commits<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a bunch of handy commands that I&#8217;ve conceived to semi-automatically remove old versions of packages that do not have stable keywords (and therefore are not subject to post-stabilization cleanups that I do normally).<\/p>\n","protected":false},"author":137,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[11],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/posts\/1752"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/users\/137"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/comments?post=1752"}],"version-history":[{"count":17,"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/posts\/1752\/revisions"}],"predecessor-version":[{"id":1769,"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/posts\/1752\/revisions\/1769"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/media?parent=1752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/categories?post=1752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/mgorny\/wp-json\/wp\/v2\/tags?post=1752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}