- for (p = configs; *p; p++) {
- if ((argc < 2) || !strcmp(argv[1], *p)) {
- if (uci_load(ctx, *p, &cfg) != UCI_OK) {
- uci_perror(ctx, "uci_load");
- return 255;
- }
- uci_foreach_entry(section, &cfg->sections, s) {
- if (!section || !strcmp(s->name, section))
- uci_show_section(s);
+
+static int package_cmd(int cmd, char *package)
+{
+ struct uci_package *p = NULL;
+
+ if (uci_load(ctx, package, &p) != UCI_OK) {
+ uci_perror(ctx, appname);
+ return 1;
+ }
+ switch(cmd) {
+ case CMD_COMMIT:
+ if (uci_commit(ctx, &p, false) != UCI_OK)
+ uci_perror(ctx, appname);
+ break;
+ case CMD_EXPORT:
+ uci_export(ctx, stdout, p, true);
+ break;
+ case CMD_SHOW:
+ uci_show_package(p);
+ break;
+ }
+
+ uci_unload(ctx, p);
+ return 0;
+}
+
+static int uci_do_import(int argc, char **argv)
+{
+ struct uci_package *package = NULL;
+ char *name = NULL;
+ int ret = UCI_OK;
+
+ if (argc > 2)
+ return 255;
+
+ if (argc == 2)
+ name = argv[1];
+ else if (flags & CLI_FLAG_MERGE)
+ /* need a package to merge */
+ return 255;
+
+ if (flags & CLI_FLAG_MERGE) {
+ if (uci_load(ctx, name, &package) != UCI_OK)
+ package = NULL;
+ }
+ ret = uci_import(ctx, input, name, &package, (name != NULL));
+ if (ret == UCI_OK) {
+ if (flags & CLI_FLAG_MERGE) {
+ ret = uci_save(ctx, package);
+ } else {
+ struct uci_element *e;
+ /* loop through all config sections and overwrite existing data */
+ uci_foreach_element(&ctx->root, e) {
+ struct uci_package *p = uci_to_package(e);
+ ret = uci_commit(ctx, &p, true);