void upgrade(HLP& hlp) { do_upgrade(Type2PID_<HLP>::value, &hlp); }
int main(int argc, char** argv) { string_map* parameters = parse_parameters(argc, argv); opkg_conf *conf = load_conf((char*)get_string_map_element(parameters, "config")); char* run_type = get_string_map_element(parameters, "run-type"); int force_overwrite_other_files = get_string_map_element(parameters, "force-overwrite") != NULL ? 1 : 0; int force_overwrite_configs = get_string_map_element(parameters, "force-overwrite-configs") != NULL ? 1 : 0; int force_depends = get_string_map_element(parameters, "force-depends") != NULL ? 1 : 0; int force_reinstall = get_string_map_element(parameters, "force-reinstall") != NULL ? 1 : 0; int remove_orphaned_depends = get_string_map_element(parameters, "autoremove") != NULL ? REMOVE_ALL_ORPHANED_DEPENDENCIES : REMOVE_NO_ORPHANED_DEPENDENCIES; remove_orphaned_depends = get_string_map_element(parameters, "autoremove-same-destination") != NULL ? REMOVE_ORPHANED_DEPENDENCIES_IN_SAME_DEST : remove_orphaned_depends; char* install_root = get_string_map_element(parameters, "install-destination"); install_root = install_root == NULL ? strdup("root") : install_root; char* link_root = get_string_map_element(parameters, "link-destination"); char* tmp_root = get_string_map_element(parameters, "tmp_dir"); tmp_root = tmp_root == NULL ? strdup("/tmp") : tmp_root; string_map* pkgs = get_string_map_element(parameters, "package-list"); char* format_str = get_string_map_element(parameters, "output-format"); int format = OUTPUT_HUMAN_READABLE; if(format_str != NULL) { format = strcmp(format_str, "json") == 0 ? OUTPUT_JSON : format; format = strcmp(format_str, "js") == 0 || strcmp(format_str, "javascript") == 0 ? OUTPUT_JAVASCRIPT : format; } if(strcmp(run_type, "install") == 0) { do_install(conf, pkgs, install_root, link_root, 0, force_overwrite_configs, force_overwrite_other_files, force_reinstall, tmp_root); } else if(strcmp(run_type, "remove") == 0) { do_remove(conf, pkgs, !force_overwrite_configs, remove_orphaned_depends, force_depends, 1); } else if(strcmp(run_type, "upgrade") == 0) { do_upgrade(conf, pkgs, !force_overwrite_configs, install_root, link_root); } else if(strcmp(run_type, "update") == 0) { update(conf); } else if((strcmp(run_type, "list") == 0) || strcmp(run_type, "list-installed") == 0 || strcmp(run_type, "list_installed") == 0) { do_list(conf, parameters, format); } else if(strcmp(run_type, "dest-info") == 0 || strcmp(run_type, "dest_info") == 0) { do_print_dest_info(conf, format); } else if(strcmp(run_type, "info") == 0) { do_print_info(conf, parameters, install_root, format); } return(0); }
void upgrade(PID pid) { do_upgrade(pid, nullptr); }
void do_upgrade_post(char *url, webs_t stream, int len, char *boundary) { char buf[POST_BUF_SIZE]; upgrade_result = EINVAL; upgrade_type = 0; /* Turn on the flag to omit the follwoing HTTP request. */ refuse_request = 1; /* Look for our part */ while (len > 0) { if (!wfgets(buf, MIN(len + 1, sizeof(buf)), stream)) return; len -= strlen(buf); if (!strncasecmp(buf, "Content-Disposition:", 20)) { if (strstr(buf, "name=\"binfile\"")) { /* upgrade image */ upgrade_type = FIRMWARE; break; } else if (strstr(buf, "name=\"cfgfile\"")) { /* import configuration */ upgrade_type = CONFIG; break; } } } #ifdef DEBUG printf("%s upgrade\n", (upgrade_type == FIRMWARE) ? "firmware" : "config" ); #endif /* Skip boundary and headers */ while (len > 0) { if (!wfgets(buf, MIN(len + 1, sizeof(buf)), stream)) return; #ifdef DEBUG printf("[%d]%s", strlen(buf), buf); #endif len -= strlen(buf); if (!strcmp(buf, "\n") || !strcmp(buf, "\r\n")) break; } #ifdef DEBUG printf("content length[%d]\n", len); #endif if ( upgrade_type == FIRMWARE ) { upgrade_result = do_upgrade(NULL, stream, &len); } if ( upgrade_type == CONFIG ) { upgrade_result = import_config(NULL, stream, &len); } /* Slurp anything remaining in the request */ while (len--) #if defined(HTTPS_SUPPORT) if (do_ssl) BIO_gets((BIO *) stream, buf, 1); else #endif (void) fgetc(stream); }