[Frugalware-darcs] setup: new plugin: loadsource
VMiklos
vmiklos at frugalware.org
Fri Mar 31 00:49:23 CEST 2006
[new plugin: loadsource
VMiklos <vmiklos at frugalware.org>**20051104235459] {
hunk ./src/Makefile 6
-CFLAGS += $(FINAL)
+CFLAGS += $(FINAL) -DARCH=$(shell arch)
hunk ./src/plugins/Makefile 6
-CFLAGS += $(FINAL)
+CFLAGS += $(FINAL) -DARCH=$(shell arch)
hunk ./src/plugins/Makefile 11
-PLUGINS=asklang dolangsh greet layout hotplug
+PLUGINS=asklang dolangsh greet layout hotplug loadsource
hunk ./src/plugins/Makefile 34
+
+loadsource: loadsource.o ../util.o
+ $(CC) $(CFLAGS) -shared -Wl,-soname,loadsource.so -o 25loadsource.so \
+ loadsource.o ../util.o $(LDFLAGS)
addfile ./src/plugins/loadsource.c
hunk ./src/plugins/loadsource.c 1
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <dialog.h>
+
+#include <setup.h>
+#include <util.h>
+#include "common.h"
+
+plugin_t plugin =
+{
+ "loadsource",
+ run,
+ NULL // dlopen handle
+};
+
+plugin_t *info()
+{
+ return &plugin;
+}
+
+int umount_if_needed(char *sourcedir)
+{
+ FILE *fp;
+ char line[PATH_MAX];
+ char *dev=NULL;
+ int i;
+
+ if ((fp = fopen("/proc/mounts", "r")) == NULL)
+ {
+ perror(_("Could not open output file for writing"));
+ return(1);
+ }
+ while(!feof(fp))
+ {
+ if(fgets(line, 256, fp) == NULL)
+ break;
+ if(strstr(line, sourcedir))
+ {
+ for(i=0;i<strlen(line);i++)
+ if(line[i]==' ')
+ line[i]='\0';
+ dev = strdup(line);
+ }
+ }
+ fclose(fp);
+ if(dev != NULL)
+ system(g_strdup_printf("umount %s >%s 2>%s", dev, LOGDEV, LOGDEV));
+ return(0);
+}
+
+GList *extract_drives(char *line)
+{
+ char *p, *s;
+ GList *drives=NULL;
+
+ for (p=line+12;p!='\0';p=strstr(p+1, "\t"))
+ {
+ s = strdup(p+1);
+ drives = g_list_append(drives, s);
+ while(!isspace(*s))
+ s++;
+ *s='\0';
+ }
+ return(drives);
+}
+
+GList *grep_drives(char *file)
+{
+ FILE *fp;
+ char line[PATH_MAX];
+
+ if ((fp = fopen(file, "r")) == NULL)
+ {
+ perror(_("Could not open output file for writing"));
+ return(NULL);
+ }
+ while(!feof(fp))
+ {
+ if(fgets(line, 256, fp) == NULL)
+ break;
+ if(line == strstr(line, "drive name:"))
+ {
+ return(extract_drives(line));
+ }
+ }
+ fclose(fp);
+ return(NULL);
+}
+
+
+int run(GList **config)
+{
+ GList *drives=NULL;
+ int i;
+
+ 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++)
+ {
+ if (!system(g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s >%s 2>%s", (char*)g_list_nth_data(drives, i), SOURCEDIR, LOGDEV, LOGDEV)))
+ {
+ data_put(config, "srcdev", (char*)g_list_nth_data(drives, i));
+ // TODO: is this a netinstall cd?
+ 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);
+ sleep(3);
+ break;
+ }
+ if(data_get(*config, "srcdev")==NULL)
+ {
+ dialog_msgbox(_("CD/DVD drive not found"), _("Sorry, no Frugalware install disc was found in your drives. Press ENTER to reboot."), 0, 0, 1);
+ exit_perform();
+ }
+ }
+
+ return(0);
+}
hunk ./src/setup.h 10
+#define SOURCEDIR "/mnt/source"
}
More information about the Frugalware-darcs
mailing list