2 # ==============================================================================
3 # portsreinstall library script
4 # - Wrappers for hiding version differences in the Ports/Packages system -
5 # Copyright (C) 2013-2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
9 # ============= Variables =============
10 PKGSYS_USE_PKGNG=yes # no: legacy pkg_* tools, yes: the new generation package (pkgng)
11 PKGSYS_CMD_PKG_DELETE='pkg delete' # Corresponding command for pkg_delete
12 PKGSYS_AVR_REFETCH_TIMES_PER_SITE=1 # Average number (integer) of retrials for retrieving package or distfiles per mirror site
13 PKGSYS_AVR_REFETCH_TIMES_FOR_CHKSUMERR=2 # Number (integer) of retrials for check sum error in retrieving a package
15 # ============= Check implementation of the ports tree =============
16 pkgsys_chk_ports_tree_implementation ()
18 fs_fix_unionfs_image_if_hidden "${PORTSDIR}/Mk/bsd.port.mk" || :
19 fs_fix_unionfs_image_if_hidden "${PORTSDIR}/Makefile" || :
20 if [ ! -d "${PORTSDIR}" ]
22 message_echo "ERROR: Ports directory ${PORTSDIR} is not found." >&2
25 if [ ! -e "${PORTSDIR}/Makefile" -o ! -e "${PORTSDIR}/Mk/bsd.port.mk" ]
27 message_echo "ERROR: Ports tree ${PORTSDIR} is missing, broken or incompatible." >&2
32 # ============= System defined value for the ports/packages =============
37 tmp_work=${TMPDIR}/pkgsys_sysvar:work
40 fs_fix_unionfs_image_if_hidden "${PORTSDIR}/Mk/bsd.port.mk"
41 make -C "$tmp_work" -f "${PORTSDIR}/Mk/bsd.port.mk" -V "$var" 2> /dev/null
44 # ============= Get the file name of package check sum file =============
45 pkgsys_pkgchksum_file ()
50 # ============= Get the origin of the currently used pkg(8) =============
51 # NOTE: Assumed to be unflavored.
52 pkgsys_portsmgmt_pkg ()
54 local origin_unflavored
55 if [ ! -e "${DBDIR}/PKG_ORIGIN" ]
57 origin_unflavored=`pkgsys_sysvar PKG_ORIGIN` || :
58 [ -n "$origin_unflavored" -a -d "${PORTSDIR}/$origin_unflavored" ] || origin_unflavored=ports-mgmt/pkg
59 echo "$origin_unflavored" > ${DBDIR}/PKG_ORIGIN
61 cat "${DBDIR}/PKG_ORIGIN"
64 # ============= Get the origin of the currently used dialog4ports(1) =============
65 # NOTE: Assumed to be unflavored.
66 pkgsys_portsmgmt_dialog4ports ()
68 local origin_unflavored
69 if [ ! -e "${DBDIR}/DIALOGPORT" ]
71 origin_unflavored=`pkgsys_sysvar DIALOGPORT` || :
72 [ -n "$origin_unflavored" -a -d "${PORTSDIR}/$origin_unflavored" ] || origin_unflavored=ports-mgmt/dialog4ports
73 echo "$origin_unflavored" > ${DBDIR}/DIALOGPORT
75 cat "${DBDIR}/DIALOGPORT"
78 # ============= Check whether a port is indispensable for the standard function of the ports/packages system =============
81 local origin origin_unflavored
83 origin_unflavored=`echo "$origin" | sed 's/@.*$//'`
84 case $origin_unflavored in
85 ports-mgmt/pkg | ports-mgmt/pkg-devel | ports-mgmt/dialog4ports | ports-mgmt/dialog4ports-static )
92 # ============= Check whether a port is indispensable for package operations =============
93 pkgsys_is_necessary_pkgtool ()
95 local origin origin_unflavored
97 origin_unflavored=`echo "$origin" | sed 's/@.*$//'`
98 [ x"$WITH_PKGNG" = x'yes' -a \( x"$origin_unflavored" = x'ports-mgmt/pkg' -o x"$origin_unflavored" = x'ports-mgmt/pkg-devel' \) ]
101 # ============= Get the extended regular expression pattern of ports for pkg(8) =============
102 pkgsys_pkgtools_ports_filter_regexp ()
104 echo '^ports-mgmt/(pkg|pkg-devel)(|@.*)$'
107 # ============= Get the extended regular expression pattern of package names for pkg(8) =============
108 pkgsys_pkgtools_pkgs_filter_regexp ()
110 echo '^(pkg|pkg-devel)-[0-9]\.'
113 # ============= Check whether the dialog for selecting port options is dialog4ports =============
114 pkgsys_is_dialog4ports_used ()
116 [ -n "`pkgsys_sysvar DIALOG4PORTS`" ]
119 # ============= Get the number of mirror sites for legacy packages =============
120 pkgsys_num_mirrorsites ()
124 echo "$siteroots" | tr '|' '\n' | wc -l
127 # ============= Get a URL one of mirror sites =============
128 pkgsys_url_from_mirrors ()
130 local siteroots subdir nsites id_site site platform version
133 nsites=`pkgsys_num_mirrorsites "$siteroots"`
134 id_site=`(set +e; random -e $nsites; echo $?)`
135 site=`echo "$siteroots" | tr '|' '\n' | sed -n $((${id_site}+1))p`
137 version=`uname -r | cut -d - -f 1,2 | tr [:upper:] [:lower:]`
139 printf "$subdir\n" "$platform" "$version"
142 # ============= Fetch a file from one of mirror sites =============
143 pkgsys_fetch_from_mirrors ()
145 local siteroots subdir filename dst tmp_work fetch itrial origdir url
150 tmp_work=${TMPDIR}/pkgsys_fetch_from_mirrors:work
153 fetch=`pkgsys_sysvar FETCH_CMD`
154 itrial=$((`pkgsys_num_mirrorsites "$siteroots"`*$PKGSYS_AVR_REFETCH_TIMES_PER_SITE))
157 while [ $itrial -ge 1 ]
159 url=`pkgsys_url_from_mirrors "$siteroots" "$subdir"`$filename
160 message_echo "INFO: Fetching from $url:"
161 $fetch "$url"&& break
163 itrial=$(($itrial-1))
166 [ -e "$tmp_work/$filename" ] || return
167 mv "$tmp_work/$filename" "$dst"
170 # ============= Get the package check sums file ready =============
171 pkgsys_ready_checksum_file ()
174 tmp_savedpath=${TMPDIR}/pkgsys_ready_checksum_file:savedpath
175 rm -f "$tmp_savedpath"
176 chksumfile=`pkgsys_pkgchksum_file`
177 if [ ! -e "${DBDIR}/checksum/$chksumfile" ]
179 [ -d "${DBDIR}/checksum" ] || mkdir "${DBDIR}/checksum"
180 if ! pkgsys_fetch_from_mirrors "${PACKAGECHECKSUMROOTS}" "${PACKAGECHECKSUMDIR}" \
181 "$chksumfile" "${DBDIR}/checksum"
183 message_echo "WARNING: No check sum file is available." >&2
187 echo "${DBDIR}/checksum/$chksumfile" > $tmp_savedpath
190 # ============= Get the location of a check sums file fetched by pkgsys_ready_checksum_file =============
191 pkgsys_ready_checksum_file__fetched_file ()
193 cat "${TMPDIR}/pkgsys_ready_checksum_file:savedpath"
196 # ============= Fetch a legacy package from one of remote sites =============
197 pkgsys_fetch_legacy_remote ()
199 local pkg tmp_work tmp_pkgpath pkg_regexp checksumpath validMD5 fetchedMD5 needs_fetch itrial
201 tmp_work=${TMPDIR}/pkgsys_fetch_legacy_remote:work
202 tmp_pkgpath=${TMPDIR}/pkgsys_fetch_legacy_remote:pkgpath
205 pkg_regexp=`str_escape_regexp "$pkg"`
206 pkgsys_ready_checksum_file || return
207 checksumpath=`pkgsys_ready_checksum_file__fetched_file`
208 validMD5=`grep -m 1 -E -e "^MD5[[:space:]]*\($pkg_regexp\.tbz\)[[:space:]]*=" "$checksumpath" | sed -E "s/^[^=]*=[[:space:]]*(.*)/\1/"`
209 if [ -z "$validMD5" ]
211 message_echo "WARNING: No check sum for $pkg.tbz." >&2
215 mkdir -p "${PKGREPOSITORY}"
216 if [ -e "${PKGREPOSITORY}/$pkg.tbz" ]
218 if [ -e "${PKGREPOSITORY}/$pkg.md5=$validMD5.tbz" ]
220 fetchedMD5=`md5 "${PKGREPOSITORY}/$pkg.md5=$validMD5.tbz" | sed -E "s/^[^=]*=[[:space:]]*(.*)/\1/"`
221 [ "x$fetchedMD5" = "x$validMD5" ] || rm "${PKGREPOSITORY}/$pkg.md5=$fetchedMD5.tbz"
223 if [ -e "${PKGREPOSITORY}/$pkg.md5=$validMD5.tbz" ]
225 ln -f "${PKGREPOSITORY}/$pkg.md5=$fetchedMD5.tbz" "${PKGREPOSITORY}/$pkg.tbz"
227 fetchedMD5=`md5 "${PKGREPOSITORY}/$pkg.tbz" | sed -E "s/^[^=]*=[[:space:]]*(.*)/\1/"`
228 if [ "x$fetchedMD5" = "x$validMD5" ]
232 mv "${PKGREPOSITORY}/$pkg.tbz" "${PKGREPOSITORY}/$pkg.md5=$fetchedMD5.tbz"
236 if [ $needs_fetch = yes ]
238 itrial=$PKGSYS_AVR_REFETCH_TIMES_FOR_CHKSUMERR
239 while [ $itrial -ge 1 ]
241 if pkgsys_fetch_from_mirrors "${PACKAGEROOTS}" "${PACKAGEDIR}" \
242 "$pkg.tbz" "$tmp_work"
244 fetchedMD5=`md5 "$tmp_work/$pkg.tbz" | sed -E "s/^[^=]*=[[:space:]]*(.*)/\1/"`
245 [ "x$fetchedMD5" = "x$validMD5" ] && break
246 message_echo "WARNING: Check sum mismatches for $pkg.tbz." >&2
248 itrial=$(($itrial-1))
250 [ $itrial -ge 1 ] || return
251 mv "$tmp_work/$pkg.tbz" "${PKGREPOSITORY}"
253 echo "${PKGREPOSITORY}/$pkg.tbz" > $tmp_pkgpath
256 # ============= Get the location of a package fetched by pkgsys_fetch_legacy_remote =============
257 pkgsys_fetch_legacy_remote__fetched_pkg ()
259 cat "${TMPDIR}/pkgsys_fetch_legacy_remote:pkgpath"
262 # ============= Check whether the dependency of a legacy package is the latest =============
263 pkgsys_is_dependency_of_a_legacypkg_latest ()
265 local pkgarc tmp_extract tmp_contents tmp_origin tmp_pkg pkg nlines iline origin_req pkg_req pkg_new
267 tmp_extract=${TMPDIR}/pkgng:pkgsys_is_dependency_of_a_legacypkg_latest:extract
268 tmp_contents=${TMPDIR}/pkgng:pkgsys_is_dependency_of_a_legacypkg_latest:contents
269 tmp_origin=${TMPDIR}/pkgng:pkgsys_is_dependency_of_a_legacypkg_latest:origin
270 tmp_pkg=${TMPDIR}/pkgng:pkgsys_is_dependency_of_a_legacypkg_latest:pkg
271 pkg=`pkgsys_pkgarc_to_pkgname "$pkgarc"`
272 [ -e "$pkgarc" ] || return
273 rm -rf "$tmp_extract"
275 tar xf "$pkgarc" -C "$tmp_extract" +CONTENTS
276 grep -e '^@pkgdep[[:space:]]' -e '^@comment[[:space:]]*DEPORIGIN:' "$tmp_extract/+CONTENTS" \
277 | sed 's/^@pkgdep[[:space:]]*//;s/^@comment[[:space:]]*DEPORIGIN://' > $tmp_contents
278 nlines=`wc -l < $tmp_contents`
280 while [ $iline -le $nlines ]
282 origin_req=`sed -n ${iline}p "$tmp_contents"`
283 pkg_req=`sed -n $(($iline+1))p "$tmp_contents"`
285 pkg_new=`cat "${DBDIR}/requires/$origin_req/new_version" 2> /dev/null` || :
286 if [ -z "$pkg_new" -o "$pkg_new" != "$pkg_req" ]
288 message_echo "WARNING: Requirements of remote package $pkg are not the latest." >&2
295 # ============= Check whether legacy package tools are available =============
296 pkgsys_is_legacy_tool_available ()
301 # ============= Define wrapper commands for hiding the differences between pkg_* tools and pkgng =============
302 pkgsys_def_pkgtools ()
304 if [ "${DBDIR}/WITH_PKGNG" -nt /etc/make.conf -o \( -e "${DBDIR}/WITH_PKGNG" -a ! -e /etc/make.conf \) ]
306 PKGSYS_USE_PKGNG=`cat "${DBDIR}/WITH_PKGNG"`
308 PKGSYS_USE_PKGNG=`pkgsys_sysvar WITH_PKG | tr '[:upper:]' '[:lower:]'`
309 [ -n "$PKGSYS_USE_PKGNG" ] || PKGSYS_USE_PKGNG=`pkgsys_sysvar WITH_PKGNG | tr '[:upper:]' '[:lower:]'`
310 if [ -d "${DBDIR}" ] && misc_is_superuser_privilege
312 echo "$PKGSYS_USE_PKGNG" > ${DBDIR}/WITH_PKGNG.tmp
313 mv "${DBDIR}/WITH_PKGNG.tmp" "${DBDIR}/WITH_PKGNG"
316 if [ "x$PKGSYS_USE_PKGNG" = xyes ]
319 export WITH_PKGNG=yes
320 PKGSYS_CMD_PKG_DELETE='pkg delete'
321 pkg_is_tool_available ()
323 if [ -x /usr/sbin/pkg ]
325 pkg -N 2> /dev/null && return
326 env ASSUME_ALWAYS_YES=yes pkg bootstrap -f
329 which -s pkg && return
334 pkg info -qa 2> /dev/null
338 # pkg info -qoa 2> /dev/null
342 # pkg info -qox "$@" 2> /dev/null
346 # pkg info -qox "$@" 2> /dev/null
350 pkg info -qO "$@" 2> /dev/null
354 pkg info -qo "$@" 2> /dev/null
358 pkg info -qd "$@" 2> /dev/null
362 pkg info -e "$@" 2> /dev/null
366 pkg info -eO "$@" 2> /dev/null
370 pkg info -Eg "$@" 2> /dev/null
374 pkg info -qr "$@" 2> /dev/null
378 pkg info -Ex "$@" 2> /dev/null
382 pkg info -ql "$@" 2> /dev/null
386 local glob_unflavored
388 pkg query -g '%At\t%Av' "$glob_unflavored" 2> /dev/null | grep -E '^flavor[[:space:]]' | cut -f 2
390 pkg_info_flavored_origin ()
392 local glob_unflavored origin_unflavored
394 origin_unflavored=`pkg_info_qo "$glob_unflavored" 2> /dev/null || :`
395 flavor=`pkg_info_flavor "$glob_unflavored" 2> /dev/null || :`
396 [ -z "$flavor" ] || flavor=@$flavor
397 echo "$origin_unflavored$flavor"
399 pkg_info_all_flavored_origins ()
401 local tmp_flavored tmp_flavored_ptn
402 tmp_flavored_ptn=${TMPDIR}/pkg_info_all_flavored_origins:flavored_ptn
403 pkg query '%o\t%At\t%Av' 2> /dev/null | grep -E '^[^[:space:]]+[[:space:]]flavor[[:space:]]' | cut -f 1,3 | tr '\t' @ | sed 's/@$//'
404 pkg query '%n\t%At' 2> /dev/null | grep -E '^[^[:space:]]+[[:space:]]flavor$' | cut -f 1 > $tmp_flavored_ptn
405 pkg query '%n\t%o' 2> /dev/null | grep -vFx -f "$tmp_flavored_ptn" | cut -f 2
409 local pkg tmp_stdout tmp_stderr
411 tmp_stdout=${TMPDIR}/pkgng:pkg_check_sanity:stdout
412 tmp_stderr=${TMPDIR}/pkgng:pkg_check_sanity:stderr
413 pkg check -s "$pkg" > $tmp_stdout 2> $tmp_stderr || :
415 grep '^[^:]*: checksum mismatch for ' "$tmp_stderr" | sed 's/^[^:]*: checksum mismatch for //' || :
416 grep '^[^:]*: missing file ' "$tmp_stderr" | sed 's/^[^:]*: missing file //' || :
417 if grep -q '^pkg: .*: No such file or directory$' "$tmp_stderr" # For the old specification of pkg(8)
419 pkg info -ql "$pkg" | while read filepath
421 [ -e "$filepath" ] || echo "$filepath"
430 pkg which -q "$filepath" 2> /dev/null
432 pkg_info_gen_pkg_origin_table ()
434 # pkg query -g '%n-%v\t%o' \* 2> /dev/null > ${DBDIR}/installed_ports:pkg_vs_origin.tbl
435 pkg info -qa | while read pkgname
437 origin=`pkg_info_flavored_origin "$pkgname"`
438 printf '%s\t%s\n' "$pkgname" "$origin"
439 done > ${DBDIR}/installed_ports:pkg_vs_origin.tbl
449 [ $no_exec_inst_script = yes ] && opt_del='-D'
450 pkg delete -fqy $opt_del "$@"
451 pkg -N 2> /dev/null || return 0 # If pkg(8) is deinstalled successfully
452 pkg info -e "$@" || return 0 # Countermeasure for a bug found for pkg-1.3.4 (at least not until 1.2.7_4)
453 pkg delete -fy $opt_del "$@"
457 local pkgarc tmp_extract prefix prefix_parent pkg
459 tmp_extract=${TMPDIR}/pkgng:pkg_add_tools:extract
460 rm -rf "$tmp_extract"
462 tar xf "$pkgarc" -C "$tmp_extract"
463 pkg=`pkgsys_pkgarc_to_pkgname "$pkgarc"`
464 if env ASSUME_ALWAYS_YES=YES $tmp_extract/usr/local/sbin/pkg-static add "$pkgarc"
466 message_echo "INFO: $pkg is successfully registered."
468 message_echo "WARNING: Failed to register $pkg, but the process is continued." >&2
474 local pkgarc pkg pkg_tool pkg_gen opt_add
479 pkg=`basename "$pkgarc"`
480 if expr "$pkg" : '^pkg-[0-9][0-9]*\..*' > /dev/null
484 pkg_gen="$pkg_gen $pkgarc"
487 [ -n "$pkg_tool" ] && pkg_add_tools "$pkg_tool"
490 rm -rf "${TMPDIR}/pkg_add_f"
491 mkdir -p "${TMPDIR}/pkg_add_f"
493 [ $no_exec_inst_script = yes ] && opt_add='-I'
494 ( cd "${TMPDIR}/pkg_add_f" && ln -s $pkg_gen && env ASSUME_ALWAYS_YES=YES pkg add $opt_add * )
501 pkg_inst_verify_pkg ()
505 pkgarc=`pkgsys_pkgname_to_pkgarc "${PKGNG_PKG_CACHEDIR}" "$pkg"` || return
506 tar tf "$pkgarc" > /dev/null 2> /dev/null
508 pkg_inst_remote_fetch ()
514 pkg_inst_remote_verify_fetch ()
518 pkg_inst_verify_pkg "$pkg" && return
519 pkg_inst_remote_fetch "$pkg" && pkg_inst_verify_pkg "$pkg"
523 local pkg pkgarc opt_add
525 pkg_inst_remote_verify_fetch "$pkg" || return
526 pkgarc=`pkgsys_pkgname_to_pkgarc "${PKGNG_PKG_CACHEDIR}" "$pkg"` || return
527 rm -rf "${TMPDIR}/pkg_inst_remote"
528 mkdir -p "${TMPDIR}/pkg_inst_remote"
530 [ $no_exec_inst_script = yes ] && opt_add='-I'
531 ( cd "${TMPDIR}/pkg_inst_remote" && ln -s "$pkgarc" && env ASSUME_ALWAYS_YES=YES pkg add $opt_add * )
533 pkg_inst_wild_verify_pkg ()
537 pkgarc=`pkgsys_pkgname_to_pkgarc "${PKGNG_PKG_CACHEDIR}" "$pkg"` || return
538 pkgsys_is_dependency_of_a_legacypkg_latest "$pkgarc"
540 pkg_inst_remote_wild_fetch ()
544 if pkg_is_tool_available
546 pkg_inst_remote "$pkg" && return
548 pkgsys_is_legacy_tool_available || return
549 message_echo "INFO: Trying to use a legacy package and convert it to pkgng."
550 pkgsys_fetch_legacy_remote "$pkg"
552 pkg_inst_remote_wild_verify_fetch ()
556 pkg_inst_wild_verify_pkg "$pkg" && return
557 pkg_inst_remote_wild_fetch "$pkg" && pkg_inst_wild_verify_pkg "$pkg"
559 pkg_inst_remote_wild ()
561 local pkg pkgarc opt_add
563 if pkg_inst_remote_wild_verify_fetch "$pkg"
565 pkgarc=`pkgsys_fetch_legacy_remote__fetched_pkg`
566 rm -rf "${TMPDIR}/pkg_inst_remote_wild"
567 mkdir -p "${TMPDIR}/pkg_inst_remote_wild"
569 [ $no_exec_inst_script = yes ] && opt_add='-I'
570 ( cd "${TMPDIR}/pkg_inst_remote_wild" && ln -s "$pkgarc" && pkg_add -ifF $opt_add * ) || return
571 message_echo "INFO: Trying to convert the installed legacy package to pkgng."
573 message_echo "INFO: Checking whether the conversion is successful."
577 pkg_get_remote_repository_version ()
579 local origin origin_unflavored pkg
581 origin_unflavored=`expr "$origin" : '\([^@]*\)'` || return
582 [ -n "$origin_unflavored" ] || return
583 pkg fetch -qyU "$origin_unflavored" > /dev/null || return
584 pkg=`pkg rquery -U %n-%v "$origin_unflavored"` || return
587 pkg_get_pkgs_timestamps ()
589 pkg query '%n-%v\tng-epoch:%t' "$@"
591 pkg_get_pkg_timestamp ()
595 pkg query '%t' "$pkg"
600 # Deafult configuration for pkg(1)
601 PKGNG_PACKAGESITE='http://pkg.freebsd.org/${ABI}/latest'
602 PKGNG_SRV_MIRRORS=YES
603 PKGNG_PKG_DBDIR=/var/db/pkg
604 PKGNG_PKG_CACHEDIR=/var/cache/pkg
605 PKGNG_PORTSDIR=/usr/ports
606 PKGNG_PUBKEY=/etc/ssl/pkg.conf
607 PKGNG_HANDLE_RC_SCRIPTS=NO
608 PKGNG_PKG_MULTIREPOS=NO
609 PKGNG_ASSUME_ALWAYS_YES=NO
613 PKGNG_PORTAUDIT_SITE='http=//portaudit.FreeBSD.org/auditfile.tbz'
614 # Load configuration for pkg(1)
615 pkg_conf=`pkg query %Fp pkg 2> /dev/null | grep '/etc/pkg\.conf\.sample$' | sed 's/\.sample$//'` || :
616 [ -n "$pkg_conf" ] || pkg_conf=${MYPREFIX}/etc/pkg.conf
617 grep -v -e '^[[:space:]]*#' -e '^[[:space:]]*$' "$pkg_conf" 2> /dev/null \
618 | grep -e '^[[:space:]]*[A-Z0-9_]*[[:space:]]*:[[:space:]]*.*' \
621 var=`expr "$srcline" : '^[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*:.*'` || :
622 val=`expr "$srcline" : '^[[:space:]]*[A-Z0-9_]*[[:space:]]*:[[:space:]]*\(.*\)'` || :
623 eval PKGNG_$var=\$val
624 misc_get_all_vardefs | grep "^PKGNG_$var="
625 done > ${TMPDIR}/pkgsys_def_pkgtools:pkg.conf.sh
626 . "${TMPDIR}/pkgsys_def_pkgtools:pkg.conf.sh"
630 local origin_portsmgmt packagepath checksumpath pkgname is_successful
631 origin_portsmgmt=`pkgsys_portsmgmt_pkg`
632 packagepath=`pkgsys_get_backup_pkg "$origin_portsmgmt"` && \
633 pkg_add_tools "$packagepath" && return
634 pkg_is_tool_available && return
635 message_echo "WARNING: WITH_PKG or WITH_PKGNG is set, but pkgng is still missing. It is installed now." >&2
636 pkgsys_ready_checksum_file || return
637 message_echo "INFO: Installing pkgng by legacy package tool."
638 checksumpath=`pkgsys_ready_checksum_file__fetched_file`
639 pkgname=`sed 's/^MD5[[:space:]]*(//;s/\.tbz)[[:space:]]*=[^=]*$//' "$checksumpath" \
640 | grep -m 1 '^pkg-[0-9]'` || :
641 [ -n "$pkgname" ] && pkg_inst_remote_wild "$pkgname" && return
642 message_echo "INFO: Failed by package, so installing pkgng by port."
643 grep -Ev '^[[:space:]]*WITH_PKG(|NG)=' /etc/make.conf > ${TMPDIR}/make.conf 2> /dev/null || :
644 echo WITHOUT_PKG=yes >> ${TMPDIR}/make.conf
645 echo WITHOUT_PKGNG=yes >> ${TMPDIR}/make.conf
651 message_echo "INFO: Attempting deinstallation of pkg(8) to make sure."
652 portsmgmt_port_path=`pkgsys_get_portpath_from_origin "$origin_portsmgmt"`
653 fs_fix_unionfs_image_if_hidden "${TMPDIR}/make.conf"
654 env __MAKE_CONF="${TMPDIR}/make.conf" make -C "$portsmgmt_port_path" deinstall || :
655 message_echo "INFO: Attempting (re)installation by pkg(8)."
656 env __MAKE_CONF="${TMPDIR}/make.conf" make -C "$portsmgmt_port_path" reinstall clean
659 pkg_is_tool_available
662 if ! pkg_rescue_tools
664 message_echo "WARNING: Pkgng is still missing, but continuing for the time being." >&2
667 elif ! pkgsys_is_legacy_tool_available
669 message_echo "ERROR: Pkgng is disabled although the legacy packages tools are unavailable. Resolve the problem manually." >&2
675 PKGSYS_CMD_PKG_DELETE='pkg_delete'
676 pkg_is_tool_available ()
678 pkgsys_is_legacy_tool_available
682 pkg_info -Ea 2> /dev/null
686 # pkg_info -qoa 2> /dev/null
690 # pkg_info -qox "$@" 2> /dev/null
694 # pkg_info -qoX "$@" 2> /dev/null
698 pkg_info -qO "$@" 2> /dev/null
702 pkg_info -qo "$@" 2> /dev/null
706 pkg_info -qr "$@" 2> /dev/null | sed -n 's/^@pkgdep[[:space:]]*//p'
710 pkg_info -e "$@" 2> /dev/null
714 [ `pkg_info -qO "$@" 2> /dev/null | wc -l` -gt 0 ]
718 pkg_info -E "$@" 2> /dev/null
722 pkg_info -qR "$@" 2> /dev/null | grep -v '^$'
726 pkg_info -Ex "$@" 2> /dev/null
730 pkg_info -qL "$@" 2> /dev/null
734 pkg_info -e "$@" 2> /dev/null && echo
737 pkg_info_flavored_origin ()
739 local glob_unflavored tmp_stdout
741 pkg_info_qo "$glob_unflavored" 2> /dev/null
743 pkg_info_all_flavored_origins ()
745 pkg_info_qoa 2> /dev/null
749 local pkg tmp_stdout tmp_stderr
751 tmp_stdout=${TMPDIR}/pkgng:pkg_check_sanity:stdout
752 tmp_stderr=${TMPDIR}/pkgng:pkg_check_sanity:stderr
753 pkg_info -qg "$pkg" > $tmp_stdout 2> $tmp_stderr || :
754 sed -n 's/ fails the original MD5 checksum$//p' "$tmp_stdout" 2> /dev/null || :
755 sed -nE "s/^pkg_info: (.*) doesn't exist$/\1/p" "$tmp_stderr" 2> /dev/null || :
761 pkg_info -qW "$filepath" 2> /dev/null
763 pkg_info_gen_pkg_origin_table ()
765 pkg_info -aE 2> /dev/null | while read pkg
767 origin=`pkg_info -qo "$pkg" 2> /dev/null`
768 printf '%s\t%s\n' "$pkg" "$origin"
769 done > ${DBDIR}/installed_ports:pkg_vs_origin.tbl
779 [ $no_exec_inst_script = yes ] && opt_del='-D'
780 pkg_delete -f $opt_del "$@"
785 rm -rf "${TMPDIR}/pkg_add_f"
786 mkdir -p "${TMPDIR}/pkg_add_f"
787 ln -s "$@" "${TMPDIR}/pkg_add_f"
789 [ $no_exec_inst_script = yes ] && opt_add='-I'
790 ( cd "${TMPDIR}/pkg_add_f" && pkg_add -if $opt_add * )
795 rm -rf "${TMPDIR}/pkg_add_f"
796 mkdir -p "${TMPDIR}/pkg_add_f"
797 ln -s "$@" "${TMPDIR}/pkg_add_f"
799 [ $no_exec_inst_script = yes ] && opt_add='-I'
800 ( cd "${TMPDIR}/pkg_add_f" && pkg_add -ifF $opt_add * )
802 pkg_inst_verify_pkg ()
806 pkgarc=`pkgsys_fetch_legacy_remote__fetched_pkg` || return
807 pkgsys_is_dependency_of_a_legacypkg_latest "$pkgarc"
809 pkg_inst_remote_fetch ()
813 pkgsys_fetch_legacy_remote "$pkg"
815 pkg_inst_remote_verify_fetch ()
819 pkg_inst_verify_pkg "$pkg" && return
820 pkg_inst_remote_fetch "$pkg" && pkg_inst_verify_pkg "$pkg"
824 local pkg pkgarc opt_add
826 if pkg_inst_remote_verify_fetch "$pkg"
828 pkgarc=`pkgsys_fetch_legacy_remote__fetched_pkg`
829 rm -rf "${TMPDIR}/pkg_inst_remote"
830 mkdir -p "${TMPDIR}/pkg_inst_remote"
831 ln -s "$@" "${TMPDIR}/pkg_add_f"
833 [ $no_exec_inst_script = yes ] && opt_add='-I'
834 ( cd "${TMPDIR}/pkg_inst_remote" && ls -s "$pkgarc" && pkg_add -ifF $opt_add * )
837 pkg_inst_wild_verify_pkg ()
839 pkg_inst_verify_pkg "$@"
841 pkg_inst_remote_wild_fetch ()
843 pkg_inst_remote_fetch "$@"
845 pkg_inst_remote_wild_verify_fetch ()
847 pkg_inst_remote_verify_fetch "$@"
849 pkg_inst_remote_wild ()
853 pkg_get_remote_repository_version ()
855 local origin checksumpath version_regexp pkgbase_regexp pkg
857 pkgsys_ready_checksum_file > /dev/null || return
858 checksumpath=`pkgsys_ready_checksum_file__fetched_file`
859 version_regexp=`database_build_make "$origin" -V PORTVERSION | str_escape_regexp_filter`
860 pkgbase_regexp=`database_build_get_new_pkgname "$origin" | sed -E "s/$version_regexp$//" | str_escape_regexp_filter`
861 pkg=`sed -nE "s/^MD5[[:space:]]*\(($pkgbase_regexp.*)\.tbz\)[[:space:]]*=.*/\1/p" "$checksumpath" | head -n 1`
864 pkg_get_pkgs_timestamps ()
866 ls -lD legacy:%s ${PKG_DBDIR} | \
867 sed -E 's/[[:space:]]+/ /g' | cut -w -f 6,7 | grep -v '^$' | \
868 sed -E 's/^([^[:space:]]*)[[:space:]]*([^[:space:]]*)/\2 \1/' | tr ' ' '\t'
870 pkg_get_pkg_timestamp ()
874 portdb=`echo "$pkg" | sed 's/-[0-9].*//'`
875 ls -lD legacy:%s "${PKG_DBDIR}/$portdb" | \
876 sed -E 's/[[:space:]]+/ /g' | cut -w -f 6 | grep -v '^$'
878 pkg_loadconf () { :; }
879 pkg_rescue_tools () { :; }
883 # ============= Get the unflavored part of a flavored origin =============
884 pkgsys_get_unflavored_origin ()
886 local origin origin_unflavored
888 origin_unflavored=`echo "$origin" | sed 's/@.*$//'`
889 echo "$origin_unflavored"
892 # ============= Get the port path from a flavored origin =============
893 pkgsys_get_portpath_from_origin ()
895 local origin origin_unflavored
897 origin_unflavored=`pkgsys_get_unflavored_origin "$origin"`
898 echo "${PORTSDIR}/$origin_unflavored"
901 # ============= Get the flavor from a flavored origin =============
902 pkgsys_get_flavor_from_origin ()
906 flavor=`echo "$origin" | sed -E 's/^[^@]*@?//'`
910 # ============= Compose a flavored origin name =============
911 pkgsys_compose_flavored_origin ()
916 origin_unflavored=`pkgsys_get_unflavored_origin "$origin"`
917 [ -z "$flavor" ] || flavor=@$flavor
918 echo "$origin_unflavored$flavor"
921 # ============= Check existence of a port for a flavored origin =============
922 pkgsys_exists_port ()
924 local origin port_path
926 port_path=`pkgsys_get_portpath_from_origin "$origin"`
930 # ============= Get the installed package name from a flavored origin =============
931 pkgsys_get_installed_pkg_from_origin ()
933 local origin origin_unflavored flavor_origin flavor_pkg
935 origin_unflavored=`pkgsys_get_unflavored_origin "$origin"`
936 flavor_origin=`pkgsys_get_flavor_from_origin "$origin"`
937 pkg_info_qO "$origin_unflavored" 2> /dev/null | while read pkgname
939 flavor_pkg=`pkg_info_flavor "$pkgname"`
940 if [ "x$flavor_origin" = "x$flavor_pkg" ]
949 # ============= Get the installed package name from glob patterns =============
950 pkgsys_get_installed_pkg_from_glob ()
955 if regexp=`expr "$glob" : ':\(.*\)'`
957 pkg_info_Ex "$regexp"
964 # ============= Check existence of an installed package for a flavored origin =============
965 pkgsys_exists_from_orig ()
967 local origin origin_unflavored flavor_origin flavor_pkg
969 origin_unflavored=`pkgsys_get_unflavored_origin "$origin"`
970 pkg_info_eO "$origin_unflavored" 2> /dev/null || return
971 flavor_origin=`pkgsys_get_flavor_from_origin "$origin"`
972 flavor_pkg=`pkg_info_flavor "$origin_unflavored"`
973 [ "x$flavor_origin" = "x$flavor_pkg" ]
976 # ============= Check existence of initially or currently installed package for a flavored origin =============
977 pkgsys_exists_or_existed_from_orig ()
981 cut -f 2 "${DBDIR}/installed_ports:pkg_vs_origin.tbl" 2> /dev/null \
982 | grep -q -Fx "$origin" || pkgsys_exists_from_orig "$origin"
985 # ============= Get the name of an initially installed package for a flavored origin =============
986 pkgsys_get_init_pkg_from_orig ()
988 local origin tmppkg origin_regexp npkgs origin_unflavored flavor_origin flavor_pkg
990 tmppkg=${TMPDIR}/pkgsys_get_init_pkg_from_orig::pkg
991 origin_regexp=`str_escape_regexp "$origin"`
992 sed -n -E "/[[:space:]]$origin_regexp$/p" "${DBDIR}/installed_ports:pkg_vs_origin.tbl" 2> /dev/null \
993 | cut -f 1 > $tmppkg || :
994 npkgs=`wc -l < $tmppkg`
999 origin_unflavored=`pkgsys_get_unflavored_origin "$origin"`
1000 flavor_origin=`pkgsys_get_flavor_from_origin "$origin"`
1001 pkg_info_qO "$origin_unflavored" 2> /dev/null | while read pkgname
1003 flavor_pkg=`pkg_info_flavor "$pkgname"`
1004 if [ "x$flavor_origin" = "x$flavor_pkg" ]
1014 # ============= Get the package name of this utility =============
1015 pkgsys_get_my_current_pkg ()
1017 pkg_info_Ex "${APPNAME}-[0-9].*"
1020 # ============= Get the flavored origin of this utility =============
1021 pkgsys_get_my_origin ()
1023 pkgsys_get_my_current_pkg | while read pkgname
1025 pkg_info_flavored_origin "$pkgname"
1029 # ============= Get the flavored origin of an initially installed package by ambiguous matching =============
1030 pkgsys_init_pkg_orig_by_ambiguous_matching ()
1032 local pkg origin tmporigin ambsuffix len_pkg pkg_regexp norigins
1034 origin=`pkg_info_flavored_origin "$pkg"`
1035 [ -n "$origin" ] && { echo "$origin"; return; }
1036 tmporigin=${TMPDIR}/pkgsys_init_pkg_orig_by_ambiguous_matching::origin
1039 len_pkg=`echo -n "$pkg" | wc -c`
1040 if [ $len_pkg -gt 0 ]
1044 pkg_regexp=`str_escape_regexp "$pkg"`$ambsuffix
1045 grep -E "^${pkg_regexp}[[:space:]]" "${DBDIR}/installed_ports:pkg_vs_origin.tbl" 2> /dev/null \
1046 | cut -f 2 > $tmporigin
1047 norigins=`wc -l < $tmporigin`
1048 [ $norigins -gt 0 ] && break
1049 ambsuffix='[a-zA-Z0-9.,_+-]*'
1050 len_pkg=$(($len_pkg-1))
1051 [ $len_pkg -gt 0 ] || break
1052 pkg=`echo -n "$pkg" | head -c $len_pkg`
1055 [ $norigins -eq 1 ] || return
1059 # ============= A part of message indicating tools for showing concerned issues in UPDATING =============
1060 pkgsys_show_pkg_updating_commands ()
1062 if [ "x$PKGSYS_USE_PKGNG" = xyes ]
1064 if which -s pkg_updating
1066 echo 'pkg-updating(8) or pkg_updating(1)'
1068 echo 'pkg-updating(8)'
1070 elif which -s pkg_updating
1072 echo 'pkg_updating(1)'
1076 # ============= Evaluation of flavored ports globs =============
1077 pkgsys_eval_ports_glob ()
1079 local pkglist unflavored_origlist tmp_flavors
1080 pkglist=${DBDIR}/pkgsys_eval_ports_glob:pkg.lst
1081 unflavored_origlist=${DBDIR}/pkgsys_eval_ports_glob:origin_unflavored.lst
1082 tmp_flavors=${TMPDIR}/pkgsys_eval_ports_glob:flavors
1083 # Test the access privilege as the superuser or not
1084 if [ ! -r "$pkglist" ]
1086 if touch "$pkglist" 2>/dev/null
1090 pkglist=${TMPDIR}/pkgsys_eval_ports_glob:pkg.lst
1093 if [ ! -r "$unflavored_origlist" ]
1095 if touch "$unflavored_origlist" 2>/dev/null
1097 rm "$unflavored_origlist"
1099 unflavored_origlist=${TMPDIR}/pkgsys_eval_ports_glob:origin.lst
1102 # Preparation of customized databases
1104 || cut -d \| -f 1 "${PORTS_INDEX_DB}" > $pkglist
1105 [ -f "$unflavored_origlist" ] \
1106 || cut -d \| -f 2 "${PORTS_INDEX_DB}" \
1107 | sed -E "s/^`str_escape_regexp "${PORTSDIR}"`\///" > $unflavored_origlist
1113 expr "x$glob" : '^x-' > /dev/null 2>&1 && continue
1114 glob_regexp=`str_convert_portsglob_to_regexp_pattern "$glob"`
1115 if expr "$glob" : '.*/' > /dev/null 2>&1
1117 if expr "$glob" : '.*@' > /dev/null 2>&1
1119 glob_regexp_unflavored=`expr "$glob_regexp" : '\([^@]*\)' || :`$
1120 glob_regexp_flavor=^`expr "$glob_regexp" : '[^@]*@\([^@]*\)' || :`
1122 grep -E "$glob_regexp_unflavored" "$unflavored_origlist" 2>&1 | while read origin_unflavored
1124 fs_fix_unionfs_image_if_hidden "${PORTSDIR}/$origin_unflavored"
1125 make -C "${PORTSDIR}/$origin_unflavored" -V FLAVORS 2> /dev/null | \
1126 tr '[:space:]' '\n' | grep -v '^$' | grep -E "$glob_regexp_flavor" | sed -E "s|^|$origin_unflavored@|"
1129 pkg_info_all_flavored_origins
1130 cut -f 2 "${DBDIR}/installed_ports:pkg_vs_origin.tbl" 2> /dev/null
1131 } | grep -E "$glob_regexp" 2>&1 || :
1133 grep -E "$glob_regexp" "$unflavored_origlist" 2>&1 | while read origin_unflavored
1135 origin_unflavored_rpl=`str_escape_replaceval "$origin_unflavored"`
1136 fs_fix_unionfs_image_if_hidden "${PORTSDIR}/$origin_unflavored"
1137 make -C "${PORTSDIR}/$origin_unflavored" -V FLAVORS 2> /dev/null | \
1138 tr '[:space:]' '\n' | grep -v '^$' > $tmp_flavors || :
1139 if [ `wc -l < $tmp_flavors` -gt 0 ]
1141 sed -E "s|^|$origin_unflavored_rpl@|" "$tmp_flavors"
1143 echo "$origin_unflavored"
1147 glob_regexp_allflavors=`echo "$glob_regexp" | sed 's/$$/(|@.*)$/'`
1149 pkg_info_all_flavored_origins
1150 cut -f 2 "${DBDIR}/installed_ports:pkg_vs_origin.tbl" 2> /dev/null
1151 } | grep -E "$glob_regexp_allflavors" 2>&1 || :
1153 if expr "$glob" : '[a-z][a-zA-Z0-9_.+-]*[a-zA-Z0-9_.+]$' > /dev/null 2>&1 && \
1154 [ `expr "$glob" : '.*-[0-9]' 2>&1` -eq 0 ]
1156 glob_regexp2=`expr "$glob_regexp" : '\(.*\)\$$' 2>&1 || :`'-[0-9]'
1158 glob_regexp2=$glob_regexp
1160 grep -n -E "$glob_regexp2" "$pkglist" 2>&1 | cut -d : -f 1 \
1163 sed -n ${index}p "$unflavored_origlist"
1164 done | while read origin_unflavored
1166 origin_unflavored_rpl=`str_escape_replaceval "$origin_unflavored"`
1167 fs_fix_unionfs_image_if_hidden "${PORTSDIR}/$origin_unflavored"
1168 make -C "${PORTSDIR}/$origin_unflavored" -V FLAVORS 2> /dev/null | \
1169 tr '[:space:]' '\n' | grep -v '^$' > $tmp_flavors || :
1170 [ `wc -l < $tmp_flavors` -gt 0 ] || echo > $tmp_flavors
1171 sed -E "s/^/$origin_unflavored_rpl /" "$tmp_flavors"
1172 done | while read origin_unflavored flavor
1176 if make -C "${PORTSDIR}/$origin_unflavored" package-name FLAVOR=$flavor 2> /dev/null | \
1177 grep -qE "$glob_regexp2"
1179 echo "$origin_unflavored@$flavor"
1182 if make -C "${PORTSDIR}/$origin_unflavored" package-name 2> /dev/null | \
1183 grep -qE "$glob_regexp2"
1185 echo "$origin_unflavored"
1189 glob_regexp2=`echo "$glob_regexp" | sed -E 's/\$*$//' 2>&1 || :`'[[:space:]]'
1190 grep -E "$glob_regexp2" "${DBDIR}/installed_ports:pkg_vs_origin.tbl" 2> /dev/null \
1192 pkg_info_Ex "$glob_regexp" | while read pkgname
1194 pkg_info_flavored_origin "$pkgname"
1200 # ============= Create a back-up package archive =============
1201 pkgsys_create_backup_pkg ()
1203 local pkgname dstdir origin backup_pkg_old pkgname_ptn backup_pkg dbpath pkgpath
1206 rm -rf "${TMPDIR}"/package.tmp
1207 mkdir "${TMPDIR}"/package.tmp
1208 origin=`pkg_info_flavored_origin "$pkgname"`
1209 if backup_pkg_old=`pkgsys_get_backup_pkg "$origin"` && \
1210 [ ! -e "${DBDIR}/requires/$origin/installed_timestamp" -o \
1211 "$backup_pkg_old" -nt "${DBDIR}/requires/$origin/installed_timestamp" ]
1213 echo "$backup_pkg_old"
1216 if ( cd "${TMPDIR}"/package.tmp && pkg_create_b "$pkgname" > /dev/null )
1218 pkgname_ptn=`str_escape_regexp "$pkgname"`
1219 backup_pkg=`ls "${TMPDIR}"/package.tmp | \
1220 grep -m 1 -E "^${pkgname_ptn}\.(txz|tbz|tgz|tar)$"` || :
1222 if [ -z "$backup_pkg" ]
1224 message_echo "WARNING: Failed to create backup package for $pkgname." >&2
1227 dbpath=${DBDIR}/backup/$origin
1229 pkg_info_qL "$pkgname" > $dbpath/previously_installed_files
1231 mv "${TMPDIR}/package.tmp/$backup_pkg" "$dstdir"
1232 pkgpath=$dstdir/$backup_pkg
1233 cat "${DBDIR}/backup_pkgarcs.lst" 2> /dev/null | \
1234 while read origin_cur pkgpath_cur
1236 [ "$pkgpath_cur" = "$pkgpath" ] && continue
1237 if [ "$origin_cur" = "$origin" ]
1239 rm -f "$pkgpath_cur"
1241 printf '%s\t%s\n' "$origin_cur" "$pkgpath_cur"
1243 done > ${DBDIR}/backup_pkgarcs.lst.tmp
1244 printf '%s\t%s\n' "$origin" "$pkgpath" >> ${DBDIR}/backup_pkgarcs.lst.tmp
1245 mv "${DBDIR}/backup_pkgarcs.lst.tmp" "${DBDIR}/backup_pkgarcs.lst"
1249 # ============= Delete a back-up package archive for a flavored port origin =============
1250 pkgsys_delete_backup_pkg ()
1252 local origin origin_regexp
1254 origin_regexp=`str_escape_regexp "$origin"`
1255 grep -E "^${origin_regexp}[[:space:]]" "${DBDIR}/backup_pkgarcs.lst" 2> /dev/null \
1256 | cut -f 2 | while read pkgpath_cur
1258 rm -f "$pkgpath_cur"
1260 grep -v -E "^${origin_regexp}[[:space:]]" "${DBDIR}/backup_pkgarcs.lst" \
1261 2> /dev/null > ${DBDIR}/backup_pkgarcs.lst.tmp || :
1262 mv "${DBDIR}/backup_pkgarcs.lst.tmp" "${DBDIR}/backup_pkgarcs.lst"
1265 # ============= Get an existing package archive path for a flavored port origin =============
1266 pkgsys_get_backup_pkg ()
1268 local origin tmpnewest origin_regexp
1270 tmpnewest=${TMPDIR}/pkgsys_get_backup_pkg::newest
1271 origin_regexp=`str_escape_regexp "$origin"`
1273 grep -E "^${origin_regexp}[[:space:]]" "${DBDIR}/backup_pkgarcs.lst" 2> /dev/null \
1274 | cut -f 2 | while read pkgpath
1276 pkgpath_newest=`cat "$tmpnewest" 2> /dev/null` || :
1277 [ -e "$pkgpath" ] || continue
1278 [ -z "$pkgpath_newest" -o "$pkgpath" -nt "$pkgpath_newest" ] || continue
1279 echo "$pkgpath" > $tmpnewest
1281 cat "$tmpnewest" 2> /dev/null
1284 # ============= Get a file list to be restored by the current backup package for a flavored port origin =============
1285 pkgsys_get_restored_files_by_backup_pkg ()
1289 cat "${DBDIR}/backup/$origin/previously_installed_files" 2> /dev/null || :
1292 # ============= Check whether any file match restored files by the current backup package for a flavored port origin =============
1293 pkgsys_chk_match_to_restored_files_by_backup_pkg ()
1295 local origin filelist dbfile
1298 dbfile=${DBDIR}/backup/$origin/previously_installed_files
1299 grep -qFx -f "$filelist" "$dbfile" 2> /dev/null
1302 # ============= Get a package name from a package archive file name =============
1303 pkgsys_pkgarc_to_pkgname ()
1307 basename "$pkgfile_path" | sed -E 's/\.(txz|tbz|tgz|tar)$//'
1310 # ============= Get the file name of an existing package archive for a package name =============
1311 pkgsys_pkgname_to_pkgarc ()
1313 local pkgdir pkgname pkgname_ptn pkgnode
1316 [ -n "$pkgname" ] || return 1
1317 [ -d "$pkgdir" ] || return 1
1318 if [ "x$PKGSYS_USE_PKGNG" = xyes ]
1320 pkgname_ptn=`str_escape_regexp "$pkgname"`
1321 pkgnode=`ls "$pkgdir" 2> /dev/null | grep -m 1 -E "^${pkgname_ptn}\.(txz|tbz|tgz|tar)$"` || :
1322 elif [ -e "$pkgdir/$pkgname.tbz" ]
1324 pkgnode=$pkgname.tbz
1326 [ -n "$pkgnode" ] || return 1
1327 echo "$pkgdir/$pkgnode"
1330 # ============= Get flavored port origins matching a glob pattern even if nonexistent =============
1331 pkgsys_eval_ports_glob_even_if_nonexistent ()
1336 pkgsys_eval_ports_glob "$glob_pattern" 2> /dev/null || :
1337 echo "$glob_pattern" | grep -E '^[a-z]+/[a-zA-Z0-9_.+-]+(|@[a-zA-Z0-9_.+-]+)$' || :
1338 } | grep -v -e '^$' | sort -u
1341 # ============= Evaluate glob patterns and add/remove non-existing/existing ones of them to/from a file =============
1342 pkgsys_register_evaluated_globs ()
1344 local mode listpath dirpath tmp_evaluated
1348 dirpath=`dirname "$listpath"`
1349 tmp_evaluated=${TMPDIR}/pkgsys_register_evaluated_globs:pkgsys_eval_ports_glob
1350 echo "$@" | sed -E 's/[ :]+/\
1351 /g' | grep -v '^$' | sort -u | while read -r glob
1353 pkgsys_eval_ports_glob "$glob" > $tmp_evaluated
1354 [ `wc -l < $tmp_evaluated` -ge 1 ] || \
1356 message_echo "WARNING: No matching ports/package glob [$glob]." >&2
1359 cat "$tmp_evaluated"
1360 done | while read origin
1364 remove ) fileedit_rm_a_line "$origin" "$listpath"
1366 add ) fileedit_add_a_line_if_new "$origin" "$listpath"
1372 # ============= Evaluate glob patterns for installed packages =============
1373 pkgsys_eval_installed_pkgs_globs ()
1376 tmp_evaluated=${TMPDIR}/pkgsys_eval_installed_pkgs_globs:origins
1377 rm -f "$tmp_evaluated"
1378 pkgsys_register_evaluated_globs add "$tmp_evaluated" "$@"
1379 [ -e "$tmp_evaluated" ] || return 0
1382 pkgsys_exists_or_existed_from_orig "$origin" || echo "$origin"
1383 done < $tmp_evaluated
1386 # ============= Get glob patterns of conflicting packages of a port =============
1387 pkgsys_get_conflicting_pkgs_patterns ()
1389 local mode origin conflicts conflicts_makevar conflicts_config
1392 conflicts=`database_query_get_makevar_val "$origin" CONFLICTS`
1395 conflicts_makevar=`database_query_get_makevar_val "$origin" CONFLICTS_BUILD`
1396 conflicts_config=`database_query_get_config_val "$origin" BUILDCONFLICT`
1399 conflicts_makevar=`database_query_get_makevar_val "$origin" CONFLICTS_INSTALL`
1400 conflicts_config=`database_query_get_config_val "$origin" INSTCONFLICT`
1407 echo "$conflicts $conflicts_makevar $conflicts_config" | tr ' ' '\n' | grep -v '^$' | sort -u
1410 # ============= Get conflicting installed packages of a port =============
1411 pkgsys_get_conflicting_installed_pkgs ()
1413 local mode origin tmp_conflicts
1416 tmp_conflicts=${TMPDIR}/pkgsys_get_conflicting_installed_pkgs::conflicts
1417 pkgsys_get_conflicting_pkgs_patterns "$mode" "$origin" | while read pkg_pattern
1419 pkgsys_get_installed_pkg_from_glob "$pkg_pattern" || :
1420 done > $tmp_conflicts
1421 cat "$tmp_conflicts"
1422 [ `wc -l < $tmp_conflicts` -gt 0 ]
1425 # ============= Check whether a package conflicts with a port =============
1426 pkgsys_chk_conflict_by_a_pkg ()
1428 local mode origin pkg tmp_conflicts_ptn
1432 tmp_conflicts_ptn=${TMPDIR}/pkgsys_chk_conflict_by_a_pkg::conflicts_ptn
1433 pkgsys_get_conflicting_pkgs_patterns "$mode" "$origin" \
1434 | str_convert_glob_to_regexp_pattern > $tmp_conflicts_ptn
1435 echo "$pkg" | grep -q -E -f "$tmp_conflicts_ptn"
1438 # ============= Check whether installed files are lost or broken for a package =============
1439 pkgsys_sanitychk_pkgcontents ()
1441 local pkg var_is_reinstall_encouraged _is_reinstall_encouraged tmp_sanity nlines iline src filename icol filename_esc pkg_owner origin
1443 var_is_reinstall_encouraged=$2
1444 tmp_sanity=${TMPDIR}/pkgsys_sanitychk_pkgcontents:sanity
1445 pkg_check_sanity "$pkg" > $tmp_sanity || :
1446 eval "$var_is_reinstall_encouraged=no"
1447 [ `wc -l < $tmp_sanity` -eq 0 ] && return
1448 nlines=`wc -l < $tmp_sanity`
1450 _is_reinstall_encouraged=no
1451 while [ $iline -le $nlines ]
1453 filename=`sed -n ${iline}p "$tmp_sanity"`
1455 if [ ! -e "$filename" ]
1457 _is_reinstall_encouraged=yes
1460 if expr "$filename" : '.*/include/.*' > /dev/null
1462 _is_reinstall_encouraged=yes
1465 filename_esc=`str_escape_regexp "$filename"`
1466 if file "$filename" | sed -E "s/^$filename_esc:[[:space:]]//" | grep -q '^ELF '
1468 _is_reinstall_encouraged=yes
1471 pkg_owner=`pkg_which "$filename"`
1472 if [ "$pkg" != "$pkg_owner" ]
1474 _is_reinstall_encouraged=yes
1478 eval "$var_is_reinstall_encouraged=\$_is_reinstall_encouraged"
1479 origin=`pkg_info_flavored_origin "$pkg"`
1480 if [ $opt_batch_mode = no ]
1482 message_echo "[$pkg ($origin)]"
1483 sed 's/^/ /' "$tmp_sanity"
1486 pkg_replace=`str_escape_replaceval "$pkg"`
1487 origin_replace=`str_escape_replaceval "$origin"`
1488 sed "s/^/$pkg_replace\\\\$origin_replace\\\\$_is_reinstall_encouraged\\\\/" "$tmp_sanity" | tr '\\' '\t'
1493 # ============= Check whether the port options database is once saved =============
1494 pkgsys_exists_saved_port_oprions_timestamps ()
1496 [ -d "${DBDIR}/ls_dbdir" ]
1499 # ============= Get the current all timestamp information of port options =============
1500 pkgsys_get_current_port_oprions_timestamp ()
1502 local portdb_needle_regexp
1503 portdb_needle_regexp=`str_escape_regexp "$1"`
1505 ls -lD %Y%m%d:%H%M%S "${PORT_DBDIR}" | if [ -n "$portdb_needle_regexp" ]
1507 grep -E "[[:space:]]$portdb_needle_regexp$" || :
1511 } 2> /dev/null | cut -w -f 6,7 | while read datetime portdb
1513 [ -d "${PORT_DBDIR}/$portdb" ] || continue
1514 if [ -e "${PORT_DBDIR}/$portdb/options" ]
1516 datetime=`ls -lD %Y%m%d:%H%M%S "${PORT_DBDIR}/$portdb/options" 2> /dev/null | cut -w -f 6`
1518 printf '%s\t%s\n' "$portdb" "$datetime"
1522 # ============= Get the saved all timestamp information of port options =============
1523 pkgsys_get_saved_port_oprions_timestamps_all ()
1525 cat "${DBDIR}/ls_dbdir/"*.log > $tmp_ls.db 2> /dev/null || :
1528 # ============= Convert a list of port origins to port options timestamp log names =============
1529 pkgsys_conv_portorigin_to_port_oprion_timestamp_logname ()
1534 # ============= Save the timestamp information of port options of a port =============
1535 pkgsys_save_port_oprion_timestamp ()
1537 local origin portoptlog portoptdb
1539 portoptlog=`echo "$origin" | pkgsys_conv_portorigin_to_port_oprion_timestamp_logname`
1540 if pkgsys_is_dialog4ports_used
1542 portoptdb=`echo "$portoptlog" | sed 's/@.*//'`
1544 portoptdb=`database_build_make "$origin" -V UNIQUENAME`
1546 mkdir -p "${DBDIR}/ls_dbdir"
1547 pkgsys_get_current_port_oprions_timestamp "$portoptdb" > ${DBDIR}/ls_dbdir/$portoptlog.log 2> /dev/null || :
1550 # ============= Get changed port options from the saved point =============
1551 pkgsys_get_changed_port_oprions ()
1553 local saved_log current_log tmp_log
1556 tmp_log=${TMPDIR}/pkgsys_get_changed_port_oprions.log
1558 grep -vxF -f "$current_log" "$saved_log" || :
1559 grep -vxF -f "$saved_log" "$current_log" || :
1560 } | cut -w -f 1 | grep -v '^$' | sort -u > $tmp_log
1561 if pkgsys_is_dialog4ports_used
1563 grep '_' "$tmp_log" || :
1569 # ============= Convert a list of port origins to port options database names =============
1570 pkgsys_conv_portorigins_to_portoptiondbs ()
1572 if pkgsys_is_dialog4ports_used
1580 # ============= Register nonexistent port options databases =============
1581 pkgsys_register_list_nonexistent_portopriondb ()
1584 dbpath=${DBDIR}/ls_dbdir/%NONEXISTENT%.log
1587 sort -u "$dbpath.new" "$dbpath" > $dbpath.tmp
1588 mv "$dbpath.tmp" "$dbpath"