script patch

Rob Crittenden rcrit at greyoak.com
Thu Apr 8 14:55:22 EDT 2004


Hi.

I was working on a multi-cd installer that uses a script to copy some of
the files from the cds. The environment variable SETUP_CDROMPATH wasn't
always being set because the installer always outputs the top of the cdrom
list. So when you're on cd 2 it tries to print the mount point for cd 1
which is NULL when you're working on cd2.

I added a cdromid attribute to the script command so one can say which
cdrom the script is operating against. So if a cdromid attrbute exists
I save a pointer to the head of the list, then seek to cdromid in the
cdrom list, then call the script and finally restore the pointer when the
script exits.

While I was at it I added 2 more attributes: size and message.

Size lets you indicate the amount of data that the script installs itself.

Message lets you replace the "Running script" message with something slightly
more useful to the end-user.

The installer I was working on used Microsoft cabinet files. Rather than
porting cabextract to a setup plugin I call it from a shell script instead.
Since the majority (90%) of the files are in .cab files the total installed
progress bar was about 5% during 95% of the installation. So instead with
the size message at the end of each installation script the total progress
goes up a bit.

A sample entry looks like:

  <script cdromid="disc1" size="3504531" message="Installing Game.cab">
   sh setup.data/install-cabGame.sh
  </script>

I wasn't sure where to submit this so I figured I'd start here rather than
bugging Ryan about it, he seems busy enough.

rob
-------------- next part --------------
Index: copy.c
===================================================================
RCS file: /cvs/cvsroot/loki_setup/copy.c,v
retrieving revision 1.74
diff -u -r1.74 copy.c
--- copy.c	1 Mar 2004 06:29:42 -0000	1.74
+++ copy.c	8 Apr 2004 18:39:13 -0000
@@ -729,16 +729,36 @@
 }
 
 int copy_script(install_info *info, xmlNodePtr node, const char *script, const char *dest,
-				int (*update)(install_info *info, const char *path, size_t progress, size_t size, const char *current))
+				int (*update)(install_info *info, const char *path, size_t progress, size_t size, const char *current), const char *from_cdrom, const char *msg)
 {
+    struct cdrom_elem *cdrom;
+    struct cdrom_elem *cdrom_start;
+    int rc;
+
 	if ( corrupts ) { /* Don't run any scripts while restoring files */
 		return 0;
 	}
 	if ( update ) {
-		if ( ! update(info, _("Running script"), 0, 0, current_option_txt) )
+		if (msg != NULL)
+			rc = update(info, msg, 0, 0, current_option_txt);
+		else
+			rc = update(info, _("Running script"), 0, 0, current_option_txt);
+		if ( !rc ) 
 			return 0;
 	}
-    return(run_script(info, script, -1, 1));
+
+    cdrom_start = info->cdroms_list;
+    while ( from_cdrom != NULL && info->cdroms_list ) {
+        cdrom = info->cdroms_list;
+        if (!strcmp(cdrom->id, from_cdrom)) {
+            break;
+        }
+        info->cdroms_list = cdrom->next;
+    }
+
+    rc = run_script(info, script, -1, 1);
+    info->cdroms_list = cdrom_start;
+    return rc;
 }
 
 ssize_t copy_node(install_info *info, xmlNodePtr node, const char *dest,
@@ -819,9 +839,16 @@
 					size += copied;
 				}
 			} else if ( strcmp(node->name, "script") == 0 ) {
-				copy_script(info, node,
+				const char *sz= xmlGetProp(node, "size");
+				const char *msg= xmlGetProp(node, "message");
+				int rc;
+				rc = copy_script(info, node,
 					    xmlNodeListGetString(info->config, node->childs, 1),
-					    path, update);
+					    path, update, from_cdrom, msg);
+				if (rc == 0 && sz) {
+					info->installed_bytes += atoi(sz);
+					size += atoi(sz);
+				}
 			}
 		}
         /* Do not handle exclusive elements here; it gets called multiple times else */
Index: README.xml
===================================================================
RCS file: /cvs/cvsroot/loki_setup/README.xml,v
retrieving revision 1.57
diff -u -r1.57 README.xml
--- README.xml	18 Feb 2004 03:56:55 -0000	1.57
+++ README.xml	8 Apr 2004 18:39:16 -0000
@@ -760,6 +760,18 @@
             string of this attribute. See 'About localization' below for
             more details.
 
+ size       If the script handles the installation of some files and you want
+            the progress bar to reflect it, indicate the size here. The size
+            is updated when the script finishes. The unit is in bytes.
+
+ message    The message to display to the user. By default this is
+            "Running script"
+
+ cdromid    When doing a multi-cd installation and running scripts then
+            SETUP_CDROMPATH may not be set as expected. To ensure that it is
+            set properly indicate which CD the script is executing against
+            if it is copying files from a CD.
+
 It is also possible to filter the scripts on system characteristics, through
 the use of the "arch", "glibc" and "distro" attributes, that work just like
 for the "files" element.


More information about the Lokisetup mailing list