]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: Add --offline mode
authorAdrian Vovk <adrianvovk@gmail.com>
Tue, 11 Jul 2023 22:35:54 +0000 (18:35 -0400)
committerTom Coldrick <thomas.coldrick@codethink.co.uk>
Fri, 12 Jul 2024 13:38:09 +0000 (14:38 +0100)
This prevents sysupdate from going out to the network to enumerate
available instances. When combined with the list command, this lets us
query installed instances

man/systemd-sysupdate.xml
src/sysupdate/sysupdate.c

index 8c1228c7d9d811f3f431c258ba74d694b9ca639e..f77bd3d0d9813ad3631c4e235d10b0a06a595a7d 100644 (file)
         <xi:include href="version-info.xml" xpointer="v251"/></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--offline</option></term>
+
+        <listitem><para>Prevents fetching metadata from the network (i.e. <filename>SHA256SUMS</filename>).
+        This is most useful when used in combination with the <command>list</command> command, to query
+        locally installed versions.</para>
+
+        <xi:include href="version-info.xml" xpointer="v257"/></listitem>
+      </varlistentry>
+
       <xi:include href="standard-options.xml" xpointer="no-pager" />
       <xi:include href="standard-options.xml" xpointer="no-legend" />
       <xi:include href="standard-options.xml" xpointer="json" />
index de90506c5005bdc5423a8b30e2d0e1e0bb580b35..462ae5ee0104191d3aaafbca9d251d412ffb17f4 100644 (file)
@@ -48,6 +48,7 @@ static bool arg_reboot = false;
 static char *arg_component = NULL;
 static int arg_verify = -1;
 static ImagePolicy *arg_image_policy = NULL;
+static bool arg_offline = false;
 
 STATIC_DESTRUCTOR_REGISTER(arg_definitions, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
@@ -356,11 +357,13 @@ static int context_discover_update_sets(Context *c) {
         if (r < 0)
                 return r;
 
-        log_info("Determining available update sets%s", special_glyph(SPECIAL_GLYPH_ELLIPSIS));
+        if (!arg_offline) {
+                log_info("Determining available update sets%s", special_glyph(SPECIAL_GLYPH_ELLIPSIS));
 
-        r = context_discover_update_sets_by_flag(c, UPDATE_AVAILABLE);
-        if (r < 0)
-                return r;
+                r = context_discover_update_sets_by_flag(c, UPDATE_AVAILABLE);
+                if (r < 0)
+                        return r;
+        }
 
         typesafe_qsort(c->update_sets, c->n_update_sets, update_set_cmp);
         return 0;
@@ -727,15 +730,17 @@ static int context_make_online(Context **ret, const char *node) {
         assert(ret);
 
         /* Like context_make_offline(), but also communicates with the update source looking for new
-         * versions. */
+         * versions (as long as --offline is not specified on the command line). */
 
         r = context_make_offline(&context, node);
         if (r < 0)
                 return r;
 
-        r = context_load_available_instances(context);
-        if (r < 0)
-                return r;
+        if (!arg_offline) {
+                r = context_load_available_instances(context);
+                if (r < 0)
+                        return r;
+        }
 
         r = context_discover_update_sets(context);
         if (r < 0)
@@ -1248,6 +1253,7 @@ static int verb_help(int argc, char **argv, void *userdata) {
                "     --sync=BOOL          Controls whether to sync data to disk\n"
                "     --verify=BOOL        Force signature verification on or off\n"
                "     --reboot             Reboot after updating to newer version\n"
+               "     --offline            Do not fetch metadata from the network\n"
                "     --no-pager           Do not pipe output into a pager\n"
                "     --no-legend          Do not show the headers and footers\n"
                "     --json=pretty|short|off\n"
@@ -1277,6 +1283,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_IMAGE_POLICY,
                 ARG_REBOOT,
                 ARG_VERIFY,
+                ARG_OFFLINE,
         };
 
         static const struct option options[] = {
@@ -1294,6 +1301,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "reboot",            no_argument,       NULL, ARG_REBOOT            },
                 { "component",         required_argument, NULL, 'C'                   },
                 { "verify",            required_argument, NULL, ARG_VERIFY            },
+                { "offline",           no_argument,       NULL, ARG_OFFLINE           },
                 {}
         };
 
@@ -1397,6 +1405,10 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
                 }
 
+                case ARG_OFFLINE:
+                        arg_offline = true;
+                        break;
+
                 case '?':
                         return -EINVAL;