{"id":1481,"date":"2020-10-30T12:07:19","date_gmt":"2020-10-30T19:07:19","guid":{"rendered":"https:\/\/outflux.net\/blog\/?p=1481"},"modified":"2020-10-30T17:37:22","modified_gmt":"2020-10-31T00:37:22","slug":"combining-apt-install-and-get-dist-upgrade","status":"publish","type":"post","link":"https:\/\/outflux.net\/blog\/archives\/2020\/10\/30\/combining-apt-install-and-get-dist-upgrade\/","title":{"rendered":"combining &#8220;apt install&#8221; and &#8220;get dist-upgrade&#8221;?"},"content":{"rendered":"<p>I frequently see a pattern in image build\/refresh scripts where a set of packages is installed, and then all packages are updated:<\/p>\n<pre class=\"brush:shell\">\r\napt update\r\napt install -y pkg1 pkg2 pkg2\r\napt dist-upgrade -y\r\n<\/pre>\n<p>While it&#8217;s not much, this results in redundant work. For example reading\/writing package database, potentially running triggers (man-page refresh, ldconfig, etc). The internal package dependency resolution stuff isn&#8217;t actually different: &#8220;install&#8221; will also do upgrades of needed packages, etc. Combining them should be entirely possible, but I haven&#8217;t found a clean way to do this yet.<\/p>\n<p>The best I&#8217;ve got so far is:<\/p>\n<pre class=\"brush:shell\">\r\napt update\r\napt-cache dumpavail | dpkg --merge-avail -\r\n(for i in pkg1 pkg2 pkg3; do echo \"$i install\") | dpkg --set-selections\r\napt-get dselect-upgrade\r\n<\/pre>\n<p>This gets me the effect of running &#8220;install&#8221; and &#8220;upgrade&#8221; at the same time, but not &#8220;dist-upgrade&#8221; (which has slightly different resolution logic that&#8217;d I&#8217;d prefer to use). Also, it includes the overhead of what should be an unnecessary update of dpkg&#8217;s database. Anyone know a better way to do this?<\/p>\n<p><strong>Update<\/strong>: <a href=\"https:\/\/mobile.twitter.com\/JulianKlode\/status\/1322294691430281218\">Julian Andres Klode pointed out that <code>dist-upgrade<\/code> actually takes package arguments too<\/a> just like <code>install<\/code>. *face palm* I didn&#8217;t even try it &#8212; I believed the man-page and the <code>-h<\/code> output. It works perfectly!<\/p>\n<p style='text-align:left'>&copy; 2020, <a href=\"https:\/\/outflux.net\/blog\/\">Kees Cook<\/a>. This work is licensed under a <a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\">Creative Commons Attribution-ShareAlike 4.0 License<\/a>.<br \/><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><img decoding=\"async\" alt=\"CC BY-SA 4.0\" style=\"border-width:0\" src=\"https:\/\/i.creativecommons.org\/l\/by-sa\/4.0\/88x31.png\" \/><\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I frequently see a pattern in image build\/refresh scripts where a set of packages is installed, and then all packages are updated: apt update apt install -y pkg1 pkg2 pkg2 apt dist-upgrade -y While it&#8217;s not much, this results in redundant work. For example reading\/writing package database, potentially running triggers (man-page refresh, ldconfig, etc). The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,18,14,19],"tags":[],"_links":{"self":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1481"}],"collection":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/comments?post=1481"}],"version-history":[{"count":5,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1481\/revisions"}],"predecessor-version":[{"id":1486,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/posts\/1481\/revisions\/1486"}],"wp:attachment":[{"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/media?parent=1481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/categories?post=1481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outflux.net\/blog\/wp-json\/wp\/v2\/tags?post=1481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}