aboutsummaryrefslogtreecommitdiffstats
path: root/archivers
diff options
context:
space:
mode:
authorjylefort <jylefort@FreeBSD.org>2005-06-13 02:17:05 +0800
committerjylefort <jylefort@FreeBSD.org>2005-06-13 02:17:05 +0800
commit786ac2bd92750d434ea66599398a6d45e86a778a (patch)
treea431e2c6eb0a85deb6638b6708a32615466bae9d /archivers
parent772fbb7d66d1f7c20db3fc55c8a2e719699d021d (diff)
downloadfreebsd-ports-gnome-786ac2bd92750d434ea66599398a6d45e86a778a.tar.gz
freebsd-ports-gnome-786ac2bd92750d434ea66599398a6d45e86a778a.tar.zst
freebsd-ports-gnome-786ac2bd92750d434ea66599398a6d45e86a778a.zip
Release version 1.0:
- Document options in --help output - Add --print-offset option
Diffstat (limited to 'archivers')
-rw-r--r--archivers/unmakeself/Makefile3
-rw-r--r--archivers/unmakeself/files/unmakeself.c261
2 files changed, 139 insertions, 125 deletions
diff --git a/archivers/unmakeself/Makefile b/archivers/unmakeself/Makefile
index 3810d54405de..af483c61c1d5 100644
--- a/archivers/unmakeself/Makefile
+++ b/archivers/unmakeself/Makefile
@@ -6,7 +6,7 @@
#
PORTNAME= unmakeself
-PORTVERSION= 0.99
+PORTVERSION= 1.0
CATEGORIES= archivers
DISTFILES=
@@ -32,7 +32,6 @@ do-build:
${FILESDIR}/unmakeself.c ${LDFLAGS}
do-install:
- ${MKDIR} ${PREFIX}/bin
${INSTALL_PROGRAM} ${WRKSRC}/unmakeself ${PREFIX}/bin
.include <bsd.port.post.mk>
diff --git a/archivers/unmakeself/files/unmakeself.c b/archivers/unmakeself/files/unmakeself.c
index 10720c6e18e2..8b2c9b92ff4e 100644
--- a/archivers/unmakeself/files/unmakeself.c
+++ b/archivers/unmakeself/files/unmakeself.c
@@ -46,105 +46,32 @@
static char *self = NULL; /* program name */
static int extract_flags = ARCHIVE_EXTRACT_TIME; /* bsdtar default */
-static void unmakeself_print_help (void);
-static void unmakeself_print_version (void);
-static void unmakeself_extract (const char *filename);
-
-int
-main (int argc, char **argv)
-{
- const struct option options[] = {
- { "help", no_argument, NULL, '?' },
- { "version", no_argument, NULL, 'v' },
- { "keep-old-files", no_argument, NULL, 'k' },
- { "modification-time", no_argument, NULL, 'm' },
- { "no-same-owner", no_argument, NULL, 'o' },
- { "preserve-permissions", no_argument, NULL, 'p' },
- { "unlink", no_argument, NULL, 'U' },
- { "unlink-first", no_argument, NULL, 'U' },
- { NULL, 0, NULL, 0 }
- };
- int c;
-
- self = argc > 0 ? strdup(argv[0]) : "unmakeself";
- setlocale(LC_ALL, "");
-
- if (geteuid() == 0) /* bsdtar does this */
- extract_flags |= ARCHIVE_EXTRACT_OWNER;
-
- while ((c = getopt_long(argc, argv, "?vkmpUx", options, NULL)) != -1)
- switch (c)
- {
- case '?':
- unmakeself_print_help();
- exit(0);
- break;
-
- case 'v':
- unmakeself_print_version();
- exit(0);
- break;
-
- case 'k': /* GNU tar, bsdtar */
- extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
- break;
-
- case 'm': /* SUSv2, bsdtar */
- extract_flags &= ~ARCHIVE_EXTRACT_TIME;
- break;
-
- case 'o': /* bsdtar */
- extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
- break;
-
- case 'p': /* GNU tar, star, bsdtar */
- extract_flags |= ARCHIVE_EXTRACT_PERM;
- extract_flags |= ARCHIVE_EXTRACT_ACL;
- extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
- break;
-
- case 'U': /* GNU tar, bsdtar */
- extract_flags |= ARCHIVE_EXTRACT_UNLINK;
- break;
-
- default:
- abort();
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc != 1)
- {
- fprintf(stderr, "%s: a file to extract must be specified\n", self);
- exit(1);
- }
-
- unmakeself_extract(argv[0]);
-
- /* on some systems, the return value of main() is ignored */
- exit(0);
-
- return 0;
-}
-
static void
unmakeself_print_help (void)
{
printf("Synopsis:\n");
- printf(" %s {-? | -v}\n", self);
- printf(" %s [-kmopU] FILE\n", self);
+ printf(" %s [OPTIONS] FILE\n", self);
+ printf("\n");
+ printf("Options:\n");
+ printf(" -?, --help Show this help\n");
+ printf(" -v, --version Show version information\n");
+ printf(" -k, --keep-old-files Do not overwrite existing files\n");
+ printf(" -m, --modification-time Do not extract modification time\n");
+ printf(" -o, --no-same-owner Do not extract ownership\n");
+ printf(" -p, --preserve-permissions Preserve file permissions\n");
+ printf(" -U, --unlink-first Unlink files before creating them\n");
+ printf(" --print-offset Only print the offset, do not extract\n");
}
static void
unmakeself_print_version (void)
{
- printf("unmakeself version 0.99\n");
+ printf("unmakeself version 1.0\n");
printf("Copyright (C) 2005 Jean-Yves Lefort\n");
}
static void
-unmakeself_extract (const char *filename)
+unmakeself_extract (const char *filename, int print_offset)
{
int fd;
char buf[4096];
@@ -183,52 +110,57 @@ unmakeself_extract (const char *filename)
}
}
- if (offset != -1) /* offset found, extract using libarchive */
+ if (offset != -1) /* offset found */
{
- struct archive *archive;
- struct archive_entry *entry;
- int status;
-
- if (lseek(fd, offset, SEEK_SET) < 0)
+ if (print_offset) /* only print the offset */
+ printf("%i\n", offset);
+ else /* extract using libarchive */
{
- fprintf(stderr, "%s: unable to seek into %s: %s\n", self, filename, strerror(errno));
- exit(1);
- }
+ struct archive *archive;
+ struct archive_entry *entry;
+ int status;
+
+ if (lseek(fd, offset, SEEK_SET) < 0)
+ {
+ fprintf(stderr, "%s: unable to seek into %s: %s\n", self, filename, strerror(errno));
+ exit(1);
+ }
- archive = archive_read_new();
+ archive = archive_read_new();
- if (archive_read_support_compression_all(archive) != ARCHIVE_OK)
- fprintf(stderr, "%s: warning: unable to support all compression formats: %s\n", self, archive_error_string(archive));
- if (archive_read_support_format_all(archive) != ARCHIVE_OK)
- fprintf(stderr, "%s: warning: unable to support all archive formats: %s\n", self, archive_error_string(archive));
+ if (archive_read_support_compression_all(archive) != ARCHIVE_OK)
+ fprintf(stderr, "%s: warning: unable to support all compression formats: %s\n", self, archive_error_string(archive));
+ if (archive_read_support_format_all(archive) != ARCHIVE_OK)
+ fprintf(stderr, "%s: warning: unable to support all archive formats: %s\n", self, archive_error_string(archive));
- /* same block size as DEFAULT_BYTES_PER_BLOCK in bsdtar.h */
- if (archive_read_open_fd(archive, fd, 20 * 512) != ARCHIVE_OK)
- {
- fprintf(stderr, "%s: unable to open %s with libarchive: %s\n", self, filename, archive_error_string(archive));
- exit(1);
- }
+ /* same block size as DEFAULT_BYTES_PER_BLOCK in bsdtar.h */
+ if (archive_read_open_fd(archive, fd, 20 * 512) != ARCHIVE_OK)
+ {
+ fprintf(stderr, "%s: unable to open %s with libarchive: %s\n", self, filename, archive_error_string(archive));
+ exit(1);
+ }
- while ((status = archive_read_next_header(archive, &entry)) == ARCHIVE_OK)
- if (archive_read_extract(archive, entry, extract_flags) != ARCHIVE_OK)
- {
- fprintf(stderr, "%s: unable to extract %s: %s\n", self, filename, archive_error_string(archive));
- exit(1);
- }
+ while ((status = archive_read_next_header(archive, &entry)) == ARCHIVE_OK)
+ if (archive_read_extract(archive, entry, extract_flags) != ARCHIVE_OK)
+ {
+ fprintf(stderr, "%s: unable to extract %s: %s\n", self, filename, archive_error_string(archive));
+ exit(1);
+ }
- if (status != ARCHIVE_EOF)
- {
- fprintf(stderr, "%s: unable to read next header of %s: %s\n", self, filename, archive_error_string(archive));
- exit(1);
- }
+ if (status != ARCHIVE_EOF)
+ {
+ fprintf(stderr, "%s: unable to read next header of %s: %s\n", self, filename, archive_error_string(archive));
+ exit(1);
+ }
- if (archive_read_close(archive) != ARCHIVE_OK)
- {
- fprintf(stderr, "%s: unable to close %s with libarchive: %s\n", self, filename, archive_error_string(archive));
- exit(1);
- }
+ if (archive_read_close(archive) != ARCHIVE_OK)
+ {
+ fprintf(stderr, "%s: unable to close %s with libarchive: %s\n", self, filename, archive_error_string(archive));
+ exit(1);
+ }
- archive_read_finish(archive);
+ archive_read_finish(archive);
+ }
}
else
{
@@ -250,3 +182,86 @@ unmakeself_extract (const char *filename)
exit(1);
}
}
+
+int
+main (int argc, char **argv)
+{
+ int print_offset = 0;
+ const struct option options[] = {
+ { "help", no_argument, NULL, '?' },
+ { "version", no_argument, NULL, 'v' },
+ { "keep-old-files", no_argument, NULL, 'k' },
+ { "modification-time", no_argument, NULL, 'm' },
+ { "no-same-owner", no_argument, NULL, 'o' },
+ { "preserve-permissions", no_argument, NULL, 'p' },
+ { "unlink", no_argument, NULL, 'U' },
+ { "unlink-first", no_argument, NULL, 'U' },
+ { "print-offset", no_argument, &print_offset, 1 },
+ { NULL, 0, NULL, 0 }
+ };
+ int c;
+
+ self = argc > 0 ? strdup(argv[0]) : "unmakeself";
+ setlocale(LC_ALL, "");
+
+ if (geteuid() == 0) /* bsdtar does this */
+ extract_flags |= ARCHIVE_EXTRACT_OWNER;
+
+ while ((c = getopt_long(argc, argv, "?vkmpUx", options, NULL)) != -1)
+ switch (c)
+ {
+ case '?':
+ unmakeself_print_help();
+ exit(0);
+ break;
+
+ case 'v':
+ unmakeself_print_version();
+ exit(0);
+ break;
+
+ case 'k': /* GNU tar, bsdtar */
+ extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
+ break;
+
+ case 'm': /* SUSv2, bsdtar */
+ extract_flags &= ~ARCHIVE_EXTRACT_TIME;
+ break;
+
+ case 'o': /* bsdtar */
+ extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
+ break;
+
+ case 'p': /* GNU tar, star, bsdtar */
+ extract_flags |= ARCHIVE_EXTRACT_PERM;
+ extract_flags |= ARCHIVE_EXTRACT_ACL;
+ extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
+ break;
+
+ case 'U': /* GNU tar, bsdtar */
+ extract_flags |= ARCHIVE_EXTRACT_UNLINK;
+ break;
+
+ case 0:
+ break;
+
+ default:
+ abort();
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1)
+ {
+ fprintf(stderr, "%s: a file to extract must be specified\n", self);
+ exit(1);
+ }
+
+ unmakeself_extract(argv[0], print_offset);
+
+ /* on some systems, the return value of main() is ignored */
+ exit(0);
+
+ return 0;
+}