Date: Tue, 30 Aug 2005 03:51:42 GMT From: soc-andrew <soc-andrew@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 82814 for review Message-ID: <200508300351.j7U3pgol028244@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82814 Change 82814 by soc-andrew@soc-andrew_serv on 2005/08/30 03:51:36 Add a basic package installation menu. There is no dependency handling yet. Affected files ... .. //depot/projects/soc2005/bsdinstaller/src/contrib/bsdinstaller/backend/installer/fn_configure.c#3 edit .. //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/fn_install_freebsd.c#8 edit Differences ... ==== //depot/projects/soc2005/bsdinstaller/src/contrib/bsdinstaller/backend/installer/fn_configure.c#3 (text+ko) ==== @@ -354,6 +354,7 @@ commands_free(cmds); } +#if 0 void fn_install_packages(struct i_fn_args *a) { @@ -444,6 +445,7 @@ dfui_form_free(f); dfui_response_free(r); } +#endif void fn_remove_packages(struct i_fn_args *a) ==== //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/fn_install_freebsd.c#8 (text+ko) ==== @@ -43,8 +43,11 @@ * It is based on the DragonFlyBSD version of fn_install_os */ +#include <sys/stat.h> +#include <sys/types.h> #include <sys/utsname.h> +#include <dirent.h> #include <limits.h> #include <string.h> @@ -92,7 +95,8 @@ static int pre_install(struct i_fn_args *); static int do_install(struct i_fn_args *); static int post_install(struct i_fn_args *); -void fn_install_os(struct i_fn_args *a); +void fn_install_os(struct i_fn_args *); +void fn_select_packages(struct i_fn_args*, struct aura_dict*, char*); static int pre_install(struct i_fn_args *a) @@ -245,7 +249,6 @@ } if (install_ports == 1) { dist_set_location("/mnt/usr"); - printf("%d\n", dist_extract(a->c, "ports")); } i_log(a, ">>> Done"); @@ -453,3 +456,218 @@ post_install(a); } +/* + * Lists all packages and installs selected ones + */ +void +fn_install_packages(struct i_fn_args *a) +{ + struct dfui_field *fi; + struct dfui_form *f; + struct dfui_response *r; + DIR *d; + struct dirent *de; + struct aura_dict *packages; + int done = 0; + + f = dfui_form_create( + "install_packages", + _("Install Packages"), + _("Select optional software packages that you want " + "installed on this system. This form lists only the " + "software packages available from the LiveCD. Thousands " + "more are available via the internet once FreeBSD " + "is installed."), + "", + + "p", "special", "fbsdinstaller_install_packages", + + NULL + ); + + d = opendir("/usr/packages/"); + if (d == NULL) { + inform(a->c, _("Could not find the package directory.")); + dfui_form_free(f); + return; + } + + while ((de = readdir(d)) != NULL) { + /* I tried to use de->d_type == DT_DIR but d_type was always 0 */ + struct stat sb; + char file[PATH_MAX]; + + if (de->d_name[0] == '.') + continue; + + snprintf(file, PATH_MAX, "/usr/packages/%s", de->d_name); + stat(file, &sb); + + if (!S_ISDIR(sb.st_mode)) + continue; + + dfui_form_action_add(f, de->d_name, + dfui_info_new(de->d_name, "", "")); + } + + closedir(d); + + dfui_form_action_add(f, "ok", + dfui_info_new(_("Accept and Install"), "", "")); + dfui_form_action_add(f, "cancel", + dfui_info_new(_("Cancel"), "", "")); + + packages = aura_dict_new(13, AURA_DICT_LIST); + + while (done == 0) + { + if (!dfui_be_present(a->c, f, &r)) + abort_backend(); + + if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) { + done = 1; + } else if (strcmp(dfui_response_get_action_id(r), "ok") == 0) { + /* Install the packages */ + char *key; + int key_len; + + aura_dict_rewind(packages); + while (!aura_dict_eof(packages)) { + struct commands *cmds; + + /* Set dist_name */ + aura_dict_get_current_key(packages, (void*)&key, + &key_len); + key[key_len] = '\0'; + + cmds = commands_new(); + + command_add(cmds, + "cp /usr/packages/All/%s.tbz /mnt/tmp", + key); + command_add(cmds, + "pkg_add -C /mnt /tmp/%s.tbz", key); + command_add(cmds, "rm /mnt/tmp/%s.tbz", key); + + commands_execute(a, cmds); + commands_free(cmds); + + aura_dict_next(packages); + } + + done = 1; + } else { + /* move to the next level window */ + fn_select_packages(a, packages, + (char*)dfui_response_get_action_id(r)); + } + } + + aura_dict_free(packages); + + dfui_response_free(r); + dfui_form_free(f); +} + +void +fn_select_packages(struct i_fn_args *a, struct aura_dict *packages, char *dir) +{ + struct dfui_field *fi; + struct dfui_form *f; + struct dfui_response *r; + struct dfui_dataset *ds; + DIR *d; + struct dirent *de; + char dir_name[PATH_MAX]; + + f = dfui_form_create( + "install_packages", + _("Install Packages"), + _("Select optional software packages that you want " + "installed on this system. This form lists only the " + "software packages installed on the LiveCD; thousands " + "more are available via the internet once FreeBSD " + "is installed."), + "", + + "p", "special", "fbsdinstaller_install_packages", + + "f", "install", "Install?", + "Install this Package", "", + "p", "control", "checkbox", + + "f", "package", "Package name", + "The name of the Package to install", "", + "p", "editable", "false", + + "a", "ok", "Back", "", "", + + NULL + ); + + dfui_form_set_multiple(f, 1); + + snprintf(dir_name, PATH_MAX, "/usr/packages/%s", dir); + + d = opendir(dir_name); + if (d == NULL) { + inform(a->c, _("Could not find the package directory.")); + dfui_form_free(f); + return; + } + + while ((de = readdir(d)) != NULL) { + /* I tried to use de->d_type == DT_DIR but d_type was always 0 */ + struct stat sb; + char file[PATH_MAX]; + char *extension; + + if (de->d_name[0] == '.') + continue; + + snprintf(file, PATH_MAX, "/usr/packages/%s/%s", dir, de->d_name); + stat(file, &sb); + + if (!S_ISREG(sb.st_mode)) + continue; + + extension = strstr(de->d_name, ".tbz"); + if (extension != NULL) + extension[0] = '\0'; + + ds = dfui_dataset_new(); + dfui_dataset_celldata_add(ds, "install", "N"); + dfui_dataset_celldata_add(ds, "package", de->d_name); + dfui_form_dataset_add(f, ds); + } + + closedir(d); + + if (!dfui_be_present(a->c, f, &r)) + abort_backend(); + + if (strcmp(dfui_response_get_action_id(r), "ok") == 0) { + /* Add the packages and dependencies to the dictonary */ + for (ds = dfui_response_dataset_get_first(r); ds != NULL; + ds = dfui_dataset_get_next(ds)) { + char install[2]; + + /* Copy the value of the install field to install */ + strncpy(install, dfui_dataset_get_value(ds, "install"), 2); + + if (strncasecmp(install, "Y", 2) == 0) { + /* Select this dist for installation */ + char *package; + int len; + + package = (char*)dfui_dataset_get_value(ds, "package"); + len = strlen(package); + aura_dict_store(packages, package, len, + package, len); + } + } + } + + dfui_response_free(r); + dfui_form_free(f); +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508300351.j7U3pgol028244>