void md_cleanup_install(void) { #ifndef DEBUG enable_rc_conf(); add_rc_conf("sshd=YES\n"); add_rc_conf("dhcpcd=YES\n"); #endif }
void md_cleanup_install(void) { #ifndef DEBUG enable_rc_conf(); add_rc_conf("wscons=YES\n"); /* Configure a single screen. */ run_program(RUN_CHROOT, "sed -an -e '/^screen/s/^/#/;/^mux/s/^/#/;" "H;$!d;g;w /etc/wscons.conf' /etc/wscons.conf"); #endif }
static int toggle_rcvar(struct menudesc *menu, void *arg) { configinfo **confp = arg; int s; const char *setting, *varname; char pattern[STRSIZE]; char buf[STRSIZE]; char *cp; int found = 0; FILE *fp; varname = confp[menu->cursel]->rcvar; s = check_rcvar(varname); /* we're toggling, so invert the sense */ if (s) { confp[menu->cursel]->setting = MSG_NO; setting = "NO"; } else { confp[menu->cursel]->setting = MSG_YES; setting = "YES"; } if (!(fp = fopen(target_expand("/etc/rc.conf"), "r"))) { msg_display(MSG_rcconf_delete_failed, varname); process_menu(MENU_ok, NULL); return -1; } while (fgets(buf, sizeof buf, fp) != NULL) { cp = buf + strspn(buf, " \t"); /* Skip initial spaces */ if (strncmp(cp, varname, strlen(varname)) == 0) { cp += strlen(varname); if (*cp != '=') continue; buf[strlen(buf) - 1] = 0; snprintf(pattern, sizeof pattern, "s,^%s$,%s=%s,", buf, varname, setting); found = 1; break; } } fclose(fp); if (!found) { add_rc_conf("%s=%s\n", varname, setting); if (logfp) { fprintf(logfp, "adding %s=%s\n", varname, setting); fflush(logfp); } } else { if (logfp) { fprintf(logfp, "replacement pattern is %s\n", pattern); fflush(logfp); } replace("/etc/rc.conf", pattern); } return 0; }
/* * Write the network config info the user entered via menus into the * config files in the target disk. Be careful not to lose any * information we don't immediately add back, in case the install * target is the currently-active root. */ void mnt_net_config(void) { char ifconfig_fn[STRSIZE]; char ifconfig_str[STRSIZE]; FILE *ifconf = NULL; if (!network_up) return; process_menu(MENU_yesno, deconst(MSG_mntnetconfig)); if (!yesno) return; /* Write hostname to /etc/rc.conf */ if ((net_dhcpconf & DHCPCONF_HOST) == 0) if (del_rc_conf("hostname") == 0) add_rc_conf("hostname=%s\n", recombine_host_domain()); /* Copy resolv.conf to target. If DHCP was used to create it, * it will be replaced on next boot anyway. */ #ifndef INET6 if (net_namesvr[0] != '\0') dup_file_into_target("/etc/resolv.conf"); #else /* * not sure if it is a good idea, to allow dhcp config to * override IPv6 configuration */ if (net_namesvr[0] != '\0' || net_namesvr6[0] != '\0') dup_file_into_target("/etc/resolv.conf"); #endif /* * bring the interface up, it will be necessary for IPv6, and * it won't make trouble with IPv4 case either */ snprintf(ifconfig_fn, sizeof ifconfig_fn, "/etc/ifconfig.%s", net_dev); ifconf = target_fopen(ifconfig_fn, "w"); if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); scripting_fprintf(ifconf, "up\n"); if (*net_media != '\0') scripting_fprintf(ifconf, "media %s\n", net_media); scripting_fprintf(NULL, "EOF\n"); } if ((net_dhcpconf & DHCPCONF_IPADDR) == 0) { FILE *hosts; /* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */ if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); if (*net_media != '\0') scripting_fprintf(ifconf, "%s netmask %s media %s\n", net_ip, net_mask, net_media); else scripting_fprintf(ifconf, "%s netmask %s\n", net_ip, net_mask); scripting_fprintf(NULL, "EOF\n"); } /* * Add IPaddr/hostname to /etc/hosts. * Be careful not to clobber any existing contents. * Relies on ordered search of /etc/hosts. XXX YP? */ hosts = target_fopen("/etc/hosts", "a"); if (hosts != 0) { scripting_fprintf(NULL, "cat <<EOF >>%s/etc/hosts\n", target_prefix()); write_etc_hosts(hosts); (void)fclose(hosts); scripting_fprintf(NULL, "EOF\n"); fclose(hosts); } if (del_rc_conf("defaultroute") == 0) add_rc_conf("defaultroute=\"%s\"\n", net_defroute); } else { if (snprintf(ifconfig_str, sizeof ifconfig_str, "ifconfig_%s", net_dev) > 0 && del_rc_conf(ifconfig_str) == 0) { add_rc_conf("ifconfig_%s=dhcp\n", net_dev); } } #ifdef INET6 if ((net_ip6conf & IP6CONF_AUTOHOST) != 0) { if (del_rc_conf("ip6mode") == 0) add_rc_conf("ip6mode=autohost\n"); if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); scripting_fprintf(ifconf, "!rtsol $int\n"); scripting_fprintf(NULL, "EOF\n"); } } #endif if (ifconf) fclose(ifconf); fflush(NULL); }
/* * Write the network config info the user entered via menus into the * config files in the target disk. Be careful not to lose any * information we don't immediately add back, in case the install * target is the currently-active root. */ void mnt_net_config(void) { char ifconfig_fn[STRSIZE]; FILE *ifconf = NULL; if (!network_up) return; if (!ask_yesno(MSG_mntnetconfig)) return; /* Write hostname to /etc/rc.conf */ if ((net_dhcpconf & DHCPCONF_HOST) == 0) if (del_rc_conf("hostname") == 0) add_rc_conf("hostname=%s\n", recombine_host_domain()); /* Copy resolv.conf to target. If DHCP was used to create it, * it will be replaced on next boot anyway. */ if (net_namesvr[0] != '\0') dup_file_into_target("/etc/resolv.conf"); /* * bring the interface up, it will be necessary for IPv6, and * it won't make trouble with IPv4 case either */ snprintf(ifconfig_fn, sizeof ifconfig_fn, "/etc/ifconfig.%s", net_dev); ifconf = target_fopen(ifconfig_fn, "w"); if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); scripting_fprintf(ifconf, "up\n"); if (*net_media != '\0') scripting_fprintf(ifconf, "media %s\n", net_media); scripting_fprintf(NULL, "EOF\n"); } if ((net_dhcpconf & DHCPCONF_IPADDR) == 0) { FILE *hosts; /* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */ if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); if (*net_media != '\0') scripting_fprintf(ifconf, "%s netmask %s media %s\n", net_ip, net_mask, net_media); else scripting_fprintf(ifconf, "%s netmask %s\n", net_ip, net_mask); scripting_fprintf(NULL, "EOF\n"); } /* * Add IPaddr/hostname to /etc/hosts. * Be careful not to clobber any existing contents. * Relies on ordered search of /etc/hosts. XXX YP? */ hosts = target_fopen("/etc/hosts", "a"); if (hosts != 0) { scripting_fprintf(NULL, "cat <<EOF >>%s/etc/hosts\n", target_prefix()); write_etc_hosts(hosts); (void)fclose(hosts); scripting_fprintf(NULL, "EOF\n"); } if (del_rc_conf("defaultroute") == 0) add_rc_conf("defaultroute=\"%s\"\n", net_defroute); } else { /* * Start dhcpcd quietly and in master mode, but restrict * it to our interface */ add_rc_conf("dhcpcd=YES\n"); add_rc_conf("dhcpcd_flags=\"-qM %s\"\n", net_dev); } if (ifconf) fclose(ifconf); fflush(NULL); }