Example #1
0
/*
 * hook called after upgrade() or install() has finished setting
 * up the target disk but immediately before the user is given the
 * ``disks are now set up'' message..
 *
 * On mvme68k, we use this opportunity to install the boot blocks.
 */
int
md_post_newfs(void)
{

	/* boot blocks ... */
	msg_display(MSG_dobootblks, diskdev);
	cp_to_target("/usr/mdec/bootsd", "/.bootsd");
	if (run_program(RUN_DISPLAY | RUN_NO_CLEAR,
	    "/usr/mdec/installboot %s /usr/mdec/bootxx /dev/r%sa",
	    target_expand("/.bootsd"), diskdev))
		process_menu(MENU_ok,
			deconst("Warning: disk is probably not bootable"));
	return 0;
}
Example #2
0
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;
}
Example #3
0
int
move_aout_libs(void)
{
	int n, backedup = 0;
	char prefix[MAXPATHLEN], src[MAXPATHLEN];
	struct stat st;

	n = handle_aout_libs(target_expand("/usr/lib"), LIB_COUNT, NULL);
	if (n <= 0)
		return n;

	/*
	 * See if /emul/aout already exists, taking symlinks into
	 * account. If so, no need to create it, just use it.
	 */
	if (target_realpath("/emul/aout", prefix) != NULL && stat(prefix, &st) == 0)
		goto domove;

	/*
	 * See if /emul exists. If not, create it.
	 */
	if (target_realpath("/emul", prefix) == NULL || stat(prefix, &st) < 0) {
		strlcpy(prefix, target_expand("/emul"), sizeof(prefix));
		if (lstat(prefix, &st) == 0) {
			run_program(0, "mv -f %s %s", prefix,
			    target_expand("/emul.old"));
			backedup = 1;
		}
		scripting_fprintf(NULL, "mkdir %s\n", prefix);
		mkdir(prefix, 0755);
	}

	/*
	 * Can use strcpy, target_expand has made sure it fits into
	 * MAXPATHLEN. XXX all this copying is because concat_paths
	 * returns a pointer to a static buffer.
	 *
	 * If an old aout link exists (apparently pointing to nowhere),
	 * move it out of the way.
	 */
	strlcpy(src, concat_paths(prefix, "aout"), sizeof(src));
	if (lstat(src, &st) == 0) {
		run_program(0, "mv -f %s %s", src,
		    concat_paths(prefix, "aout.old"));
		backedup = 1;
	}

	/*
	 * We have created /emul if needed. Since no previous /emul/aout
	 * existed, we'll use a symbolic link in /emul to /usr/aout, to
	 * avoid overflowing the root partition.
	 */
	strlcpy(prefix, target_expand("/usr/aout"), sizeof(prefix));
	if (run_program(0, "mkdir -p %s", prefix))
		abort_libupdate();
	if (run_program(0, "ln -s %s %s", "/usr/aout", src))
		abort_libupdate();

domove:
	/*
	 * Rename etc and usr/lib if they already existed, so that we
	 * do not overwrite old files.
	 *
	 * Then, move /etc/ld.so.conf to /emul/aout/etc/ld.so.conf,
	 * and all a.out dynamic libraries from /usr/lib to
	 * /emul/aout/usr/lib. This is where the a.out code in ldconfig
	 * and ld.so respectively will find them.
	 */
	strlcpy(src, concat_paths(prefix, "usr/lib"), sizeof(src));
	run_program(0, "mv -f %s %s", src, concat_paths(prefix, "usr/lib.old"));
	strlcpy(src, concat_paths(prefix, "etc/ld.so.conf"), sizeof(src));
	run_program(0, "mv -f %s %s",
	    src, concat_paths(prefix, "etc/ld.so.conf.old"));
	if (run_program(0, "mkdir -p %s ", concat_paths(prefix, "usr/lib")))
		abort_libupdate();
	if (run_program(0, "mkdir -p %s ", concat_paths(prefix, "etc")))
		abort_libupdate();

	strlcpy(src, target_expand("/etc/ld.so.conf"), sizeof(src));
	if (run_program(0, "mv -f %s %s",
	    src, concat_paths(prefix, "etc/ld.so.conf")))
		abort_libupdate();

	strlcpy(src, target_expand("/usr/lib"), sizeof(src));
	n = handle_aout_libs(src, LIB_MOVE, concat_paths(prefix, "usr/lib"));

	if (run_program(0, "mkdir -p %s ",
	    concat_paths(prefix, "usr/X11R6/lib")))
		abort_libupdate();

	strlcpy(src, target_expand("/usr/X11R6/lib"), sizeof(src));
	handle_aout_x_libs(src, concat_paths(prefix, "usr/X11R6/lib"));

	if (backedup) {
		msg_display(MSG_emulbackup);
		process_menu(MENU_ok, NULL);
	}

	return n;
}