Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-arch/makeself/files: makeself-unpack
Date: Thu, 26 Feb 2009 19:27:44
Message-Id: E1LcltX-0002Ht-1d@stork.gentoo.org
1 vapier 09/02/26 19:27:43
2
3 Added: makeself-unpack
4 Log:
5 Add a script to unpack makeself archives.
6 (Portage version: 2.2_rc23/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.1 app-arch/makeself/files/makeself-unpack
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-arch/makeself/files/makeself-unpack?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-arch/makeself/files/makeself-unpack?rev=1.1&content-type=text/plain
13
14 Index: makeself-unpack
15 ===================================================================
16 #!/bin/bash
17
18 # Glue to keep unpack_makeself() unchanged
19 source /etc/init.d/functions.sh
20 find_unpackable_file() { echo "$@"; }
21 debug-print() { :; }
22 emktemp() { mktemp "$@"; }
23 alias assert='_pipestatus="${PIPESTATUS[*]}"; [[ "${_pipestatus// /}" -eq 0 ]] || die'
24
25 # Straight copied from eutils.eclass ... should be kept in sync
26 unpack_makeself() {
27 local src_input=${1:-${A}}
28 local src=$(find_unpackable_file "${src_input}")
29 local skip=$2
30 local exe=$3
31
32 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'"
33
34 local shrtsrc=$(basename "${src}")
35 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
36 if [[ -z ${skip} ]] ; then
37 local ver=$(grep -a '#.*Makeself' "${src}" | awk '{print $NF}')
38 local skip=0
39 exe=tail
40 case ${ver} in
41 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
42 skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
43 ;;
44 2.0|2.0.1)
45 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-)
46 ;;
47 2.1.1)
48 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-)
49 let skip="skip + 1"
50 ;;
51 2.1.2)
52 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1)
53 let skip="skip + 1"
54 ;;
55 2.1.3)
56 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
57 let skip="skip + 1"
58 ;;
59 2.1.4|2.1.5)
60 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
61 skip=$(head -n ${skip} "${src}" | wc -c)
62 exe="dd"
63 ;;
64 *)
65 eerror "I'm sorry, but I was unable to support the Makeself file."
66 eerror "The version I detected was '${ver}'."
67 eerror "Please file a bug about the file ${shrtsrc} at"
68 eerror "http://bugs.gentoo.org/ so that support can be added."
69 die "makeself version '${ver}' not supported"
70 ;;
71 esac
72 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
73 fi
74 case ${exe} in
75 tail) exe="tail -n +${skip} '${src}'";;
76 dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";;
77 *) die "makeself cant handle exe '${exe}'"
78 esac
79
80 # lets grab the first few bytes of the file to figure out what kind of archive it is
81 local tmpfile=$(emktemp)
82 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
83 local filetype=$(file -b "${tmpfile}")
84 case ${filetype} in
85 *tar\ archive*)
86 eval ${exe} | tar --no-same-owner -xf -
87 ;;
88 bzip2*)
89 eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
90 ;;
91 gzip*)
92 eval ${exe} | tar --no-same-owner -xzf -
93 ;;
94 compress*)
95 eval ${exe} | gunzip | tar --no-same-owner -xf -
96 ;;
97 *)
98 eerror "Unknown filetype \"${filetype}\" ?"
99 false
100 ;;
101 esac
102 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
103 }
104
105 for x; do unpack_makeself "$x" ; done