Exemplo n.º 1
0
int run_discs_detection(GList **config)
{
	GList *drives=NULL;
	int i;
	int found = 0;
	char *ptr;

	umount_if_needed(SOURCEDIR);
    makepath(SOURCEDIR);

	drives = grep_drives("/proc/sys/dev/cdrom/info");
	for (i = 0; i < g_list_length(drives); i++) {
		ptr = get_blkid((char*)g_list_nth_data(drives, i));
		if(ptr && !strcmp(ptr, "Frugalware Install")) {
			LOG("install medium found in %s", (char*)g_list_nth_data(drives, i));
			free(ptr);
			ptr = g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s",
				(char*)g_list_nth_data(drives, i),
				SOURCEDIR);
			fw_system(ptr);
			free(ptr);

			if(!is_netinstall(SOURCEDIR)) {
				data_put(config, "srcdev", (char*)g_list_nth_data(drives, i));
				found = 1;
				break;
			}
		} else {
			LOG("skipping non-install medium in %s", (char*)g_list_nth_data(drives, i));
        }
	}

	return found;
}
Exemplo n.º 2
0
int setcharset(char *name, GList **config)
{
	char *ptr;

	//TODO: maybe there is a proper system call for this?
	ptr = g_strdup_printf("setfont %s", name);
	fw_system(ptr);
	FREE(ptr);
	// save the font for later usage
	data_put(config, "font", strdup(name));
	return(0);
}
Exemplo n.º 3
0
int run(GList **config)
{
	char *fn;
	FILE* fp;
	GtkTreeModel *model = NULL;
	GtkTreeIter iter;
	char *laycons, *xlayout, *xvariant;

	GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(viewlayout));
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(viewlayout));

	if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
		gtk_tree_model_get (model, &iter, 1, &xlayout, 2, &xvariant, 3, &laycons, -1);
	}

	/* Create /sysconfig/keymap temporary file */
	fn = strdup("/tmp/setup_XXXXXX");
	mkstemp(fn);
	if ((fp = fopen(fn, "w")) == NULL) {
		perror(_("Could not open output file for writing"));
		return(1);
	}
	fprintf(fp, "# /etc/sysconfig/keymap\n\n"
		"# specify the keyboard map, maps are in "
		"/usr/share/keymaps\n\n");
	if(strstr(laycons, "/"))
		fprintf(fp, "keymap=%s\n", strstr(laycons, "/")+1);

	fclose(fp);

	/* Put data in config */
	data_put(config, "keymap", fn);
	data_put(config, "xlayout", strdup(xlayout));
	data_put(config, "xvariant", strdup(xvariant));

	return 0;
}
Exemplo n.º 4
0
int run(GList **config)
{
	GList *partlist;
	char **nrdevs, *ptr, *op, *np, *dest;
	int ret;
	char my_buffer[MAX_LEN + 1] = "";

	detect_parts(0);

	// select swap partitions to use
	partlist = selswap();

	// format swap partitions
	if(doswap(partlist, config) == -1)
		return(-1);

	// root partition
	ptr = selrootdev();
	if(ptr == NULL)
		return(-1);
	if(formatdev(ptr) == -1)
		return(-1);
	mountdev(ptr, "/", config);

	// move temporarily stuff to the final location
	chdir(TARGETDIR);
	np = g_strdup_printf("%s/%s", TARGETDIR, "/etc/profile.d");
	makepath(np);
	FREE(np);
	op = (char*)data_get(*config, "fstab");
	np = g_strdup_printf("%s/%s", TARGETDIR, "/etc/fstab");
	copyfile(op, np);
	unlink(op);
	chmod (np, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
	data_put(config, "fstab", strdup(np));
	FREE(np);

	np = g_strdup_printf("%s/%s", TARGETDIR, "/etc/sysconfig");
	makepath(np);
	FREE(np);

	// so that 1) the user can't mount a partition as /dev because
	// it'll be used 2) install scriptlets will be able to do
	// >/dev/null
	makepath(TARGETDIR "/dev");
	makepath(TARGETDIR "/proc");
	makepath(TARGETDIR "/sys");
	fw_system("mount none -t devtmpfs " TARGETDIR "/dev");
	fw_system("mount none -t proc " TARGETDIR "/proc");
	fw_system("mount none -t sysfs " TARGETDIR "/sys");

	// non-root partitions
	dialog_vars.backtitle=gen_backtitle(_("Selecting other partitions"));
	while(1)
	{
		dialog_vars.input_result = my_buffer;
		nrdevs = parts2dialog(parts);
		dlg_put_backtitle();
		dlg_clear();
		dialog_vars.cancel_label = _("Continue");
		dialog_vars.input_result = my_buffer;
		dialog_vars.input_result[0]='\0';
		ret = dialog_menu(
		_("Select other Linux partitions for /etc/fstab"),
		_("You may use your other partitions to distribute your Linux "
		"system across more than one partition. Currently, you have "
		"only mounted your / partition. You might want to mount "
		"directories such as /boot, /home or /usr/local on separate "
		"partitions. You should not try to mount /usr, /etc, /sbin or "
		"/bin on their own partitions since they contain utilities "
		"needed to bring the system up and mount partitions. Also, "
		"do not reuse a partition that you've already entered before. "
		"Please select one of the partitions listed below, or if "
		"you're done, hit Continue."),
		0, 0, 0, g_list_length(parts)/2, nrdevs);
		dialog_vars.cancel_label = '\0';
		FREE(nrdevs);
		if (ret != DLG_EXIT_CANCEL)
		{
			if(!strcmp(_("(in use)"), dialog_vars.input_result))
				continue;
			ptr = strdup(dialog_vars.input_result);
			if(formatdev(ptr) == -1)
				return(-1);
			dest = asktowhere(ptr);
			if(dest == NULL)
				return(-1);
			mountdev(ptr, dest, config);
			FREE(dest);
			FREE(ptr);
		}
		else
			break;
	}

	makepath(g_strdup_printf("%s/%s", TARGETDIR, "/var/log"));
	np = g_strdup_printf("%s/%s", TARGETDIR, LOGFILE);
	copyfile(LOGFILE, np);
	unlink(LOGFILE);
	chmod (np, S_IRUSR|S_IWUSR);
	FREE(np);

	// disable caching for cds
	// this is needed here since when the cds is loaded we had no
	// formatted root partition
	if((char*)data_get(*config, "netinstall")==NULL)
	{
		char *pacbindir = g_strdup_printf("%s/frugalware-%s", SOURCEDIR, ARCH);
		char *ptr;

		ptr = g_strdup_printf("%s/var/cache/pacman-g2/pkg", TARGETDIR);
		makepath(ptr);
		FREE(ptr);
		disable_cache(pacbindir);
		FREE(pacbindir);
	}
	return(0);
}
Exemplo n.º 5
0
int doswap(GList *partlist, GList **config)
{
	char *fn, *item, *ptr;
	FILE* fp;
	int i;

	// create an initial fstab
	fn = strdup("/tmp/setup_XXXXXX");
	mkstemp(fn);
	if ((fp = fopen(fn, "wb")) == NULL)
	{
		perror(_("Could not open output file for writing"));
		FREE(fn);
		return(-1);
	}
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"none", "/proc", "proc", "defaults", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"none", "/sys", "sysfs", "defaults", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"devpts", "/dev/pts", "devpts", "gid=5,mode=620", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"usbfs", "/proc/bus/usb", "usbfs", "devgid=23,devmode=664", "0", "0");
	fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
		"tmpfs", "/dev/shm", "tmpfs", "defaults", "0", "0");

	// format the partitions
	for (i=0; i<g_list_length(partlist); i++)
	{
		char *tmp;
		dialog_vars.input_result[0]='\0';
		item = strdup((char*)g_list_nth_data(partlist, i));
		ptr = selmkswapmode(item);
		if(ptr == NULL)
			return(-1);
		if(!strcmp("format", ptr))
		{
			tmp = g_strdup_printf(_("Formatting %s as a swap "
						"partition"), item);
			fw_info(_("Formatting swap partition"), tmp);
			FREE(tmp);
			tmp = g_strdup_printf("%s %s", MKSWAP, item);
			fw_system(tmp);
			FREE(tmp);
		}
		else if (!strcmp("check", ptr))
		{
			tmp = g_strdup_printf(_("Formatting %s as a swap "
						"partition and checking for bad blocks"), item);
			fw_info(_("Formatting swap partition"), tmp);
			FREE(tmp);
			tmp = g_strdup_printf("%s -c %s", MKSWAP, item);
			fw_system(tmp);
			FREE(tmp);
		}
		ptr = g_strdup_printf("%s %s", SWAPON, item);
		fw_system(ptr);
		FREE(ptr);
		char *uuid = get_uuid(item);
		fprintf(fp, "%-16s %-16s %-11s %-16s %-3s %s\n",
			uuid, "swap", "swap", "defaults", "0", "0");
		free(uuid);
	}

	fclose(fp);

	// save fstab location for later
	data_put(config, "fstab", fn);
	// re-detect parts so that new swap partitions will recognized as swap
	// partitions
	detect_parts(0);
	return(0);
}
Exemplo n.º 6
0
int run(GList **config)
{
	char *fn;
	FILE* fp;

	GtkTreeModel *model = NULL;
	GtkTreeIter iter;
	char* selected;
	GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(GTK_TREE_VIEW(view)));
	if(gtk_tree_selection_get_selected(selection, &model, &iter))
	{
		gtk_tree_model_get (model, &iter, COLUMN_LANG_CODE, &selected, -1);
	}
	else
		selected = "en_US";

	setenv("LC_ALL", selected, 1);
	setenv("LANG", selected, 1);
	setenv("LANGUAGE", selected, 1);
	/* setlocale with tr_TR create some weird errors */
	setlocale(LC_ALL, selected);
	/* workaround for turkish lang */
	if(!strcmp(selected, "tr_TR"))
		setlocale(LC_CTYPE, "C");

	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

	if(!strcmp("en_US", selected))
		setenv("CHARSET", "iso-8859-1", 1);
	else if(!strcmp("es_AR", selected))
	{
		setenv("CHARSET", "iso-8859-1", 1);
		setcharset("lat1-16.psfu.gz", config);
	}
	else if(!strcmp("de_DE", selected))
		setenv("CHARSET", "iso-8859-15", 1);
	else if(!strcmp("fr_FR", selected))
		setenv("CHARSET", "iso-8859-15", 1);
        else if(!strcmp("id_ID", selected))
		setenv("CHARSET", "iso-8859-1", 1);
	else if(!strcmp("it_IT", selected))
	{
		setenv("CHARSET", "iso-8859-1", 1);
		setcharset("lat9w-16.psfu.gz", config);
	}
	else if(!strcmp("cs_CZ", selected))
	{
		setenv("CHARSET", "iso-8859-2", 1);
		setcharset("lat2-16.psfu.gz", config);
	}
	else if(!strcmp("hu_HU", selected))
	{
		setenv("CHARSET", "iso-8859-2", 1);
		setcharset("lat2-16.psfu.gz", config);
	}
	else if(!strcmp("nl_NL", selected))
		setenv("CHARSET", "iso-8859-1", 1);
	else if(!strcmp("pl_PL", selected))
	{
		setenv("CHARSET", "iso-8859-2", 1);
		setcharset("lat2-16.psfu.gz", config);
	}
	else if(!strcmp("pt_PT", selected))
	{
		setenv("CHARSET", "iso-8859-1", 1);
		setcharset("lat1-16.psfu.gz", config);
	}
	else if(!strcmp("sk_SK", selected))
	{
		setenv("CHARSET", "iso-8859-2", 1);
		setcharset("lat2-16.psfu.gz", config);
	}
	else if(!strcmp("tr_TR", selected))
	{
		setenv("CHARSET", "iso-8859-9", 1);
	}

	//* Create language files *//
	fn = strdup("/tmp/setup_XXXXXX");
	mkstemp(fn);
	if ((fp = fopen(fn, "w")) == NULL)
	{
		perror(_("Could not open output file for writing"));
		return(-1);
	}
	fprintf(fp, "#!/bin/sh\n\n"
		"# /etc/profile.d/lang.sh\n\n"
		"# Set the system locale\n"
		"# For a list of locales which are supported by this machine, "
		"type: locale -a\n\n");
	if(!getenv("LANG") || strcmp(getenv("LANG"), "zh_CN"))
		fprintf(fp, "export LANG=%s\n", getenv("LANG"));
	else
	{
		fprintf(fp, "if [ \"$TERM\" = \"linux\" ]; then\n\techo -ne \"\\e%%G\"\nfi\n");
		fprintf(fp, "export LANG=zh_CN.utf8\n");
	}
	fprintf(fp, "export LC_ALL=$LANG\n");
	if(getenv("CHARSET"))
		fprintf(fp, "export CHARSET=%s\n", getenv("CHARSET"));
	fclose(fp);

	// sample: adds a "content" string titled "stuff" to the config list
	data_put(config, "lang.sh", fn);
	return 0;
}
Exemplo n.º 7
0
int run(GList **config)
{
	GList *drives=NULL;
	int i;
	int found = 0;
	char *ptr;

	umount_if_needed(SOURCEDIR);

	dialog_vars.backtitle=gen_backtitle(_("Selecting source media"));
	dlg_put_backtitle();
	dlg_clear();
	dialog_msgbox(_("Scanning"), _("Scanning for a CD/DVD drive containing "
		"a Frugalware install disc..."), 0, 0, 0);
	
	drives = grep_drives("/proc/sys/dev/cdrom/info");
	for (i=0; i<g_list_length(drives); i++)
	{
		ptr = get_blkid((char*)g_list_nth_data(drives, i));
		if(ptr && !strcmp(ptr, "Frugalware Install"))
		{
			LOG("install medium found in %s", (char*)g_list_nth_data(drives, i));
			FREE(ptr);
			ptr = g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s", (char*)g_list_nth_data(drives, i),
					SOURCEDIR);
			fw_system(ptr);
			data_put(config, "srcdev", (char*)g_list_nth_data(drives, i));
			dlg_put_backtitle();
			dialog_msgbox(_("CD/DVD drive found"), g_strdup_printf(_("A Frugalware install disc was found in device /dev/%s."), (char*)g_list_nth_data(drives, i)), 0, 0, 0);
			if(is_netinstall(SOURCEDIR))
			{
				data_put(config, "netinstall", "");
				LOG("install medium contains no packages, performing a network installation");
			}
			else
				LOG("install medium contains packages, performing an offline installation");
			found = 1;
			break;
		}
		else
			LOG("skipping non-install medium in %s", (char*)g_list_nth_data(drives, i));
		FREE(ptr);
	}
	if(!found)
	{
		LOG("no package database found, performing a network installation");
		data_put(config, "netinstall", "");
	}
	// disable caching for cds
	if((char*)data_get(*config, "netinstall")==NULL)
	{
		char *pacbindir = g_strdup_printf("%s/frugalware-%s", SOURCEDIR, ARCH);
		disable_cache(pacbindir);
		FREE(pacbindir);
	}
	if(data_get(*config, "srcdev")==NULL)
	{
		LOG("no cd/dvd drive found, this is normal if you are running setup from a pendrive or in an emulator");
	}
	return(0);
}
Exemplo n.º 8
0
int run(GList **config)
{
	char **array;
	char *fn, *ptr, *layout;
	FILE* fp;
	int ret = 0;
	
	if (layoutl)
	{
		g_list_free(layoutl);
		layoutl = NULL;
	}
	find("/usr/share/keymaps/i386");
	layoutl = g_list_sort(layoutl, sort_layouts);
	array = glist4dialog(layoutl, "");
	
	dialog_vars.backtitle=gen_backtitle(_("Configuring the keyboard"));
	dlg_put_backtitle();
	dlg_clear();
	/* this string should be the best keyboard layout for the given
	 * language from /usr/share/keymaps/i386 */
	dialog_vars.default_item=strdup(_("qwerty/us.map.gz"));
	if(fw_menu(_("Keyboard map selection"),
		_("You may select one of the following keyboard maps. If you "
		"do not select a keyboard map, 'qwerty/us.map.gz' (the US "
		"keyboard map) is the default. Use the UP/DOWN arrow keys and "
		"PageUp/PageDown to scroll through the whole list of choices."),
		0, 0, 0, g_list_length(layoutl), array) == -1)
		ret = -1;
	FREE(dialog_vars.default_item);
	if(ret == -1)
		return(ret);
	layout=strdup(dialog_vars.input_result);

	FREE(array);
	// drop .map.gz
	if(strlen(layout) >= 7)
		layout[strlen(layout)-7]='\0';
	
	//TODO: maybe there is a proper system call for this?
	LOG("selected layout '%s'", layout);
	ptr = g_strdup_printf("loadkeys /usr/share/keymaps/i386/%s.map.gz", layout);
	fw_system(ptr);
	FREE(ptr);
	
	fn = strdup("/tmp/setup_XXXXXX");
	mkstemp(fn);
	if ((fp = fopen(fn, "w")) == NULL)
	{
		perror(_("Could not open output file for writing"));
		return(1);
	}
	fprintf(fp, "# /etc/vconsole.conf\n\n"
		"# specify the keyboard map, maps are in "
		"/usr/share/keymaps\n\n");
	if(strstr(layout, "/"))
		fprintf(fp, "KEYMAP=%s\n", strstr(layout, "/")+1);
	fprintf(fp,"\n# specify the console font\nFONT=lat1-16.psfu.gz\n");
	FREE(layout);
	fclose(fp);

	data_put(config, "vconsole.conf", fn);
	return(0);
}
Exemplo n.º 9
0
static int sqlite3_add_sysinfo(void *storage, struct system *sys)
{
	struct sqlite3_data *d = (struct sqlite3_data *) storage;
	char **stmt = &d->stmt;
	size_t *stmt_len = &d->stmt_size;
	char **buf1 = &d->buf1;
	size_t *buf1_len = &d->buf1_size;
	const struct header *hdr;
	struct data *dat;
	char system_cpu_sha[65];
	sha256_context ctx;
	sqlite3_stmt *sqstmt;
	int ret;
	int i;

	d->sys_sha = sys->sha256;

	hdr = system_info_hdr(sys);
	if (!hdr) {
		printk(KERN_ERR "Failed to get system header\n");
		return -1;
	}

	ret = sqlite3_alter_by_hdr("system", d, hdr, "cpus_sha,system_sha UNIQUE PRIMARY KEY");
	if (ret) {
		goto error;
	}

	ret = sqlite3_prepare_insert_stmt(d->db, &sqstmt, stmt, stmt_len, buf1,
			buf1_len, "system", hdr, "system_sha,cpus_sha", 2);
	if (ret) {
		printk(KERN_ERR "Failed to prepare statement\n");
		return -1;
	}

	dat = system_info_data(sys);
	if (!dat) {
		printk(KERN_ERR "Failed getting system info data\n");
		goto error;
	}

	ret = sqlite3_bind_text(sqstmt, 1, sys->sha256, -1, SQLITE_STATIC);
	ret |= sqlite3_bind_text(sqstmt, 2, sys->hw.cpus_sha256, -1, SQLITE_STATIC);
	ret |= sqlite3_bind_data(sqstmt, 3, dat);
	if (ret != SQLITE_OK) {
		printk(KERN_ERR "Failed binding all values for system info\n");
		goto error;
	}

	ret = sqlite3_step(sqstmt);
	data_put(dat);
	if (ret != SQLITE_DONE) {
		printk(KERN_ERR "Failed inserting system data (%s): %s\n",
				*stmt, sqlite3_errmsg(d->db));
		goto error;
	}
	sqlite3_finalize(sqstmt);
	sqstmt = NULL;

	hdr = system_cpu_type_hdr(sys->hw.cpus);
	if (!hdr) {
		printk(KERN_ERR "Failed to get system cpu type header\n");
		goto error;
	}

	ret = sqlite3_alter_by_hdr("cpu_type", d, hdr, "cpu_type_sha UNIQUE PRIMARY KEY");
	if (ret) {
		printk(KERN_ERR "Failed to alter system_cpus\n");
		goto error;
	}

	ret = sqlite3_prepare_insert_stmt(d->db, &sqstmt, stmt, stmt_len, buf1,
			buf1_len, "cpu_type", hdr, "cpu_type_sha", 1);
	if (ret) {
		printk(KERN_ERR "Failed to prepare statement for cpu_type\n");
		goto error;
	}

	for (i = 0; i != sys->hw.nr_cpus; ++i) {
		struct system_cpu *cpu = &sys->hw.cpus[i];

		dat = system_cpu_type_data(cpu);
		if (!dat) {
			printk(KERN_ERR "Failed to get system cpu type values for %d\n", i);
			goto error;
		}

		ret = sqlite3_bind_text(sqstmt, 1, cpu->type_sha256, -1, SQLITE_STATIC);
		ret |= sqlite3_bind_data(sqstmt, 2, dat);
		if (ret != SQLITE_OK) {
			printk(KERN_ERR "Failed binding cputype to sqlstatement\n");
			goto error;
		}

		ret = sqlite3_step(sqstmt);
		data_put(dat);
		if (ret != SQLITE_DONE) {
			printk(KERN_ERR "Failed executing statement for system cpu\n");
			goto error;
		}

		sqlite3_reset(sqstmt);
	}
	sqlite3_finalize(sqstmt);
	sqstmt = NULL;


	hdr = system_cpu_hdr(sys->hw.cpus);
	if (!hdr) {
		printk(KERN_ERR "Failed to get system cpu type header\n");
		goto error;
	}

	ret = sqlite3_alter_by_hdr("system_cpu", d, hdr, "sha UNIQUE PRIMARY KEY,cpus_sha,cpu_type_sha");
	if (ret) {
		printk(KERN_ERR "Failed to alter system_cpus\n");
		goto error;
	}

	ret = sqlite3_prepare_insert_stmt(d->db, &sqstmt, stmt, stmt_len, buf1,
			buf1_len, "system_cpu", hdr, "cpus_sha, sha, cpu_type_sha",
			3);
	if (ret) {
		printk(KERN_ERR "Failed to prepare statement for system_cpu\n");
		goto error;
	}

	for (i = 0; i != sys->hw.nr_cpus; ++i) {
		struct system_cpu *cpu = &sys->hw.cpus[i];

		sha256_starts(&ctx);
		sha256_add_str(&ctx, sys->hw.cpus_sha256);
		sha256_add_str(&ctx, cpu->type_sha256);
		sha256_add_str(&ctx, cpu->sha256);
		sha256_finish_str(&ctx, system_cpu_sha);

		dat = system_cpu_data(cpu);
		if (!dat) {
			printk(KERN_ERR "Failed to get system cpu type values for %d\n", i);
			goto error;
		}


		ret = sqlite3_bind_text(sqstmt, 1, sys->hw.cpus_sha256, -1, SQLITE_STATIC);
		ret |= sqlite3_bind_text(sqstmt, 2, cpu->sha256, -1, SQLITE_STATIC);
		ret |= sqlite3_bind_text(sqstmt, 3, cpu->type_sha256, -1, SQLITE_STATIC);
		ret |= sqlite3_bind_data(sqstmt, 4, dat);
		if (ret != SQLITE_OK) {
			data_put(dat);
			goto error;
		}

		ret = sqlite3_step(sqstmt);
		data_put(dat);
		if (ret != SQLITE_DONE) {
			printk(KERN_ERR "Failed to insert cpu: %s\n",
					sqlite3_errmsg(d->db));
			goto error;
		}
		sqlite3_reset(sqstmt);
	}
	sqlite3_finalize(sqstmt);
	return 0;
error:
	if (sqstmt)
		sqlite3_finalize(sqstmt);
	return -1;
}