2 # ==================================================================================
3 # portsreinstall main script
4 # Copyright (C) 2010-2014 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
5 # This software is distributed under the 2-Clause BSD License.
6 # ==================================================================================
8 # ==================================================
9 # ================== ENVIRONMENT ===================
10 # ==================================================
12 # ============ Set up of environment =============
13 APPNAME=`basename "$0"`
16 # COMPATIBLE_VERSIONS='^(3\.0\.[0-9]+)$'
17 # Template for development versions
18 MYVERSION=3.0.5+toward_3.0.6_20140602024014
19 COMPATIBLE_VERSIONS='^(3\.0\.[0-9]+\+toward_3\.0\.[0-9]+_[0-9]+|3\.0\.[0-9]+)$'
20 MYPREFIX=`dirname "\`dirname \"$0\"\`" | sed 's|/bin$||'`
21 MYPREFIX=${MYPREFIX:-/usr/local}
22 LIBDIR=${MYPREFIX}/lib/${APPNAME}
24 . ${LIBDIR}/libtemp.sh
26 . ${LIBDIR}/liboptions.sh
27 . ${LIBDIR}/libusage.sh
28 . ${LIBDIR}/libmessage.sh
29 . ${LIBDIR}/libpkgsys.sh
30 . ${LIBDIR}/libmisc.sh
31 . ${LIBDIR}/libfileedit.sh
32 . ${LIBDIR}/libconf.sh
33 . ${LIBDIR}/libdatabase_build.sh
34 . ${LIBDIR}/libdatabase_query.sh
35 . ${LIBDIR}/libdatabase_record.sh
36 . ${LIBDIR}/libcommand.sh
37 . ${LIBDIR}/libprogram.sh
38 . ${LIBDIR}/libreinstall.sh
39 . ${LIBDIR}/libdeinstall.sh
43 DBDIR=/var/tmp/${APPNAME}.db
44 CONFFILE=${MYPREFIX}/etc/${APPNAME}.conf
45 PKGTOOLSCONF=${MYPREFIX}/etc/pkgtools.conf
47 # ==================================================
48 # ========= PARSING OPTIONS AND ARGUMENTS ==========
49 # ==================================================
51 # ============= Save arguments for upgraded restart =============
52 options_dump_args "$@" > ${TMPDIR}/restart_command.sh
54 # ============= Option check =============
57 options_getopts "$@" || :
58 if [ $OPTIONS_ERRNO -eq 2 ]
60 message_echo "INTERNAL ERROR: In parsing options" >&2
63 shift "${OPTIONS_SHIFT}"
65 # ============= Argument check for no-command options =============
66 if [ $opt_help_mode -ne 0 -o $opt_show_version = yes ]
74 # ============= Output usage if the case of a help mode or option/argument errors =============
75 if [ $OPTIONS_ERRNO -ne 0 ]
78 elif [ $opt_help_mode -eq 1 ]
82 elif [ $opt_help_mode -eq 2 ]
88 # ============= Output version number =============
89 if [ $opt_show_version = yes ]
95 # ============= Set up variables for environment of ports and packages =============
97 conf_setup_packages_envs
99 # ============= Execute command operations before getting the temporary database ready =============
100 command_exec_before_db_creation "$@"
102 # ============= Creation of temporary database directory =============
103 database_build_create
105 # ============= Argument check for conventional runs =============
106 command_parse_args "$@"
107 shift "${COMMAND_SHIFT}"
110 # ==================================================
111 # ================== TOOLS SET UP ==================
112 # ==================================================
114 # ============= Termination messages during construction of the temporary database =============
116 # Set termination messages
117 temp_terminate_process_common ()
120 [ $opt_batch_mode = yes ] && return
121 msg_where=`temp_get_msg_current_stage`
122 [ -n "$msg_where" ] && msg_where=" during $msg_where"
124 if [ $errno -eq 130 ]
126 echo "INFO: Terminated at `message_timestamp`$msg_where."
128 echo " You can restart this process from the terminated point by"
130 echo "INFO: Aborted at `message_timestamp`$msg_where."
132 echo " You may restart this process from the aborted point by"
134 echo "executing without options or arguments as:"
135 if [ -n "$COMMAND_RESTART" ]
137 echo " ${APPNAME} $COMMAND_RESTART"
143 temp_terminate_process ()
146 tmp_msg=${TMPDIR}/temp_terminate_process:msg
147 [ $errno -eq 0 -o $opt_batch_mode = yes ] && return
148 temp_terminate_process_common
149 [ -n "$COMMAND_RESTART" ] && return
150 cat > $tmp_msg << eof
151 Instead, if you only want to construct the temporary database so as to stop before the actual reinstallation, execute as:
154 message_cat "$tmp_msg"
157 # ============= Opening title =============
160 [ $COMMAND_MODE = do -o $COMMAND_MODE = redo -o $COMMAND_MODE = forget ] && \
161 message_opening_notice
164 # ============= Execute command operations which do not need package tools =============
166 command_exec_without_pkgtools "$@"
167 misc_is_superuser_privilege && touch "${DBDIR}/in_use"
169 # ============= Definition of environment dependent functions =============
173 # ============= Option settings =============
175 # Execute command operations which are not affected by saved option settings
176 command_exec_irrespective_of_saved_options "$@"
178 # Load, renew and save option values
180 options_chk_invalid_optvals_renewal non_renewable || optcomb_err=$?
181 if [ \( $opt_reload_conf = yes -o $opt_reset_targets = yes \) -a "x$COMMAND_MODE" != xredo ]
183 message_echo "ERROR: Options -L and -N are available only in the initial run of redo command." >&2
187 if [ $opt_batch_ports_only = yes -a $opt_interactive_ports_only = yes ]
189 message_echo "ERROR: Options -A and -I conflict with each other." >&2
193 if [ -e "${DBDIR}/saved_options.sh" ]
196 options_renewed_optvals M renewable_anytime || optcomb_err=$?
197 options_renewed_optvals N renewable_in_redo_on_target || optcomb_err=$?
198 options_renewed_optvals L renewable_in_redo_on_conf || optcomb_err=$?
199 } > ${TMPDIR}/renewed_optvals.sh
200 [ $optcomb_err -eq 0 ] || exit $optcomb_err
201 . "${DBDIR}/saved_options.sh"
202 . "${TMPDIR}/renewed_optvals.sh"
204 misc_is_superuser_privilege && misc_get_all_vardefs | options_filter saved > ${DBDIR}/saved_options.sh
207 if [ -e "${DBDIR}/saved_options.sh" -a $opt_batch_mode = no \
208 -a \( $COMMAND_MODE = do -o $COMMAND_MODE = redo \) ]
210 message_echo "INFO: List of option values:"
211 message_echo "-----------------------------------------"
212 message_cat "${DBDIR}/saved_options.sh"
213 message_echo "-----------------------------------------"
217 # ============= Configurations =============
219 # Save the previous configuration if exists
221 _program_exec_and_record_completion__operation ()
223 rm -rf "${DBDIR}/conf.prev"
224 [ -d "${DBDIR}/conf" ] && \
225 cp -Rp "${DBDIR}/conf" "${DBDIR}/conf.prev"
228 program_exec_and_record_completion SAVE_PREV_CONF
230 # Get complete configuration variable definitions by importing pkgtools.conf(5) if available
231 PROGRAM_DEPENDS='SAVE_PREV_CONF'
232 _program_exec_and_record_completion__operation ()
236 rm -rf "${DBDIR}/conf"
237 mkdir -p "${DBDIR}/conf"
238 [ "x`options_get_effective_opt_load_pkgtoolsconf 2> /dev/null`" != xno -a $opt_batch_mode = no ] \
240 [ $need_msg = yes ] && \
241 message_section_title "Parsing pkgtools.conf (by using installed portupgrade)"
242 conf_get_complete_var_defs > ${DBDIR}/conf/complete_setup.sh
243 [ $need_msg = yes ] && { message_echo "===> ok"; message_echo; }
246 program_exec_and_record_completion GET_COMPLETE_CONF_VAR_DEF
248 # Parse the configuration
249 PROGRAM_DEPENDS='GET_COMPLETE_CONF_VAR_DEF'
250 _program_exec_and_record_completion__operation ()
252 message_section_title "Parsing the configuration"
253 conf_manipulate_available_var_defs
254 . "${DBDIR}/conf/manipulated_defs.sh"
256 conf_build_effective_MOVED
257 # Environmental variables
258 conf_setup_effective_env > ${DBDIR}/conf/setenv.sh
259 . "${DBDIR}/conf/setenv.sh"
261 conf_parse_vars_for_each_port_glob HOLD
262 str_escape_regexp_filter < ${DBDIR}/conf/HOLD:PORTS.parsed \
263 | sed 's/^/^/;s/$/$/' > ${DBDIR}/conf/HOLD_PORTS.grep_pattern
265 conf_parse_vars_for_each_port_glob TABOO
266 fileedit_combine_lists "${DBDIR}/conf/TABOO:PORTS.parsed" "${DBDIR}/taboo.list" \
267 > ${DBDIR}/taboo.all.list
269 conf_parse_vars_for_each_port_glob NOPKG
271 conf_build_replacement_patterns_from_REPLACE
273 conf_parse_vars_for_each_port_glob_with_bound_val MARG TARGET DEF
275 conf_parse_vars_for_each_port_glob_with_bound_val MENV TARGET DEF
277 conf_parse_vars_for_each_port_glob_with_bound_val BEFOREBUILD TARGET COMMAND
279 conf_parse_vars_for_each_port_glob_with_bound_val BEFOREDEINSTALL TARGET COMMAND
281 conf_parse_vars_for_each_port_glob_with_bound_val AFTERINSTALL TARGET COMMAND
284 program_exec_and_record_completion PARSE_CONF
286 . "${DBDIR}/conf/setenv.sh"
288 # ============= Upgrade of tools =============
290 # Execute command operations which should be done without upgrade of tools
291 command_exec_before_tools_upgrade "$@"
293 # Check whether the temporary database is newer than the ports tree and refresh if so
294 database_build_refresh_if_obsolete
296 # Get the port origin for this utility if installed by port
297 MYPORTORIGIN=`pkgsys_get_my_origin 2> /dev/null` || :
299 # Collect all installed packages
301 _program_exec_and_record_completion__operation ()
303 message_section_title "Collecting all installed packages"
304 pkg_info_qoa > ${DBDIR}/installed_ports
305 pkg_info_gen_pkg_origin_table
306 str_escape_regexp_filter < "${DBDIR}/installed_ports" \
307 | sed 's/^/^/; s/$/$/' > ${DBDIR}/installed_ports.grep_pattern
310 program_exec_and_record_completion COLLECT_ALL_INSTALLED_PACKAGES
312 # Preliminary inspection of tools which have to be up-to-date
313 # (No need depend on PARSE_CONF because INSPECT_ALL_DEPENDENCIES will take the task.)
315 _program_exec_restartable_loop_operation__routine ()
319 database_build_inspect_dependencies "$origin"
321 _program_exec_and_record_completion__operation ()
324 message_section_title "Preliminary inspection of tools which have to be up-to-date"
326 [ "$PKGSYS_USE_PKGNG" = yes ] && echo 'ports-mgmt/pkg'
327 pkgsys_is_dialog4ports_used && echo 'ports-mgmt/dialog4ports'
328 [ -n "$MYPORTORIGIN" ] && echo "$MYPORTORIGIN"
329 } 2> /dev/null > ${DBDIR}/stage.loop_list/tools_to_inspect
331 program_exec_restartable_loop_operation tools_to_inspect
332 database_build_post_inspect_dependencies
335 program_exec_and_record_completion PRELIMINARY_INSPECTION_OF_TOOLS
337 # Upgrade of ports-mgmt/pkg if new
338 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
339 if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
340 -a $opt_dry_run = no -a $opt_suppress_pkgtools_upadte = no \
341 -a "$PKGSYS_USE_PKGNG" = yes ]
343 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
344 _program_exec_and_record_completion__operation ()
346 local _MSG_CURRENT_STAGE_general
347 _MSG_CURRENT_STAGE_general="pkgng upgrade"
348 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
349 message_section_title "Upgrade of ports-mgmt/pkg if new"
350 touch "${DBDIR}/target_all"
351 reinstall_exec ports-mgmt/pkg
352 reinstall_restore_conflicts
353 rm -f "${DBDIR}/target_all"
354 temp_set_msg_current_stage
357 program_exec_and_record_completion UPGRADE_PKGNG
360 # Upgrade of ports-mgmt/dialog4ports if new
361 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
362 if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
363 -a $opt_dry_run = no -a $opt_suppress_pkgtools_upadte = no ] \
364 && pkgsys_is_dialog4ports_used
366 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
367 _program_exec_and_record_completion__operation ()
369 local _MSG_CURRENT_STAGE_general
370 _MSG_CURRENT_STAGE_general="pkgng dialog4ports"
371 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
372 message_section_title "Upgrade of dialog4ports if new"
373 touch "${DBDIR}/target_all"
374 reinstall_exec ports-mgmt/dialog4ports
375 reinstall_restore_conflicts
376 rm -f "${DBDIR}/target_all"
377 temp_set_msg_current_stage
380 program_exec_and_record_completion UPGRADE_DIALOG4PORTS
383 # Upgrade of this utility if new
384 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
385 if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
386 -a $opt_dry_run = no -a $opt_suppress_self_upadte = no \
387 -a -n "$MYPORTORIGIN" ]
389 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
390 _program_exec_and_record_completion__operation ()
392 local _MSG_CURRENT_STAGE_general
393 _MSG_CURRENT_STAGE_general="pkgng upgrade"
394 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
395 message_section_title "Upgrade of this utility if new"
396 touch "${DBDIR}/target_all"
397 reinstall_exec "$MYPORTORIGIN"
398 reinstall_restore_conflicts
399 rm -f "${DBDIR}/target_all"
400 temp_set_msg_current_stage
403 program_exec_and_record_completion UPGRADE_SELF
406 if [ "x`${APPNAME} -aV 2> /dev/null`" != "x$MYVERSION" ]
408 message_echo "INFO: ${APPNAME} is upgraded and the temporary database needs refresh."
409 database_build_clean_for_self_upgrade || :
410 message_echo "INFO: Restarting with the new version."
412 temp_trap_for_invoking_new_version
413 . "${TMPDIR}"/restart_command.sh
418 # ==================================================
419 # ================== PREPARATION ===================
420 # ==================================================
422 # ============= Correspondence to configuration changes =============
424 # Patch to the temporary database by reflecting changes in configuration
425 PROGRAM_DEPENDS='PARSE_CONF'
426 _program_exec_and_record_completion__operation ()
428 local tmpfile_diff tmpfile_old tmpfile_new key
429 [ -d "${DBDIR}/conf.prev" ] || return 0
430 message_section_title "Patch to the temporary database by reflecting changes in configuration"
431 tmpfile_old=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::old
432 tmpfile_new=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::new
433 tmpfile_updated_ports=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::updated_ports
434 if fileedit_manipulate_old_new_lines \
435 "${DBDIR}/conf.prev/setenv.sh" "${DBDIR}/conf/setenv.sh" "$tmpfile_old" "$tmpfile_new"
437 if grep -q -e ^LOCALBASE= -e ^LINUXBASE= -e ^PORTSDIR= "$tmpfile_old" "$tmpfile_new"
439 message_echo "ERROR: Migration of the temporary database is unavailable because LOCALBASE, LINUXBASE or PORTSDIR was changed." >&2
440 message_echo " ${APPNAME} clean" >&2
441 message_echo "must be executed in advance." >&2
445 cut -s -d '|' -f 1,2 "${DBDIR}/conf.prev/MOVED_ALT.parsed" | tr '|' '\t' > ${TMPDIR}/MOVED_ALT.old
446 cut -s -d '|' -f 1,2 "${DBDIR}/conf/MOVED_ALT.parsed" | tr '|' '\t' > ${TMPDIR}/MOVED_ALT.new
447 if fileedit_manipulate_old_new_lines \
448 "${TMPDIR}/MOVED_ALT.old" "${TMPDIR}/MOVED_ALT.new" "$tmpfile_old" "$tmpfile_new"
450 cat "$tmpfile_old" "$tmpfile_new" | while read from to
453 [ -n "$to" ] && echo "$to"
455 fi > $tmpfile_updated_ports
456 if fileedit_manipulate_old_new_lines \
457 "${DBDIR}/conf.prev/REPLACE.csv" "${DBDIR}/conf/REPLACE.csv" "$tmpfile_old" "$tmpfile_new"
459 cat "$tmpfile_old" "$tmpfile_new" | while read from to
462 [ -n "$to" ] && echo "$to"
464 fi >> $tmpfile_updated_ports
465 [ `wc -l < $tmpfile_updated_ports` -gt 0 ] && rm -f "${DBDIR}/REPLACE.complete_sed_pattern"
466 [ -d "${DBDIR}/conf/each_port" ] && find "${DBDIR}/conf/each_port" -depth 2 \
469 origin=`str_dirpath_to_origin "$dbpath"`
470 dbpath_prev=${DBDIR}/conf.prev/each_port/$origin
471 diff -r "$dbpath_prev" "$dbpath" > /dev/null 2>&1 && continue
473 done >> $tmpfile_updated_ports
474 [ -d "${DBDIR}/conf.prev/each_port" ] && find "${DBDIR}/conf.prev/each_port" -depth 2 \
475 | while read dbpath_prev
477 origin=`str_dirpath_to_origin "$dbpath_prev"`
478 dbpath=${DBDIR}/conf/each_port/$origin
479 [ -d "$dbpath" ] && continue
481 done >> $tmpfile_updated_ports
482 if [ `wc -l < $tmpfile_updated_ports` -gt 0 ]
484 sort -u "$tmpfile_updated_ports" | while read origin
486 database_build_patch_reconf "$origin"
488 program_deregister_stage_complete INSPECT_ALL_DEPENDENCIES
492 program_exec_and_record_completion PATCH_TO_TMPDB_REFLECT_CONF_CHANGES
494 # ============= Database construction =============
496 # Execute command operations which must be done before building the temporary database
497 command_exec_before_building_tempdb "$@"
499 # Meta process for redo
501 _program_exec_and_record_completion__operation ()
503 rm -f "${DBDIR}/new_success_in_current_run"
504 [ "x$COMMAND_MODE" = xredo ] || return 0
505 message_echo "[REDO mode]"
508 program_exec_and_record_completion REDO_INIT
510 # Determine specified targets
512 _program_exec_and_record_completion__operation ()
514 local tag level dbsuffix
515 message_section_title "Determining specified targets"
516 cat "${DBDIR}/stage.loop_list/target_itself.specified" \
517 "${DBDIR}/stage.loop_list/target_dependents.specified" \
518 "${DBDIR}/stage.loop_list/target_requirements.specified" \
519 "${DBDIR}/need.list" \
520 "${DBDIR}/targets_specified_so_far" 2> /dev/null \
521 | sort -u > ${DBDIR}/targets_specified_so_far.tmp
522 mv "${DBDIR}/targets_specified_so_far.tmp" "${DBDIR}/targets_specified_so_far"
523 rm -f "${DBDIR}/stage.loop_list/target_itself.specified" \
524 "${DBDIR}/stage.loop_list/target_dependents.specified" \
525 "${DBDIR}/stage.loop_list/target_requirements.specified"
526 if [ -n "$opt_target_itself$opt_target_dependents$opt_target_requirements" ]
528 options_select_new_ports_if_duplicated O \
529 "${DBDIR}/stage.loop_list/target_itself.specified" "$opt_target_itself"
530 options_select_new_ports_if_duplicated t \
531 "${DBDIR}/stage.loop_list/target_dependents.specified" "$opt_target_dependents"
532 options_select_new_ports_if_duplicated T \
533 "${DBDIR}/stage.loop_list/target_requirements.specified" "$opt_target_requirements"
534 if [ `cat "${DBDIR}/stage.loop_list/target_itself.specified" \
535 "${DBDIR}/stage.loop_list/target_dependents.specified" \
536 "${DBDIR}/stage.loop_list/target_requirements.specified" | wc -l` -eq 0 ]
538 message_echo "ERROR: No matching port for target globs." >&2
542 cat "${DBDIR}/stage.loop_list/target_itself.specified" \
543 "${DBDIR}/stage.loop_list/target_dependents.specified" \
544 "${DBDIR}/stage.loop_list/target_requirements.specified" \
545 | sort -u > ${TMPDIR}/DETERMINE_SPECIFIED_TARGETS.reset
546 cat "${TMPDIR}/DETERMINE_SPECIFIED_TARGETS.reset" "${DBDIR}/need.list" 2> /dev/null \
547 | sort -u > ${DBDIR}/need.list.tmp
548 mv "${DBDIR}/need.list.tmp" "${DBDIR}/need.list"
549 sort -u "${DBDIR}/need.list" "${DBDIR}/targets_specified_so_far" \
550 > ${DBDIR}/targets_specified_so_far.tmp
551 mv "${DBDIR}/targets_specified_so_far.tmp" "${DBDIR}/targets_specified_so_far"
552 for tag in all run build none
554 for level in direct full
558 cat "${TMPDIR}/DETERMINE_SPECIFIED_TARGETS.reset"
559 cat "${DBDIR}/stage.loop_list/target_dependents.specified" | while read origin
561 nodedir=${DBDIR}/requires/$origin
562 cat "$nodedir/dependents.$dbsuffix" 2> /dev/null
564 cat "${DBDIR}/stage.loop_list/target_requirements.specified" | while read origin
566 nodedir=${DBDIR}/requires/$origin
567 cat "$nodedir/requirements.$dbsuffix" 2> /dev/null
569 } | sort -u | while read origin
571 fileedit_rm_a_line "$origin" "${DBDIR}/success.$dbsuffix.list"
572 fileedit_rm_a_line "$origin" "${DBDIR}/todo_after_requirements_succeed.$dbsuffix.list"
573 rm -f "${DBDIR}/requires/$origin/succeeded_once"
580 program_exec_and_record_completion DETERMINE_SPECIFIED_TARGETS
582 # Show specified targets
583 if [ -n "$opt_target_itself$opt_target_dependents$opt_target_requirements" -a $opt_batch_mode = no ]
585 message_echo "INFO: (Re/de-)installation will be carried out only for the targets:"
587 if [ `wc -l < ${DBDIR}/stage.loop_list/target_itself.specified` -gt 0 ]
589 message_echo "[Targets only]"
590 echo "----------------------------------------"
591 cat "${DBDIR}/stage.loop_list/target_itself.specified"
592 echo "----------------------------------------"
595 if [ `wc -l < ${DBDIR}/stage.loop_list/target_dependents.specified` -gt 0 ]
597 message_echo "[Targets with their `options_get_dependency_msgterm` dependents]"
598 echo "----------------------------------------"
599 cat "${DBDIR}/stage.loop_list/target_dependents.specified"
600 echo "----------------------------------------"
603 if [ `wc -l < ${DBDIR}/stage.loop_list/target_requirements.specified` -gt 0 ]
605 message_echo "[Targets with their `options_get_dependency_msgterm` requirements]"
606 echo "----------------------------------------"
607 cat "${DBDIR}/stage.loop_list/target_requirements.specified"
608 echo "----------------------------------------"
613 # Determine all target ports
614 PROGRAM_DEPENDS='DETERMINE_SPECIFIED_TARGETS COLLECT_ALL_INSTALLED_PACKAGES'
615 _program_exec_and_record_completion__operation ()
617 message_section_title "Determining all target ports"
619 if [ $opt_only_target_scope = no ]
621 cat "${DBDIR}/installed_ports" 2> /dev/null || :
623 cat "${DBDIR}/stage.loop_list/target_itself.specified" || :
624 cat "${DBDIR}/stage.loop_list/target_dependents.specified" || :
625 cat "${DBDIR}/stage.loop_list/target_requirements.specified" || :
626 cat "${DBDIR}/targets_specified_so_far" || :
627 } 2> /dev/null | sort -u > "${DBDIR}/stage.loop_list/ports_to_inspect"
630 program_exec_and_record_completion DETERMINE_ALL_TARGET_PORTS
632 # Inspection of all dependencies
633 PROGRAM_DEPENDS='PARSE_CONF DETERMINE_ALL_TARGET_PORTS'
634 _program_exec_restartable_loop_operation__routine ()
638 database_build_inspect_dependencies "$origin"
640 _program_exec_and_record_completion__operation ()
643 message_section_title "Inspecting dependencies of the all installed packages"
644 [ $opt_only_target_scope = no -a -n "$opt_target_itself$opt_target_dependents$opt_target_requirements" ] && \
645 message_echo "INFO: Ports which seem irrelevant to the targets are also inspected in order to get complete information."
647 program_exec_restartable_loop_operation ports_to_inspect
648 database_build_post_inspect_dependencies
651 program_exec_and_record_completion INSPECT_ALL_DEPENDENCIES
653 # Convert dependency-lists to actual ones
654 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES'
655 _program_exec_restartable_loop_operation__routine ()
657 local origin table dbtag level tag target
659 for table in dependents requirements
661 for dbtag in requires obsolete
663 for level in direct full
665 for tag in all run build
667 target=${DBDIR}/$dbtag/$origin/${table}.${tag}.${level}
668 if [ -e "$target.src" ]
670 sed -E -f "${DBDIR}/REPLACE.complete_sed_pattern" "$target.src" \
671 | grep -v '^$' | sort -u > $target.tmp
672 [ -e "$target" ] && ! diff "$target.tmp" "$target" > /dev/null \
673 && echo "$origin" >> ${DBDIR}/update_dependencies
674 mv "$target.tmp" "$target"
676 [ -e "$target" ] && echo "$origin" >> ${DBDIR}/update_dependencies
684 _program_exec_and_record_completion__operation ()
686 message_section_title "Conversion of dependency-lists to actual ones"
687 program_exec_restartable_loop_operation convert_dependency_lists
688 sort -u "${DBDIR}/update_dependencies" > ${DBDIR}/update_dependencies.tmp
689 mv "${DBDIR}/update_dependencies.tmp" "${DBDIR}/update_dependencies"
690 str_escape_regexp_filter < ${DBDIR}/update_dependencies \
691 | sed 's/^/^/; s/$/$/' > ${DBDIR}/update_dependencies.grep_pattern
692 for tag in all run build
694 ( cd "${DBDIR}/requires" && \
695 find . -depth 3 -type f -name requirements.${tag}.full | sed 's|^./||;s|/[^/]*$||' ) \
696 | grep -v -E -f "${DBDIR}/update_dependencies.grep_pattern" \
697 | str_escape_regexp_filter | sed 's/^/^/; s/$/$/' \
698 > ${TMPDIR}/convert_requirements_list:full_complete.grep_pattern || :
699 ( cd "${DBDIR}/requires" && \
700 find . -depth 3 -type f -name requirements.${tag}.direct | sed 's|^./||;s|/[^/]*$||' ) \
701 | grep -v -E -f "${TMPDIR}/convert_requirements_list:full_complete.grep_pattern" \
702 > ${DBDIR}/stage.loop_list/complete_${tag}time_reqlists || :
704 for inspected_level_tmp in direct node
706 cat "${DBDIR}/ports.inspected.${inspected_level_tmp}.list" || :
707 done 2> /dev/null | sort -u > ${DBDIR}/stage.loop_list/trim_dependency_lists_rm_uninspected_ports
708 find "${DBDIR}/requires" -depth 2 -type d > ${DBDIR}/stage.loop_list/inspect_dependent
709 [ -e "${DBDIR}/dependents_files" ] && \
710 mv "${DBDIR}/dependents_files" "${DBDIR}/dependents_files.prev"
711 rm -f "${DBDIR}/stage.loop_list/make_dependents_lists_unique.tmp" "${DBDIR}/dependents_files.tmp"
714 program_exec_and_record_completion CONVERT_REQUIREMENTS_LIST
716 # Completion of recursive requirement lists
717 for _REQUIREMENT_LISTS_tag in all run build
719 PROGRAM_DEPENDS='CONVERT_REQUIREMENTS_LIST'
720 _program_exec_restartable_loop_operation__routine ()
722 local tag dbpath origin
723 tag=${_REQUIREMENT_LISTS_tag}
725 origin=`str_dirpath_to_origin "$dbpath"`
726 database_build_get_complete_recursive_dependency requirements.${tag} "$origin" > /dev/null
728 _program_exec_and_record_completion__operation ()
731 tag=${_REQUIREMENT_LISTS_tag}
732 message_section_title "Completion of ${tag}-time requirement lists"
733 program_exec_restartable_loop_operation complete_${tag}time_reqlists
736 program_exec_and_record_completion REQUIREMENT_LISTS:${_REQUIREMENT_LISTS_tag}
739 # Trim dependency lists by removing uninspected ports
740 if [ $opt_only_target_scope = yes ]
742 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES CONVERT_REQUIREMENTS_LIST'
743 _program_exec_restartable_loop_operation__routine ()
745 local dbpath tag level srcdb
747 for tag in all run build
749 for level in direct full
751 srcdb=requirements.${tag}.${level}
752 [ -e "$dbpath/$srcdb" ] || continue
753 grep -E -f "${DBDIR}/inspected_ports.grep_pattern" "$dbpath/$srcdb" \
754 > $dbpath/$srcdb.tmp || :
755 mv "$dbpath/$srcdb.tmp" "$dbpath/$srcdb"
759 _program_exec_and_record_completion__operation ()
761 message_section_title "Trimming dependency lists by removing uninspected ports"
762 program_exec_restartable_loop_operation trim_dependency_lists_rm_uninspected_ports
765 program_exec_and_record_completion TRIM_DEPENDENCY_LISTS_RM_UNINSPECTED_PORTS
768 # Inspection of dependents
769 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES CONVERT_REQUIREMENTS_LIST TRIM_DEPENDENCY_LISTS_RM_UNINSPECTED_PORTS'
770 _program_exec_restartable_loop_operation__routine ()
772 local dbpath origin tag level srcdb dstdb
774 origin=`str_dirpath_to_origin "$dbpath"`
775 for tag in all run build
777 for level in direct full
779 srcdb=requirements.${tag}.${level}
780 dstdb=dependents.${tag}.${level}
781 [ -e "$dbpath/$srcdb" ] || continue
782 while read origin_requirement
784 dstpath=${DBDIR}/requires/$origin_requirement
785 echo "$dstpath/$dstdb" >> ${DBDIR}/dependents_files.tmp
786 [ "$dstpath/$dstdb" -nt "$dbpath/$srcdb" ] && continue
787 [ -d "$dstpath" ] || mkdir -p "$dstpath"
788 echo "$origin" >> $dstpath/$dstdb.raw
789 echo "$dstpath/$dstdb" >> ${DBDIR}/stage.loop_list/make_dependents_lists_unique.tmp
790 done < $dbpath/$srcdb
794 _program_exec_and_record_completion__operation ()
796 local dbrequires_valesc
797 message_section_title "Inspection of dependents"
798 dbrequires_valesc=`str_escape_replaceval "${DBDIR}/requires/"`
799 program_exec_restartable_loop_operation inspect_dependent
800 sort -u "${DBDIR}/stage.loop_list/make_dependents_lists_unique.tmp" 2> /dev/null \
801 > ${DBDIR}/stage.loop_list/make_dependents_lists_unique || :
802 sort -u "${DBDIR}/dependents_files.tmp" 2> /dev/null > ${DBDIR}/dependents_files || :
803 [ -e "${DBDIR}/make_dependents_lists_unique.prev" ] && \
804 fileedit_manipulate_old_lines "${DBDIR}/dependents_files.prev" "${DBDIR}/dependents_files" \
808 program_exec_and_record_completion INSPECT_DEPENDENTS
810 # Remove duplicated lines in dependents lists
811 PROGRAM_DEPENDS='CONVERT_REQUIREMENTS_LIST INSPECT_DEPENDENTS'
812 _program_exec_restartable_loop_operation__routine ()
814 local dbpath tag level dstdb
816 cat "$dstdb" "$dstdb.raw" 2> /dev/null | sort -u > $dstdb.tmp
817 mv "$dstdb.tmp" "$dstdb"
820 _program_exec_and_record_completion__operation ()
822 local dbrequires_valesc
823 message_section_title "Removing duplicated items in dependents lists"
824 program_exec_restartable_loop_operation make_dependents_lists_unique
827 program_exec_and_record_completion MAKE_DEPENDENTS_LISTS_UNIQUE
829 # Preparation of target attribute information
830 for _TARGET_ATTR_INFO_table in requirements dependents itself
832 [ `cat "${DBDIR}/stage.loop_list/target_${_TARGET_ATTR_INFO_table}.replaced.specified" 2> /dev/null \
833 | wc -l` -gt 0 ] || continue
834 PROGRAM_DEPENDS='DETERMINE_SPECIFIED_TARGETS CONVERT_REQUIREMENTS_LIST'
835 _program_exec_restartable_loop_operation__routine ()
837 local origin dbtargets_valesc table
839 dbtargets_valesc=`str_escape_replaceval "${DBDIR}/targets/"`
840 table=${_TARGET_ATTR_INFO_table}
841 for database in requires initial
843 dbpath=${DBDIR}/$database/$origin
844 dstpath=${DBDIR}/targets/$origin
845 [ -d "$dstpath" ] || mkdir -p "$dstpath"
846 touch "$dstpath/target_itself"
847 echo "$origin" >> ${DBDIR}/all_targets.lst
848 [ $table = itself ] && continue
849 for tag in all run build
851 for level in direct full
853 srcdb=${table}.${tag}.${level}
854 dstdb=target_${database}_${table}.${tag}.${level}
855 [ -e "$dbpath/$srcdb" ] || continue
856 cat "$dbpath/$srcdb" >> ${DBDIR}/all_targets.lst
857 sed -E "s/^/$dbtargets_valesc/; s|$|/$dstdb|" "$dbpath/$srcdb" \
858 | fileedit_add_a_line_to_files_if_new "$origin"
863 _program_exec_and_record_completion__operation ()
866 table=${_TARGET_ATTR_INFO_table}
867 message_section_title "Preparation of target attribute information for dependency [$table]"
868 program_exec_restartable_loop_operation target_$table.replaced.specified
871 program_exec_and_record_completion TARGET_ATTR_INFO:${_TARGET_ATTR_INFO_table}
874 # Post-process after the preparation of target attribute information
875 PROGRAM_DEPENDS='MAKE_DEPENDENTS_LISTS_UNIQUE TARGET_ATTR_INFO:requirements TARGET_ATTR_INFO:dependents'
876 _program_exec_and_record_completion__operation ()
878 message_section_title "Post-process after the preparation of target attribute information"
879 sort -u "${DBDIR}/all_targets.lst" 2> /dev/null \
880 | grep -E -f "${DBDIR}/inspected_ports.grep_pattern" \
881 | sed -E -f "${DBDIR}/REPLACE.complete_sed_pattern" \
882 > ${DBDIR}/all_targets.lst.tmp || :
883 mv "${DBDIR}/all_targets.lst.tmp" "${DBDIR}/all_targets.lst"
884 find "${DBDIR}/targets" -depth 2 -type d > ${DBDIR}/stage.loop_list/build_complement_to_new_dependents_for_targets 2> /dev/null || :
886 cat "${DBDIR}/all_targets.lst" "${DBDIR}/need.with_replaced.list" 2> /dev/null || :
887 find "${DBDIR}/requires" -depth 3 -type f -name installed_version \
888 | sed -E 's|.*/([^/]+/[^/]+)/[^/]*$|\1|'
889 } | sort -u > ${DBDIR}/stage.loop_list/inspect_necessity
890 cp /dev/null "${DBDIR}/stage.loop_list/parse_target_attr_info"
891 find -E "${DBDIR}/requires" -depth 3 -type f -regex '.*/necessary_port\.(direct|full)$' -delete
894 program_exec_and_record_completion TARGET_ATTR_INFO_POSTPROCESS
896 # Build of data on complement to new dependents for target attribute information
897 PROGRAM_DEPENDS='TARGET_ATTR_INFO_POSTPROCESS TARGET_ATTR_INFO:requirements TARGET_ATTR_INFO:dependents CONVERT_REQUIREMENTS_LIST'
898 _program_exec_restartable_loop_operation__routine ()
902 origin=`str_dirpath_to_origin "$dbpath"`
903 database_build_complement_to_new_dependents_for_targets "$origin"
905 _program_exec_and_record_completion__operation ()
907 message_section_title "Build of data on complement to new dependents for target attribute information"
908 program_exec_restartable_loop_operation build_complement_to_new_dependents_for_targets
909 sort -u "${DBDIR}/stage.loop_list/parse_target_attr_info" > ${DBDIR}/stage.loop_list/parse_target_attr_info.tmp
910 mv "${DBDIR}/stage.loop_list/parse_target_attr_info.tmp" "${DBDIR}/stage.loop_list/parse_target_attr_info"
913 program_exec_and_record_completion COMPLEMENT_TO_NEW_DEPENDENTS_FOR_TARGET_ATTR_INFO
915 # Parse target attribute information
916 PROGRAM_DEPENDS='COMPLEMENT_TO_NEW_DEPENDENTS_FOR_TARGET_ATTR_INFO'
917 _program_exec_restartable_loop_operation__routine ()
921 origin=`str_dirpath_to_origin "$dbpath"`
922 database_build_target_attributes "$origin"
924 _program_exec_and_record_completion__operation ()
926 message_section_title "Parsing target attribute information"
927 program_exec_restartable_loop_operation parse_target_attr_info
930 program_exec_and_record_completion PARSE_TARGET_ATTR_INFO
932 # Inspection of necessity
933 PROGRAM_DEPENDS='TARGET_ATTR_INFO_POSTPROCESS REQUIREMENT_LISTS:run-time REQUIREMENT_LISTS:build-time INSPECT_ALL_DEPENDENCIES'
934 _program_exec_restartable_loop_operation__routine ()
938 for level in direct full
940 database_build_inspect_necessity_for_only_new_upgrade "$origin" "$level"
943 _program_exec_and_record_completion__operation ()
945 message_section_title "Inspection of necessity"
946 program_exec_restartable_loop_operation inspect_necessity
947 for level in direct full
949 find "${DBDIR}/requires" -depth 3 -type f -name "necessary_port.${level}" \
950 > ${DBDIR}/stage.loop_list/necessary_ports.${level}
954 program_exec_and_record_completion INSPECT_NECESSITY
956 # Inspection of necessary upgrades
957 for _NECESSARY_UPDATES_level in direct full
959 PROGRAM_DEPENDS='INSPECT_NECESSITY INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE'
960 _program_exec_restartable_loop_operation__routine ()
962 local markerpath level dbpath origin tag
964 level=${_NECESSARY_UPDATES_level}
965 dbpath=`dirname "$markerpath"`
966 origin=`str_dirpath_to_origin "$dbpath"`
967 database_query_does_a_port_need_update "$origin" || return 0
968 for tag in all run build none
970 touch "$dbpath/necessary_upgrade.$tag.${level}"
971 [ -e "$dbpath/dependents.$tag.${level}" ] || continue
972 while read origin_dependent
974 touch "${DBDIR}/requires/$origin_dependent/necessary_upgrade.$tag.${level}"
975 done < $dbpath/dependents.$tag.${level}
978 _program_exec_and_record_completion__operation ()
981 level=${_NECESSARY_UPDATES_level}
982 message_section_title "Inspection of necessary upgrades at the $level level"
983 program_exec_restartable_loop_operation necessary_ports.${level}
986 program_exec_and_record_completion NECESSARY_UPDATES:${_NECESSARY_UPDATES_level}
989 # Preparation for inspection of new leaf ports
990 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
992 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE PARSE_CONF'
993 _program_exec_and_record_completion__operation ()
995 message_section_title "Preparation for inspection of new leaf ports"
996 find "${DBDIR}/requires" -depth 3 -type f -name dependents.all.full \
997 | sed -E 's|.*/([^/]+/[^/]+)/[^/]+$|\1|' \
998 | sort -u > ${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:nonleaf_ports
999 sort -u "${DBDIR}/inspected_ports" > ${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:inspected_ports
1000 fileedit_manipulate_new_lines \
1001 "${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:nonleaf_ports" \
1002 "${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:inspected_ports" \
1003 | grep -v -E -f "${DBDIR}/conf/HOLD_PORTS.grep_pattern" \
1004 > ${DBDIR}/stage.loop_list/leaf_ports_primary_candidates || :
1005 cp /dev/null "${DBDIR}/grep.leaf_ports.pattern"
1006 cp /dev/null "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates"
1009 program_exec_and_record_completion PREPARE_INSPECT_LEAF_PORTS
1012 # Inspection of new primary leaf ports
1013 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1015 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE PREPARE_INSPECT_LEAF_PORTS PARSE_CONF'
1016 _program_exec_restartable_loop_operation__routine ()
1018 local origin origin_ini origin_esc dbpath origin_req
1020 pkgsys_is_pkgtool "$origin" && return
1021 dbpath=${DBDIR}/requires/$origin
1022 origin_esc=`str_escape_regexp "$origin"`
1023 grep -q -E "^$origin_esc$" "${DBDIR}/need.with_replaced.list" 2> /dev/null && return
1024 if ! grep -q -E "^$origin_esc$" "${DBDIR}/noneed.list" 2> /dev/null
1026 if [ -e "$dbpath/initial_orig" ]
1028 origin_ini=`cat "$dbpath/initial_orig"`
1029 [ -e "${DBDIR}/initial/$origin_ini/installed_version" \
1030 -a `cat "${DBDIR}/initial/$origin_ini/dependents.all.full" 2> /dev/null | wc -l` -eq 0 ] \
1033 [ -e "${DBDIR}/initial/$origin/installed_version" \
1034 -a `cat "${DBDIR}/initial/$origin/dependents.all.full" 2> /dev/null | wc -l` -eq 0 ] \
1037 if [ -e "$dbpath/requirements.all.full" ]
1039 grep -v -E -f "${DBDIR}/conf/HOLD_PORTS.grep_pattern" "$dbpath/requirements.all.full" | \
1040 fileedit_add_lines_if_new "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates" || :
1042 fileedit_add_a_line_if_new "^$origin_esc$" "${DBDIR}/grep.leaf_ports.pattern"
1044 _program_exec_and_record_completion__operation ()
1046 local num_leaves num_leaves_prev
1047 message_section_title "Inspection of new primary leaf ports"
1048 program_exec_restartable_loop_operation leaf_ports_primary_candidates
1049 wc -l < ${DBDIR}/grep.leaf_ports.pattern | tr -d ' ' > ${DBDIR}/num_leaves
1050 cp /dev/null "${DBDIR}/leaf_ports_secondary_candidates.new_requirements"
1051 message_echo " `cat "${DBDIR}/num_leaves"` primary leaf port(s) is/are found."
1054 program_exec_and_record_completion INSPECT_PRIMARY_LEAF_PORTS
1057 # Inspection of requirements of new leaf ports
1058 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1060 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE INSPECT_PRIMARY_LEAF_PORTS PARSE_CONF'
1061 _program_exec_and_record_completion__operation ()
1063 local num_leaves num_leaves_prev num_inspect num_leaves_new
1064 message_section_title "Inspection of requirements of new leaf ports"
1065 message_echo "INFO: The inspection proceeds by iterative method."
1068 _program_exec_restartable_loop_operation__routine ()
1070 local origin origin_esc dbpath
1072 pkgsys_is_pkgtool "$origin" && return
1073 dbpath=${DBDIR}/requires/$origin
1074 origin_esc=`str_escape_regexp "$origin"`
1075 grep -q -E "^$origin_esc$" "${DBDIR}/need.with_replaced.list" 2> /dev/null && return
1076 grep -E -v -f "${DBDIR}/grep.leaf_ports.pattern" \
1077 "$dbpath/dependents.all.full" > /dev/null 2>&1 && return
1078 cat "$dbpath/requirements.all.full" 2> /dev/null \
1079 >> ${DBDIR}/leaf_ports_secondary_candidates.new_requirements || :
1080 fileedit_add_a_line_if_new "^$origin_esc$" "${DBDIR}/grep.leaf_ports.pattern"
1082 program_exec_restartable_loop_operation leaf_ports_secondary_candidates
1083 num_leaves_prev=`cat "${DBDIR}/num_leaves"`
1084 num_leaves=`wc -l < ${DBDIR}/grep.leaf_ports.pattern | tr -d ' '`
1085 num_leaves_new=`echo $(($num_leaves-$num_leaves_prev)) | tr -d ' '`
1086 if [ $num_leaves_new -eq 0 ]
1088 message_echo " No more leaf port is found."
1089 message_echo " $num_leaves leaf port(s) is/are found in total."
1093 grep -E -v -f "${DBDIR}/grep.leaf_ports.pattern" \
1094 "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates" || :
1095 cat "${DBDIR}/leaf_ports_secondary_candidates.new_requirements" || :
1096 } | grep -v -E -f "${DBDIR}/conf/HOLD_PORTS.grep_pattern" | sort -u \
1097 > ${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates.tmp || :
1098 program_reset_loop_for_stage INSPECT_REQUIREMENTS_OF_LEAF_PORTS
1099 mv "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates.tmp" \
1100 "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates"
1101 cp /dev/null "${DBDIR}/leaf_ports_secondary_candidates.new_requirements"
1102 echo "$num_leaves" > ${DBDIR}/num_leaves
1103 num_inspect=`wc -l < ${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates | tr -d ' '`
1104 message_echo " $num_leaves_new leaf port(s) is/are newly found; continue for $num_inspect candidate(s)."
1106 grep -E -f "${DBDIR}/grep.leaf_ports.pattern" "${DBDIR}/inspected_ports" | sort -u > ${DBDIR}/leaf_ports || :
1109 program_exec_and_record_completion INSPECT_REQUIREMENTS_OF_LEAF_PORTS
1112 # Order the ports considering dependencies
1113 PROGRAM_DEPENDS='CONVERT_REQUIREMENTS_LIST'
1114 _program_exec_and_record_completion__operation ()
1116 message_section_title "Ordering dependencies"
1117 if ! database_build_order_ports_considering_dependencies
1119 message_echo "ERROR: Unsatisfied dependencies are remained:" >&2
1120 message_cat "${DBDIR}/unsatisfied.list"
1121 message_echo "*** Aborted by ${APPNAME}"
1122 message_echo "The ports tree seems broken. You might have caught an incomplete version."
1123 message_echo "You are encouraged to update the ports tree by portsnap(8)."
1124 message_echo "Then execute"
1125 message_echo " ${APPNAME} clean"
1126 message_echo "before restart."
1127 temp_terminate_process () { :; }
1132 program_exec_and_record_completion ORDER_ALL_DEPENDENCIES
1134 # Selection of removing leaf ports
1135 PROGRAM_DEPENDS='INSPECT_REQUIREMENTS_OF_LEAF_PORTS'
1136 _program_exec_and_record_completion__operation ()
1138 message_section_title "Selection of removing leaf ports"
1139 deinstall_select_leaf_ports_to_delete
1142 program_exec_and_record_completion SELECT_LEAF_PORTS
1144 # Selection of removing obsolete ports
1145 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES PARSE_CONF'
1146 _program_exec_and_record_completion__operation ()
1148 message_section_title "Selection of removing obsolete ports"
1149 deinstall_select_obsolete_ports_to_delete
1152 program_exec_and_record_completion SELECT_OBSOLETE_PORTS
1154 # Collection of leaf ports to delete
1155 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1157 PROGRAM_DEPENDS='SELECT_LEAF_PORTS'
1158 _program_exec_and_record_completion__operation ()
1160 local src src_unselected reqptn_file src_with_initial_origins
1161 message_section_title "Collecting leaf ports to delete"
1162 src=${DBDIR}/leaf_ports
1163 src_unselected=${DBDIR}/leaf_ports_to_delete.unselected
1164 src_with_initial_origins=${DBDIR}/leaf_ports.with_ini
1165 reqptn_file=${DBDIR}/leaf_ports.requirements_of_unselected.grep_pattern
1166 cat "$src_unselected" 2> /dev/null | while read origin
1168 cat "${DBDIR}/requires/$origin/requirements.all.full" || :
1169 done | sort -u | str_escape_regexp_filter \
1170 | sed 's/^/^/;s/$/$/' > $reqptn_file
1171 database_query_add_initial_origins < $src > $src_with_initial_origins
1174 program_exec_and_record_completion COLLECT_LEAF_PORTS_TO_DELETE
1177 # Collection of obsolete ports to delete
1178 PROGRAM_DEPENDS='SELECT_OBSOLETE_PORTS'
1179 _program_exec_and_record_completion__operation ()
1181 local src src_selected src_unselected dst_selected reqptn_file
1182 message_section_title "Collecting obsolete ports to delete"
1183 src=${DBDIR}/obsolete_ports.can_be_deleted
1184 src_selected=${DBDIR}/obsolete_ports_to_delete.selected
1185 src_unselected=${DBDIR}/obsolete_ports_to_delete.unselected
1186 dst_selected=${DBDIR}/obsolete_ports_to_delete
1187 reqptn_file=${DBDIR}/obsolete_ports.requirements_of_unselected.grep_pattern
1188 cat "$src_unselected" 2> /dev/null | while read origin
1190 cat "${DBDIR}/initial/$origin/requirements.run.full" || :
1191 cat "${DBDIR}/obsolete/$origin/requirements.run.full" || :
1192 done | sort -u | str_escape_regexp_filter \
1193 | sed 's/^/^/;s/$/$/' > $reqptn_file
1194 grep -v -E -f "$reqptn_file" "$src_selected" > $dst_selected 2> /dev/null || :
1197 program_exec_and_record_completion COLLECT_OBSOLETE_PORTS_TO_DELETE
1199 # Set up the list of ports to reinstall
1200 PROGRAM_DEPENDS='ORDER_ALL_DEPENDENCIES'
1201 _program_exec_and_record_completion__operation ()
1203 message_section_title "Setting up the list of ports to reinstall"
1204 cp -p "${DBDIR}/reinst_order.list" "${DBDIR}/stage.loop_list/reinst_todo"
1207 program_exec_and_record_completion SETUP_REINST_TODO
1209 # Composition of a list for deinstallation of obsolete and leaf packages
1210 PROGRAM_DEPENDS='COLLECT_LEAF_PORTS_TO_DELETE COLLECT_OBSOLETE_PORTS_TO_DELETE'
1211 _program_exec_and_record_completion__operation ()
1213 local reqptn_leaf reqptn_obs leaf_selected leaf_selected_src obs_selected obs_selected_src grepptn preserved
1214 message_section_title "Composing a list for deinstallation of obsolete and leaf packages"
1215 reqptn_leaf=${DBDIR}/leaf_ports.requirements_of_unselected.grep_pattern
1216 reqptn_obs=${DBDIR}/obsolete_ports.requirements_of_unselected.grep_pattern
1217 leaf_selected_src=${DBDIR}/leaf_ports_to_delete.selected
1218 leaf_selected=${DBDIR}/leaf_ports_to_delete
1219 obs_selected_src=${DBDIR}/obsolete_ports_to_delete.selected
1220 obs_selected=${DBDIR}/obsolete_ports_to_delete
1221 grepptn=${DBDIR}/ports_to_delete.grep_pattern
1222 grepptn_col1=${DBDIR}/ports_to_delete.grep_pattern_col1
1223 preserved=${TMPDIR}/LIST_DEINST_PKGS::preserved
1224 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1226 cat "$reqptn_leaf" "$reqptn_obs" 2> /dev/null | sort -u > $grepptn
1227 grep -v -E -f "$grepptn" "$leaf_selected_src" 2> /dev/null \
1228 | database_query_add_initial_origins > $leaf_selected || :
1229 cat "$obs_selected" "$leaf_selected" 2> /dev/null || :
1231 rm -f "$leaf_selected"
1232 cat "$obs_selected" 2> /dev/null
1233 fi | sort -u > ${DBDIR}/stage.loop_list/ports_to_delete
1234 str_escape_regexp_filter < ${DBDIR}/stage.loop_list/ports_to_delete \
1235 | sed 's/^/^/;s/$/$/' > $grepptn
1236 str_escape_regexp_filter < ${DBDIR}/stage.loop_list/ports_to_delete \
1237 | sed 's/^/^/;s/$/[[:space:]]/' > $grepptn_col1
1238 cat "${DBDIR}/leaf_ports.with_ini" "${DBDIR}/obsolete_ports" 2> /dev/null \
1239 | grep -E -v -f "$grepptn" > ${DBDIR}/stage.loop_list/ports_to_restore || :
1240 if [ $opt_batch_mode = no ]
1242 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ] && \
1243 grep -v -E -f "$grepptn" "$leaf_selected_src" > $preserved 2> /dev/null
1245 message_echo "INFO: Following leaf ports are preserved because required by other preserved leaf/obsolete ports."
1246 message_echo "----------------"
1249 pkgtag=`cat "${DBDIR}/required/$origin/pkgtag" 2> /dev/null` || :
1252 echo "$origin" "($pkgtag)"
1257 message_echo "----------------"
1259 if grep -v -E -f "$grepptn" "$obs_selected_src" > $preserved 2> /dev/null
1261 message_echo "INFO: Following obsolete ports are preserved because required by other obsolete ports."
1262 message_echo "----------------"
1265 pkgtag=`cat "${DBDIR}/initial/$origin/installed_version" 2> /dev/null` || :
1268 echo "$origin" "($pkgtag)"
1273 message_echo "----------------"
1278 program_exec_and_record_completion LIST_DEINST_PKGS
1280 # Collect entire distfiles list
1281 if [ $opt_inspect_entire_distinfo = yes ]
1284 _program_exec_and_record_completion__operation ()
1286 message_section_title "Collecting entire distfiles list"
1287 find "${PORTSDIR}" -depth 3 -name distinfo -exec cat {} \; \
1288 | grep '^SHA256 ' | sed -E 's/^SHA256 \(([^)]*)\).*/\1/' \
1289 | sort -u > ${DBDIR}/distfiles.entire.tmp
1290 mv "${DBDIR}/distfiles.entire.tmp" "${DBDIR}/distfiles.entire"
1293 program_exec_and_record_completion COLLECT_ALL_DISTFILES_LIST
1296 # Inspection of all required distfiles
1297 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES COLLECT_ALL_DISTFILES_LIST'
1298 _program_exec_and_record_completion__operation ()
1300 message_section_title "Summarizing distfiles list"
1301 cat "${DBDIR}/distfiles.entire" "${DBDIR}/distfiles.inspected" 2> /dev/null \
1302 | sort -u | str_escape_regexp_filter \
1303 | sed 's|^|^\\.\\/|; s|$|$|' > ${DBDIR}/distfiles.grep.pattern || :
1306 program_exec_and_record_completion DISTFILES_LIST
1308 # Clean up of reinstallation status for preparation
1309 PROGRAM_DEPENDS='REDO_INIT INSPECT_ALL_DEPENDENCIES'
1310 _program_exec_and_record_completion__operation ()
1312 message_section_title "Cleaning up of reinstallation status for preparation"
1313 rm -rf "${DBDIR}/status.ports"
1316 program_exec_and_record_completion CLEANUP_REINST_STATUS
1318 # Completion of building the temporary database
1319 PROGRAM_DEPENDS='REDO_INIT SETUP_REINST_TODO CLEANUP_REINST_STATUS PARSE_CONF INSPECT_ALL_DEPENDENCIES NECESSARY_UPDATES:direct NECESSARY_UPDATES:full PARSE_TARGET_ATTR_INFO MAKE_DEPENDENTS_LISTS_UNIQUE COLLECT_LEAF_PORTS_TO_DELETE'
1320 _program_exec_and_record_completion__operation ()
1322 message_section_title "The temporary database is completely built up"
1325 program_exec_and_record_completion PREPARATION
1328 # ==================================================
1329 # ====================== MAIN ======================
1330 # ==================================================
1332 # Execute command operations which must be done before actual (re/de)installation processes
1333 command_exec_before_actual_re_de_installation "$@"
1335 # Set termination messages
1336 temp_terminate_process ()
1338 temp_terminate_process_common
1341 # Reinstallation of remained ports
1342 PROGRAM_DEPENDS='PREPARATION'
1343 _program_exec_restartable_loop_operation__routine ()
1347 _program_exec_and_record_completion__operation ()
1349 local _MSG_CURRENT_STAGE_general
1350 _MSG_CURRENT_STAGE_general="reinstallation"
1351 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1352 message_section_title "Reinstallation"
1353 program_exec_restartable_loop_operation reinst_todo
1354 reinstall_restore_conflicts
1355 temp_set_msg_current_stage
1358 program_exec_and_record_completion REINSTALLATION
1360 # Restoration of obsolete and leaf packages which have been deinstalled but unselected from the deletion list again
1361 PROGRAM_DEPENDS='REDO_INIT LIST_DEINST_PKGS'
1362 _program_exec_restartable_loop_operation__routine ()
1364 deinstall_restore "$@"
1366 _program_exec_and_record_completion__operation ()
1368 local _MSG_CURRENT_STAGE_general
1369 _MSG_CURRENT_STAGE_general="restoration of unselected obsolete/leaf packages"
1370 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1371 message_section_title "Restoration of unselected obsolete/leaf packages"
1372 program_exec_restartable_loop_operation ports_to_restore
1373 temp_set_msg_current_stage
1376 program_exec_and_record_completion RESTORE_ONCE_DEINST_PKGS
1378 # Deinstallation of unused obsolete and leaf packages
1379 PROGRAM_DEPENDS='REDO_INIT LIST_DEINST_PKGS'
1380 _program_exec_restartable_loop_operation__routine ()
1384 _program_exec_and_record_completion__operation ()
1386 local _MSG_CURRENT_STAGE_general
1387 _MSG_CURRENT_STAGE_general="deinstallation of obsolete/leaf packages"
1388 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1389 message_section_title "Deinstallation of unused obsolete/leaf packages"
1390 program_exec_restartable_loop_operation ports_to_delete
1391 temp_set_msg_current_stage
1394 program_exec_and_record_completion DEINST_UNUSED_PKGS
1396 # Clean up obsolete or unused distfiles
1397 if [ $opt_only_target_scope = no -a $opt_keep_distfiles = no ]
1399 PROGRAM_DEPENDS='REINSTALLATION DISTFILES_LIST'
1400 _program_exec_and_record_completion__operation ()
1402 local tmp_distfiles_exists
1403 message_section_title "Cleaning up obsolete or unused distfiles"
1404 tmp_distfiles_exists=${TMPDIR}/CLEANUP_OBSLETE_DISTFILES::distfiles_exists
1405 [ $opt_dry_run = yes ] && message_echo "INFO: The operations are not actually carried out."
1406 ( set -e; cd "${DISTDIR}" && find . -type f ) \
1407 | sed 's|^\./||' | sort -u > $tmp_distfiles_exists
1408 fileedit_manipulate_old_lines "$tmp_distfiles_exists" "${DBDIR}/distfiles.entire" \
1409 | while read distfile
1411 if [ $opt_batch_mode = no ]
1415 [ $opt_dry_run = yes ] && continue
1416 rm -f "${DISTDIR}/$distfile"
1420 program_exec_and_record_completion CLEANUP_OBSLETE_DISTFILES
1423 # Rebuild of package database
1424 PROGRAM_DEPENDS='REINSTALLATION RESTORE_ONCE_DEINST_PKGS DEINST_UNUSED_PKGS'
1425 _program_exec_and_record_completion__operation ()
1427 which -s pkgdb || return 0
1428 message_section_title "Rebuilding package database for portupgrade"
1432 program_exec_and_record_completion REBUILD_PKGDB
1435 # ==================================================
1436 # ================ ENDING MESSAGES =================
1437 # ==================================================
1439 # Notice of failures
1440 exists_unresolved_ports=
1441 message_summary_dependents_of_failed_reinstallation failure || exists_unresolved_ports=y
1442 message_summary_dependents_of_failed_reinstallation redo || exists_unresolved_ports=y
1443 message_summary_dependents_of_failed_reinstallation conflict || exists_unresolved_ports=y
1444 [ -n "$exists_unresolved_ports" ] && message_summary_advice_on_manual_solution
1447 temp_terminate_process () { :; }
1449 if [ -z "$exists_unresolved_ports" ]
1451 message_section_title "COMPLETELY DONE"
1452 message_echo "- E N D -"
1454 message_warn_no_achieved_progress || :
1455 message_section_title "Done with some unresolved problems"
1456 message_echo "- To be continued -"