Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Jan 2001 16:07:55 +0200
From:      Maxim Sobolev <sobomax@FreeBSD.org>
To:        ports@FreeBSD.org, asami@FreeBSD.org, jkh@FreeBSD.org
Subject:   [RFC] Patch to allow create/install bzip2-compressed packages
Message-ID:  <3A65A73A.7F2F18B7@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------C4E75579AE697BB959F3AA7D
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 7bit

Hi,

With this message I'm attaching patches for pkg_install to allow it
create/install/operate bzip2-compressed package tarballs. Currently it supports
creation of tbz2 packages and installation of those packages from local media
(there is intentionally no attempt to provide support for remote tbz2 packages,
as it's expected that tgz will remain default and the only net distribution
format).

I would like to hear comments/suggestions/whatever regarding those patches.

-Maxim
P.S. You can create bzip2-compressed packages by defining PKG_SUFX=.tbz2 in
your /etc/make.conf

--------------C4E75579AE697BB959F3AA7D
Content-Type: text/plain; charset=koi8-r;
 name="pkg_install-bzip2.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="pkg_install-bzip2.diff"

Index: add/main.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/add/main.c,v
retrieving revision 1.30
diff -d -u -r1.30 main.c
--- add/main.c	2000/03/13 18:47:48	1.30
+++ add/main.c	2001/01/17 13:56:55
@@ -168,7 +168,7 @@
 	usage();
     }
     /* Make sure the sub-execs we invoke get found */
-    setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
+    setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin", 1);
 
     /* Set a reasonable umask */
     umask(022);
Index: create/create.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/create/create.h,v
retrieving revision 1.16
diff -d -u -r1.16 create.h
--- create/create.h	2000/10/23 07:01:30	1.16
+++ create/create.h	2001/01/17 13:56:55
@@ -41,6 +41,7 @@
 extern char	PlayPen[];
 extern int	Dereference;
 extern int	PlistOnly;
+extern int	UseBzip2;
 
 void		check_list(char *, Package *);
 int		pkg_perform(char **);
Index: create/main.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/create/main.c,v
retrieving revision 1.23
diff -d -u -r1.23 main.c
--- create/main.c	2001/01/16 08:27:28	1.23
+++ create/main.c	2001/01/17 13:56:55
@@ -18,7 +18,7 @@
 #include "lib.h"
 #include "create.h"
 
-static char Options[] = "YNOhvf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:";
+static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:";
 
 char	*Prefix		= NULL;
 char	*Comment        = NULL;
@@ -38,6 +38,7 @@
 char	PlayPen[FILENAME_MAX];
 int	Dereference	= FALSE;
 int	PlistOnly	= FALSE;
+int	UseBzip2	= FALSE;
 
 static void usage __P((void));
 
@@ -134,6 +135,10 @@
 	    Origin = optarg;
 	    break;
 
+	case 'y':
+	    UseBzip2 = TRUE;
+	    break;
+
 	case '?':
 	default:
 	    usage();
@@ -167,7 +172,7 @@
 usage()
 {
     fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
-"usage: pkg_create [-YNOhv] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
+"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
 "                  [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ",
 "                  [-t template] [-X excludefile] [-D displayfile] ",
 "                  [-m mtreefile] [-o origin] -c comment -d description ",
Index: create/perform.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/create/perform.c,v
retrieving revision 1.52
diff -d -u -r1.52 perform.c
--- create/perform.c	2001/01/16 08:27:28	1.52
+++ create/perform.c	2001/01/17 13:56:55
@@ -70,14 +70,23 @@
     if (len > 4) {
 	if (!strcmp(&pkg[len - 4], ".tgz")) {
 	    compress = TRUE;
+	    UseBzip2 = FALSE;
 	    pkg[len - 4] = '\0';
 	}
 	else if (!strcmp(&pkg[len - 4], ".tar")) {
 	    compress = FALSE;
+	    UseBzip2 = FALSE;
 	    pkg[len - 4] = '\0';
 	}
+	else if ((len > 5) && (!strcmp(&pkg[len - 5], ".tbz2"))) {
+	    compress = FALSE;
+	    UseBzip2 = TRUE;
+	    pkg[len - 5] = '\0';
+	}
     }
-    if (compress)
+    if (UseBzip2)
+	suf = "tbz2";
+    else if (compress)
 	suf = "tgz";
     else
 	suf = "tar";
@@ -225,6 +234,7 @@
     int pipefds[2];
     FILE *totar;
     pid_t pid;
+    char *cname;
 
     args[nargs++] = "tar";	/* argv[0] */
 
@@ -236,8 +246,16 @@
     args[nargs++] = "-c";
     args[nargs++] = "-f";
     args[nargs++] = tball;
-    if (strchr(suffix, 'z'))	/* Compress/gzip? */
-	args[nargs++] = "-z";
+    if (strchr(suffix, 'z')) {	/* Compress/gzip/bzip2? */
+	if (UseBzip2) {
+	    args[nargs++] = "-y";
+	    cname = "bzip";
+	}
+	else {
+	    args[nargs++] = "-z";
+	    cname = "gzip";
+	}
+    }
     if (Dereference)
 	args[nargs++] = "-h";
     if (ExcludeFrom) {
@@ -249,7 +267,7 @@
     args[nargs] = NULL;
 
     if (Verbose)
-	printf("Creating gzip'd tar ball in '%s'\n", tball);
+	printf("Creating %s'd tar ball in '%s'\n", cname, tball);
 
     /* Set up a pipe for passing the filenames, and fork off a tar process. */
     if (pipe(pipefds) == -1) {
Index: create/pkg_create.1
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/create/pkg_create.1,v
retrieving revision 1.38
diff -d -u -r1.38 pkg_create.1
--- create/pkg_create.1	2000/12/27 15:30:18	1.38
+++ create/pkg_create.1	2001/01/17 13:57:01
@@ -31,7 +31,7 @@
 .Nd a utility for creating software package distributions
 .Sh SYNOPSIS
 .Nm
-.Op Fl YNOhv
+.Op Fl YNOhvy
 .Op Fl P Ar pkgs
 .Op Fl p Ar prefix
 .Op Fl f Ar contents
@@ -252,6 +252,21 @@
 .Em "Ports Collection" .
 It should be in the form
 .Pa MASTERCATEGORY/PORTDIR .
+.It Fl y
+Use
+.Xr bzip2 1
+utility to compress package tarball instead of
+.Xr gzip 1 .
+Please note that this option is no-op if format of the resulting
+archive is explicitly specified by the recognizeable suffix of
+.Ar pkg-name .
+Currently
+.Nm
+recognizes the following suffixes:
+.Dq .tgz ,
+.Dq .tar
+and
+.Dq .tbz2 .
 .El
 .Pp
 .Sh PACKING LIST DETAILS
Index: lib/file.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/file.c,v
retrieving revision 1.45
diff -d -u -r1.45 file.c
--- lib/file.c	2000/10/29 15:39:51	1.45
+++ lib/file.c	2001/01/17 13:57:01
@@ -248,6 +248,8 @@
 {
     static char tmp[FILENAME_MAX];
     char *cp;
+    char *suffixes[] = {".tgz", ".tbz2", NULL};
+    int i;
 
     if (fexists(fname) && isfile(fname)) {
 	strcpy(tmp, fname);
@@ -260,24 +262,27 @@
 	if (cp) {
 	    *cp = '\0';	/* chop name */
 	    cp = strrchr(tmp, '/');
-	}
-	if (cp) {
-	    *(cp + 1) = '\0';
-	    strcat(cp, "All/");
-	    strcat(cp, fname);
-	    strcat(cp, ".tgz");
-	    if (fexists(tmp))
-		return tmp;
 	}
+	if (cp)
+	    for (i = 0; suffixes[i] != NULL; i++) {
+		*(cp + 1) = '\0';
+		strcat(cp, "All/");
+		strcat(cp, fname);
+		strcat(cp, suffixes[i]);
+		if (fexists(tmp))
+		    return tmp;
+	    }
     }
 
     cp = getenv("PKG_PATH");
     while (cp) {
 	char *cp2 = strsep(&cp, ":");
 
-	snprintf(tmp, FILENAME_MAX, "%s/%s.tgz", cp2 ? cp2 : cp, fname);
-	if (fexists(tmp) && isfile(tmp))
-	    return tmp;
+	for (i = 0; suffixes[i] != NULL; i++) {
+	    snprintf(tmp, FILENAME_MAX, "%s/%s%s", cp2 ? cp2 : cp, fname, suffixes[i]);
+	    if (fexists(tmp) && isfile(tmp))
+		return tmp;
+	}
     }
     return NULL;
 }
@@ -438,14 +443,18 @@
     args[0] = '\0';
     /*
      * Figure out by a crude heuristic whether this or not this is probably
-     * compressed.
+     * compressed and whichever compression utility was used (gzip or bzip2).
      */
     if (strcmp(pkg, "-")) {
 	cp = strrchr(pkg, '.');
 	if (cp) {
 	    strcpy(suffix, cp + 1);
-	    if (strchr(suffix, 'z') || strchr(suffix, 'Z'))
-		strcpy(args, "-z");
+	    if (strchr(suffix, 'z') || strchr(suffix, 'Z')) {
+		if (strchr(suffix, 'b'))
+		    strcpy(args, "-y");
+		else
+		    strcpy(args, "-z");
+	    }
 	}
     }
     else

--------------C4E75579AE697BB959F3AA7D--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A65A73A.7F2F18B7>