int start()
{
	int i,stret,cnt;
	clrscr();

	printf("PLEASE ENTER YOUR NAME:-\t");
	flushall();
	gets(name);

	for(i=1,cnt=0;i<=10;i++)
	{
		switch(i)
		{
		  case 1:  stret=mcq(1);
					break;
		  case 2:  stret=mcq(2);
					break;
		  case 3:  stret=fil_blnk(3);
					break;
		  case 4:  stret=tr_fl(4);
					break;
		  case 5:  stret=fil_blnk(5);
					break;
		  case 6:  stret=tr_fl(6);
					break;
		  case 7:  stret=numerical(7);
					break;
		  case 8:  stret=mcq(8);
					break;
		  case 9:  stret=fil_blnk(9);
					break;
		  case 10: stret=numerical(10);
		}
		if(stret==1)
			cnt++;
	}
	return cnt;
}
Beispiel #2
0
/* Installs a single succesfully downloaded PKGBUILD using makepkg -si
 * Assumes that the package has been extracted into its own directory
 *
 * returns 0 if installation is successful
 * returns -1 for errors, -2 for fatal errors
 */
static int install_single_package(char *pkgname)
{
	static const char choices[] = {'y', 'n', 'a', 'Y', 'N', 'A'};
	int ret;
	char cwd[PATH_MAX];
	char buf[PATH_MAX];
	char *dotinstall;
	pid_t pid;

	if (!getcwd(cwd, PATH_MAX)) {
		return error(PW_ERR_GETCWD);
	}

	if (chdir(pkgname)) {
		return error(PW_ERR_CHDIR, pkgname);
	}

	if (config->noconfirm) {
		goto fork_pacman;
	}

	/* Ask user to edit PKGBUILD */
	snprintf(buf, PATH_MAX, "Edit PKGBUILD for %s? [Y/n/a]", pkgname);
	ret = mcq(buf, choices, sizeof(choices) / sizeof(*choices), 0);

	switch (ret) {
	case 1:
		goto edit_dotinstall;
	case 2:
		/* Abort, propagate upwards */
		return -2;
	}

	/* Fork editor */
	pid = fork();
	if (pid == (pid_t) -1) {
		return error(PW_ERR_FORK_FAILED);
	} else if (pid == 0) {
		/* Open editor */
		execlp(powaur_editor, powaur_editor, "PKGBUILD", NULL);
	} else {
		ret = wait_or_whine(pid, "vim");
		if (ret) {
			return -1;
		}
	}

edit_dotinstall:
	/* First, check if we have .install file */
	dotinstall = have_dotinstall();
	if (dotinstall) {
		snprintf(buf, PATH_MAX, "Edit .install for %s? [Y/n/a]", pkgname);
		ret = mcq(buf, choices, sizeof(choices) / sizeof(*choices), 0);

		switch (ret) {
		case 1:
			goto fork_pacman;
		case 2:
			free(dotinstall);
			return -2;
		}

		pid = fork();
		if (pid == (pid_t) - 1) {
			return error(PW_ERR_FORK_FAILED);
		} else if (pid == 0) {
			execlp(powaur_editor, powaur_editor, dotinstall, NULL);
		} else {
			ret = wait_or_whine(pid, "vim");
			if (ret) {
				free(dotinstall);
				return -1;
			}
		}
	}

fork_pacman:
	free(dotinstall);

	if (!config->noconfirm && !yesno("Continue installing %s?", pkgname)) {
		return -2;
	}

	alpm_list_t *args = alpm_list_add(NULL, xstrdup("makepkg"));
	alpm_list_add(args, xstrdup("-si"));

	if (config->noconfirm) {
		alpm_list_add(args, xstrdup("--noconfirm"));
	}

	/* Check if we're root. Invoke makepkg with --asroot if so */
	uid_t myuid = geteuid();
	if (myuid == 0) {
		alpm_list_add(args, xstrdup("--asroot"));
	}

	char **argv = list_to_argv(args);
	pid = fork();
	if (pid == (pid_t) -1) {
		return error(PW_ERR_FORK_FAILED);
	} else if (pid == 0) {
		execvp("makepkg", argv);
	} else {
		/* Parent process */
		ret = wait_or_whine(pid, "makepkg");
		if (ret) {
			ret = -1;
			goto cleanup;
		}

		ret = 0;
	}

cleanup:
	free(argv);
	FREELIST(args);

	/* Change back to old directory */
	if (chdir(cwd)) {
		RET_ERR(PW_ERR_RESTORECWD, -2);
	}

	return ret;
}