/** * Register `configure system` commands. * * Those are the commands to configure protocol-independant stuff. */ void register_commands_configure_system(struct cmd_node *configure, struct cmd_node *unconfigure) { struct cmd_node *configure_system = commands_new( configure, "system", "System configuration", cmd_check_no_env, NULL, "ports"); struct cmd_node *unconfigure_system = commands_new( unconfigure, "system", "System configuration", cmd_check_no_env, NULL, "ports"); struct cmd_node *configure_interface = commands_new( configure_system, "interface", "Interface related items", NULL, NULL, NULL); struct cmd_node *unconfigure_interface = commands_new( unconfigure_system, "interface", "Interface related items", NULL, NULL, NULL); commands_new( commands_new( commands_new(configure_system, "description", "Override chassis description", NULL, NULL, NULL), NULL, "Chassis description", NULL, cmd_store_env_value, "description"), NEWLINE, "Override chassis description", NULL, cmd_system_description, "system"); commands_new( commands_new(unconfigure_system, "description", "Don't override chassis description", NULL, NULL, NULL), NEWLINE, "Don't override chassis description", NULL, cmd_system_description, "system"); commands_new( commands_new( commands_new(configure_system, "chassisid", "Override chassis ID", NULL, NULL, NULL), NULL, "Chassis ID", NULL, cmd_store_env_value, "description"), NEWLINE, "Override chassis ID", NULL, cmd_system_chassisid, "system"); commands_new( commands_new(unconfigure_system, "chassisid", "Don't override chassis ID", NULL, NULL, NULL), NEWLINE, "Don't override chassis ID", NULL, cmd_system_chassisid, "system"); commands_new( commands_new( commands_new(configure_system, "platform", "Override platform description", NULL, NULL, NULL), NULL, "Platform description (CDP)", NULL, cmd_store_env_value, "platform"), NEWLINE, "Override platform description", NULL, cmd_system_description, "platform"); commands_new( commands_new(unconfigure_system, "platform", "Don't override platform description", NULL, NULL, NULL), NEWLINE, "Don't override platform description", NULL, cmd_system_description, "platform"); commands_new( commands_new( commands_new(configure_system, "hostname", "Override system name", NULL, NULL, NULL), NULL, "System name", NULL, cmd_store_env_value, "hostname"), NEWLINE, "Override system name", NULL, cmd_hostname, NULL); commands_new( commands_new(unconfigure_system, "hostname", "Don't override system name", NULL, NULL, NULL), NEWLINE, "Don't override system name", NULL, cmd_hostname, NULL); commands_new( commands_new( commands_new(configure_system, "max-neighbors", "Set maximum number of neighbors per port", cmd_check_no_env, NULL, "ports"), NULL, "Maximum number of neighbors", NULL, cmd_store_env_value, "max-neighbors"), NEWLINE, "Set maximum number of neighbors per port", NULL, cmd_maxneighs, NULL); commands_new( commands_new( commands_new( commands_new( commands_new(configure_system, "ip", "IP related options", NULL, NULL, NULL), "management", "IP management related options", NULL, NULL, NULL), "pattern", "Set IP management pattern", NULL, NULL, NULL), NULL, "IP management pattern (comma-separated list of wildcards)", NULL, cmd_store_env_value, "management-pattern"), NEWLINE, "Set IP management pattern", NULL, cmd_management, NULL); commands_new( commands_new( commands_new( commands_new(unconfigure_system, "ip", "IP related options", NULL, NULL, NULL), "management", "IP management related options", NULL, NULL, NULL), "pattern", "Delete any IP management pattern", NULL, NULL, NULL), NEWLINE, "Delete any IP management pattern", NULL, cmd_management, NULL); commands_new( commands_new( commands_new(configure_interface, "pattern", "Set active interface pattern", NULL, NULL, NULL), NULL, "Interface pattern (comma-separated list of wildcards)", NULL, cmd_store_env_value, "iface-pattern"), NEWLINE, "Set active interface pattern", NULL, cmd_iface_pattern, NULL); commands_new( commands_new(unconfigure_interface, "pattern", "Delete any interface pattern", NULL, NULL, NULL), NEWLINE, "Clear interface pattern", NULL, cmd_iface_pattern, NULL); commands_new( commands_new( commands_new(configure_interface, "permanent", "Set permanent interface pattern", NULL, NULL, NULL), NULL, "Permanent interface pattern (comma-separated list of wildcards)", NULL, cmd_store_env_value, "iface-pattern"), NEWLINE, "Set permanent interface pattern", NULL, cmd_perm_iface_pattern, NULL); commands_new( commands_new(unconfigure_interface, "permanent", "Clear permanent interface pattern", NULL, NULL, NULL), NEWLINE, "Delete any interface pattern", NULL, cmd_perm_iface_pattern, NULL); commands_new( commands_new(configure_interface, "description", "Update interface descriptions with neighbor name", NULL, NULL, NULL), NEWLINE, "Update interface descriptions with neighbor name", NULL, cmd_update_descriptions, "enable"); commands_new( commands_new(unconfigure_interface, "description", "Don't update interface descriptions with neighbor name", NULL, NULL, NULL), NEWLINE, "Don't update interface descriptions with neighbor name", NULL, cmd_update_descriptions, NULL); commands_new( commands_new(configure_interface, "promiscuous", "Enable promiscuous mode on managed interfaces", NULL, NULL, NULL), NEWLINE, "Enable promiscuous mode on managed interfaces", NULL, cmd_iface_promisc, "enable"); commands_new( commands_new(unconfigure_interface, "promiscuous", "Don't enable promiscuous mode on managed interfaces", NULL, NULL, NULL), NEWLINE, "Don't enable promiscuous mode on managed interfaces", NULL, cmd_iface_promisc, NULL); register_commands_srcmac_type(configure_system); }
/** * Register `configure lldp` commands. * * Those are the commands that are related to the LLDP protocol but not * Dot1/Dot3/MED. Commands not related to LLDP should go in system instead. */ void register_commands_configure_lldp(struct cmd_node *configure, struct cmd_node *unconfigure) { struct cmd_node *configure_lldp = commands_new( configure, "lldp", "LLDP configuration", NULL, NULL, NULL); struct cmd_node *unconfigure_lldp = commands_new( unconfigure, "lldp", "LLDP configuration", NULL, NULL, NULL); commands_new( commands_new( commands_new(configure_lldp, "tx-interval", "Set LLDP transmit delay", cmd_check_no_env, NULL, "ports"), NULL, "LLDP transmit delay in seconds", NULL, cmd_store_env_value, "tx-interval"), NEWLINE, "Set LLDP transmit delay", NULL, cmd_txdelay, NULL); commands_new( commands_new( commands_new(configure_lldp, "tx-hold", "Set LLDP transmit hold", cmd_check_no_env, NULL, "ports"), NULL, "LLDP transmit hold in seconds", NULL, cmd_store_env_value, "tx-hold"), NEWLINE, "Set LLDP transmit hold", NULL, cmd_txhold, NULL); struct cmd_node *status = commands_new(configure_lldp, "status", "Set administrative status", NULL, NULL, NULL); for (lldpctl_map_t *status_map = lldpctl_key_get_map(lldpctl_k_port_status); status_map->string; status_map++) { const char *tag = strdup(totag(status_map->string)); commands_new( commands_new(status, tag, status_map->string, NULL, cmd_store_status_env_value, status_map->string), NEWLINE, "Set port administrative status", NULL, cmd_status, NULL); } /* Now handle the various portid subtypes we can configure. */ struct cmd_node *configure_lldp_portid_type = commands_new( configure_lldp, "portidsubtype", "LLDP PortID TLV Subtype ", NULL, NULL, NULL); for (lldpctl_map_t *b_map = lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); b_map->string; b_map++) { if (!strcmp(b_map->string, "ifname")) { commands_new( commands_new(configure_lldp_portid_type, b_map->string, "Interface Name", cmd_check_no_env, NULL, "ports"), NEWLINE, NULL, NULL, cmd_portid_type, b_map->string); } else if (!strcmp(b_map->string, "local")) { struct cmd_node *port_id = commands_new( commands_new(configure_lldp_portid_type, b_map->string, "Local", NULL, NULL, NULL), NULL, "Port ID", NULL, cmd_store_env_value, "port-id"); commands_new(port_id, NEWLINE, "Set local port ID", NULL, cmd_portid_type_local, b_map->string); commands_new( commands_new( commands_new(port_id, "description", "Also set port description", NULL, NULL, NULL), NULL, "Port description", NULL, cmd_store_env_value, "port-descr"), NEWLINE, "Set local port ID and description", NULL, cmd_portid_type_local, NULL); } else if (!strcmp(b_map->string, "macaddress")) { commands_new( commands_new(configure_lldp_portid_type, b_map->string, "MAC Address", cmd_check_no_env, NULL, "ports"), NEWLINE, NULL, NULL, cmd_portid_type, b_map->string); } } commands_new( commands_new(configure_lldp, "capabilities-advertisements", "Enable chassis capabilities advertisement", cmd_check_no_env, NULL, "ports"), NEWLINE, "Enable chassis capabilities advertisement", NULL, cmd_chassis_cap_advertise, "enable"); commands_new( commands_new(unconfigure_lldp, "capabilities-advertisements", "Don't enable chassis capabilities advertisement", NULL, NULL, NULL), NEWLINE, "Don't enable chassis capabilities advertisement", NULL, cmd_chassis_cap_advertise, NULL); commands_new( commands_new(configure_lldp, "management-addresses-advertisements", "Enable management addresses advertisement", NULL, NULL, NULL), NEWLINE, "Enable management addresses advertisement", NULL, cmd_chassis_mgmt_advertise, "enable"); commands_new( commands_new(unconfigure_lldp, "management-addresses-advertisements", "Don't enable management addresses advertisement", NULL, NULL, NULL), NEWLINE, "Don't enable management addresses advertisement", NULL, cmd_chassis_mgmt_advertise, NULL); #ifdef ENABLE_CUSTOM register_commands_configure_lldp_custom_tlvs(configure_lldp); commands_new( commands_new(unconfigure_lldp, "custom-tlv", "Clear all (previously set) custom TLVs", NULL, NULL, NULL), NEWLINE, "Clear all (previously set) custom TLVs", NULL, cmd_custom_tlv_set, NULL); #endif }
/** * Register `configure med policy` commands. */ static void register_commands_medpol(struct cmd_node *configure_med) { struct cmd_node *configure_medpolicy = commands_new( configure_med, "policy", "MED policy configuration", NULL, NULL, NULL); commands_new( configure_medpolicy, NEWLINE, "Apply new MED policy", cmd_check_env, cmd_medpolicy, "application"); /* Application */ struct cmd_node *configure_application = commands_new( configure_medpolicy, "application", "MED policy application", cmd_check_no_env, NULL, "application"); for (lldpctl_map_t *pol_map = lldpctl_key_get_map(lldpctl_k_med_policy_type); pol_map->string; pol_map++) { char *tag = strdup(totag(pol_map->string)); /* TODO: memory leak, happens once */ commands_new( configure_application, tag, pol_map->string, NULL, cmd_store_app_env_value_and_pop2, pol_map->string); } /* Remaining keywords */ commands_new( configure_medpolicy, "unknown", "Set unknown flag", cmd_check_application_but_no, cmd_store_env_and_pop, "unknown"); commands_new( commands_new( configure_medpolicy, "vlan", "VLAN advertising", cmd_check_application_but_no, NULL, "vlan"), NULL, "VLAN ID to advertise", NULL, cmd_store_env_value_and_pop2, "vlan"); commands_new( commands_new( configure_medpolicy, "dscp", "DiffServ advertising", cmd_check_application_but_no, NULL, "dscp"), NULL, "DSCP value to advertise (between 0 and 63)", NULL, cmd_store_env_value_and_pop2, "dscp"); struct cmd_node *priority = commands_new( configure_medpolicy, "priority", "MED policy priority", cmd_check_application_but_no, NULL, "priority"); for (lldpctl_map_t *prio_map = lldpctl_key_get_map(lldpctl_k_med_policy_priority); prio_map->string; prio_map++) { char *tag = strdup(totag(prio_map->string)); /* TODO: memory leak, happens once */ commands_new( priority, tag, prio_map->string, NULL, cmd_store_prio_env_value_and_pop2, prio_map->string); } }
/** * Register `configure system` commands. * * Those are the commands to configure protocol-independant stuff. */ void register_commands_configure_system(struct cmd_node *configure, struct cmd_node *unconfigure) { struct cmd_node *configure_system = commands_new( configure, "system", "System configuration", cmd_check_no_env, NULL, "ports"); struct cmd_node *unconfigure_system = commands_new( unconfigure, "system", "System configuration", cmd_check_no_env, NULL, "ports"); struct cmd_node *configure_interface = commands_new( configure_system, "interface", "Interface related items", NULL, NULL, NULL); struct cmd_node *unconfigure_interface = commands_new( unconfigure_system, "interface", "Interface related items", NULL, NULL, NULL); commands_new( commands_new( commands_new(configure_system, "description", "Override chassis description", NULL, NULL, NULL), NULL, "Chassis description", NULL, cmd_store_env_value, "description"), NEWLINE, "Override chassis description", NULL, cmd_system_description, NULL); commands_new( commands_new( commands_new(configure_system, "platform", "Override platform description", NULL, NULL, NULL), NULL, "Platform description (CDP)", NULL, cmd_store_env_value, "platform"), NEWLINE, "Override platform description", NULL, cmd_system_description, NULL); commands_new( commands_new( commands_new(configure_interface, "pattern", "Set active interface pattern", NULL, NULL, NULL), NULL, "Interface pattern (comma separated list of wildcards)", NULL, cmd_store_env_value, "iface-pattern"), NEWLINE, "Set active interface pattern", NULL, cmd_iface_pattern, NULL); commands_new( commands_new(configure_interface, "description", "Update interface descriptions with neighbor name", NULL, NULL, NULL), NEWLINE, "Update interface descriptions with neighbor name", NULL, cmd_update_descriptions, "enable"); commands_new( commands_new(unconfigure_interface, "description", "Don't update interface descriptions with neighbor name", NULL, NULL, NULL), NEWLINE, "Don't update interface descriptions with neighbor name", NULL, cmd_update_descriptions, NULL); register_commands_srcmac_type(configure_system); }
/* * fn_install_os: actually put DragonFly on a disk. */ void fn_install_os(struct i_fn_args *a) { struct subpartition *sp; struct commands *cmds; struct command *cmd; int i, seen_it, prefix, j, needcrypt; FILE *sources_conf; char line[256]; char cp_src[64][256]; char file_path[256]; char *string; int lines = 0; /* * Read SOURCES_CONF_FILE and populate our copy sources. */ snprintf(file_path, 256, "%s%s", a->os_root, SOURCES_CONF_FILE); sources_conf = fopen(file_path, "r"); i_log(a, "Reading %s", file_path); while(fgets(line, 256, sources_conf) != NULL && lines < 63) { if(strlen(line)>0) line[strlen(line)-1] = '\0'; strlcpy(cp_src[lines], line, 256); i_log(a,"Adding %s to copy source table.", cp_src[lines]); lines++; } i_log(a,"Added %i total items to copy source table.", lines); strcpy(cp_src[lines], ""); fclose(sources_conf); cmds = commands_new(); /* * If swap isn't mounted yet, mount it. */ if (measure_activated_swap(a) == 0) { for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (!subpartition_is_swap(sp)) continue; command_add(cmds, "%s%s %sdev/%s", a->os_root, cmd_name(a, "SWAPON"), a->os_root, subpartition_is_encrypted(sp) ? "mapper/swap" : subpartition_get_device_name(sp)); } } /* * Unmount anything already mounted on /mnt. */ unmount_all_under(a, cmds, "%smnt", a->os_root); /* Check if crypto support is needed */ needcrypt = 0; for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (subpartition_is_encrypted(sp)) { needcrypt = 1; break; } } for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) { if (use_hammer == 1) { command_add(cmds, "%s%s %sdev/%s %smnt%s", a->os_root, cmd_name(a, "MOUNT_HAMMER"), a->os_root, subpartition_is_encrypted(sp) ? "mapper/root" : subpartition_get_device_name(sp), a->os_root, subpartition_get_mountpoint(sp)); } else { command_add(cmds, "%s%s %sdev/%s %smnt%s", a->os_root, cmd_name(a, "MOUNT"), a->os_root, subpartition_get_device_name(sp), a->os_root, subpartition_get_mountpoint(sp)); } } } /* * Create mount points and mount subpartitions on them. */ for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (subpartition_is_swap(sp)) { /* * Set this subpartition as the dump device. */ if (subpartition_get_capacity(sp) < storage_get_memsize(a->s)) continue; command_add(cmds, "%s%s -v %sdev/%s", a->os_root, cmd_name(a, "DUMPON"), a->os_root, subpartition_is_encrypted(sp) ? "mapper/swap" : subpartition_get_device_name(sp)); asprintf(&string, "/dev/%s", subpartition_is_encrypted(sp) ? "mapper/swap" : subpartition_get_device_name(sp)); config_var_set(rc_conf, "dumpdev", string); free(string); continue; } if (use_hammer == 0) { /* / is already mounted */ if (strcmp(subpartition_get_mountpoint(sp), "/") != 0) { command_add(cmds, "%s%s -p %smnt%s", a->os_root, cmd_name(a, "MKDIR"), a->os_root, subpartition_get_mountpoint(sp)); /* Don't mount it if it's TMPFS-backed. */ if (subpartition_is_tmpfsbacked(sp)) continue; if (subpartition_is_encrypted(sp)) { command_add(cmds, "%s%s %sdev/mapper/%s %smnt%s", a->os_root, cmd_name(a, "MOUNT"), a->os_root, subpartition_get_mountpoint(sp) + 1, a->os_root, subpartition_get_mountpoint(sp)); } else { command_add(cmds, "%s%s %sdev/%s %smnt%s", a->os_root, cmd_name(a, "MOUNT"), a->os_root, subpartition_get_device_name(sp), a->os_root, subpartition_get_mountpoint(sp)); } } } else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) { command_add(cmds, "%s%s -p %smnt%s", a->os_root, cmd_name(a, "MKDIR"), a->os_root, subpartition_get_mountpoint(sp)); command_add(cmds, "%s%s %sdev/%s %smnt%s", a->os_root, cmd_name(a, "MOUNT"), a->os_root, subpartition_get_device_name(sp), a->os_root, subpartition_get_mountpoint(sp)); } } /* * Take care of HAMMER PFS. */ if (use_hammer == 1) handle_pfs(a, cmds); /* * Actually copy files now. */ for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) { char *src, *dest, *dn, *tmp_dest; dest = cp_src[i]; /* * If dest would be on an TMPFS-backed * mountpoint, don't bother copying it. */ sp = subpartition_of(storage_get_selected_slice(a->s), "%s%s", a->os_root, &dest[1]); if (sp != NULL && subpartition_is_tmpfsbacked(sp)) { continue; } /* * Create intermediate directories, if needed. */ tmp_dest = aura_strdup(dest); dn = dirname(tmp_dest); if (is_dir("%s%s", a->os_root, &dn[1]) && !is_dir("%smnt%s", a->os_root, dn)) { command_add(cmds, "%s%s -p %smnt%s", a->os_root, cmd_name(a, "MKDIR"), a->os_root, dn); } aura_free(tmp_dest, "directory name"); /* * If a directory by the same name but with the suffix * ".hdd" exists on the installation media, cpdup that * instead. This is particularly useful with /etc, which * may have significantly different behaviour on the * live CD compared to a standard HDD boot. */ if (is_dir("%s%s.hdd", a->os_root, &dest[1])) asprintf(&src, "%s.hdd", &dest[1]); else asprintf(&src, "%s", &dest[1]); if (is_dir("%s%s", a->os_root, src) || is_file("%s%s", a->os_root, src)) { /* * Cpdup the chosen file or directory onto the HDD. * if it exists on the source. */ cmd = command_add(cmds, "%s%s %s%s %smnt%s", a->os_root, cmd_name(a, "CPDUP"), a->os_root, src, a->os_root, dest); command_set_log_mode(cmd, COMMAND_LOG_QUIET); } } /* * Now, because cpdup does not cross mount points, * we must copy anything that the user might've made a * seperate mount point for (e.g. /usr/libdata/lint.) */ for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { /* * If the subpartition is a swap subpartition or an * TMPFS-backed mountpoint, don't try to copy anything * into it. */ if (subpartition_is_swap(sp) || subpartition_is_tmpfsbacked(sp)) continue; /* * If the mountpoint doesn't even exist on the installation * medium, don't try to copy anything from it! We assume * it's an empty subpartition for the user's needs. */ if (!is_dir("%s%s", a->os_root, &subpartition_get_mountpoint(sp)[1])) continue; /* * Don't bother copying the mountpoint IF: * - we've already said to copy it, or something besides it * (it's a prefix of something in cp_src); or * - we haven't said to copy it * (nothing in cp_src is a prefix of it.) */ seen_it = 0; prefix = 0; for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) { if (strncmp(subpartition_get_mountpoint(sp), cp_src[i], strlen(subpartition_get_mountpoint(sp))) == 0) { seen_it = 1; break; } if (strncmp(cp_src[i], subpartition_get_mountpoint(sp), strlen(cp_src[i])) == 0) { prefix = 1; } } if (seen_it || !prefix) continue; /* * Otherwise, cpdup the subpartition. * * XXX check for .hdd-extended source dirs here, too, * eventually - but for now, /etc.hdd will never be * the kind of tricky sub-mount-within-a-mount-point * that this part of the code is meant to handle. */ cmd = command_add(cmds, "%s%s %s%s %smnt%s", a->os_root, cmd_name(a, "CPDUP"), a->os_root, &subpartition_get_mountpoint(sp)[1], a->os_root, subpartition_get_mountpoint(sp)); command_set_log_mode(cmd, COMMAND_LOG_QUIET); } /* * Create symlinks. */ /* Take care of /sys. */ command_add(cmds, "%s%s -s usr/src/sys %smnt/sys", a->os_root, cmd_name(a, "LN"), a->os_root); /* * If the user has both /var and /tmp subpartitions, * symlink /var/tmp to /tmp. */ if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") != NULL && subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) { command_add(cmds, "%s%s 1777 %smnt/tmp", a->os_root, cmd_name(a, "CHMOD"), a->os_root); command_add(cmds, "%s%s -rf %smnt/var/tmp", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s -s /tmp %smnt/var/tmp", a->os_root, cmd_name(a, "LN"), a->os_root); } /* * If the user has /var, but no /tmp, * symlink /tmp to /var/tmp. */ if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") == NULL && subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) { command_add(cmds, "%s%s -rf %smnt/tmp", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s -s /var/tmp %smnt/tmp", a->os_root, cmd_name(a, "LN"), a->os_root); } /* * If the user has /usr, but no /home, * symlink /home to /usr/home. */ if (subpartition_find(storage_get_selected_slice(a->s), "/home") == NULL && subpartition_find(storage_get_selected_slice(a->s), "/usr") != NULL) { command_add(cmds, "%s%s -rf %smnt/home", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s %smnt/usr/home", a->os_root, cmd_name(a, "MKDIR"), a->os_root); command_add(cmds, "%s%s -s /usr/home %smnt/home", a->os_root, cmd_name(a, "LN"), a->os_root); } /* * XXX check for other possible combinations too? */ /* * Clean up. In case some file didn't make it, use rm -f */ command_add(cmds, "%s%s -f %smnt/boot/loader.conf", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s -f %smnt/tmp/install.log", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s -f %smnt/tmp/t[12]", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s -f %smnt/tmp/test_in", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s -f %smnt/tmp/test_out", a->os_root, cmd_name(a, "RM"), a->os_root); /* * Copy pristine versions over any files we might have installed. * This allows the resulting file tree to be customized. */ for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) { char *src, *dest, *dn, *tmp_dest; src = cp_src[i]; dest = cp_src[i]; /* * Get the directory that the desired thing to * copy resides in. */ tmp_dest = aura_strdup(dest); dn = dirname(tmp_dest); /* * If this dir doesn't exist in PRISTINE_DIR * on the install media, just skip it. */ if (!is_dir("%s%s%s", a->os_root, PRISTINE_DIR, dn)) { aura_free(tmp_dest, _("directory name")); continue; } /* * Create intermediate directories, if needed. */ if (!is_dir("%smnt%s", a->os_root, dn)) { command_add(cmds, "%s%s -p %smnt%s", a->os_root, cmd_name(a, "MKDIR"), a->os_root, dn); } aura_free(tmp_dest, "directory name"); /* * Cpdup the chosen file or directory onto the HDD. */ cmd = command_add(cmds, "%s%s %s%s %smnt%s", a->os_root, cmd_name(a, "CPDUP"), a->os_root, src, a->os_root, dest); cmd = command_add(cmds, "%s%s %s%s%s %smnt%s", a->os_root, cmd_name(a, "CPDUP"), a->os_root, PRISTINE_DIR, src, a->os_root, dest); command_set_log_mode(cmd, COMMAND_LOG_QUIET); } /* * Rebuild the user database, to get rid of any extra users * from the LiveCD that aren't supposed to be installed * (copying a pristine master.passwd isn't enough.) */ command_add(cmds, "%s%s -p -d %smnt/etc %smnt/etc/master.passwd", a->os_root, cmd_name(a, "PWD_MKDB"), a->os_root, a->os_root); /* Create missing directories. */ command_add(cmds, "%s%s %smnt/proc", a->os_root, cmd_name(a, "MKDIR"), a->os_root); command_add(cmds, "%s%s %smnt/mnt", a->os_root, cmd_name(a, "MKDIR"), a->os_root); /* Write new fstab. */ command_add(cmds, "%s%s '%s' >%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), "# Device\t\tMountpoint\tFStype\tOptions\t\tDump\tPass#", a->os_root); for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (strcmp(subpartition_get_mountpoint(sp), "swap") == 0) { command_add(cmds, "%s%s '/dev/%s\t\tnone\t\tswap\tsw\t\t0\t0' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_is_encrypted(sp) ? "mapper/swap" : subpartition_get_device_name(sp), a->os_root); if (subpartition_is_encrypted(sp)) { command_add(cmds, "%s%s 'swap\t/dev/%s\tnone\tnone' >>%smnt/etc/crypttab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), a->os_root); } } else if (use_hammer == 0) { if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) { command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), subpartition_get_mountpoint(sp), a->os_root); } else if (subpartition_is_tmpfsbacked(sp)) { command_add(cmds, "%s%s 'tmpfs\t\t\t%s\t\ttmpfs\trw,-s%luM\t1\t1' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_mountpoint(sp), subpartition_get_capacity(sp), a->os_root); } else if (subpartition_is_encrypted(sp)) { command_add(cmds, "%s%s '%s\t/dev/%s\tnone\tnone' >>%smnt/etc/crypttab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_mountpoint(sp) + 1, subpartition_get_device_name(sp), a->os_root); command_add(cmds, "%s%s '/dev/mapper/%s\t\t%s\t\tufs\trw\t\t2\t2' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_mountpoint(sp) + 1, subpartition_get_mountpoint(sp), a->os_root); } else { command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t2\t2' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), subpartition_get_mountpoint(sp), a->os_root); } } else { if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) { command_add(cmds, "%s%s '/dev/%s\t\t%s\t\thammer\trw\t\t1\t1' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), subpartition_get_mountpoint(sp), a->os_root); if (subpartition_is_encrypted(sp)) { command_add(cmds, "%s%s 'vfs.root.mountfrom=\"ufs:md0s0\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), a->os_root); command_add(cmds, "%s%s 'vfs.root.realroot=\"crypt:hammer:%s:root\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), a->os_root); } else { command_add(cmds, "%s%s 'vfs.root.mountfrom=\"hammer:%s\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), a->os_root); } } else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) { command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), subpartition_get_device_name(sp), subpartition_get_mountpoint(sp), a->os_root); } } } /* * Take care of HAMMER PFS null mounts. */ if (use_hammer == 1) { for (j = 0; pfs_mountpt[j] != NULL; j++) { if (rindex(pfs_mountpt[j]+1, '/') != NULL) command_add(cmds, "%s%s '/pfs%s.%s\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), dirname(pfs_mountpt[j]), basename(pfs_mountpt[j]), pfs_mountpt[j], a->os_root); else command_add(cmds, "%s%s '/pfs%s\t\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), pfs_mountpt[j], pfs_mountpt[j], a->os_root); } } command_add(cmds, "%s%s '%s' >>%smnt/etc/fstab", a->os_root, cmd_name(a, "ECHO"), "proc\t\t\t/proc\t\tprocfs\trw\t\t0\t0", a->os_root); /* Backup the disklabel and the log. */ command_add(cmds, "%s%s %s > %smnt/etc/disklabel.%s", a->os_root, cmd_name(a, "DISKLABEL64"), slice_get_device_name(storage_get_selected_slice(a->s)), a->os_root, slice_get_device_name(storage_get_selected_slice(a->s))); /* 'chflags nohistory' as needed */ for (j = 0; pfs_mountpt[j] != NULL; j++) if (pfs_nohistory[j] == 1) command_add(cmds, "%s%s -R nohistory %smnt%s", a->os_root, cmd_name(a, "CHFLAGS"), a->os_root, pfs_mountpt[j]); command_add(cmds, "%s%s %sinstall.log %smnt/var/log/install.log", a->os_root, cmd_name(a, "CP"), a->tmp, a->os_root); command_add(cmds, "%s%s 600 %smnt/var/log/install.log", a->os_root, cmd_name(a, "CHMOD"), a->os_root); /* Do some preparation if encrypted partitions were configured */ if (needcrypt) { command_add(cmds, "%s%s 'dm_load=\"yes\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), a->os_root); command_add(cmds, "%s%s 'dm_target_crypt_load=\"yes\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), a->os_root); if (use_hammer) { command_add(cmds, "%s%s -b %smnt/boot -t %smnt/tmp", a->os_root, cmd_name(a, "MKINITRD"), a->os_root, a->os_root); command_add(cmds, "%s%s -rf %smnt/tmp/initrd", a->os_root, cmd_name(a, "RM"), a->os_root); command_add(cmds, "%s%s 'initrd.img_load=\"YES\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), a->os_root); command_add(cmds, "%s%s 'initrd.img_type=\"md_image\"' >>%smnt/boot/loader.conf", a->os_root, cmd_name(a, "ECHO"), a->os_root); } } /* Customize stuff here */ if(is_file("%susr/local/bin/after_installation_routines.sh", a->os_root)) { command_add(cmds, "%susr/local/bin/after_installation_routines.sh", a->os_root); } /* * Do it! */ /* commands_preview(a->c, cmds); */ if (!commands_execute(a, cmds)) { inform(a->c, _("%s was not fully installed."), OPERATING_SYSTEM_NAME); a->result = 0; } else { a->result = 1; } commands_free(cmds); cmds = commands_new(); if (a->result) { config_vars_write(rc_conf, CONFIG_TYPE_SH, "%smnt/etc/rc.conf", a->os_root); config_vars_free(rc_conf); rc_conf = config_vars_new(); } /* * Unmount everything we mounted on /mnt. This is done in a seperate * command chain, so that partitions are unmounted, even if an error * occurs in one of the preceding commands, or it is cancelled. */ unmount_all_under(a, cmds, "%smnt", a->os_root); /* * Once everything is unmounted, if the install went successfully, * make sure once and for all that the disklabel is bootable. */ if (a->result) command_add(cmds, "%s%s -B %s", a->os_root, cmd_name(a, "DISKLABEL64"), slice_get_device_name(storage_get_selected_slice(a->s))); if (!commands_execute(a, cmds)) inform(a->c, _("Warning: subpartitions were not correctly unmounted.")); commands_free(cmds); /* * Finally, remove all swap and any mappings. */ if (swapoff_all(a) == NULL) inform(a->c, _("Warning: swap could not be turned off.")); if (remove_all_mappings(a) == NULL) inform(a->c, _("Warning: mappings could not be removed.")); }
/** * Register `configure med location coordinate` commands. */ static void register_commands_medloc_coord(struct cmd_node *configure_medlocation) { /* MED location coordinate (set) */ struct cmd_node *configure_medloc_coord = commands_new( configure_medlocation, "coordinate", "MED location coordinate configuration", NULL, NULL, NULL); commands_new(configure_medloc_coord, NEWLINE, "Configure MED location coordinates", cmd_check_env, cmd_medlocation_coordinate, "latitude,longitude,altitude,altitude-unit,datum"); commands_new( commands_new( configure_medloc_coord, "latitude", "Specify latitude", cmd_check_no_env, NULL, "latitude"), NULL, "Latitude as xx.yyyyN or xx.yyyyS", NULL, cmd_store_env_value_and_pop2, "latitude"); commands_new( commands_new( configure_medloc_coord, "longitude", "Specify longitude", cmd_check_no_env, NULL, "longitude"), NULL, "Longitude as xx.yyyyE or xx.yyyyW", NULL, cmd_store_env_value_and_pop2, "longitude"); struct cmd_node *altitude = commands_new( commands_new( configure_medloc_coord, "altitude", "Specify altitude", cmd_check_no_env, NULL, "altitude"), NULL, "Altitude", NULL, cmd_store_env_value, "altitude"); commands_new(altitude, "m", "meters", NULL, cmd_store_env_value_and_pop3, "altitude-unit"); commands_new(altitude, "f", "floors", NULL, cmd_store_env_value_and_pop3, "altitude-unit"); struct cmd_node *datum = commands_new(configure_medloc_coord, "datum", "Specify datum", cmd_check_no_env, NULL, "datum"); for (lldpctl_map_t *datum_map = lldpctl_key_get_map(lldpctl_k_med_location_geoid); datum_map->string; datum_map++) commands_new(datum, datum_map->string, NULL, NULL, cmd_store_env_value_and_pop2, "datum"); }
int format_slice(struct i_fn_args *a) { struct commands *cmds; struct command *cmd; int result; int cyl, hd, sec; cmds = commands_new(); /* * The information in a->s NEEDS to be accurate here! * Presumably we just did a survey_storage() recently. * XXX should we do another one here anyway just to be paranoid? */ /* * Set the slice's sysid to 165. */ disk_get_geometry(storage_get_selected_disk(a->s), &cyl, &hd, &sec); command_add(cmds, "%s%s 'g c%d h%d s%d' >%snew.fdisk", a->os_root, cmd_name(a, "ECHO"), cyl, hd, sec, a->tmp); command_add(cmds, "%s%s 'p %d %d %lu %lu' >>%snew.fdisk", a->os_root, cmd_name(a, "ECHO"), slice_get_number(storage_get_selected_slice(a->s)), 165, slice_get_start(storage_get_selected_slice(a->s)), slice_get_size(storage_get_selected_slice(a->s)), a->tmp); if (slice_get_flags(storage_get_selected_slice(a->s)) & 0x80) { command_add(cmds, "%s%s 'a %d' >>%snew.fdisk", a->os_root, cmd_name(a, "ECHO"), slice_get_number(storage_get_selected_slice(a->s)), a->tmp); } command_add(cmds, "%s%s %snew.fdisk", a->os_root, cmd_name(a, "CAT"), a->tmp); temp_file_add(a, "new.fdisk"); /* * Execute the fdisk script. */ cmd = command_add(cmds, "%s%s -v -f %snew.fdisk %s", a->os_root, cmd_name(a, "FDISK"), a->tmp, disk_get_device_name(storage_get_selected_disk(a->s))); if (slice_get_size(storage_get_selected_slice(a->s)) == 0xFFFFFFFFU) command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE); /* * If there is an old 'virgin' disklabel hanging around * in the temp dir, get rid of it. This won't happen * from a real CD, but might happen with '-o' installs. */ command_add(cmds, "%s%s -f %sinstall.disklabel.%s", a->os_root, cmd_name(a, "RM"), a->tmp, slice_get_device_name(storage_get_selected_slice(a->s))); result = commands_execute(a, cmds); commands_free(cmds); return(result); }
void fn_install_bootblocks(struct i_fn_args *a, const char *device) { struct dfui_form *f; struct dfui_response *r; struct dfui_dataset *ds; struct disk *d; struct commands *cmds; struct command *cmd; char disk[64], boot0cfg[32], packet[32]; char msg_buf[1][1024]; snprintf(msg_buf[0], sizeof(msg_buf[0]), "'Packet Mode' refers to using newer BIOS calls to boot " "from a partition of the disk. It is generally not " "required unless:\n\n" "- your BIOS does not support legacy mode; or\n" "- your %s primary partition resides on a " "cylinder of the disk beyond cylinder 1024; or\n" "- you just can't get it to boot without it.", OPERATING_SYSTEM_NAME); f = dfui_form_create( "install_bootstrap", _("Install Bootblock(s)"), a->short_desc, msg_buf[0], "p", "special", "dfinstaller_install_bootstrap", "f", "disk", _("Disk Drive"), _("The disk on which you wish to install a bootblock"), "", "p", "editable", "false", "f", "boot0cfg", _("Install Bootblock?"), _("Install a bootblock on this disk"), "", "p", "control", "checkbox", "f", "packet", _("Packet Mode?"), _("Select this to use 'packet mode' to boot the disk"), "", "p", "control", "checkbox", "a", "ok", _("Accept and Install Bootblocks"), "", "", "a", "cancel", a->cancel_desc, "", "", "p", "accelerator", "ESC", NULL ); dfui_form_set_multiple(f, 1); if (device != NULL) { ds = dfui_dataset_new(); dfui_dataset_celldata_add(ds, "disk", device); dfui_dataset_celldata_add(ds, "boot0cfg", "Y"); dfui_dataset_celldata_add(ds, "packet", "Y"); dfui_form_dataset_add(f, ds); } else { for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d)) { ds = dfui_dataset_new(); dfui_dataset_celldata_add(ds, "disk", disk_get_device_name(d)); dfui_dataset_celldata_add(ds, "boot0cfg", "Y"); dfui_dataset_celldata_add(ds, "packet", "Y"); dfui_form_dataset_add(f, ds); } } if (!dfui_be_present(a->c, f, &r)) abort_backend(); a->result = 0; if (strcmp(dfui_response_get_action_id(r), "ok") == 0) { cmds = commands_new(); for (ds = dfui_response_dataset_get_first(r); ds != NULL; ds = dfui_dataset_get_next(ds)) { strlcpy(disk, dfui_dataset_get_value(ds, "disk"), 64); strlcpy(boot0cfg, dfui_dataset_get_value(ds, "boot0cfg"), 32); strlcpy(packet, dfui_dataset_get_value(ds, "packet"), 32); if (strcasecmp(boot0cfg, "Y") == 0) { cmd = command_add(cmds, "%s%s -B -o %spacket %s", a->os_root, cmd_name(a, "BOOT0CFG"), strcasecmp(packet, "Y") == 0 ? "" : "no", disk); command_set_failure_mode(cmd, COMMAND_FAILURE_WARN); command_set_tag(cmd, "%s", disk); cmd = command_add(cmds, "%s%s -v %s", a->os_root, cmd_name(a, "BOOT0CFG"), disk); command_set_failure_mode(cmd, COMMAND_FAILURE_WARN); command_set_tag(cmd, "%s", disk); } } if (!commands_execute(a, cmds)) { ask_to_wipe_boot_sector(a, cmds); } else { inform(a->c, _("Bootblocks were successfully installed!")); a->result = 1; } commands_free(cmds); } dfui_form_free(f); dfui_response_free(r); }
/* * If ss->selected_disk == NULL, user will be asked for which disk. * Returns 1 if disk was formatted, 0 if it wasn't. * If it was, ss->selected_disk and ss->selected_slice are set to it. */ void fn_format_disk(struct i_fn_args *a) { struct commands *cmds; char *selected_disk_string; if (storage_get_selected_disk(a->s) == NULL) { a->short_desc = _("Select a disk to format."); a->cancel_desc = _("Return to Utilities Menu"); fn_select_disk(a); if (!a->result || storage_get_selected_disk(a->s) == NULL) { a->result = 0; return; } } if (confirm_dangerous_action(a->c, _("WARNING! ALL data in ALL partitions on the disk\n\n" "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY " "SURE you wish to take this action? This is your " "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) { cmds = commands_new(); command_add(cmds, "%s%s -BI %s", a->os_root, cmd_name(a, "FDISK"), disk_get_device_name(storage_get_selected_disk(a->s))); if (!commands_execute(a, cmds)) { inform(a->c, _("The disk\n\n%s\n\nwas " "not correctly formatted, and may " "now be in an inconsistent state. " "We recommend re-formatting it " "before attempting to install " "%s on it."), disk_get_desc(storage_get_selected_disk(a->s)), OPERATING_SYSTEM_NAME); commands_free(cmds); a->result = 0; return; } commands_free(cmds); /* * Since one of the disks has now changed, we must * refresh our view of them and re-select the disk * since the selected_disk pointer will be invalidated. */ selected_disk_string = aura_strdup( disk_get_device_name(storage_get_selected_disk(a->s))); if (!survey_storage(a)) { inform(a->c, _("Errors occurred while probing " "the system for its storage capabilities.")); } storage_set_selected_disk(a->s, disk_find(a->s, selected_disk_string)); free(selected_disk_string); /* * Note that we formatted this disk and that we want * to use the first (and only) slice of it. */ disk_set_formatted(storage_get_selected_disk(a->s), 1); storage_set_selected_slice(a->s, disk_slice_first(storage_get_selected_disk(a->s))); if (!format_slice(a)) { inform(a->c, _("The sole primary partition of " "the disk\n\n%s\n\nwas " "not correctly formatted, and may " "now be in an inconsistent state. " "We recommend re-formatting the " "disk before attempting to install " "%s on it."), disk_get_desc(storage_get_selected_disk(a->s)), OPERATING_SYSTEM_NAME); a->result = 0; return; } inform(a->c, _("The disk\n\n%s\n\nwas formatted."), disk_get_desc(storage_get_selected_disk(a->s))); a->result = 1; } else { inform(a->c, _("Action cancelled - no disks were formatted.")); a->result = 0; } }
/* * Given a set of subpartitions-to-be in the selected slice, * create them. */ static int create_subpartitions(struct i_fn_args *a) { struct subpartition *sp; struct commands *cmds; int result = 0; int num_partitions; cmds = commands_new(); if (!is_file("%sinstall.disklabel.%s", a->tmp, slice_get_device_name(storage_get_selected_slice(a->s)))) { /* * Get a copy of the 'virgin' disklabel. * XXX It might make more sense for this to * happen right after format_slice() instead. */ command_add(cmds, "%s%s -r %s >%sinstall.disklabel.%s", a->os_root, cmd_name(a, "DISKLABEL64"), slice_get_device_name(storage_get_selected_slice(a->s)), a->tmp, slice_get_device_name(storage_get_selected_slice(a->s))); } /* * Weave together a new disklabel out the of the 'virgin' * disklabel, and the user's subpartition choices. */ /* * Take everything from the 'virgin' disklabel up until the * '16 partitions' line. */ num_partitions = 16; command_add(cmds, "%s%s '$2==\"partitions:\" || cut { cut = 1 } !cut { print $0 }' <%sinstall.disklabel.%s >%sinstall.disklabel", a->os_root, cmd_name(a, "AWK"), a->tmp, slice_get_device_name(storage_get_selected_slice(a->s)), a->tmp); /* * 16 partitions: * # size offset fstype * c: 16383969 0 unused # 7999.985MB */ command_add(cmds, "%s%s '%d partitions:' >>%sinstall.disklabel", a->os_root, cmd_name(a, "ECHO"), num_partitions ,a->tmp); command_add(cmds, "%s%s '%s' >>%sinstall.disklabel", a->os_root, cmd_name(a, "ECHO"), "# size offset fstype", a->tmp); #ifdef DEBUG for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { command_add(cmds, "%s%s 'mountpoint: %s device: %s'", a->os_root, cmd_name(a, "ECHO"), subpartition_get_mountpoint(sp), subpartition_get_device_name(sp)); } #endif /* * Write a line for each subpartition the user wants. */ for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (subpartition_is_tmpfsbacked(sp)) { continue; } if (subpartition_is_swap(sp)) { command_add(cmds, "%s%s ' %c:\t%s\t*\tswap' >>%sinstall.disklabel", a->os_root, cmd_name(a, "ECHO"), subpartition_get_letter(sp), capacity_to_string(subpartition_get_capacity(sp)), a->tmp); } else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) { command_add(cmds, "%s%s ' %c:\t%s\t0\t4.2BSD' >>%sinstall.disklabel", a->os_root, cmd_name(a, "ECHO"), subpartition_get_letter(sp), capacity_to_string(subpartition_get_capacity(sp)), a->tmp); } else { command_add(cmds, "%s%s ' %c:\t%s\t*\tHAMMER' >>%sinstall.disklabel", a->os_root, cmd_name(a, "ECHO"), subpartition_get_letter(sp), capacity_to_string(subpartition_get_capacity(sp)), a->tmp); } } temp_file_add(a, "install.disklabel"); /* * Label the slice from the disklabel we just wove together. */ command_add(cmds, "%s%s -R -B -r %s %sinstall.disklabel", a->os_root, cmd_name(a, "DISKLABEL64"), slice_get_device_name(storage_get_selected_slice(a->s)), a->tmp); /* * Create a snapshot of the disklabel we just created * for debugging inspection in the log. */ command_add(cmds, "%s%s %s", a->os_root, cmd_name(a, "DISKLABEL64"), slice_get_device_name(storage_get_selected_slice(a->s))); /* * If encryption was specified, load dm(4). */ for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (subpartition_is_encrypted(sp)) { fn_get_passphrase(a); break; } } /* * Create filesystems on the newly-created subpartitions. */ for (sp = slice_subpartition_first(storage_get_selected_slice(a->s)); sp != NULL; sp = subpartition_next(sp)) { if (subpartition_is_swap(sp) || subpartition_is_tmpfsbacked(sp)) { if (subpartition_is_swap(sp) && subpartition_is_encrypted(sp)) { command_add(cmds, "%s%s -d /tmp/t1 luksFormat /dev/%s", a->os_root, cmd_name(a, "CRYPTSETUP"), subpartition_get_device_name(sp)); command_add(cmds, "%s%s -d /tmp/t1 luksOpen /dev/%s swap", a->os_root, cmd_name(a, "CRYPTSETUP"), subpartition_get_device_name(sp)); } continue; } if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) { command_add(cmds, "%s%s /dev/%s", a->os_root, cmd_name(a, "NEWFS"), subpartition_get_device_name(sp)); } else { if (subpartition_is_encrypted(sp)) { command_add(cmds, "%s%s -d /tmp/t1 luksFormat /dev/%s", a->os_root, cmd_name(a, "CRYPTSETUP"), subpartition_get_device_name(sp)); command_add(cmds, "%s%s -d /tmp/t1 luksOpen /dev/%s root", a->os_root, cmd_name(a, "CRYPTSETUP"), subpartition_get_device_name(sp)); } command_add(cmds, "%s%s -f -L ROOT /dev/%s", a->os_root, cmd_name(a, "NEWFS_HAMMER"), subpartition_is_encrypted(sp) ? "mapper/root" : subpartition_get_device_name(sp)); } } result = commands_execute(a, cmds); commands_free(cmds); return(result); }
/** * Register `configure med dot3` commands. */ void register_commands_dot3pow(struct cmd_node *configure_dot3) { struct cmd_node *configure_dot3power = commands_new( configure_dot3, "power", "Dot3 power configuration", NULL, NULL, NULL); commands_new( configure_dot3power, NEWLINE, "Apply new Dot3 power configuration", cmd_check_env_power, cmd_dot3power, NULL); /* Type: PSE or PD */ commands_new( configure_dot3power, "pd", "Dot3 power consumer", cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); commands_new( configure_dot3power, "pse", "Dot3 power provider", cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); /* Flags */ commands_new( configure_dot3power, "supported", "MDI power support present", cmd_check_type_but_no, cmd_store_env_and_pop, "supported"); commands_new( configure_dot3power, "enabled", "MDI power support enabled", cmd_check_type_but_no, cmd_store_env_and_pop, "enabled"); commands_new( configure_dot3power, "paircontrol", "MDI power pair can be selected", cmd_check_type_but_no, cmd_store_env_and_pop, "paircontrol"); /* Power pairs */ struct cmd_node *powerpairs = commands_new( configure_dot3power, "powerpairs", "Which pairs are currently used for power (mandatory)", cmd_check_type_but_no, NULL, "powerpairs"); for (lldpctl_map_t *pp_map = lldpctl_key_get_map(lldpctl_k_dot3_power_pairs); pp_map->string; pp_map++) { commands_new( powerpairs, pp_map->string, pp_map->string, NULL, cmd_store_powerpairs_env_value_and_pop2, pp_map->string); } /* Class */ struct cmd_node *class = commands_new( configure_dot3power, "class", "Power class", cmd_check_type_but_no, NULL, "class"); for (lldpctl_map_t *class_map = lldpctl_key_get_map(lldpctl_k_dot3_power_class); class_map->string; class_map++) { const char *tag = strdup(totag(class_map->string)); commands_new( class, tag, class_map->string, NULL, cmd_store_class_env_value_and_pop2, class_map->string); } /* 802.3at type */ struct cmd_node *typeat = commands_new( configure_dot3power, "type", "802.3at device type", cmd_check_type_but_no, NULL, "typeat"); commands_new(typeat, "1", "802.3at type 1", NULL, cmd_store_env_value_and_pop2, "typeat"); commands_new(typeat, "2", "802.3at type 2", NULL, cmd_store_env_value_and_pop2, "typeat"); /* Source */ struct cmd_node *source = commands_new( configure_dot3power, "source", "802.3at dot3 power source (mandatory)", cmd_check_typeat_but_no, NULL, "source"); register_commands_pow_source(source); /* Priority */ struct cmd_node *priority = commands_new( configure_dot3power, "priority", "802.3at dot3 power priority (mandatory)", cmd_check_typeat_but_no, NULL, "priority"); register_commands_pow_priority(priority, lldpctl_k_dot3_power_priority); /* Values */ commands_new( commands_new(configure_dot3power, "requested", "802.3at dot3 power value requested (mandatory)", cmd_check_typeat_but_no, NULL, "requested"), NULL, "802.3at power value requested in milliwatts", NULL, cmd_store_env_value_and_pop2, "requested"); commands_new( commands_new(configure_dot3power, "allocated", "802.3at dot3 power value allocated (mandatory)", cmd_check_typeat_but_no, NULL, "allocated"), NULL, "802.3at power value allocated in milliwatts", NULL, cmd_store_env_value_and_pop2, "allocated"); }