UnTGZ plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(→‎Links: reflect proper size, maybe refreshed attached info?)
(→‎Example usage: checking $0 is wrong ($R0 instead), see Talk:UnTGZ_plug-in#Wrong_example_in_doc)
 
(16 intermediate revisions by 5 users not shown)
Line 4: Line 4:
Download:<br>
Download:<br>
<attach>Untgz.zip</attach><br>
<attach>Untgz.zip</attach><br>
[[Image:Zip.gif]] [http://www.fdos.org/win32/nsis/plugins/untgz.1.0.13.zip Untgz.1.0.13.zip] (251 KB) (Mirror #1)<br>
[[Image:Zip.gif]] [http://www.fdos.org/win32/nsis/plugins/untgz.1.0.18.zip Untgz.1.0.18.zip] (261 KB) (Mirror #1)<br>
<br>
<br>
<attach>Untbgz.zip</attach> Older Untgz plugin with bz2 support, requires MSVCRT.DLL<br>
<attach>Untbgz.zip</attach> Older Untgz plugin with bz2 support, requires MSVCRT.DLL<br>
Line 12: Line 12:


== Description ==
== Description ==
'''Version:''' 1.0.13
'''Version:''' 1.0.18


UnTGZ plugin is similar to ExtractDLL and ZipDLL plugins, except it allows one to extract the files from a tarball. Only simple tarballs are supported, those with filenames longer than 100 characters or including special files may not be supported well (please send me information including where to obtain a sample tarball if better support is required for one of these).<br>
UnTGZ plugin is similar to ExtractDLL and ZipDLL plugins, except it allows one to extract the files from a tarball. Only simple tarballs are supported, those with filenames longer than 100 characters or including special files may not be supported well (please send me information including where to obtain a sample tarball if better support is required for one of these).<br>
''(Basic support for longer than 100 char filenames added to 1.0.16, but does not yet support unicode or all methods of using long names.)''  Limited support for hard links.<br>


Supports TAR files with no compression (*.tar), gzipped [zlib compatible] compression (*.tgz / *.tar.gz), lzma compression (*.tlz / *.tar.lzma), and bzip2 compression (*.tbz / *.tar.bz2).<br>
Supports TAR files with no compression (*.tar), gzipped [zlib compatible] compression (*.tgz / *.tar.gz), lzma compression (*.tlz / *.tar.lzma), and bzip2 compression (*.tbz / *.tar.bz2).<br>
Line 21: Line 22:


== Usage ==
== Usage ==
; '''untgz<nowiki>::</nowiki>extract''' [''-j''] [''-d basedir''] [''-k''] [''-z<type>''] tarball.tgz
; '''untgz<nowiki>::</nowiki>extract''' [''-j''] [''-d basedir''] [''-h''] [''-k''] [''-z<type>''] tarball.tgz
: extracts all files from tarball.tgz
: extracts all files from tarball.tgz
: if -j is specified then ignore paths in tarball (junkpaths)
: if -j is specified then ignore paths in tarball (junkpaths)
: if -d is specified will extract relative to basedir
: if -d is specified will extract relative to basedir
: if -h is specified will return error if fails to create hard link
: if -k is specified will not overwrite existing files (keep)
: if -k is specified will not overwrite existing files (keep)
: if -u is specified will only overwrite nonexisting or older files (update)
: if -u is specified will only overwrite nonexisting or older files (update)
: if -z is specified determines compression used, see below
: if -z is specified determines compression used, see below


; '''untgz<nowiki>::</nowiki>extractV''' [''-j''] [''-d basedir''] [''-k''] [''-z<type>''] tarball.tgz [''-i {iList}''] [''-x {xList}''] '''--'''
; '''untgz<nowiki>::</nowiki>extractV''' [''-j''] [''-d basedir''] [''-h''] [''-k''] [''-z<type>''] tarball.tgz [''-i {iList}''] [''-x {xList}''] '''--'''
: extracts files from tarball.tgz
: extracts files from tarball.tgz
: if -j is specified then ignore paths in tarball (junkpaths)
: if -j is specified then ignore paths in tarball (junkpaths)
: if -d is specified will extract relative to basedir
: if -d is specified will extract relative to basedir
: if -h is specified will return error if fails to create hard link
: if -k is specified will not overwrite existing files (keep)
: if -k is specified will not overwrite existing files (keep)
: if -u is specified will only overwrite nonexisting or older files (update)
: if -u is specified will only overwrite nonexisting or older files (update)
Line 42: Line 45:
; '''untgz<nowiki>::</nowiki>extractFile''' [''-d basedir''] [''-z<type>''] tarball.tgz file
; '''untgz<nowiki>::</nowiki>extractFile''' [''-d basedir''] [''-z<type>''] tarball.tgz file
: extracts just the file specified
: extracts just the file specified
: path information is ignored, implictly -j is specified (may also be explicit)
: path information is ignored, implictly -j and -h are specified (may also be explicit)




Line 49: Line 52:
: -f archive-name indicates name of tarball (filename), note even when used, the filename must be last argument
: -f archive-name indicates name of tarball (filename), note even when used, the filename must be last argument


;If the tarball uses a compression other than gz, then the '''-z''<type>''''' option must be specified to indicate how tar file is compressed.
;The -z<type> option may be specified to explicitly indicate how tar file is compressed.
: -z      indicates gzip (.tgz/.tar.gz) compression, uses zlib, this is the default if -z<type> option is omitted
: -z      indicates gzip (.tgz/.tar.gz) compression, uses zlib,
: -zgz    alias for -z
: -znone  indicates uncompressed tar file (.tar), may be omitted (internally same as -z)
: -znone  indicates uncompressed tar file (.tar), may be omitted (internally same as -z)
: -zlzma  indicates lzma (.tlz/.tar.lzma) compression
: -zlzma  indicates lzma (.tlz/.tar.lzma) compression
: -zbz2  indicates bzip2 (.tbz/.tar.bz2) compression
: -zbz2  indicates bzip2 (.tbz/.tar.bz2) compression
: -zauto  determines type based on content & extension this is the default if -z<type> option is omitted  '''NOTE:''' prior to version 1.0.15 -z was the default so .tlz & .tbz required -zlzma & -zbz2 respectively if those compression methods used.


;NOTES:
;NOTES:
Without -j there is a security issue as no checking is done to paths, allowing untrusted tarballs to overwrite arbitrary files (e.g. /bin/*).  Also no checking is done to directory or file names.  In untar.c there is a hook so custom versions can modify/strip filepaths prior to opening.  The -d option is currently implemented by a chdir to indicatd directory prior to extraction; future versions may instead prepend to extracted path.
Without -j there is a security issue as no checking is done to paths, allowing untrusted tarballs to overwrite arbitrary files (e.g. /bin/*).  Also no checking is done to directory or file names.  In untar.c there is a hook so custom versions can modify/strip filepaths prior to opening.  The -d option is currently implemented by a chdir to indicated directory prior to extraction; future versions may instead prepend to extracted path.


== Example usage ==
== Example usage ==
This is a snippet from [[AbiWord]]'s NSIS2 script:
This is a snippet from [[AbiWord]]'s NSIS2 script ([http://svn.abisource.com/abiword-msvc2008/trunk/Setup/NSISv2/abi_dict_misc.nsh abi_dict_misc.nsh]):
<highlight-nsis> doDictInst:
<highlight-nsis>; Unzip $TEMP\$FILENAME into installation directory
; Unzip dictionary into dictionary subdirectory
untgz::extract "-j" "-d" "$INSTDIR" "$TEMP\$FILENAME"
untgz::extract "-j" "-d" "$INSTDIR\dictionary" "$TEMP\${DICT_FILENAME}"
StrCmp $R0 "success" +4
DetailPrint " Failed to extract ${DICT_FILENAME}"
; Delete temporary files
MessageBox MB_OK|MB_ICONEXCLAMATION|MB_DEFBUTTON1 "  Failed to extract $FILENAME"
Delete "$TEMP\${DICT_FILENAME}"
Abort


Finish:
; Delete temporary files
Delete "$TEMP\$FILENAME"
</highlight-nsis>
</highlight-nsis>


Line 74: Line 81:


Based on ExDLL/ExDLL.h and Zlib's untgz, all dependencies included, simply extract to your contrib directory and build with MSVC 6 (or later) or copy included untgz.dll to the plugins subdirectory of your NSIS installation.
Based on ExDLL/ExDLL.h and Zlib's untgz, all dependencies included, simply extract to your contrib directory and build with MSVC 6 (or later) or copy included untgz.dll to the plugins subdirectory of your NSIS installation.
Some parts (such as extraction with paths) not as well tested.
Some parts (such as extraction with paths, hard links, long names) not as well tested.
See included README.TXT for more details.
See included README.TXT for more details.


Note: 1.0.9 version fixes problems extracting files from some valid tarballs (updated zlib),
Version 1.0.15 automatically determine compression type if not explicity indicated.
which while tested, some issues may still exist that I haven't seen;
please test (see also [[Plugin Tester (or Wrapper)|Plugin Tester]]) your tarballs with it and report to
me should any problems occur. Thanks.
 
As of version 1.0.10, untgz plugin supports lzma compressed TAR files (adds about 5KB to plugin size, so can optionally be compiled out).  Create a normal uncompressed tar file (*.tar), then instead of gzipping (or bzipping/compress'ing) use lzma from LZMA SDK (http://www.7zip.org/sdk.html).  E.g.  'lzma e myarchive.tar myarchive.tlz'


Version 1.0.11 adds support for compiling with MSVC 8 (Express 2005 + SDK)Unless you wish to recompile with VC8 there no need to update from 1.0.10
Version 1.0.16 is an update to 1.0.15 that supports the prefix in the tar header for file names longer than 100 charactersCompiled with MSVC6.


Version 1.0.12 finally implements -k keep option, also adds -u update option (same as keep, but will overwrite a file if older than one in archive), and now aborts extraction with error when it fails to extract a file (such as file readonly or open -- previously is just silently skipped the file and returned success).
Version 1.0.17 adds support for Unicode NSIS; does NOT yet support Unicode file names.  No functional changes from 1.0.16 for standard NSIS.


Version 1.0.13 integrated BZip2 (v1.0.3) support using miniclib (this version now supports none, gzip, bzip2, or lzma compressed TAR files)Updated to lzma sdk 4.43(Note: missing call to FindClose(h); when -u is used and file not overwritten.)
Version 1.0.18 has initial support for hard linksWill issue a warning if a hard link is found and unable to create. The option -h may be used to force failure if unable to create a hard linkOnly works on NT5 or higher on NTFS; will fail to create hard link on all earlier versions of Windows, if file system is FAT or non NTFS, or if accessing NTFS file system via a share (mapped drive).




[[Category:Plugins]]
[[Category:Plugins]]
[[Category:Compression]]

Latest revision as of 15:24, 26 January 2016

Author: PerditionC (talk, contrib)


Links

Download:
Untgz.zip (259 KB)
Zip.gif Untgz.1.0.18.zip (261 KB) (Mirror #1)

Untbgz.zip (249 KB) Older Untgz plugin with bz2 support, requires MSVCRT.DLL
Zip.gif Untgz.1.0.10.zip (158 KB) Older Untgz plugin with only gzip & LZMA support

Older releases may be found at http://www.fdos.org/win32/nsis/plugins/.

Description

Version: 1.0.18

UnTGZ plugin is similar to ExtractDLL and ZipDLL plugins, except it allows one to extract the files from a tarball. Only simple tarballs are supported, those with filenames longer than 100 characters or including special files may not be supported well (please send me information including where to obtain a sample tarball if better support is required for one of these).
(Basic support for longer than 100 char filenames added to 1.0.16, but does not yet support unicode or all methods of using long names.) Limited support for hard links.

Supports TAR files with no compression (*.tar), gzipped [zlib compatible] compression (*.tgz / *.tar.gz), lzma compression (*.tlz / *.tar.lzma), and bzip2 compression (*.tbz / *.tar.bz2).

For problems, corrections, etc. send email to PerditionC __at gmail.com (or jeremyd --at-- fdos.org)

Usage

untgz::extract [-j] [-d basedir] [-h] [-k] [-z<type>] tarball.tgz
extracts all files from tarball.tgz
if -j is specified then ignore paths in tarball (junkpaths)
if -d is specified will extract relative to basedir
if -h is specified will return error if fails to create hard link
if -k is specified will not overwrite existing files (keep)
if -u is specified will only overwrite nonexisting or older files (update)
if -z is specified determines compression used, see below
untgz::extractV [-j] [-d basedir] [-h] [-k] [-z<type>] tarball.tgz [-i {iList}] [-x {xList}] --
extracts files from tarball.tgz
if -j is specified then ignore paths in tarball (junkpaths)
if -d is specified will extract relative to basedir
if -h is specified will return error if fails to create hard link
if -k is specified will not overwrite existing files (keep)
if -u is specified will only overwrite nonexisting or older files (update)
if -z is specified determines compression used, see below
if -i is specified will only extract files whose filename matches
if -x is specified will NOT extract files whose filename matches
the -- is required and marks the end of the file lists
untgz::extractFile [-d basedir] [-z<type>] tarball.tgz file
extracts just the file specified
path information is ignored, implictly -j and -h are specified (may also be explicit)


For compatibility with tar command, the following option specifiers may be used prior to tar file name (tarball.tgz), however, they are simply ignored.
-x indicates action to perform is extraction (extract)
-f archive-name indicates name of tarball (filename), note even when used, the filename must be last argument
The -z<type> option may be specified to explicitly indicate how tar file is compressed.
-z indicates gzip (.tgz/.tar.gz) compression, uses zlib,
-zgz alias for -z
-znone indicates uncompressed tar file (.tar), may be omitted (internally same as -z)
-zlzma indicates lzma (.tlz/.tar.lzma) compression
-zbz2 indicates bzip2 (.tbz/.tar.bz2) compression
-zauto determines type based on content & extension this is the default if -z<type> option is omitted NOTE: prior to version 1.0.15 -z was the default so .tlz & .tbz required -zlzma & -zbz2 respectively if those compression methods used.


NOTES

Without -j there is a security issue as no checking is done to paths, allowing untrusted tarballs to overwrite arbitrary files (e.g. /bin/*). Also no checking is done to directory or file names. In untar.c there is a hook so custom versions can modify/strip filepaths prior to opening. The -d option is currently implemented by a chdir to indicated directory prior to extraction; future versions may instead prepend to extracted path.

Example usage

This is a snippet from AbiWord's NSIS2 script (abi_dict_misc.nsh):

; Unzip $TEMP\$FILENAME into installation directory
untgz::extract "-j" "-d" "$INSTDIR" "$TEMP\$FILENAME"
StrCmp $R0 "success" +4
	DetailPrint "  Failed to extract ${DICT_FILENAME}"
	MessageBox MB_OK|MB_ICONEXCLAMATION|MB_DEFBUTTON1 "  Failed to extract $FILENAME"
	Abort
 
; Delete temporary files
Delete "$TEMP\$FILENAME"

Notes

Currently tested with NSIS 2.0x

Based on ExDLL/ExDLL.h and Zlib's untgz, all dependencies included, simply extract to your contrib directory and build with MSVC 6 (or later) or copy included untgz.dll to the plugins subdirectory of your NSIS installation. Some parts (such as extraction with paths, hard links, long names) not as well tested. See included README.TXT for more details.

Version 1.0.15 automatically determine compression type if not explicity indicated.

Version 1.0.16 is an update to 1.0.15 that supports the prefix in the tar header for file names longer than 100 characters. Compiled with MSVC6.

Version 1.0.17 adds support for Unicode NSIS; does NOT yet support Unicode file names. No functional changes from 1.0.16 for standard NSIS.

Version 1.0.18 has initial support for hard links. Will issue a warning if a hard link is found and unable to create. The option -h may be used to force failure if unable to create a hard link. Only works on NT5 or higher on NTFS; will fail to create hard link on all earlier versions of Windows, if file system is FAT or non NTFS, or if accessing NTFS file system via a share (mapped drive).