summaryrefslogtreecommitdiff
path: root/pkgtools/pkg_tarup/files/pkg_tarup
blob: 67bbce8e0ab1748d43f363f7a53aecfcb1d0375a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#! @SH@
#
# $Id: pkg_tarup,v 1.12 2004/04/20 16:26:07 wiz Exp $
#
# Tar up installed package
#
# Package names are assumed to not contain spaces.
#
# (c) Copyright 2000-2002 Hubert Feyrer <hubert@feyrer.de>
#

PREFIX=${PREFIX:-@PREFIX@}

PATH=/sbin:/usr/sbin:/bin:/usr/bin:${PREFIX}/sbin:${PREFIX}/bin:@PKG_TOOLS_BIN@
export PATH

OS=`uname -s`

AWK=${AWK:-@AWK@}
ECHO=${ECHO:-@ECHO@}
HEAD=${HEAD:-@HEAD@}
ID=${ID:-@ID@}
SU=${SU:-@SU@}

if [ `${ID} -u` != 0 ]; then
	${ECHO} "Becoming root@`/bin/hostname` to create a binary package"
	${ECHO} -n "`${ECHO} ${SU} | ${AWK} '{ print $1 }'` ";\
	exec ${SU} root -c "$0 $@"
fi

PKG_DBDIR=${PKG_DBDIR:-@PKG_DBDIR@}
PKG_SUFX=${PKG_SUFX:-@PKG_SUFX@}

PKGREPOSITORY=${PKGREPOSITORY:-/tmp}

usage()
{
	${ECHO} "Usage: $1 installed_pkg|pattern [...]"
	exit 1
}

check_and_add()
{
	opt="$1"
	file="$2"

	if [ x"$opt" = x"" -o x"$file" = x"" ]; then
	   ${ECHO} Usage: check_and_add -opt +FILE
	   exit 1
	fi

	if [ -f "$file" ]
	then
	    PKG_ARGS="${PKG_ARGS} ${opt} ${file}"
	fi
}

create_package()
{
	PKG="$1"
	PKG_ARGS=
	${ECHO} "Creating binary package: $PKG"

	check_and_add -c ${PKG_DBDIR}/${PKG}/+COMMENT
	check_and_add -d ${PKG_DBDIR}/${PKG}/+DESC
	check_and_add -b ${PKG_DBDIR}/${PKG}/+BUILD_VERSION
	check_and_add -B ${PKG_DBDIR}/${PKG}/+BUILD_INFO
	check_and_add -s ${PKG_DBDIR}/${PKG}/+SIZE_PKG
	check_and_add -S ${PKG_DBDIR}/${PKG}/+SIZE_ALL
	check_and_add -i ${PKG_DBDIR}/${PKG}/+INSTALL
	check_and_add -k ${PKG_DBDIR}/${PKG}/+DEINSTALL
	check_and_add -r ${PKG_DBDIR}/${PKG}/+REQUIRE
	check_and_add -D ${PKG_DBDIR}/${PKG}/+DISPLAY
	check_and_add -m ${PKG_DBDIR}/${PKG}/+MTREE		#NOTYET#

	PLIST=/tmp/+CONTENTS.$$
	sed -n \
		-e '/^@comment MD5:/d' \
		-e '/^@cwd \.$/,$d' \
		-e '/\$NetBSD/,$p' \
		<${PKG_DBDIR}/${PKG}/+CONTENTS >$PLIST

	# Duplicate first @cwd (work around pkg_create "feature" ...)
	grep '^@cwd' $PLIST | ${HEAD} -1 >$PLIST.1
	if [ -s ${PLIST}.1 ]
	then
		sed \
		   -e "/`cat ${PLIST}.1 | sed 's,/,\\\\/,g'`/r${PLIST}.1" \
		   <${PLIST} >${PLIST}.2
		mv ${PLIST}.2 ${PLIST}
	fi
	rm ${PLIST}.1

	# ${ECHO} -----
	# cat $PLIST
	# ${ECHO} -----
	# exit 0

	# Just for kicks ...
	# pkg_admin check "${PKG}"
	  
	pkg_create \
			${PKG_ARGS} \
		-v \
		-f ${PLIST} \
		-l \
		-p "`pkg_info -qp ${PKG} | ${AWK} 'NR == 1 { print $2; exit }'`" \
		-P "`pkg_info -qf ${PKG} | ${AWK} '/^@pkgdep/ { print $2 }'`" \
		-C "`pkg_info -qf ${PKG} | ${AWK} '/^@pkgcfl/ { print $2 }'`" \
		${PKGREPOSITORY}/${PKG}${PKG_SUFX}

	rm -f ${PLIST}
	return 0
}

while [ $# -gt 0 ] ; do
	rPKG="`pkg_info -e \"$1\"`"
	if [ -z "$rPKG" -o -f "${PKG_DBDIR}/${rPKG}" ] ; then
		${ECHO} "Error: package $1 not found"
		usage "$0"
	fi
	PKGS="$PKGS $rPKG"
	shift
done
if [ -z "$PKGS" ] ; then
	usage "$0"
fi
for xPKG in $PKGS ; do
	create_package "$xPKG"
	if [ $? -ne 0 ] ; then
		exit 1
	fi
done

exit 0


+REQUIRED_BY:

 - maybe the squirelling away of +REQUIRED_BY should be done here
   instead of in the bsd.pkg.mk framework that normally calls this.


mtree file considerations:

 - keeping uncompressed mtree file adds ~10% to the size of /var/db/pkg

 - could gzip file, space saving: 5kb->850b (plus some intelligence to
   uncompress them when needed)

 - not keeping mtree file results in pkgs w/o mtree file (but should work)

integration:

 - how/where?  I'd prefer not to have yet another pkg_* utility flying
   around, integration into pkg_admin would be nice.  But how merge a
   shell script into a C executable?  REWRITE in C of course!  ;-)