From olgeni@uli.it  Thu Jan 17 13:16:26 2002
Return-Path: <olgeni@uli.it>
Received: from mail.ctonet.it (mail.ctonet.it [212.110.160.100])
	by hub.freebsd.org (Postfix) with ESMTP
	id 5CDB937B41A; Thu, 17 Jan 2002 13:16:24 -0800 (PST)
Received: from olgeni.olgeni (ppp-133.dial5.ctonet.it [212.110.180.133])
	by mail.ctonet.it (Postfix) with ESMTP
	id 651E41239C; Thu, 17 Jan 2002 22:16:09 +0100 (CET)
Received: (from olgeni@localhost)
	by olgeni.olgeni (8.11.6/8.11.6) id g0HLG1p16097;
	Thu, 17 Jan 2002 22:16:01 +0100 (CET)
	(envelope-from olgeni)
Message-Id: <200201172116.g0HLG1p16097@olgeni.olgeni>
Date: Thu, 17 Jan 2002 22:16:01 +0100 (CET)
From: Jimmy Olgeni <olgeni@uli.it>
Reply-To: Jimmy Olgeni <olgeni@uli.it>
To: FreeBSD-gnats-submit@freebsd.org
Cc: re@freebsd.org
Subject: pkg_create -b forgets to include install scripts
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         34007
>Category:       bin
>Synopsis:       pkg_create -b forgets to include install scripts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 17 13:20:02 PST 2002
>Closed-Date:    Fri May 10 12:29:10 PDT 2002
>Last-Modified:  Fri May 10 12:29:10 PDT 2002
>Originator:     Jimmy Olgeni
>Release:        FreeBSD 4.5-RC i386
>Organization:
Colby
>Environment:
>Description:

The -b option of pkg_create can be used to build binary packages from
installed ports. However, it will skip files which are essential to
pkg_add operation (like +INSTALL for the package installation script).

>How-To-Repeat:

Try to create packages with "pkg_create -b" and the misc/pkg_tarup
port, then compare the package contents (I used the postgresql port as
an example only).

$ pkg_tarup postgresql-7.1.3
$ tar tvfz /var/tmp/postgresql-7.1.3.tgz
-rw-r--r-- root/wheel    71942 Jan 11 11:27 2002 +CONTENTS
-rw-r--r-- root/wheel       50 Jan 11 11:27 2002 +COMMENT
-rw-r--r-- root/wheel     1346 Jan 11 11:27 2002 +DESC
-rwxr-xr-x root/wheel      910 Jan 11 11:27 2002 +INSTALL
-rw-r--r-- root/wheel     1262 Jan 11 11:27 2002 +DISPLAY
-rw-r--r-- root/wheel     1552 Sep 13 15:23 2001 man/man1/createdb.1.gz
-rw-r--r-- root/wheel     1077 Sep 13 15:23 2001 man/man1/createlang.1.gz
-rw-r--r-- root/wheel     1455 Sep 13 15:23 2001 man/man1/createuser.1.gz
...
(this is ok)

$ pkg_create -b postgresql-7.1.3
$ tar tvfz postgresql-7.1.3.tgz
-rw-r--r-- root/wheel    71748 Nov 16 13:01 2001 +CONTENTS
-rw-r--r-- root/wheel       50 Oct  1 18:39 2001 +COMMENT
-rw-r--r-- root/wheel     1346 Oct  1 18:39 2001 +DESC
-rw-r--r-- root/wheel     1552 Sep 13 15:23 2001 man/man1/createdb.1.gz
-rw-r--r-- root/wheel     1077 Sep 13 15:23 2001 man/man1/createlang.1.gz
-rw-r--r-- root/wheel     1455 Sep 13 15:23 2001 man/man1/createuser.1.gz
...

The package from pkg_create is missing both +DISPLAY and +INSTALL.

>Fix:

The misc/pkg_tarup utility can be used as a workaround.
>Release-Note:
>Audit-Trail:

From: Mark Hannon <markhannon@optushome.com.au>
To: freebsd-gnats-submit@FreeBSD.org, olgeni@uli.it
Cc:  
Subject: Re: bin/34007: pkg_create -b forgets to include install scripts
Date: Sat, 09 Mar 2002 00:19:35 +1100

 This is a multi-part message in MIME format.
 --------------5C0AF1159856F2BC17D7793D
 Content-Type: text/plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 Please try these patches. /mark
 --------------5C0AF1159856F2BC17D7793D
 Content-Type: text/plain; charset=us-ascii;
  name="pkg_install.3"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="pkg_install.3"
 
 Index: lib/lib.h
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/lib.h,v
 retrieving revision 1.29.2.9
 diff -c -r1.29.2.9 lib.h
 *** lib/lib.h	2001/10/24 10:06:56	1.29.2.9
 --- lib/lib.h	2002/03/08 13:17:11
 ***************
 *** 112,118 ****
   typedef struct _plist *PackingList;
   
   struct _pack {
 !     struct _plist *head, *tail;
       int fmtver_maj, fmtver_mnr;
   };
   typedef struct _pack Package;
 --- 112,118 ----
   typedef struct _plist *PackingList;
   
   struct _pack {
 !     struct _plist *current, *head, *tail;
       int fmtver_maj, fmtver_mnr;
   };
   typedef struct _pack Package;
 ***************
 *** 174,179 ****
 --- 174,180 ----
   PackingList	new_plist_entry(void);
   PackingList	last_plist(Package *);
   PackingList	find_plist(Package *, plist_t);
 + PackingList	find_plist_next(Package *, plist_t);
   char		*find_plist_option(Package *, const char *name);
   void		plist_delete(Package *, Boolean, plist_t, const char *);
   void		free_plist(Package *);
 Index: lib/plist.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/plist.c,v
 retrieving revision 1.29.2.6
 diff -c -r1.29.2.6 plist.c
 *** lib/plist.c	2001/10/24 10:06:56	1.29.2.6
 --- lib/plist.c	2002/03/08 13:17:12
 ***************
 *** 84,98 ****
   }
   
   /* Find a given item in a packing list and, if so, return it (else NULL) */
 ! PackingList
   find_plist(Package *pkg, plist_t type)
   {
       PackingList p = pkg->head;
   
       while (p) {
 ! 	if (p->type == type)
   	    return p;
   	p = p->next;
       }
       return NULL;
   }
 --- 84,127 ----
   }
   
   /* Find a given item in a packing list and, if so, return it (else NULL) */
 !   PackingList
   find_plist(Package *pkg, plist_t type)
   {
       PackingList p = pkg->head;
   
       while (p) {
 ! 	if (p->type == type){
 ! 	    pkg->current = p;
   	    return p;
 + 	}
   	p = p->next;
 +     }
 +     return NULL;
 + }
 + 
 + /* 
 +  * Find the next given item in a packing list and, if so, return it (else NULL)
 +  * Unlike the previous function, this version pre-increments the current pointer
 +  * before returning a value, this means that the function may be called several
 +  * times and it will continue to return a valid value for each matching plist_t
 +  *
 +  * This function MAY ONLY be called immediately after getting a non NULL result
 +  * from a call to find_plist, ie call find_plist to initialize and then iterate
 +  * with find_plist_next.
 +  */
 +     PackingList
 + find_plist_next(Package *pkg, plist_t type)
 + {
 +     PackingList p;
 + 
 +     p = pkg->current;
 + 
 +     while (p) {
 + 	p = p->next;		
 + 	if (p && p->type == type){
 + 	    pkg->current = p;
 + 	    return p;
 + 	}
       }
       return NULL;
   }
 
 --------------5C0AF1159856F2BC17D7793D
 Content-Type: text/plain; charset=us-ascii;
  name="pkg_install.4"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="pkg_install.4"
 
 Index: create/create.h
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/pkg_install/create/create.h,v
 retrieving revision 1.15.2.4
 diff -c -r1.15.2.4 create.h
 *** create/create.h	2001/10/23 09:16:03	1.15.2.4
 --- create/create.h	2002/03/08 13:16:07
 ***************
 *** 47,51 ****
   void		check_list(const char *, Package *);
   int		pkg_perform(char **);
   void		copy_plist(const char *, Package *);
 - 
   #endif	/* _INST_CREATE_H_INCLUDE */
 --- 47,50 ----
 Index: create/perform.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/pkg_install/create/perform.c,v
 retrieving revision 1.49.2.11
 diff -c -r1.49.2.11 perform.c
 *** create/perform.c	2002/01/18 08:37:46	1.49.2.11
 --- create/perform.c	2002/03/08 13:16:08
 ***************
 *** 37,45 ****
 --- 37,53 ----
   static void sanity_check(void);
   static void make_dist(const char *, const char *, const char *, Package *);
   static int create_from_installed(const char *, const char *);
 + static void is_a_special_file(const char *name);
   
   static char *home;
   
 + char	*Display;
 + char	*Install;
 + char	*PostInstall;
 + char	*DeInstall;
 + char	*PostDeInstall;
 + char	*Mtree;
 + 
   int
   pkg_perform(char **pkgs)
   {
 ***************
 *** 413,418 ****
 --- 421,427 ----
   {
       FILE *fp;
       Package plist;
 +     PackingList plistp;
       char homedir[MAXPATHLEN], log_dir[FILENAME_MAX];
   
       snprintf(log_dir, sizeof(log_dir), "%s/%s", LOG_DIR, InstalledPkg);
 ***************
 *** 436,443 ****
 --- 445,503 ----
       read_plist(&plist, fp);
       fclose(fp);
   
 +     /*
 +      * Given that we are building the package in-situ we need
 +      * to check the package contents definition of the installed
 +      * package instead of relying upon command line arguments 
 +      * for install, post-install etc. scripts.
 +      */
 + 
 +     if ( (plistp = find_plist(&plist, PLIST_FILE)) != NULL ){
 + 	is_a_special_file(plistp->name);
 + 	while ( (plistp = find_plist_next(&plist, PLIST_FILE)) != NULL ){
 + 	    is_a_special_file(plistp->name);
 + 	}
 +     }
 + 
       make_dist(homedir, pkg, suf, &plist);
   
       free_plist(&plist);
       return TRUE;
 + }
 + 
 + /*
 +  * Check the filename received from the plist and check if
 +  * it matches one of the 'special' files.  If so, then set 
 +  * the appropriate variable to a non-NULL pointer value
 +  */
 + 
 + void 
 + is_a_special_file(const char *filename){
 + 
 +     char fake_argument[10]; /* To provide a ptr to pass */
 + 
 +     if ( strcmp(INSTALL_FNAME, filename) == 0 
 + 	    && Install == NULL)
 + 	Install = fake_argument;
 +     if ( strcmp(POST_INSTALL_FNAME, filename) == 0 
 + 	    && PostInstall == NULL)
 + 	PostInstall = fake_argument;
 +     if ( strcmp(DEINSTALL_FNAME, filename) == 0 
 + 	    && DeInstall == NULL)
 + 	DeInstall = fake_argument;
 +     if ( strcmp(POST_DEINSTALL_FNAME, filename) == 0
 + 	    && PostDeInstall == NULL )
 + 	PostDeInstall = fake_argument;
 +     if ( strcmp(REQUIRE_FNAME, filename) == 0
 + 	    && Require == NULL )
 + 	Require = fake_argument;
 +     if ( strcmp(DISPLAY_FNAME, filename) == 0
 + 	    && Display == NULL )
 + 	Display = fake_argument;
 +     if ( strcmp(MTREE_FNAME, filename) == 0
 + 	    && Mtree == NULL )
 + 	Mtree = fake_argument;
 + 
 +     return;
 + 
   }
 
 --------------5C0AF1159856F2BC17D7793D--
 

From: Jimmy Olgeni <olgeni@uli.it>
To: Mark Hannon <markhannon@optushome.com.au>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/34007: pkg_create -b forgets to include install scripts
Date: Tue, 12 Mar 2002 22:51:02 +0100 (CET)

 On Sat, 9 Mar 2002, Mark Hannon wrote:
 
 > Please try these patches. /mark
 
 I just tried them and it looks like everything is fixed... thanks!
 
 -- 
 jimmy
 
State-Changed-From-To: open->closed 
State-Changed-By: olgeni 
State-Changed-When: Fri May 10 12:26:25 PDT 2002 
State-Changed-Why:  
sobomax committed the fix (usr.sbin/pkg_install/create/perform.c 1.70). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34007 
>Unformatted:
