Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwife.git;a=commitdiff;h=7e2846a399a02c6aff779bb546c20c268c5972c0

commit 7e2846a399a02c6aff779bb546c20c268c5972c0
Author: Elentir <elen...@frugalware.org>
Date:   Sun Jan 23 11:55:51 2011 +0100

add support for install from cd/dvd

diff --git a/configure.ac b/configure.ac
index 8b010d2..9c820b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,6 +96,7 @@ AC_CHECK_LIB([fwtimeconfig], [fwtime_find], 
[PLUGINS_LIBS="$PLUGINS_LIBS -lfwtim
AC_CHECK_LIB([fwutil], [fwutil_init], [PLUGINS_LIBS="$PLUGINS_LIBS -lfwutil"])
AC_CHECK_LIB([pacman], [pacman_initialize], [PLUGINS_LIBS="$PLUGINS_LIBS 
-lpacman"])
AC_CHECK_LIB([parted], [ped_device_read], [PLUGINS_LIBS="$PLUGINS_LIBS 
-lparted"])
+AC_CHECK_LIB([blkid], [blkid_new_probe], [PLUGINS_LIBS="$PLUGINS_LIBS 
-lblkid"])

AC_SUBST(PLUGINS_LIBS)

diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index d095699..a6d476d 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -26,7 +26,7 @@ asklang_la_SOURCES = asklang.c
asklang_la_LDFLAGS = -module -avoid-version -shared
asklang_la_LIBADD = @LIBS@ @GTK_LIBS@ @PLUGINS_LIBS@

-configsource_la_SOURCES = configsource.c configsource-network.c
+configsource_la_SOURCES = configsource.c configsource-network.c 
configsource-discs.c
configsource_la_LDFLAGS = -module -avoid-version -shared
configsource_la_LIBADD = @LIBS@ @GTK_LIBS@ @PLUGINS_LIBS@

diff --git a/src/plugins/configsource-discs.c b/src/plugins/configsource-discs.c
new file mode 100644
index 0000000..4b5016b
--- /dev/null
+++ b/src/plugins/configsource-discs.c
@@ -0,0 +1,181 @@
+/*
+ *  configsource-discs.c for Fwife
+ *
+ *  Copyright (c) 2011 by Albar Boris <bori...@cegetel.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <gtk/gtk.h>
+#include <sys/stat.h>
+#include <blkid/blkid.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "common.h"
+
+#define BLKGETSIZE64 _IOR(0x12,114,size_t)
+
+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 is_netinstall(char *path)
+{
+       struct stat statbuf;
+       char *ptr;
+       int ret;
+
+       ptr = g_strdup_printf("%s/frugalware-%s", path, ARCH);
+       if(!stat(ptr, &statbuf)
+               && S_ISDIR(statbuf.st_mode))
+               ret = 0;
+       else
+               ret = 1;
+
+       free(ptr);
+       return(ret);
+}
+
+static char* get_blkid(char *device)
+{
+       int fd;
+       blkid_probe pr = NULL;
+       uint64_t size;
+       const char *label;
+       char *ret;
+       char path[PATH_MAX];
+
+       if(!device || !strlen(device))
+               return NULL;
+
+       snprintf(path, PATH_MAX, "/dev/%s", device);
+
+       fd = open(path, O_RDONLY);
+       if(fd<0)
+               return NULL;
+       pr = blkid_new_probe ();
+       blkid_probe_set_request (pr, BLKID_PROBREQ_LABEL);
+       ioctl(fd, BLKGETSIZE64, &size);
+       blkid_probe_set_device (pr, fd, 0, size);
+       blkid_do_safeprobe (pr);
+       blkid_probe_lookup_value(pr, "LABEL", &label, NULL);
+       ret = strdup(label);
+       blkid_free_probe (pr);
+       close(fd);
+       return ret;
+}
+
+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);
+                       data_put(config, "srcdev", 
(char*)g_list_nth_data(drives, i));
+
+                       if(!is_netinstall(SOURCEDIR)) {
+                               found = 1;
+                               break;
+                       }
+               } else {
+                       LOG("skipping non-install medium in %s", 
(char*)g_list_nth_data(drives, i));
+        }
+       }
+
+       return found;
+}
+
+int run_discs_config(GList **config)
+{
+       int ret = fwife_question(_("Do you want to search for a installation 
CD/DVD?\n\n"
+                       "If you want an installation from a CD/DVD, you should 
answer 'Yes'.\n"
+                       "Otherwise if you want a network installation, you 
should answer 'No'"));
+
+       /* if the user whant a cd/dvd install */
+       if(ret == GTK_RESPONSE_YES) {
+               if(run_discs_detection(config)) {
+                       char *pacbindir = g_strdup_printf("%s/frugalware-%s", 
SOURCEDIR, ARCH);
+                       disable_cache(pacbindir);
+                       FREE(pacbindir);
+                       skip_to_next_plugin();
+            return 1;
+               } else {
+                       fwife_error("No package database found.\nPerforming a 
network installation.");
+               }
+       }
+
+       return 0;
+}
diff --git a/src/plugins/configsource.c b/src/plugins/configsource.c
index 3f17b76..93da736 100644
--- a/src/plugins/configsource.c
+++ b/src/plugins/configsource.c
@@ -2,7 +2,7 @@
*  configsource.c for Fwife
*
*  Copyright (c) 2005 by Miklos Vajna <vmik...@frugalware.org>
- *  Copyright (c) 2008,2009,2010 by Albar Boris <bori...@cegetel.net>
+ *  Copyright (c) 2008,2009,2010,2011 by Albar Boris <bori...@cegetel.net>
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
@@ -36,14 +36,15 @@

#include "common.h"

-static GList *mirrorlist = NULL;
+static GList *mirrorlist;

-static GtkWidget *viewserver = NULL;
-static char *PACCONF = NULL;
+static GtkWidget *viewserver;
+char *PACCONF;

extern GtkWidget *assistant;

int run_net_config(GList **config);
+int run_discs_config(GList **config);
int is_connected(char *host, int port, int timeouttime);

enum
@@ -306,6 +307,9 @@ int prerun(GList **config)
// get the branch used
PACCONF = data_get(*config, "pacconf");

+       if(run_discs_config(config) == 1)
+               return 0;
+
while(run_net_config(config) == -1) {}

if(mirrorlist == NULL) {
@@ -339,6 +343,7 @@ int prerun(GList **config)
free(testurl);
}
}
+
return 0;
}

@@ -348,6 +353,9 @@ int run(GList **config)
gboolean toggled;
GList *newmirrorlist = NULL;

+       if(data_get(*config, "srcdev") != NULL)
+               return 0;
+
GtkTreeIter iter;
GtkTreeView *treeview = (GtkTreeView *)viewserver;
GtkTreeModel *model = gtk_tree_view_get_model (treeview);
diff --git a/src/plugins/install.c b/src/plugins/install.c
index 8fa7ec8..f3dfa5f 100644
--- a/src/plugins/install.c
+++ b/src/plugins/install.c
@@ -1,7 +1,7 @@
/*
*  install.c for Fwife
*
- *  Copyright (c) 2008,2009,2010 by Albar Boris <bori...@cegetel.net>
+ *  Copyright (c) 2008,2009,2010,2011 by Albar Boris <bori...@cegetel.net>
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
@@ -250,7 +250,7 @@ void progress_event(unsigned char event, void *data1, void 
*data2)
return;
}

-int installpkgs(GList *pkgs)
+int install_pkgs(GList *pkgs)
{
int i = 0, questret;
PM_LIST *pdata = NULL, *pkgsl;
@@ -362,6 +362,55 @@ retry:     if(pacman_trans_init(PM_TRANS_TYPE_SYNC, 
PM_TRANS_FLAG_FORCE|PM_TRANS_FLA
return 0;
}

+int install_pkgs_discs(GList *pkgs, char *srcdev)
+{
+       int i, first = 1, ret;
+
+       while(pkgs) {
+               GList *list = NULL;
+               struct stat buf;
+               char *ptr;
+
+               if(first) {
+                       // for the first time the volume is already loaded
+                       first = 0;
+               } else {
+                       eject(srcdev, SOURCEDIR);
+                       ret = fwife_question(_("Please insert the next 
Frugalware install disc and press "
+                                                               "ENTER to 
continue installing packages. If you don't "
+                                                               "have more 
discs, choose NO, and then you can finish  "
+                                                               "the 
installation. Have you inserted the next disc?"));
+                       if(ret == GTK_RESPONSE_NO)
+                               return 0;
+
+            ptr = g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s",
+                               srcdev,
+                               SOURCEDIR);
+                       fw_system(ptr);
+            free(ptr);
+        }
+
+               // see what packages can be useful from this volume
+               for(i = 0; i < g_list_length(pkgs); i++) {
+                       ptr = g_strdup_printf("%s/frugalware-%s/%s-%s.fpm", 
SOURCEDIR, ARCH,
+                               (char*)g_list_nth_data(pkgs, i), ARCH);
+                       if(!stat(ptr, &buf))
+                               list = g_list_append(list, 
strdup((char*)g_list_nth_data(pkgs, i)));
+                       free(ptr);
+               }
+
+               // remove them from the full list
+               for(i = 0; i < g_list_length(list); i++)
+                       pkgs = g_list_strremove(pkgs, 
(char*)g_list_nth_data(list, i));
+
+               // install them
+               if(install_pkgs(list) == -1)
+                       return -1;
+       }
+
+       return 0;
+}
+
int prerun(GList **config)
{
// fix gtk graphical bug : forward button is clicked in
@@ -374,13 +423,21 @@ int prerun(GList **config)
makepath(TARGETDIR "/dev");
fw_system("mount /dev -o bind " TARGETDIR "/dev");

-       if(installpkgs((GList*)data_get(*config, "packages")) == -1) {
-               fwife_error(_("An error occurs during packages installation 
(see /var/log/fwife.log for more details)"));
-               return -1;
+       if(data_get(*config, "srcdev") != NULL) {
+               if(install_pkgs_discs((GList*)data_get(*config, "packages"), 
(char*)data_get(*config, "srcdev")) == -1) {
+                       fwife_error(_("An error occurs during packages 
installation (see /var/log/fwife.log for more details)"));
+                       return -1;
+               }
+       } else {
+               if(install_pkgs((GList*)data_get(*config, "packages")) == -1) {
+                       fwife_error(_("An error occurs during packages 
installation (see /var/log/fwife.log for more details)"));
+                       return -1;
+               }
}
+
gtk_label_set_label(GTK_LABEL(labelpkg), _("Packages installation completed"));
set_page_completed();
-       return(0);
+       return 0;
}

int run(GList **config)
diff --git a/src/plugins/select.c b/src/plugins/select.c
index e6c5265..3fbe5b9 100644
--- a/src/plugins/select.c
+++ b/src/plugins/select.c
@@ -210,10 +210,11 @@ GList *getcat(PM_DB *db)
return catlist;
}

-int prepare_pkgdb(void)
+int prepare_pkgdb(char *srcdev)
{
-       char *ptr;
-       int ret;
+       char *ptr, *pkgdb, *uncompress;
+       int ret = 0;
+    FILE *fp;
PM_DB *db;

// pacman can't lock & log without these
@@ -223,6 +224,8 @@ int prepare_pkgdb(void)
ptr = g_strdup_printf("%s/var/log", TARGETDIR);
makepath(ptr);
free(ptr);
+       pkgdb = g_strdup_printf("%s/var/lib/pacman-g2/%s", TARGETDIR, PACCONF);
+       makepath(pkgdb);

if (pacman_parse_config("/etc/pacman-g2.conf", NULL, "") == -1) {
LOG("Failed to parse pacman-g2 configuration file (%s)", 
pacman_strerror(pm_errno));
@@ -236,8 +239,25 @@ int prepare_pkgdb(void)
PACCONF, pacman_strerror(pm_errno));
return(-1);
} else {
-               LOG("updating the database");
-               ret = pacman_db_update(1, db);
+               if(srcdev != NULL) {
+                       uncompress = g_strdup_printf("tar 
--use-compress-program=xz -xf %s/frugalware-%s/%s.fdb -C %s",
+                               SOURCEDIR, ARCH, PACCONF, pkgdb);
+                       fw_system(uncompress);
+                       free(uncompress);
+
+                       if ((fp = fopen("/etc/pacman-g2.conf", "w")) == NULL) {
+                               LOG("could not open output file 
'/etc/pacman-g2.conf' for writing: %s", strerror(errno));
+                               return(1);
+                       }
+                       fprintf(fp, "[options]\n");
+                       fprintf(fp, "LogFile     = /var/log/pacman-g2.log\n");
+                       fprintf(fp, "[%s]\n", PACCONF);
+                       fprintf(fp, "Server = file://%s/frugalware-%s\n\n", 
SOURCEDIR, ARCH);
+                       fclose(fp);
+               } else {
+                       LOG("updating the database");
+                       ret = pacman_db_update(1, db);
+               }

if(ret == 0) {
LOG("database update done");
@@ -254,6 +274,7 @@ int prepare_pkgdb(void)
syncs = g_list_append(syncs, db);
}

+       free(pkgdb);
return(0);
}

@@ -330,9 +351,8 @@ int prerun(GList **config)
while (gtk_events_pending())
gtk_main_iteration ();

-               if(prepare_pkgdb() == -1) {
+               if(prepare_pkgdb((char*)data_get(*config, "srcdev")) == -1)
return(-1);
-               }

gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.5);
while (gtk_events_pending())
diff --git a/src/util.c b/src/util.c
index 1473c9b..71fce96 100644
--- a/src/util.c
+++ b/src/util.c
@@ -42,6 +42,7 @@
#include <stdarg.h>
#include <libintl.h>
#include <unistd.h>
+#include <linux/cdrom.h>

#include "fwife.h"
#include "util.h"
@@ -314,6 +315,32 @@ int disable_cache(char *path)
return(0);
}

+GList *g_list_strremove(GList *list, char *str)
+{
+       int i;
+
+       for(i=0;i<g_list_length(list);i++)
+               if(!strcmp(g_list_nth_data(list, i), str))
+                       return(g_list_remove(list, g_list_nth_data(list, i)));
+       return(NULL);
+}
+
+int eject(char *dev, char *target)
+{
+       int fd;
+
+       umount2(target, MNT_FORCE);
+
+       if((fd = open(dev, O_RDONLY|O_NONBLOCK))==-1)
+               return(1);
+
+       if((ioctl(fd, CDROMEJECT)) == -1)
+               return(1);
+
+       close(fd);
+       return(0);
+}
+
void signal_handler(int signum)
{
if (signum == SIGSEGV)
diff --git a/src/util.h b/src/util.h
index 1d5c932..fcfb4ea 100644
--- a/src/util.h
+++ b/src/util.h
@@ -73,6 +73,8 @@ int rmrf(char *path);
int umount_if_needed(char *sourcedir);
char *drop_version(char *str);
int disable_cache(char *path);
+GList *g_list_strremove(GList *list, char *str);
+int eject(char *dev, char *target);
void signal_handler(int signum);
int fwife_log(char *file, int line, char *fmt, ...);
void cb_log(unsigned short level, char *msg);
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to