tazpkg diff modules/extract @ rev 955

modules/search: allow search file with dash at start: tazpkg -sf "-spi"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Dec 22 00:02:54 2017 +0200 (2017-12-22)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/extract	Fri Dec 22 00:02:54 2017 +0200
     1.3 @@ -0,0 +1,54 @@
     1.4 +#!/bin/sh
     1.5 +# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
     1.6 +# extract - TazPkg module
     1.7 +# Extract .tazpkg cpio archive into a directory
     1.8 +
     1.9 +
    1.10 +# Connect function libraries
    1.11 +. /lib/libtaz.sh
    1.12 +
    1.13 +# Get TazPkg working environment
    1.14 +. @@MODULES@@/getenv
    1.15 +
    1.16 +
    1.17 +
    1.18 +
    1.19 +# Extract a package with cpio and gzip/lzma.
    1.20 +
    1.21 +extract_package() {
    1.22 +	action 'Extracting package...'
    1.23 +	cpio -idm --quiet < "$1" && rm -f "$1"
    1.24 +	if [ -f fs.cpio.lzma ]; then
    1.25 +		unlzma < fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
    1.26 +	elif [ -f fs.cpio.gz ]; then
    1.27 +		zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
    1.28 +	fi
    1.29 +	status
    1.30 +}
    1.31 +
    1.32 +
    1.33 +
    1.34 +
    1.35 +PACKAGE_FILE="$1"
    1.36 +TARGET_DIR="$2"
    1.37 +PACKAGE="$(basename "$PACKAGE_FILE" .tazpkg)"
    1.38 +
    1.39 +title 'Extracting package "%s"' "$PACKAGE"
    1.40 +
    1.41 +# If no directory destination is found on the cmdline
    1.42 +# we create one in the current dir using the package name.
    1.43 +if [ -n "$TARGET_DIR" ]; then
    1.44 +	DESTDIR="$TARGET_DIR/$PACKAGE"
    1.45 +else
    1.46 +	DESTDIR="$PACKAGE"
    1.47 +fi
    1.48 +mkdir -p "$DESTDIR"
    1.49 +
    1.50 +action 'Copying original package...'
    1.51 +cp "$PACKAGE_FILE" "$DESTDIR"
    1.52 +status
    1.53 +
    1.54 +cd "$DESTDIR"
    1.55 +extract_package "${PACKAGE_FILE##*/}"
    1.56 +
    1.57 +[ -e "receipt" ] && footer "$(_ 'Package "%s" is extracted to "%s"' "$PACKAGE" "$DESTDIR")"