Bug 79398 - [patch] bsd.port.mk: add USE_MAKESELF knob
Summary: [patch] bsd.port.mk: add USE_MAKESELF knob
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Port Management Team
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-31 15:20 UTC by Jean-Yves Lefort
Modified: 2007-05-25 01:11 UTC (History)
0 users

See Also:


Attachments
file.diff (2.26 KB, patch)
2005-03-31 15:20 UTC, Jean-Yves Lefort
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Lefort 2005-03-31 15:20:04 UTC
Here's a port for extracting Makeself archives. They are the .run or
.sh self-extracting shell scripts most commercial games ship as.

Several ports (mostly games) use Makeself archives as distfiles. With
the provided bsd.port.mk patch, they can now define USE_MAKESELF=yes
instead of manually specifying EXTRACT_SUFX and do-extract.

Fix: # This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	unmakeself
#	unmakeself/files
#	unmakeself/files/unmakeself.c
#	unmakeself/pkg-descr
#	unmakeself/Makefile
#
echo c - unmakeself
mkdir -p unmakeself > /dev/null 2>&1
echo c - unmakeself/files
mkdir -p unmakeself/files > /dev/null 2>&1
echo x - unmakeself/files/unmakeself.c
sed 's/^X//' >unmakeself/files/unmakeself.c << 'END-of-unmakeself/files/unmakeself.c'
X/*
X * unmakeself - extracts Makeself archives
X *
X * Copyright (C) 2005 Jean-Yves Lefort
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. Neither the name of Jean-Yves Lefort nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
X * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
X * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
X * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
X * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
X * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
X * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
X * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
X * POSSIBILITY OF SUCH DAMAGE.
X */
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <locale.h>
X#include <string.h>
X#include <errno.h>
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/uio.h>
X#include <unistd.h>
X#include <getopt.h>
X#include <archive.h>
X
Xstatic char *self = NULL;				/* program name */
Xstatic int extract_flags = ARCHIVE_EXTRACT_TIME;	/* bsdtar default */
X
Xstatic void unmakeself_print_help (void);
Xstatic void unmakeself_print_version (void);
Xstatic void unmakeself_extract (const char *filename);
X
Xint
Xmain (int argc, char **argv)
X{
X  const struct option options[] = {
X    { "help",			no_argument,	NULL, '?'	},
X    { "version",		no_argument,	NULL, 'v'	},
X    { "keep-old-files",		no_argument,	NULL, 'k'	},
X    { "modification-time",	no_argument,	NULL, 'm'	},
X    { "no-same-owner",		no_argument,	NULL, 'o'	},
X    { "preserve-permissions",	no_argument,	NULL, 'p'	},
X    { "unlink",			no_argument,	NULL, 'U'	},
X    { "unlink-first",		no_argument,	NULL, 'U'	},
X    { NULL,			0,		NULL, 0		}
X  };
X  int c;
X
X  self = argc > 0 ? strdup(argv[0]) : "unmakeself";
X  setlocale(LC_ALL, "");
X
X  if (geteuid() == 0)		/* bsdtar does this */
X    extract_flags |= ARCHIVE_EXTRACT_OWNER;
X
X  while ((c = getopt_long(argc, argv, "?vkmpUx", options, NULL)) != -1)
X    switch (c)
X      {
X      case '?':
X	unmakeself_print_help();
X	exit(0);
X	break;
X
X      case 'v':
X	unmakeself_print_version();
X	exit(0);
X	break;
X
X      case 'k':			/* GNU tar, bsdtar */
X	extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
X	break;
X
X      case 'm':			/* SUSv2, bsdtar */
X	extract_flags &= ~ARCHIVE_EXTRACT_TIME;
X	break;
X
X      case 'o':			/* bsdtar */
X	extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
X	break;
X
X      case 'p':			/* GNU tar, star, bsdtar */
X	extract_flags |= ARCHIVE_EXTRACT_PERM;
X	extract_flags |= ARCHIVE_EXTRACT_ACL;
X	extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
X	break;
X
X      case 'U':			/* GNU tar, bsdtar */
X	extract_flags |= ARCHIVE_EXTRACT_UNLINK;
X	break;
X
X      default:
X	abort();
X      }
X
X  argc -= optind;
X  argv += optind;
X
X  if (argc != 1)
X    {
X      fprintf(stderr, "%s: a file to extract must be specified\n", self);
X      exit(1);
X    }
X
X  unmakeself_extract(argv[0]);
X
X  /* on some systems, the return value of main() is ignored */
X  exit(0);
X
X  return 0;
X}
X
Xstatic void
Xunmakeself_print_help (void)
X{
X  printf("Synopsis:\n");
X  printf("  %s {-? | -v}\n", self);
X  printf("  %s [-kmopU] FILE\n", self);
X}
X
Xstatic void
Xunmakeself_print_version (void)
X{
X  printf("unmakeself version 0.99\n");
X  printf("Copyright (C) 2005 Jean-Yves Lefort\n");
X}
X
Xstatic void
Xunmakeself_extract (const char *filename)
X{
X  int fd;
X  char buf[4096];
X  int pos = 0;
X  int last_newline = -1;
X  int offset = -1;
X  int done = 0;
X  ssize_t len;
X
X  fd = open(filename, O_RDONLY);
X  if (fd < 0)
X    {
X      fprintf(stderr, "%s: unable to open %s: %s\n", self, filename, strerror(errno));
X      exit(1);
X    }
X
X  /*
X   * We find the start offset of the archive inside the shell script
X   * by locating the first non-printable character following a
X   * newline. The archive starts immediately after that newline.
X   */
X  while (! done && (len = read(fd, buf, sizeof(buf))) > 0)
X    {
X      int i;
X
X      for (i = 0; i < len; i++, pos++)
X	if (buf[i] == '\n')
X	  last_newline = pos;
X	else if (buf[i] != '\t' && (buf[i] < 32 || buf[i] > 126))
X	  {
X	    if (last_newline != -1)
X	      offset = last_newline + 1;
X	    
X	    done = 1;
X	    break;
X	  }
X    }
X
X  if (offset != -1)		/* offset found, extract using libarchive */
X    {
X      struct archive *archive;
X      struct archive_entry *entry;
X      int status;
X
X      if (lseek(fd, offset, SEEK_SET) < 0)
X	{
X	  fprintf(stderr, "%s: unable to seek into %s: %s\n", self, filename, strerror(errno));
X	  exit(1);
X	}
X      
X      archive = archive_read_new();
X
X      if (archive_read_support_compression_all(archive) != ARCHIVE_OK)
X	fprintf(stderr, "%s: warning: unable to support all compression formats: %s\n", self, archive_error_string(archive));
X      if (archive_read_support_format_all(archive) != ARCHIVE_OK)
X	fprintf(stderr, "%s: warning: unable to support all archive formats: %s\n", self, archive_error_string(archive));
X
X      /* same block size as DEFAULT_BYTES_PER_BLOCK in bsdtar.h */
X      if (archive_read_open_fd(archive, fd, 20 * 512) != ARCHIVE_OK)
X	{
X	  fprintf(stderr, "%s: unable to open %s with libarchive: %s\n", self, filename, archive_error_string(archive));
X	  exit(1);
X	}
X      
X      while ((status = archive_read_next_header(archive, &entry)) == ARCHIVE_OK)
X	if (archive_read_extract(archive, entry, extract_flags) != ARCHIVE_OK)
X	  {
X	    fprintf(stderr, "%s: unable to extract %s: %s\n", self, filename, archive_error_string(archive));
X	    exit(1);
X	  }
X
X      if (status != ARCHIVE_EOF)
X	{
X	  fprintf(stderr, "%s: unable to read next header of %s: %s\n", self, filename, archive_error_string(archive));
X	  exit(1);
X	}
X      
X      if (archive_read_close(archive) != ARCHIVE_OK)
X	{
X	  fprintf(stderr, "%s: unable to close %s with libarchive: %s\n", self, filename, archive_error_string(archive));
X	  exit(1);
X	}
X      
X      archive_read_finish(archive);
X    }
X  else
X    {
X      if (len >= 0)		/* EOF, or couldn't find start offset */
X	{
X	  fprintf(stderr, "%s: %s is not a valid Makeself archive\n", self, filename);
X	  exit(1);
X	}
X      else			/* read error */
X	{
X	  fprintf(stderr, "%s: unable to read %s: %s\n", self, filename, strerror(errno));
X	  exit(1);
X	}
X    }
X
X  if (close(fd) < 0)
X    {
X      fprintf(stderr, "%s: unable to close %s: %s\n", self, filename, strerror(errno));
X      exit(1);
X    }
X}
END-of-unmakeself/files/unmakeself.c
echo x - unmakeself/pkg-descr
sed 's/^X//' >unmakeself/pkg-descr << 'END-of-unmakeself/pkg-descr'
Xunmakeself is a program for extracting Makeself archives without
Xhaving to run the self-extracting shell script.
X
X- Jean-Yves Lefort
Xjylefort@brutele.be
END-of-unmakeself/pkg-descr
echo x - unmakeself/Makefile
sed 's/^X//' >unmakeself/Makefile << 'END-of-unmakeself/Makefile'
X# New ports collection makefile for:	unmakeself
X# Date created:			31 Mar 2005
X# Whom:				Jean-Yves Lefort <jylefort@brutele.be>
X#
X# $FreeBSD$
X#
X
XPORTNAME=		unmakeself
XPORTVERSION=		0.99
XCATEGORIES=		archivers
XDISTFILES=
X
XMAINTAINER=		jylefort@brutele.be
XCOMMENT=		Extract Makeself archives
X
XLDFLAGS=		-larchive -lbz2 -lz
XUSE_GETOPT_LONG=	yes
XNO_WRKSUBDIR=		yes
X
XPLIST_FILES=		bin/unmakeself
X
X.include <bsd.port.pre.mk>
X
X.if ${OSVERSION} < 502103
XBUILD_DEPENDS+=		${LOCALBASE}/lib/libarchive.a:${PORTSDIR}/archivers/libarchive
XCPPFLAGS+=		-I${LOCALBASE}/include
XLDFLAGS+=		-L${LOCALBASE}/lib
X.endif
X
Xdo-build:
X	${CC} ${CFLAGS} ${CPPFLAGS} -o ${WRKSRC}/unmakeself \
X		${FILESDIR}/unmakeself.c ${LDFLAGS}
X
Xdo-install:
X	${MKDIR} ${PREFIX}/bin
X	${INSTALL_PROGRAM} ${WRKSRC}/unmakeself ${PREFIX}/bin
X
X.include <bsd.port.post.mk>
END-of-unmakeself/Makefile
exit
Comment 1 Florent Thoumie freebsd_committer freebsd_triage 2005-04-10 20:03:32 UTC
Responsible Changed
From-To: freebsd-ports-bugs->flz

Grab. I'll re-assign the PR to portmgr once the port is committed.
Comment 2 Florent Thoumie freebsd_committer freebsd_triage 2005-04-10 21:47:45 UTC
Responsible Changed
From-To: flz->portmgr

New port added, over to portmgr for bpm part.
Comment 3 Kris Kennaway 2005-06-01 20:37:10 UTC
How many ports actually use this extraction tool and would benefit
from a bsd.port.mk knob?

Kris
Comment 4 Florent Thoumie freebsd_committer freebsd_triage 2005-06-01 20:50:19 UTC
Le Mercredi 01 juin 2005 à 15:37 -0400, Kris Kennaway a écrit :
> How many ports actually use this extraction tool and would benefit
> from a bsd.port.mk knob?

	Jean Yves sent some updates for ports to use this knob, it 
	mainly concerns games, not sure how many will use it.

	He's much more in games that I am and he sent the PR, so
	he better answer himself.

	(Note: jylefort cc'ed)

-- 
Florent Thoumie
flz@FreeBSD.org
Comment 5 Jean-Yves Lefort freebsd_committer freebsd_triage 2005-06-01 22:17:06 UTC
On Wed, 01 Jun 2005 21:50:19 +0200
Florent Thoumie <flz@FreeBSD.org> wrote:

> Le Mercredi 01 juin 2005 à 15:37 -0400, Kris Kennaway a écrit :
> > How many ports actually use this extraction tool and would benefit
> > from a bsd.port.mk knob?
> 
> 	Jean Yves sent some updates for ports to use this knob, it 
> 	mainly concerns games, not sure how many will use it.
> 
> 	He's much more in games that I am and he sent the PR, so
> 	he better answer himself.


archivers/makeself
games/atitd
games/linux-doom3-demo
games/linux-enemyterritory
games/linux-enemyterritory-fortress
games/linux-q3ademo
games/linux-ut2004-demo
games/q3server
games/rt2-demo
games/rtcw
games/smacx

-- 
Jean-Yves Lefort

jylefort@FreeBSD.org
http://lefort.be.eu.org/
Comment 6 Mark Linimon freebsd_committer freebsd_triage 2007-05-16 22:26:23 UTC
State Changed
From-To: open->analyzed

Accepted for a test build on the cluster.
Comment 7 dfilter service freebsd_committer freebsd_triage 2007-05-25 01:09:43 UTC
linimon     2007-05-25 00:09:37 UTC

  FreeBSD ports repository

  Modified files:
    .                    CHANGES 
    Mk                   bsd.port.mk bsd.port.subdir.mk 
  Log:
  * Make 'make-deinstall-all' check for moved ports. [1]
  
  * Defined the installation directories PORTEXAMPLES and PORTDATA. [2]
  
  * Add USE_MAKESELF knob is added for ports that use the makeself archiver. [3]
  
  * Update the description of fetch-list; add targets fetch-required-list,
    fetch-url-list, and fetch-urlall-list. [4]
  
  * Make 'make search' also search in ports/MOVED. [5]
  
  * Move several Makevar definitions to the pre-makefile section:
    DATADIR, DOCSDIR, ETCDIR, EXAMPLESDIR, WWWDIR. [6]
  
  * The target 'ignorelist-verbose' was added for portsmon. [7]
  
  PR:     69965 [1], 78490 [2], 79398 [3], 86776 [4], 104161 [5], 110781 [6]
  
  Submitted by:   Dancho Penev <dpenev at mnet dot bg> [1], mnag [2],
                  jylefort [3], edwin [4], Lars Engels <lars dot engels
                  at 0x20 dot net> [5], Alexander Logvinov <ports at
                  logvinov dot com> [6], linimon [7]
  
  Revision  Changes    Path
  1.70      +23 -1     ports/CHANGES
  1.568     +220 -23   ports/Mk/bsd.port.mk
  1.70      +34 -5     ports/Mk/bsd.port.subdir.mk
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 8 Mark Linimon freebsd_committer freebsd_triage 2007-05-25 01:11:02 UTC
State Changed
From-To: analyzed->closed

Committed, thanks.