View | Details | Raw Unified | Return to bug 182388
Collapse All | Expand All

(-)pkg_replace/Makefile (-8 / +10 lines)
Lines 3-13 Link Here
3
3
4
PORTNAME=	pkg_replace
4
PORTNAME=	pkg_replace
5
PORTVERSION=	0.8.0
5
PORTVERSION=	0.8.0
6
PORTREVISION=	2
6
PORTREVISION=	3
7
CATEGORIES=	ports-mgmt
7
CATEGORIES=	ports-mgmt
8
MASTER_SITES=	${MASTER_SITE_SOURCEFORGE_JP}
8
MASTER_SITES=	${MASTER_SITE_SOURCEFORGE_JP}
9
MASTER_SITE_SUBDIR=portutil/22116
9
MASTER_SITE_SUBDIR=portutil/22116
10
10
11
PATCH_SITES=	http://member.tokoha-u.ac.jp/~kdeguchi/download/
12
PATCHFILES=	${PKGNAME}.patch
13
11
MAINTAINER=	kdeguchi@sz.tokoha-u.ac.jp
14
MAINTAINER=	kdeguchi@sz.tokoha-u.ac.jp
12
COMMENT=	Utility for upgrading installed packages
15
COMMENT=	Utility for upgrading installed packages
13
16
Lines 15-22 Link Here
15
MAKE_ARGS=	PREFIX="${PREFIX}" \
18
MAKE_ARGS=	PREFIX="${PREFIX}" \
16
		PORTSDIR="${PORTSDIR}" PKG_DBDIR="${PKG_DBDIR}"
19
		PORTSDIR="${PORTSDIR}" PKG_DBDIR="${PKG_DBDIR}"
17
20
18
MAN1=		pkg_replace.1
21
#MANCOMPRESSED=	maybe
19
MANCOMPRESSED=	maybe
20
22
21
OPTIONS_DEFINE=		ZSH
23
OPTIONS_DEFINE=		ZSH
22
24
Lines 29-41 Link Here
29
31
30
OPTIONS_SUB=	yes
32
OPTIONS_SUB=	yes
31
33
32
NO_STAGE=	yes
33
.include <bsd.port.options.mk>
34
.include <bsd.port.options.mk>
34
35
35
.if ${PORT_OPTIONS:MPKGDB_FIX}
36
MAN1+=	pkgdb_fix.1
37
.endif
38
39
post-patch:
36
post-patch:
40
.if ${PORT_OPTIONS:MPKGDB_FIX}
37
.if ${PORT_OPTIONS:MPKGDB_FIX}
41
	@${REINPLACE_CMD} -e 's/pkg_replace/pkg_replace pkgdb_fix/;' ${WRKSRC}/sbin/Makefile
38
	@${REINPLACE_CMD} -e 's/pkg_replace/pkg_replace pkgdb_fix/;' ${WRKSRC}/sbin/Makefile
Lines 44-47 Link Here
44
	@${REINPLACE_CMD} -e  's/^	sbin \\$$/	sbin/;s/^	share$$//;' ${WRKSRC}/Makefile
41
	@${REINPLACE_CMD} -e  's/^	sbin \\$$/	sbin/;s/^	share$$//;' ${WRKSRC}/Makefile
45
.endif
42
.endif
46
43
44
pre-install:
45
.if ${PORT_OPTIONS:MZSH}
46
	${MKDIR} ${STAGEDIR}${LOCALBASE}/share/zsh/site-functions
47
.endif
48
47
.include <bsd.port.mk>
49
.include <bsd.port.mk>
(-)pkg_replace/distinfo (+2 lines)
Lines 1-2 Link Here
1
SHA256 (pkg_replace-0.8.0.tar.bz2) = 3092f5fc0d18529eb5d38776941c0ee4d0073ecb524ab17671c81ca69c29e214
1
SHA256 (pkg_replace-0.8.0.tar.bz2) = 3092f5fc0d18529eb5d38776941c0ee4d0073ecb524ab17671c81ca69c29e214
2
SIZE (pkg_replace-0.8.0.tar.bz2) = 17296
2
SIZE (pkg_replace-0.8.0.tar.bz2) = 17296
3
SHA256 (pkg_replace-0.8.0_3.patch) = cfa2adb3643a8684281143e4c241b8597510251730657816d68926701615ae98
4
SIZE (pkg_replace-0.8.0_3.patch) = 11125
(-)pkg_replace/files/patch-pkg_replace_pkgng (-423 lines)
Lines 1-423 Link Here
1
--- sbin/pkg_replace/pkg_replace.sh.orig	2007-01-25 21:55:46.000000000 +0900
2
+++ sbin/pkg_replace/pkg_replace.sh	2013-09-03 06:58:43.000000000 +0900
3
@@ -125,14 +125,27 @@
4
 	: ${PACKAGEROOT="ftp://ftp.NetBSD.org"}
5
 	: ${PKG_SUFX=".tgz"}
6
 #else
7
+	: ${use_pkgng="`/usr/bin/make -f/usr/share/mk/bsd.port.mk -V WITH_PKGNG`"}
8
+	if [ "x${use_pkgng}" = "xdevel" ]; then
9
+		use_pkgng="yes"
10
+	fi
11
 	: ${PORTSDIR="/usr/ports"}
12
+	if is_yes ${use_pkgng}; then
13
+	: ${PKGREPOSITORY="/var/cache/pkg/All"}
14
+	else
15
 	: ${PKGREPOSITORY="${PORTSDIR}/packages/All"}
16
+	fi
17
 #ifdef WITH_OPENBSD
18
 	: ${PACKAGEROOT="ftp://ftp.OpenBSD.org"}
19
 	: ${PKG_SUFX=".tgz"}
20
 #else
21
+	if is_yes ${use_pkgng}; then
22
+	: ${PACKAGEROOT="http://pkgbeta.FreeBSD.org"}
23
+	: ${PKG_SUFX=".txz"}
24
+	else
25
 	: ${PACKAGEROOT="ftp://ftp.FreeBSD.org"}
26
 	: ${PKG_SUFX=".tbz"}
27
+	fi
28
 #endif
29
 #endif
30
 	: ${PKG_BACKUP_DIR=${PKGREPOSITORY}}
31
@@ -152,10 +165,18 @@
32
 }
33
 
34
 init_pkgtools() {
35
+	if is_yes ${use_pkgng}; then
36
+	PKG_ADD="pkg add"
37
+	PKG_CREATE="pkg create"
38
+	PKG_DELETE="pkg delete"
39
+	PKG_INFO="pkg info"
40
+	PKG_SET="pkg set"
41
+	else
42
 	PKG_ADD="pkg_add"
43
 	PKG_CREATE="pkg_create"
44
 	PKG_DELETE="pkg_delete"
45
 	PKG_INFO="pkg_info"
46
+	fi
47
 	MAKE="@MAKE@"
48
 }
49
 
50
@@ -213,7 +234,7 @@
51
 			expand_path 'file' "${p##*=}"
52
 			file_exist "${file}" || continue
53
 			p=${p%=*} ;;
54
-		*.t[bg]z)
55
+		*.t[bgx]z)
56
 			expand_path 'file' "$p"
57
 			get_pkgname_for_binary 'p' "${file}" || continue
58
 			p=${p%-*} ;;
59
@@ -423,6 +444,7 @@
60
 	file_exist "$2" || return 1
61
 
62
 	case $2 in
63
+	*.txz)	_opt=J ;;
64
 	*.tbz)	_opt=j ;;
65
 	*.tgz)	_opt=z ;;
66
 	*)	return 1 ;;
67
@@ -434,6 +456,7 @@
68
 #ifdef WITH_OPENBSD
69
 	X=`@TAR@ x${_opt}f "$2" -O "+CONTENTS" |
70
 #else
71
+	is_yes ${use_pkgng} && X=`${PKG_INFO} -F "$2"` ||
72
 	X=`@TAR@ x${_opt}f "$2" -O --fast-read "+CONTENTS" |
73
 #endif
74
 #endif
75
@@ -467,6 +490,11 @@
76
 		done < "${PKG_DBDIR}/$2/+BUILD_INFO"
77
 	fi
78
 #else
79
+	if is_yes ${use_pkgng}; then
80
+		X=`${PKG_INFO} -qo $2`
81
+		eval $1=\$X
82
+		return 0
83
+	fi
84
 	if [ -r "${PKG_DBDIR}/$2/+CONTENTS" ]; then
85
 		while read X; do
86
 			case $X in
87
@@ -488,7 +516,11 @@
88
 }
89
 
90
 set_pkg_vars() {
91
+	if is_yes ${use_pkgng}; then
92
+	${PKG_INFO} -e $1 || return 1
93
+	else
94
 	[ -d "${PKG_DBDIR}/$1" ] || return 1
95
+	fi
96
 
97
 	pkg_name=$1
98
 	pkg_pkgdir=${PKG_DBDIR}/$1
99
@@ -526,10 +558,27 @@
100
 
101
 	for _arg in ${1+"$@"}; do
102
 		_pattern=${_arg#${PKG_DBDIR}/}
103
+		if is_yes ${use_pkgng}; then
104
+			for p in `${PKG_INFO} -g "${_pattern}" 2>/dev/null`; do
105
+				if is_yes ${opt_depends}; then
106
+					pkg_depends '_deps' "$p"
107
+					eval ${_var}=\"\$${_var} \${_deps}\"
108
+				fi
109
+
110
+				eval ${_var}=\"\$${_var} \$p\"
111
 
112
+				if is_yes ${opt_required_by}; then
113
+					pkg_required_by '_req_by' "$p"
114
+					eval ${_var}=\"\$${_var} \${_req_by}\"
115
+				fi
116
+			done
117
+			if [ -z "${pkgs}" ]; then
118
+				warn "No such installed package: ${_arg}"
119
+			fi
120
+		else
121
 		case ${_pattern} in
122
-		*\**|*-pl[0-9]*|*-[0-9]*[0-9.][a-z]|*-[0-9]*[0-9]) ;;
123
-		*)		_pattern="${_pattern}-[0-9]*[0-9a-z]" ;;
124
+		*\**|*-[0-9]*|*-[brv.][0-9]*|*-a.[0-9]*|*-pl[0-9]*|*-b.r[0-9]*|*-cr.[a-z]*) ;;
125
+		*)		_pattern="${_pattern}-[0-9]*[0-9a-zA-Z]" ;;
126
 		esac
127
 
128
 		for p in ${PKG_DBDIR}/${_pattern}/+CONTENTS; do
129
@@ -552,6 +601,7 @@
130
 				warn "No such installed package: ${_arg}"
131
 			fi
132
 		done
133
+		fi
134
 	done
135
 
136
 	set -f
137
@@ -568,6 +618,12 @@
138
 		done < "${PKG_DBDIR}/$2/+REQUIRING"
139
 	fi
140
 #else
141
+	if is_yes ${use_pkgng}; then
142
+		X=`${PKG_INFO} -qd $2`
143
+		eval $1=\"\${X}\"
144
+		return 0
145
+	fi
146
+
147
 	if [ -r "${PKG_DBDIR}/$2/+CONTENTS" ]; then
148
 		while read X; do
149
 			case $X in
150
@@ -588,6 +644,12 @@
151
 pkg_required_by() {
152
 	local X
153
 
154
+	if is_yes ${use_pkgng}; then
155
+		X=`${PKG_INFO} -qr $2`
156
+		eval $1=\"\$X\"
157
+		return 0
158
+	fi
159
+
160
 	eval $1=
161
 	if [ -r "${PKG_DBDIR}/$2/+REQUIRED_BY" ]; then
162
 		while read X; do
163
@@ -597,7 +659,7 @@
164
 }
165
 
166
 pkg_sort() {
167
-	local p _var _sorted _unsorted _arg _deps
168
+	local p _var _sorted _unsorted _arg _deps _deplist
169
 
170
 	_var=$1; shift
171
 	_sorted=
172
@@ -612,7 +674,13 @@
173
 		*" ${_arg} "*)	continue ;;
174
 		esac
175
 
176
-		if [ -s "${PKG_DBDIR}/${_arg}/+REQUIRED_BY" ]; then
177
+		_deplist=
178
+		if is_yes ${use_pkgng}; then
179
+			_deplist=`${PKG_INFO} -qr ${_arg}`
180
+		else
181
+			_deplist="${PKG_DBDIR}/${_arg}/+REQUIRED_BY"
182
+		fi
183
+		if [ -s "${_deplist}" ]; then
184
 			pkg_depends '_deps' "${_arg}"
185
 
186
 			for p in ${_deps}; do
187
@@ -715,7 +783,7 @@
188
 	if empty ${_log}; then
189
 		try "$@" || return $?
190
 	else
191
-		_cookie="${tmpdir}/.$1_failed"
192
+		_cookie="${tmpdir}/.${1##*/}_failed"
193
 
194
 		{ try "$@" || echo $? > "${_cookie}"; } | tee -a "${_log}" ||
195
 			warn "tee(1) failed."
196
@@ -757,9 +825,11 @@
197
 	info "Installing '$1'"
198
 
199
 	case $1 in
200
-	*.t[bg]z)
201
+	*.t[bgx]z)
202
 		is_yes ${opt_force} && install_args="-f"
203
+		if ! is_yes ${use_pkgng}; then
204
 		is_yes ${opt_verbose} && install_args="${install_args} -v"
205
+		fi
206
 
207
 		xtry "${2-}" ${PKG_ADD} ${install_args} "$1" || return 1
208
 		;;
209
@@ -795,7 +865,11 @@
210
 
211
 	deinstall_args=
212
 	is_yes ${opt_force} && deinstall_args="-f"
213
+	if is_yes ${use_pkgng}; then
214
+	deinstall_args="${deinstall_args} -y"
215
+	else
216
 	is_yes ${opt_verbose} && deinstall_args="${deinstall_args} -v"
217
+	fi
218
 
219
 #ifdef WITH_PKGSRC
220
 	if [ -e "${PKG_DBDIR}/$1/+PRESERVE" ]; then
221
@@ -915,7 +989,11 @@
222
 		*)		subdir="${OS_MAJOR}-stable" ;;
223
 		esac
224
 
225
+		if is_yes ${use_pkgng}; then
226
+		uri_path=/freebsd-${OS_MAJOR}-${ARCH}/latest/All/
227
+		else
228
 		uri_path="/pub/FreeBSD/ports/${ARCH}/packages-${subdir}/All/"
229
+		fi
230
 #endif
231
 #endif
232
 		uri="${PACKAGEROOT}${uri_path}${pkg}"
233
@@ -987,7 +1065,11 @@
234
 		return 1
235
 	fi
236
 #else
237
+	if is_yes ${use_pkgng}; then
238
+	try ${PKG_CREATE} -f ${PKG_SUFX} -o "${2%/*}" "$1" || return 1
239
+	else
240
 	try ${PKG_CREATE} -b "$1" "$2" || return 1
241
+	fi
242
 #endif
243
 #endif
244
 }
245
@@ -1031,12 +1113,17 @@
246
 }
247
 
248
 preserve_libs() {
249
-	local file
250
+	local file pkg_info_opts
251
 
252
 	is_yes ${opt_preserve_libs} || return 0
253
 
254
+	if is_yes ${use_pkgng}; then
255
+		pkg_info_opts='-ql'
256
+	else
257
+		pkg_info_opts='-qL'
258
+	fi
259
 	preserved_files=
260
-	for file in $(${PKG_INFO} -qL "$1"); do
261
+	for file in $(${PKG_INFO} ${pkg_info_opts} "$1"); do
262
 		case ${file##*/} in
263
 		lib*.so.[0-9]*)
264
 			if [ -f "${file}" ]; then
265
@@ -1080,20 +1167,30 @@
266
 fix_dependencies() {
267
 #ifndef WITH_PKGSRC
268
 #ifndef WITH_OPENBSD
269
-	local p deps newdep opt_depends opt_required_by
270
+	local p deps newdep opt_depends opt_required_by dep_installed
271
 
272
 	opt_depends=NO
273
 	opt_required_by=NO
274
 	pkg_depends 'deps' "$1"
275
 
276
 	for p in ${deps}; do
277
-		if [ ! -d "${PKG_DBDIR}/$p" ]; then
278
+		dep_installed=no
279
+		if is_yes ${use_pkgng}; then
280
+			${PKG_INFO} -e $p && dep_installed=yes || dep_installed=no
281
+		else
282
+			[ -d "${PKG_DBDIR}/$p" ] && dep_installed=yes || dep_installed=no
283
+		fi
284
+		if ! is_yes ${dep_installed}; then
285
 			pkg_glob 'newdep' "${p%-*}" 2>/dev/null
286
 
287
 			if empty ${newdep}; then
288
 				warn "'$1' depends on '$p', but it is NOT installed!"
289
 			else
290
+				if is_yes ${use_pkgng}; then
291
+				${PKG_SET} -y -o `${PKG_INFO} -qo $1`:`${PKG_INFO} -qo $p` || return 1
292
+				else
293
 				update_pkgdep "$1" "$p" "${newdep##* }" || return 1
294
+				fi
295
 			fi
296
 		fi
297
 	done
298
@@ -1102,6 +1199,11 @@
299
 }
300
 
301
 update_dependencies() {
302
+	if is_yes ${use_pkgng}; then
303
+		info "Updating the dependencies"
304
+		[ "x$1" = "x$2" ] && return 0 || ${PKG_SET} -y -o $1:$2
305
+		info "	$1 -> $2"
306
+	else
307
 	local p req_by
308
 
309
 	pkg_required_by 'req_by' "$2"
310
@@ -1114,6 +1216,7 @@
311
 			update_pkgdep "$p" "$1-[^-]*" "$2" || return 1
312
 		done
313
 	fi
314
+	fi
315
 }
316
 
317
 have_pkgdep() {
318
@@ -1122,7 +1225,7 @@
319
 	if [ -r "${PKG_DBDIR}/$1/+CONTENTS" ]; then
320
 		while read X; do
321
 			case $X in
322
-			@pkgdep\ $2-[0-9]*|@pkgdep\ $2-pl[0-9]*)
323
+			@pkgdep\ $2-[0-9]*|@pkgdep\ $2-[brv.][0-9]*|@pkgdep\ $2-a.[0-9]*|@pkgdep\ $2-pl[0-9]*|@pkgdep\ $2-b.r[0-9]*|@pkgdep\ $2-cr.[a-z]*)
324
 				return 0 ;;
325
 			[!@]*)	break ;;
326
 			esac
327
@@ -1134,7 +1237,7 @@
328
 
329
 update_pkgdep() {
330
 	update_file "${PKG_DBDIR}/$1/+CONTENTS" \
331
-	"s/^@pkgdep $2\$/@pkgdep $3/" || return 1
332
+	"/^@pkgdep $2\$/,/^@comment DEPORIGIN:/ { s|^@pkgdep $2\$|@pkgdep $3|; s|^@comment DEPORIGIN:.*\$|@comment DEPORIGIN:${pkg_origin}|; }" || return 1
333
 }
334
 
335
 delete_pkgdep() {
336
@@ -1325,7 +1428,7 @@
337
 
338
 init_install() {
339
 	case $1 in
340
-	*.t[bg]z)
341
+	*.t[bgx]z)
342
 		set_pkg_vars_for_binary "$1" || return 1 ;;
343
 	/*)	set_port_vars "$1" || return 1 ;;
344
 	*)	set_port_vars "${PORTSDIR}/$1" || return 1 ;;
345
@@ -1351,7 +1454,7 @@
346
 	done
347
 
348
 	case ${replace_with} in
349
-	*.t[bg]z)
350
+	*.t[bgx]z)
351
 		pkg_binary=${replace_with} ;;
352
 	?*)
353
 		pkg_portdir=${replace_with}
354
@@ -1428,6 +1531,12 @@
355
 do_replace() {
356
 	local pkg_log pkg_tmpdir old_package old_required_by preserved_files
357
 
358
+	if is_yes ${use_pkgng}; then
359
+		local old_origin new_origin
360
+		old_origin=
361
+		new_origin=
362
+	fi
363
+
364
 	init_replace "$1" || { status=skipped; return 0; }
365
 
366
 	if [ "${cur_pkg_name}" != "${pkg_name}" ]; then
367
@@ -1482,7 +1591,9 @@
368
 	fi
369
 
370
 	pkg_tmpdir="${tmpdir}/${cur_pkg_name}"
371
+	if ! is_yes ${use_pkgng}; then
372
 	old_required_by="${pkg_tmpdir}/+REQUIRED_BY"
373
+	fi
374
 
375
 	if ! find_package 'old_package' "${cur_pkg_name}"; then
376
 		old_package="${pkg_tmpdir}/${cur_pkg_name}${PKG_SUFX}"
377
@@ -1491,7 +1602,11 @@
378
 	if ! {
379
 		create_dir "${pkg_tmpdir}" &&
380
 		backup_package "${cur_pkg_name}" "${old_package}" &&
381
-		backup_file "${cur_pkg_pkgdir}/+REQUIRED_BY" "${old_required_by}" &&
382
+		if is_yes ${use_pkgng}; then
383
+			old_origin=`${PKG_INFO} -qo ${cur_pkg_name}` || return 1
384
+		else
385
+			backup_file "${cur_pkg_pkgdir}/+REQUIRED_BY" "${old_required_by}"
386
+		fi &&
387
 		preserve_libs "${cur_pkg_name}"
388
 	}; then
389
 		log="backup error"
390
@@ -1503,6 +1618,9 @@
391
 		if install_package "${pkg_binary:-${pkg_portdir}}" "${pkg_log}"; then
392
 			status=done
393
 			cur_pkg_pkgdir=${PKG_DBDIR}/${pkg_name}
394
+			if is_yes ${use_pkgng}; then
395
+				new_origin=`${PKG_INFO} -qo ${pkg_name}`
396
+			fi
397
 		else
398
 			log="install error"
399
 			restore_package "${old_package}" || {
400
@@ -1515,8 +1633,10 @@
401
 		log="deinstall error"
402
 	fi
403
 
404
+	if ! is_yes ${use_pkgng}; then
405
 	restore_file "${old_required_by}" "${cur_pkg_pkgdir}/+REQUIRED_BY" ||
406
 		warn "Failed to restore the +REQUIRED_BY file."
407
+	fi
408
 	process_package "${old_package}" ||
409
 		warn "Failed to keep the old version."
410
 	clean_libs ||
411
@@ -1527,7 +1647,11 @@
412
 	case ${status} in
413
 	done)
414
 		fix_dependencies "${pkg_name}" || return 1
415
-		update_dependencies "${cur_pkg_name%-*}" "${pkg_name}" || return 1 ;;
416
+		if is_yes ${use_pkgng}; then
417
+		update_dependencies "${old_origin}" "${new_origin}" || return 1
418
+		else
419
+		update_dependencies "${cur_pkg_name%-*}" "${pkg_name}" || return 1
420
+		fi ;;
421
 	*)
422
 		return 1 ;;
423
 	esac
(-)pkg_replace/pkg-plist (-1 / +4 lines)
Lines 1-6 Link Here
1
etc/pkg_replace.conf.sample
2
man/man1/pkg_replace.1.gz
3
%%PKGDB_FIX%%man/man1/pkgdb_fix.1.gz
1
sbin/pkg_replace
4
sbin/pkg_replace
2
%%PKGDB_FIX%%sbin/pkgdb_fix
5
%%PKGDB_FIX%%sbin/pkgdb_fix
3
etc/pkg_replace.conf.sample
4
%%ZSH%%share/zsh/site-functions/_pkg_replace
6
%%ZSH%%share/zsh/site-functions/_pkg_replace
5
%%ZSH%%@unexec [ -f %D/bin/zsh ] || rmdir %D/share/zsh/site-functions 2>/dev/null || true
7
%%ZSH%%@unexec [ -f %D/bin/zsh ] || rmdir %D/share/zsh/site-functions 2>/dev/null || true
8
%%ZSH%%@dirrmtry share/zsh/site-functions
6
%%ZSH%%@dirrmtry share/zsh
9
%%ZSH%%@dirrmtry share/zsh

Return to bug 182388