Bug 181077 - [patch] ports-mgmt/pkg_replace support pkgng
Summary: [patch] ports-mgmt/pkg_replace support pkgng
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Alex Kozlov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-06 03:30 UTC by Ken DEGUCHI
Modified: 2013-09-26 19:06 UTC (History)
0 users

See Also:


Attachments
file.diff (9.82 KB, patch)
2013-08-06 03:30 UTC, Ken DEGUCHI
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ken DEGUCHI 2013-08-06 03:30:00 UTC
ports-mgmt/pkg_replace does not support pkgng.

I made a patch to support pkgng for pkg_replace.

Fix: I made a patch to support pkgng for pkg_replace.

Patch attached with submission follows:
How-To-Repeat: ports-mgmt/pkg_replace does not support pkgng.
Comment 1 Alex Kozlov freebsd_committer freebsd_triage 2013-09-20 12:42:17 UTC
State Changed
From-To: open->closed

Superseded by ports/181643.
Comment 2 dfilter service freebsd_committer freebsd_triage 2013-09-20 12:44:24 UTC
Author: ak
Date: Fri Sep 20 11:44:15 2013
New Revision: 327692
URL: http://svnweb.freebsd.org/changeset/ports/327692

Log:
  - Undeprecate, give maintainership to submitter
  - Add pkgng support
  
  PR:	ports/181077
  Submitted by:	Ken DEGUCHI <kdeguchi@sz.tokoha-u.ac.jp>

Added:
  head/ports-mgmt/pkg_replace/files/
  head/ports-mgmt/pkg_replace/files/patch-pkg_replace_pkgng   (contents, props changed)
Modified:
  head/ports-mgmt/pkg_replace/Makefile
  head/ports-mgmt/pkg_replace/pkg-plist   (contents, props changed)

Modified: head/ports-mgmt/pkg_replace/Makefile
==============================================================================
--- head/ports-mgmt/pkg_replace/Makefile	Fri Sep 20 11:31:01 2013	(r327691)
+++ head/ports-mgmt/pkg_replace/Makefile	Fri Sep 20 11:44:15 2013	(r327692)
@@ -3,16 +3,14 @@
 
 PORTNAME=	pkg_replace
 PORTVERSION=	0.8.0
+PORTREVISION=	1
 CATEGORIES=	ports-mgmt
 MASTER_SITES=	${MASTER_SITE_SOURCEFORGE_JP}
 MASTER_SITE_SUBDIR=portutil/22116
 
-MAINTAINER=	ports@FreeBSD.org
+MAINTAINER=	kdeguchi@sz.tokoha-u.ac.jp
 COMMENT=	Utility for upgrading installed packages
 
-DEPRECATED=	Abandoned upstream, does not support pkgng. Consider using ports-mgmt/portmaster, ports-mgmt/portupgrade or pkgng
-EXPIRATION_DATE=	2013-12-31
-
 USE_BZIP2=	YES
 MAKE_ARGS=	PREFIX="${PREFIX}" \
 		PORTSDIR="${PORTSDIR}" PKG_DBDIR="${PKG_DBDIR}"
@@ -20,4 +18,27 @@ MAKE_ARGS=	PREFIX="${PREFIX}" \
 MAN1=		pkg_replace.1
 MANCOMPRESSED=	maybe
 
+OPTIONS_DEFINE=		ZSH
+
+.if empty(WITH_PKGNG)
+OPTIONS_DEFINE+=	PKGDB_FIX
+PKGDB_FIX_DESC=		Fixing tool of installed package dependencies
+.endif
+
+OPTIONS_SUB=	yes
+
+.include <bsd.port.options.mk>
+
+.if ${PORT_OPTIONS:MPKGDB_FIX}
+MAN1+=	pkgdb_fix.1
+.endif
+
+post-patch:
+.if ${PORT_OPTIONS:MPKGDB_FIX}
+	@${REINPLACE_CMD} -e 's/pkg_replace/pkg_replace pkgdb_fix/;' ${WRKSRC}/sbin/Makefile
+.endif
+.if !${PORT_OPTIONS:MZSH}
+	@${REINPLACE_CMD} -e  's/^	sbin \\$$/	sbin/;s/^	share$$//;' ${WRKSRC}/Makefile
+.endif
+
 .include <bsd.port.mk>

Added: head/ports-mgmt/pkg_replace/files/patch-pkg_replace_pkgng
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/ports-mgmt/pkg_replace/files/patch-pkg_replace_pkgng	Fri Sep 20 11:44:15 2013	(r327692)
@@ -0,0 +1,414 @@
+--- sbin/pkg_replace/pkg_replace.sh.orig	2007-01-25 21:55:46.000000000 +0900
++++ sbin/pkg_replace/pkg_replace.sh	2013-05-31 04:13:29.000000000 +0900
+@@ -125,14 +125,27 @@
+ 	: ${PACKAGEROOT="ftp://ftp.NetBSD.org"}
+ 	: ${PKG_SUFX=".tgz"}
+ #else
++	: ${use_pkgng="`/usr/bin/make -f/usr/share/mk/bsd.port.mk -V WITH_PKGNG`"}
++	if [ "x${use_pkgng}" = "xdevel" ]; then
++		use_pkgng="yes"
++	fi
+ 	: ${PORTSDIR="/usr/ports"}
++	if is_yes ${use_pkgng}; then
++	: ${PKGREPOSITORY="/var/cache/pkg/All"}
++	else
+ 	: ${PKGREPOSITORY="${PORTSDIR}/packages/All"}
++	fi
+ #ifdef WITH_OPENBSD
+ 	: ${PACKAGEROOT="ftp://ftp.OpenBSD.org"}
+ 	: ${PKG_SUFX=".tgz"}
+ #else
++	if is_yes ${use_pkgng}; then
++	: ${PACKAGEROOT="http://pkgbeta.FreeBSD.org"}
++	: ${PKG_SUFX=".txz"}
++	else
+ 	: ${PACKAGEROOT="ftp://ftp.FreeBSD.org"}
+ 	: ${PKG_SUFX=".tbz"}
++	fi
+ #endif
+ #endif
+ 	: ${PKG_BACKUP_DIR=${PKGREPOSITORY}}
+@@ -152,10 +165,18 @@
+ }
+ 
+ init_pkgtools() {
++	if is_yes ${use_pkgng}; then
++	PKG_ADD="pkg add"
++	PKG_CREATE="pkg create"
++	PKG_DELETE="pkg delete"
++	PKG_INFO="pkg info"
++	PKG_SET="pkg set"
++	else
+ 	PKG_ADD="pkg_add"
+ 	PKG_CREATE="pkg_create"
+ 	PKG_DELETE="pkg_delete"
+ 	PKG_INFO="pkg_info"
++	fi
+ 	MAKE="@MAKE@"
+ }
+ 
+@@ -213,7 +234,7 @@
+ 			expand_path 'file' "${p##*=}"
+ 			file_exist "${file}" || continue
+ 			p=${p%=*} ;;
+-		*.t[bg]z)
++		*.t[bgx]z)
+ 			expand_path 'file' "$p"
+ 			get_pkgname_for_binary 'p' "${file}" || continue
+ 			p=${p%-*} ;;
+@@ -423,6 +444,7 @@
+ 	file_exist "$2" || return 1
+ 
+ 	case $2 in
++	*.txz)	_opt=J ;;
+ 	*.tbz)	_opt=j ;;
+ 	*.tgz)	_opt=z ;;
+ 	*)	return 1 ;;
+@@ -434,6 +456,7 @@
+ #ifdef WITH_OPENBSD
+ 	X=`@TAR@ x${_opt}f "$2" -O "+CONTENTS" |
+ #else
++	is_yes ${use_pkgng} && X=`${PKG_INFO} -F "$2"` ||
+ 	X=`@TAR@ x${_opt}f "$2" -O --fast-read "+CONTENTS" |
+ #endif
+ #endif
+@@ -467,6 +490,11 @@
+ 		done < "${PKG_DBDIR}/$2/+BUILD_INFO"
+ 	fi
+ #else
++	if is_yes ${use_pkgng}; then
++		X=`${PKG_INFO} -qo $2`
++		eval $1=\$X
++		return 0
++	fi
+ 	if [ -r "${PKG_DBDIR}/$2/+CONTENTS" ]; then
+ 		while read X; do
+ 			case $X in
+@@ -488,7 +516,11 @@
+ }
+ 
+ set_pkg_vars() {
++	if is_yes ${use_pkgng}; then
++	${PKG_INFO} -e $1 || return 1
++	else
+ 	[ -d "${PKG_DBDIR}/$1" ] || return 1
++	fi
+ 
+ 	pkg_name=$1
+ 	pkg_pkgdir=${PKG_DBDIR}/$1
+@@ -526,10 +558,27 @@
+ 
+ 	for _arg in ${1+"$@"}; do
+ 		_pattern=${_arg#${PKG_DBDIR}/}
++		if is_yes ${use_pkgng}; then
++			for p in `${PKG_INFO} -g "${_pattern}" 2>/dev/null`; do
++				if is_yes ${opt_depends}; then
++					pkg_depends '_deps' "$p"
++					eval ${_var}=\"\$${_var} \${_deps}\"
++				fi
++
++				eval ${_var}=\"\$${_var} \$p\"
+ 
++				if is_yes ${opt_required_by}; then
++					pkg_required_by '_req_by' "$p"
++					eval ${_var}=\"\$${_var} \${_req_by}\"
++				fi
++			done
++			if [ -z "${pkgs}" ]; then
++				warn "No such installed package: ${_arg}"
++			fi
++		else
+ 		case ${_pattern} in
+-		*\**|*-pl[0-9]*|*-[0-9]*[0-9.][a-z]|*-[0-9]*[0-9]) ;;
+-		*)		_pattern="${_pattern}-[0-9]*[0-9a-z]" ;;
++		*\**|*-[0-9]*|*-[brv.][0-9]*|*-a.[0-9]*|*-pl[0-9]*|*-b.r[0-9]*|*-cr.[a-z]*) ;;
++		*)		_pattern="${_pattern}-[0-9]*[0-9a-zA-Z]" ;;
+ 		esac
+ 
+ 		for p in ${PKG_DBDIR}/${_pattern}/+CONTENTS; do
+@@ -552,6 +601,7 @@
+ 				warn "No such installed package: ${_arg}"
+ 			fi
+ 		done
++		fi
+ 	done
+ 
+ 	set -f
+@@ -568,6 +618,12 @@
+ 		done < "${PKG_DBDIR}/$2/+REQUIRING"
+ 	fi
+ #else
++	if is_yes ${use_pkgng}; then
++		X=`${PKG_INFO} -qd $2`
++		eval $1=\"\${X}\"
++		return 0
++	fi
++
+ 	if [ -r "${PKG_DBDIR}/$2/+CONTENTS" ]; then
+ 		while read X; do
+ 			case $X in
+@@ -588,6 +644,12 @@
+ pkg_required_by() {
+ 	local X
+ 
++	if is_yes ${use_pkgng}; then
++		X=`${PKG_INFO} -qr $2`
++		eval $1=\"\$X\"
++		return 0
++	fi
++
+ 	eval $1=
+ 	if [ -r "${PKG_DBDIR}/$2/+REQUIRED_BY" ]; then
+ 		while read X; do
+@@ -597,7 +659,7 @@
+ }
+ 
+ pkg_sort() {
+-	local p _var _sorted _unsorted _arg _deps
++	local p _var _sorted _unsorted _arg _deps _deplist
+ 
+ 	_var=$1; shift
+ 	_sorted=
+@@ -612,7 +674,13 @@
+ 		*" ${_arg} "*)	continue ;;
+ 		esac
+ 
+-		if [ -s "${PKG_DBDIR}/${_arg}/+REQUIRED_BY" ]; then
++		_deplist=
++		if is_yes ${use_pkgng}; then
++			_deplist=`${PKG_INFO} -qr ${_arg}`
++		else
++			_deplist="${PKG_DBDIR}/${_arg}/+REQUIRED_BY"
++		fi
++		if [ -s "${_deplist}" ]; then
+ 			pkg_depends '_deps' "${_arg}"
+ 
+ 			for p in ${_deps}; do
+@@ -757,9 +825,11 @@
+ 	info "Installing '$1'"
+ 
+ 	case $1 in
+-	*.t[bg]z)
++	*.t[bgx]z)
+ 		is_yes ${opt_force} && install_args="-f"
++		if ! is_yes ${use_pkgng}; then
+ 		is_yes ${opt_verbose} && install_args="${install_args} -v"
++		fi
+ 
+ 		xtry "${2-}" ${PKG_ADD} ${install_args} "$1" || return 1
+ 		;;
+@@ -795,7 +865,11 @@
+ 
+ 	deinstall_args=
+ 	is_yes ${opt_force} && deinstall_args="-f"
++	if is_yes ${use_pkgng}; then
++	deinstall_args="${deinstall_args} -y"
++	else
+ 	is_yes ${opt_verbose} && deinstall_args="${deinstall_args} -v"
++	fi
+ 
+ #ifdef WITH_PKGSRC
+ 	if [ -e "${PKG_DBDIR}/$1/+PRESERVE" ]; then
+@@ -915,7 +989,11 @@
+ 		*)		subdir="${OS_MAJOR}-stable" ;;
+ 		esac
+ 
++		if is_yes ${use_pkgng}; then
++		uri_path=/freebsd-${OS_MAJOR}-${ARCH}/latest/All/
++		else
+ 		uri_path="/pub/FreeBSD/ports/${ARCH}/packages-${subdir}/All/"
++		fi
+ #endif
+ #endif
+ 		uri="${PACKAGEROOT}${uri_path}${pkg}"
+@@ -987,7 +1065,11 @@
+ 		return 1
+ 	fi
+ #else
++	if is_yes ${use_pkgng}; then
++	try ${PKG_CREATE} -f ${PKG_SUFX} -o "${2%/*}" "$1" || return 1
++	else
+ 	try ${PKG_CREATE} -b "$1" "$2" || return 1
++	fi
+ #endif
+ #endif
+ }
+@@ -1031,12 +1113,17 @@
+ }
+ 
+ preserve_libs() {
+-	local file
++	local file pkg_info_opts
+ 
+ 	is_yes ${opt_preserve_libs} || return 0
+ 
++	if is_yes ${use_pkgng}; then
++		pkg_info_opts='-ql'
++	else
++		pkg_info_opts='-qL'
++	fi
+ 	preserved_files=
+-	for file in $(${PKG_INFO} -qL "$1"); do
++	for file in $(${PKG_INFO} ${pkg_info_opts} "$1"); do
+ 		case ${file##*/} in
+ 		lib*.so.[0-9]*)
+ 			if [ -f "${file}" ]; then
+@@ -1080,20 +1167,30 @@
+ fix_dependencies() {
+ #ifndef WITH_PKGSRC
+ #ifndef WITH_OPENBSD
+-	local p deps newdep opt_depends opt_required_by
++	local p deps newdep opt_depends opt_required_by dep_installed
+ 
+ 	opt_depends=NO
+ 	opt_required_by=NO
+ 	pkg_depends 'deps' "$1"
+ 
+ 	for p in ${deps}; do
+-		if [ ! -d "${PKG_DBDIR}/$p" ]; then
++		dep_installed=no
++		if is_yes ${use_pkgng}; then
++			${PKG_INFO} -e $p && dep_installed=yes || dep_installed=no
++		else
++			[ -d "${PKG_DBDIR}/$p" ] && dep_installed=yes || dep_installed=no
++		fi
++		if ! is_yes ${dep_installed}; then
+ 			pkg_glob 'newdep' "${p%-*}" 2>/dev/null
+ 
+ 			if empty ${newdep}; then
+ 				warn "'$1' depends on '$p', but it is NOT installed!"
+ 			else
++				if is_yes ${use_pkgng}; then
++				${PKG_SET} -y -o `${PKG_INFO} -qo $1`:`${PKG_INFO} -qo $p` || return 1
++				else
+ 				update_pkgdep "$1" "$p" "${newdep##* }" || return 1
++				fi
+ 			fi
+ 		fi
+ 	done
+@@ -1102,6 +1199,11 @@
+ }
+ 
+ update_dependencies() {
++	if is_yes ${use_pkgng}; then
++		info "Updating the dependencies"
++		${PKG_SET} -y -o $1:$2 || return 1
++		info "	$1 -> $2"
++	else
+ 	local p req_by
+ 
+ 	pkg_required_by 'req_by' "$2"
+@@ -1114,6 +1216,7 @@
+ 			update_pkgdep "$p" "$1-[^-]*" "$2" || return 1
+ 		done
+ 	fi
++	fi
+ }
+ 
+ have_pkgdep() {
+@@ -1122,7 +1225,7 @@
+ 	if [ -r "${PKG_DBDIR}/$1/+CONTENTS" ]; then
+ 		while read X; do
+ 			case $X in
+-			@pkgdep\ $2-[0-9]*|@pkgdep\ $2-pl[0-9]*)
++			@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]*)
+ 				return 0 ;;
+ 			[!@]*)	break ;;
+ 			esac
+@@ -1134,7 +1237,7 @@
+ 
+ update_pkgdep() {
+ 	update_file "${PKG_DBDIR}/$1/+CONTENTS" \
+-	"s/^@pkgdep $2\$/@pkgdep $3/" || return 1
++	"/^@pkgdep $2\$/,/^@comment DEPORIGIN:/ { s|^@pkgdep $2\$|@pkgdep $3|; s|^@comment DEPORIGIN:.*\$|@comment DEPORIGIN:${pkg_origin}|; }" || return 1
+ }
+ 
+ delete_pkgdep() {
+@@ -1325,7 +1428,7 @@
+ 
+ init_install() {
+ 	case $1 in
+-	*.t[bg]z)
++	*.t[bgx]z)
+ 		set_pkg_vars_for_binary "$1" || return 1 ;;
+ 	/*)	set_port_vars "$1" || return 1 ;;
+ 	*)	set_port_vars "${PORTSDIR}/$1" || return 1 ;;
+@@ -1351,7 +1454,7 @@
+ 	done
+ 
+ 	case ${replace_with} in
+-	*.t[bg]z)
++	*.t[bgx]z)
+ 		pkg_binary=${replace_with} ;;
+ 	?*)
+ 		pkg_portdir=${replace_with}
+@@ -1428,6 +1531,12 @@
+ do_replace() {
+ 	local pkg_log pkg_tmpdir old_package old_required_by preserved_files
+ 
++	if is_yes ${use_pkgng}; then
++		local old_origin new_origin
++		old_origin=
++		new_origin=
++	fi
++
+ 	init_replace "$1" || { status=skipped; return 0; }
+ 
+ 	if [ "${cur_pkg_name}" != "${pkg_name}" ]; then
+@@ -1482,7 +1591,9 @@
+ 	fi
+ 
+ 	pkg_tmpdir="${tmpdir}/${cur_pkg_name}"
++	if ! is_yes ${use_pkgng}; then
+ 	old_required_by="${pkg_tmpdir}/+REQUIRED_BY"
++	fi
+ 
+ 	if ! find_package 'old_package' "${cur_pkg_name}"; then
+ 		old_package="${pkg_tmpdir}/${cur_pkg_name}${PKG_SUFX}"
+@@ -1491,7 +1602,11 @@
+ 	if ! {
+ 		create_dir "${pkg_tmpdir}" &&
+ 		backup_package "${cur_pkg_name}" "${old_package}" &&
+-		backup_file "${cur_pkg_pkgdir}/+REQUIRED_BY" "${old_required_by}" &&
++		if is_yes ${use_pkgng}; then
++			old_origin=`${PKG_INFO} -qo ${cur_pkg_name}` || return 1
++		else
++			backup_file "${cur_pkg_pkgdir}/+REQUIRED_BY" "${old_required_by}"
++		fi &&
+ 		preserve_libs "${cur_pkg_name}"
+ 	}; then
+ 		log="backup error"
+@@ -1503,6 +1618,9 @@
+ 		if install_package "${pkg_binary:-${pkg_portdir}}" "${pkg_log}"; then
+ 			status=done
+ 			cur_pkg_pkgdir=${PKG_DBDIR}/${pkg_name}
++			if is_yes ${use_pkgng}; then
++				new_origin=`${PKG_INFO} -qo ${pkg_name}`
++			fi
+ 		else
+ 			log="install error"
+ 			restore_package "${old_package}" || {
+@@ -1515,8 +1633,10 @@
+ 		log="deinstall error"
+ 	fi
+ 
++	if ! is_yes ${use_pkgng}; then
+ 	restore_file "${old_required_by}" "${cur_pkg_pkgdir}/+REQUIRED_BY" ||
+ 		warn "Failed to restore the +REQUIRED_BY file."
++	fi
+ 	process_package "${old_package}" ||
+ 		warn "Failed to keep the old version."
+ 	clean_libs ||
+@@ -1527,7 +1647,11 @@
+ 	case ${status} in
+ 	done)
+ 		fix_dependencies "${pkg_name}" || return 1
+-		update_dependencies "${cur_pkg_name%-*}" "${pkg_name}" || return 1 ;;
++		if is_yes ${use_pkgng}; then
++		update_dependencies "${old_origin}" "${new_origin}" || return 1
++		else
++		update_dependencies "${cur_pkg_name%-*}" "${pkg_name}" || return 1
++		fi ;;
+ 	*)
+ 		return 1 ;;
+ 	esac

Modified: head/ports-mgmt/pkg_replace/pkg-plist
==============================================================================
--- head/ports-mgmt/pkg_replace/pkg-plist	Fri Sep 20 11:31:01 2013	(r327691)
+++ head/ports-mgmt/pkg_replace/pkg-plist	Fri Sep 20 11:44:15 2013	(r327692)
@@ -1,5 +1,6 @@
 sbin/pkg_replace
+%%PKGDB_FIX%%sbin/pkgdb_fix
 etc/pkg_replace.conf.sample
-share/zsh/site-functions/_pkg_replace
-@unexec [ -f %D/bin/zsh ] || rmdir %D/share/zsh/site-functions 2>/dev/null || true
-@dirrmtry share/zsh
+%%ZSH%%share/zsh/site-functions/_pkg_replace
+%%ZSH%%@unexec [ -f %D/bin/zsh ] || rmdir %D/share/zsh/site-functions 2>/dev/null || true
+%%ZSH%%@dirrmtry share/zsh
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 3 Alex Kozlov freebsd_committer freebsd_triage 2013-09-26 19:06:16 UTC
Responsible Changed
From-To: freebsd-ports-bugs->ak

I'll take it.