2 # ==================================================================================
3 # portsreinstall main script
4 # Copyright (C) 2010-2013 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.0+toward_3.0.1_20130610150827
19 # COMPATIBLE_VERSIONS='^(3\.0\.0\+toward_3\.0\.1_[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
44 DBDIR=/var/tmp/${APPNAME}.db
45 CONFFILE=${MYPREFIX}/etc/${APPNAME}.conf
46 PKGTOOLSCONF=${MYPREFIX}/etc/pkgtools.conf
49 # ==================================================
50 # ========= PARSING OPTIONS AND ARGUMENTS ==========
51 # ==================================================
53 # ============= Save arguments for upgraded restart =============
54 options_dump_args "$@" > ${TMPDIR}/restart_command.sh
56 # ============= Option check =============
59 options_getopts "$@" || :
60 if [ $OPTIONS_ERRNO -eq 2 ]
62 message_echo "INTERNAL ERROR: In parsing options" >&2
65 shift "${OPTIONS_SHIFT}"
67 # ============= Argument check for no-command options =============
68 if [ $opt_help_mode -ne 0 -o $opt_show_version = yes ]
76 # ============= Output usage if the case of a help mode or option/argument errors =============
77 if [ $OPTIONS_ERRNO -ne 0 ]
80 elif [ $opt_help_mode -eq 1 ]
84 elif [ $opt_help_mode -eq 2 ]
90 # ============= Output version number =============
91 if [ $opt_show_version = yes ]
97 # ============= Execute command operations before getting the temporary database ready =============
98 command_exec_before_db_creation "$@"
100 # ============= Creation of temporary database directory =============
101 database_build_create
103 # ============= Argument check for conventional runs =============
104 command_parse_args "$@"
105 shift "${COMMAND_SHIFT}"
108 # ==================================================
109 # ================== TOOLS SET UP ==================
110 # ==================================================
112 # ============= Opening title =============
115 [ $COMMAND_MODE = do -o $COMMAND_MODE = redo -o $COMMAND_MODE = forget ] && \
116 message_opening_notice
119 # ============= Execute command operations which do not need package tools =============
121 command_exec_without_pkgtools "$@"
122 misc_is_superuser_privilege && touch "${DBDIR}/in_use"
124 # ============= Definition of environment dependent functions =============
128 # ============= Option settings =============
130 # Execute command operations which are not affected by saved option settings
131 command_exec_irrespective_of_saved_options "$@"
133 # Load, renew and save option values
135 options_chk_invalid_optvals_renewal non_renewable || optcomb_err=$?
136 if [ \( $opt_reload_conf = yes -o $opt_reset_targets = yes \) -a "x$COMMAND_MODE" != xredo ]
138 message_echo "ERROR: Option -N is available only in the initial run of redo command." >&2
142 if [ $opt_batch_ports_only = yes -a $opt_interactive_ports_only = yes ]
144 message_echo "ERROR: Options -A and -I conflict with each other." >&2
148 if [ -e "${DBDIR}/saved_options.sh" ]
151 options_renewed_optvals M renewable_anytime || optcomb_err=$?
152 options_renewed_optvals N renewable_in_redo_on_target || optcomb_err=$?
153 options_renewed_optvals L renewable_in_redo_on_conf || optcomb_err=$?
154 } > ${TMPDIR}/renewed_optvals.sh
155 [ $optcomb_err -eq 0 ] || exit $optcomb_err
156 . "${DBDIR}/saved_options.sh"
157 . "${TMPDIR}/renewed_optvals.sh"
159 misc_is_superuser_privilege && misc_get_all_vardefs | options_filter saved > ${DBDIR}/saved_options.sh
162 if [ -e "${DBDIR}/saved_options.sh" -a $opt_batch_mode = no \
163 -a \( $COMMAND_MODE = do -o $COMMAND_MODE = redo \) ]
165 message_echo "INFO: List of option values:"
166 message_echo "-----------------------------------------"
167 message_cat "${DBDIR}/saved_options.sh"
168 message_echo "-----------------------------------------"
172 # ============= Termination messages during construction of the temporary database =============
174 # Set termination messages
175 temp_terminate_process_common ()
178 [ $opt_batch_mode = yes ] && return
179 msg_where=`temp_get_msg_current_stage`
180 [ -n "$msg_where" ] && msg_where=" during $msg_where"
182 if [ $errno -eq 130 ]
184 echo "INFO: Terminated at `message_timestamp`$msg_where."
186 echo " You can restart this process from the terminated point by"
188 echo "INFO: Aborted at `message_timestamp`$msg_where."
190 echo " You may restart this process from the aborted point by"
192 echo "executing without options or arguments as:"
193 if [ -n "$COMMAND_RESTART" ]
195 echo " ${APPNAME} $COMMAND_RESTART"
201 temp_terminate_process ()
203 [ $errno -eq 0 -o $opt_batch_mode = yes ] && return
204 temp_terminate_process_common
205 [ -n "$COMMAND_RESTART" ] || message_cat 3<< eof
206 Instead, if you only want to construct the temporary database so as to stop before the actual reinstallation, execute as:
211 # ============= Configurations =============
213 # Save the previous configuration if exists
215 _program_exec_and_record_completion__operation ()
217 rm -rf "${DBDIR}/conf.prev"
218 [ -d "${DBDIR}/conf" ] && \
219 cp -Rp "${DBDIR}/conf" "${DBDIR}/conf.prev"
222 program_exec_and_record_completion SAVE_PREV_CONF
224 # Get complete configuration variable definitions by importing pkgtools.conf(5) if available
225 PROGRAM_DEPENDS='SAVE_PREV_CONF'
226 _program_exec_and_record_completion__operation ()
230 rm -rf "${DBDIR}/conf"
231 mkdir -p "${DBDIR}/conf"
232 [ "x`options_get_effective_opt_load_pkgtoolsconf`" != xno -a $opt_batch_mode = no ] \
234 [ $need_msg = yes ] && \
235 message_section_title "Parsing pkgtools.conf (by using installed portupgrade)"
236 conf_get_complete_var_defs > ${DBDIR}/conf/complete_setup.sh
237 [ $need_msg = yes ] && { message_echo "===> ok"; message_echo; }
240 program_exec_and_record_completion GET_COMPLETE_CONF_VAR_DEF
242 # Parse the configuration
243 PROGRAM_DEPENDS='GET_COMPLETE_CONF_VAR_DEF'
244 _program_exec_and_record_completion__operation ()
246 message_section_title "Parsing the configuration"
247 conf_manipulate_available_var_defs
248 . "${DBDIR}/conf/manipulated_defs.sh"
250 conf_build_effective_MOVED
251 # Environmental variables
252 conf_setup_effective_env > ${DBDIR}/conf/setenv.sh
253 . "${DBDIR}/conf/setenv.sh"
255 conf_parse_vars_for_each_port_glob HOLD
256 str_escape_regexp_filter < ${DBDIR}/conf/HOLD:PORTS.parsed \
257 | sed 's/^/^/;s/$/$/' > ${DBDIR}/conf/HOLD_PORTS.grep_pattern
259 conf_parse_vars_for_each_port_glob TABOO
260 fileedit_combine_lists "${DBDIR}/conf/TABOO:PORTS.parsed" "${DBDIR}/taboo.list" \
261 > ${DBDIR}/taboo.all.list
263 conf_parse_vars_for_each_port_glob NOPKG
265 conf_build_replacement_patterns_from_REPLACE
267 conf_parse_vars_for_each_port_glob_with_bound_val MARG TARGET DEF
269 conf_parse_vars_for_each_port_glob_with_bound_val MENV TARGET DEF
271 conf_parse_vars_for_each_port_glob_with_bound_val BEFOREBUILD TARGET COMMAND
273 conf_parse_vars_for_each_port_glob_with_bound_val BEFOREDEINSTALL TARGET COMMAND
275 conf_parse_vars_for_each_port_glob_with_bound_val AFTERINSTALL TARGET COMMAND
278 program_exec_and_record_completion PARSE_CONF
280 . "${DBDIR}/conf/setenv.sh"
282 # ============= Upgrade of tools =============
284 # Execute command operations which should be done without upgrade of tools
285 command_exec_before_tools_upgrade "$@"
287 # Check whether the temporary database is newer than the ports tree and refresh if so
288 database_build_refresh_if_obsolete
290 # Get the port origin for this utility if installed by port
291 MYPORTORIGIN=`pkgsys_get_my_origin 2> /dev/null` || :
293 # Collect all installed packages
295 _program_exec_and_record_completion__operation ()
297 message_section_title "Collecting all installed packages"
298 pkg_info_qoa > ${DBDIR}/installed_ports
299 pkg_info_gen_pkg_origin_table
300 str_escape_regexp_filter < "${DBDIR}/installed_ports" \
301 | sed 's/^/^/; s/$/$/' > ${DBDIR}/installed_ports.grep_pattern
304 program_exec_and_record_completion COLLECT_ALL_INSTALLED_PACKAGES
306 # Preliminary inspection of tools which have to be up-to-date
307 # (No need depend on PARSE_CONF because INSPECT_ALL_DEPENDENCIES will take the task.)
309 _program_exec_restartable_loop_operation__routine ()
313 database_build_inspect_dependencies "$origin"
315 _program_exec_and_record_completion__operation ()
318 message_section_title "Preliminary inspection of tools which have to be up-to-date"
320 [ "$PKGSYS_USE_PKGNG" = yes ] && echo 'ports-mgmt/pkg'
321 pkgsys_is_dialog4ports_used && echo 'ports-mgmt/dialog4ports'
322 [ -n "$MYPORTORIGIN" ] && echo "$MYPORTORIGIN"
323 } 2> /dev/null > ${DBDIR}/stage.loop_list/tools_to_inspect
325 program_exec_restartable_loop_operation tools_to_inspect
326 database_build_post_inspect_dependencies
329 program_exec_and_record_completion PRELIMINARY_INSPECTION_OF_TOOLS
331 # Upgrade of ports-mgmt/pkg if new
332 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
333 if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
334 -a $opt_dry_run = no -a $opt_suppress_pkgtools_upadte = no \
335 -a "$PKGSYS_USE_PKGNG" = yes ]
337 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
338 _program_exec_and_record_completion__operation ()
340 local _MSG_CURRENT_STAGE_general
341 _MSG_CURRENT_STAGE_general="pkgng upgrade"
342 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
343 message_section_title "Upgrade of ports-mgmt/pkg if new"
344 touch "${DBDIR}/target_all"
345 reinstall_exec ports-mgmt/pkg
346 reinstall_restore_conflicts
347 rm -f "${DBDIR}/target_all"
350 program_exec_and_record_completion UPGRADE_PKGNG
353 # Upgrade of ports-mgmt/dialog4ports if new
354 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
355 if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
356 -a $opt_dry_run = no -a $opt_suppress_pkgtools_upadte = no ] \
357 && pkgsys_is_dialog4ports_used
359 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
360 _program_exec_and_record_completion__operation ()
362 local _MSG_CURRENT_STAGE_general
363 _MSG_CURRENT_STAGE_general="pkgng dialog4ports"
364 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
365 message_section_title "Upgrade of dialog4ports if new"
366 touch "${DBDIR}/target_all"
367 reinstall_exec ports-mgmt/dialog4ports
368 reinstall_restore_conflicts
369 rm -f "${DBDIR}/target_all"
372 program_exec_and_record_completion UPGRADE_DIALOG4PORTS
375 # Upgrade of this utility if new
376 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
377 if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
378 -a $opt_dry_run = no -a $opt_suppress_self_upadte = no \
379 -a -n "$MYPORTORIGIN" ]
381 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
382 _program_exec_and_record_completion__operation ()
384 local _MSG_CURRENT_STAGE_general
385 _MSG_CURRENT_STAGE_general="pkgng upgrade"
386 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
387 message_section_title "Upgrade of this utility if new"
388 touch "${DBDIR}/target_all"
389 reinstall_exec "$MYPORTORIGIN"
390 reinstall_restore_conflicts
391 rm -f "${DBDIR}/target_all"
394 program_exec_and_record_completion UPGRADE_SELF
397 if [ "x`${APPNAME} -aV 2> /dev/null`" != "x$MYVERSION" ]
399 message_echo "INFO: ${APPNAME} is upgraded and the temporary database needs refresh."
400 database_build_clean_for_self_upgrade || :
401 message_echo "INFO: Restarting with the new version."
403 temp_trap_for_invoking_new_version
404 . "${TMPDIR}"/restart_command.sh
409 # ==================================================
410 # ================== PREPARATION ===================
411 # ==================================================
413 # ============= Correspondence to configuration changes =============
415 # Patch to the temporary database by reflecting changes in configuration
416 PROGRAM_DEPENDS='PARSE_CONF'
417 _program_exec_and_record_completion__operation ()
419 local tmpfile_diff tmpfile_old tmpfile_new key
420 [ -d "${DBDIR}/conf.prev" ] || return 0
421 message_section_title "Patch to the temporary database by reflecting changes in configuration"
422 tmpfile_old=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::old
423 tmpfile_new=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::new
424 tmpfile_updated_ports=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::updated_ports
425 if fileedit_manipulate_old_new_lines \
426 "${DBDIR}/conf.prev/setenv.sh" "${DBDIR}/conf/setenv.sh" "$tmpfile_old" "$tmpfile_new"
428 if grep -q -e ^LOCALBASE= -e ^LINUXBASE= -e ^PORTSDIR= "$tmpfile_old" "$tmpfile_new"
430 message_echo "ERROR: Migration of the temporary database is unavailable because LOCALBASE, LINUXBASE or PORTSDIR was changed." >&2
431 message_echo " ${APPNAME} clean" >&2
432 message_echo "must be executed in advance." >&2
436 cut -s -d '|' -f 1,2 "${DBDIR}/conf.prev/MOVED_ALT.parsed" | tr '|' '\t' > ${TMPDIR}/MOVED_ALT.old
437 cut -s -d '|' -f 1,2 "${DBDIR}/conf/MOVED_ALT.parsed" | tr '|' '\t' > ${TMPDIR}/MOVED_ALT.new
438 if fileedit_manipulate_old_new_lines \
439 "${TMPDIR}/MOVED_ALT.old" "${TMPDIR}/MOVED_ALT.new" "$tmpfile_old" "$tmpfile_new"
441 cat "$tmpfile_old" "$tmpfile_new" | while read from to
444 [ -n "$to" ] && echo "$to"
446 fi > $tmpfile_updated_ports
447 if fileedit_manipulate_old_new_lines \
448 "${DBDIR}/conf.prev/REPLACE.csv" "${DBDIR}/conf/REPLACE.csv" "$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 [ `wc -l < $tmpfile_updated_ports` -gt 0 ] && rm -f "${DBDIR}/REPLACE.complete_sed_pattern"
457 [ -d "${DBDIR}/conf/each_port" ] && find "${DBDIR}/conf/each_port" -depth 2 \
460 origin=`str_dirpath_to_origin "$dbpath"`
461 dbpath_prev=${DBDIR}/conf.prev/each_port/$origin
462 diff -r "$dbpath_prev" "$dbpath" > /dev/null 2>&1 && continue
464 done >> $tmpfile_updated_ports
465 [ -d "${DBDIR}/conf.prev/each_port" ] && find "${DBDIR}/conf.prev/each_port" -depth 2 \
466 | while read dbpath_prev
468 origin=`str_dirpath_to_origin "$dbpath_prev"`
469 dbpath=${DBDIR}/conf/each_port/$origin
470 [ -d "$dbpath" ] && continue
472 done >> $tmpfile_updated_ports
473 if [ `wc -l < $tmpfile_updated_ports` -gt 0 ]
475 sort -u "$tmpfile_updated_ports" | while read origin
477 database_build_patch_reconf "$origin"
479 program_deregister_stage_complete INSPECT_ALL_DEPENDENCIES
483 program_exec_and_record_completion PATCH_TO_TMPDB_REFLECT_CONF_CHANGES
485 # ============= Database construction =============
487 # Execute command operations which must be done before building the temporary database
488 command_exec_before_building_tempdb "$@"
490 # Meta process for redo
492 _program_exec_and_record_completion__operation ()
494 rm -f "${DBDIR}/new_success_in_current_run"
495 [ "x$COMMAND_MODE" = xredo ] || return 0
496 message_echo "[REDO mode]"
499 program_exec_and_record_completion REDO_INIT
501 # Determine specified targets
503 _program_exec_and_record_completion__operation ()
505 local tag level dbsuffix
506 message_section_title "Determining specified targets"
507 cat "${DBDIR}/stage.loop_list/target_itself.specified" \
508 "${DBDIR}/stage.loop_list/target_dependents.specified" \
509 "${DBDIR}/stage.loop_list/target_requirements.specified" \
510 "${DBDIR}/need.list" \
511 "${DBDIR}/targets_specified_so_far" 2> /dev/null \
512 | sort -u > ${DBDIR}/targets_specified_so_far.tmp
513 mv "${DBDIR}/targets_specified_so_far.tmp" "${DBDIR}/targets_specified_so_far"
514 rm -f "${DBDIR}/stage.loop_list/target_itself.specified" \
515 "${DBDIR}/stage.loop_list/target_dependents.specified" \
516 "${DBDIR}/stage.loop_list/target_requirements.specified"
517 if [ -n "$opt_target_itself$opt_target_dependents$opt_target_requirements" ]
519 options_select_new_ports_if_duplicated O \
520 "${DBDIR}/stage.loop_list/target_itself.specified" "$opt_target_itself"
521 options_select_new_ports_if_duplicated t \
522 "${DBDIR}/stage.loop_list/target_dependents.specified" "$opt_target_dependents"
523 options_select_new_ports_if_duplicated T \
524 "${DBDIR}/stage.loop_list/target_requirements.specified" "$opt_target_requirements"
525 if [ `cat "${DBDIR}/stage.loop_list/target_itself.specified" \
526 "${DBDIR}/stage.loop_list/target_dependents.specified" \
527 "${DBDIR}/stage.loop_list/target_requirements.specified" | wc -l` -eq 0 ]
529 message_echo "ERROR: No matching port for target globs." >&2
533 cat "${DBDIR}/stage.loop_list/target_itself.specified" \
534 "${DBDIR}/stage.loop_list/target_dependents.specified" \
535 "${DBDIR}/stage.loop_list/target_requirements.specified" \
536 | sort -u > ${TMPDIR}/DETERMINE_SPECIFIED_TARGETS.reset
537 cat "${TMPDIR}/DETERMINE_SPECIFIED_TARGETS.reset" "${DBDIR}/need.list" 2> /dev/null \
538 | sort -u > ${DBDIR}/need.list.tmp
539 mv "${DBDIR}/need.list.tmp" "${DBDIR}/need.list"
540 sort -u "${DBDIR}/need.list" "${DBDIR}/targets_specified_so_far" \
541 > ${DBDIR}/targets_specified_so_far.tmp
542 mv "${DBDIR}/targets_specified_so_far.tmp" "${DBDIR}/targets_specified_so_far"
543 for tag in all run build none
545 for level in direct full
549 cat "${TMPDIR}/DETERMINE_SPECIFIED_TARGETS.reset"
550 cat "${DBDIR}/stage.loop_list/target_dependents.specified" | while read origin
552 nodedir=${DBDIR}/requires/$origin
553 cat "$nodedir/dependents.$dbsuffix" 2> /dev/null
555 cat "${DBDIR}/stage.loop_list/target_requirements.specified" | while read origin
557 nodedir=${DBDIR}/requires/$origin
558 cat "$nodedir/requirements.$dbsuffix" 2> /dev/null
560 } | sort -u | while read origin
562 fileedit_rm_a_line "$origin" "${DBDIR}/success.$dbsuffix.list"
563 fileedit_rm_a_line "$origin" "${DBDIR}/todo_after_requirements_succeed.$dbsuffix.list"
564 rm -f "${DBDIR}/requires/$origin/succeeded_once"
571 program_exec_and_record_completion DETERMINE_SPECIFIED_TARGETS
573 # Show specified targets
574 if [ -n "$opt_target_itself$opt_target_dependents$opt_target_requirements" -a $opt_batch_mode = no ]
576 message_echo "INFO: (Re/de-)installation will be carried out only for the targets:"
578 if [ `wc -l < ${DBDIR}/stage.loop_list/target_itself.specified` -gt 0 ]
580 message_echo "[Targets only]"
581 echo "----------------------------------------"
582 cat "${DBDIR}/stage.loop_list/target_itself.specified"
583 echo "----------------------------------------"
586 if [ `wc -l < ${DBDIR}/stage.loop_list/target_dependents.specified` -gt 0 ]
588 message_echo "[Targets with their `options_get_dependency_msgterm` dependents]"
589 echo "----------------------------------------"
590 cat "${DBDIR}/stage.loop_list/target_dependents.specified"
591 echo "----------------------------------------"
594 if [ `wc -l < ${DBDIR}/stage.loop_list/target_requirements.specified` -gt 0 ]
596 message_echo "[Targets with their `options_get_dependency_msgterm` requirements]"
597 echo "----------------------------------------"
598 cat "${DBDIR}/stage.loop_list/target_requirements.specified"
599 echo "----------------------------------------"
604 # Determine all target ports
605 PROGRAM_DEPENDS='DETERMINE_SPECIFIED_TARGETS COLLECT_ALL_INSTALLED_PACKAGES'
606 _program_exec_and_record_completion__operation ()
608 message_section_title "Determining all target ports"
610 if [ $opt_only_target_scope = no ]
612 cat "${DBDIR}/installed_ports" 2> /dev/null || :
614 cat "${DBDIR}/stage.loop_list/target_itself.specified" || :
615 cat "${DBDIR}/stage.loop_list/target_dependents.specified" || :
616 cat "${DBDIR}/stage.loop_list/target_requirements.specified" || :
617 cat "${DBDIR}/targets_specified_so_far" || :
618 } 2> /dev/null | sort -u > "${DBDIR}/stage.loop_list/ports_to_inspect"
621 program_exec_and_record_completion DETERMINE_ALL_TARGET_PORTS
623 # Inspection of all dependencies
624 PROGRAM_DEPENDS='PARSE_CONF DETERMINE_ALL_TARGET_PORTS'
625 _program_exec_restartable_loop_operation__routine ()
629 database_build_inspect_dependencies "$origin"
631 _program_exec_and_record_completion__operation ()
634 message_section_title "Inspecting dependencies of the all installed packages"
635 [ $opt_only_target_scope = no -a -n "$opt_target_itself$opt_target_dependents$opt_target_requirements" ] && \
636 message_echo "INFO: Ports which seem irrelevant to the targets are also inspected in order to get complete information."
638 program_exec_restartable_loop_operation ports_to_inspect
639 database_build_post_inspect_dependencies
642 program_exec_and_record_completion INSPECT_ALL_DEPENDENCIES
644 # Convert dependency-lists to actual ones
645 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES'
646 _program_exec_restartable_loop_operation__routine ()
648 local origin table dbtag level tag target
650 for table in dependents requirements
652 for dbtag in requires obsolete
654 for level in direct full
656 for tag in all run build
658 target=${DBDIR}/$dbtag/$origin/${table}.${tag}.${level}
659 [ -e "$target.src" ] || continue
660 sed -E -f "${DBDIR}/REPLACE.complete_sed_pattern" "$target.src" \
661 | grep -v '^$' | sort -u > $target.tmp
662 [ -e "$target" ] && ! diff "$target.tmp" "$target" > /dev/null \
663 && echo "$origin" >> ${DBDIR}/update_dependencies
664 mv "$target.tmp" "$target"
670 _program_exec_and_record_completion__operation ()
672 message_section_title "Conversion of dependency-lists to actual ones"
673 program_exec_restartable_loop_operation convert_dependency_lists
674 sort -u "${DBDIR}/update_dependencies" > ${DBDIR}/update_dependencies.tmp
675 mv "${DBDIR}/update_dependencies.tmp" "${DBDIR}/update_dependencies"
676 str_escape_regexp_filter < ${DBDIR}/update_dependencies \
677 | sed 's/^/^/; s/$/$/' > ${DBDIR}/update_dependencies.grep_pattern
678 for tag in all run build
680 ( cd "${DBDIR}/requires" && \
681 find . -depth 3 -type f -name requirements.${tag}.full | sed 's|^./||;s|/[^/]*$||' ) \
682 | grep -v -E -f "${DBDIR}/update_dependencies.grep_pattern" \
683 | str_escape_regexp_filter | sed 's/^/^/; s/$/$/' \
684 > ${TMPDIR}/convert_requirements_list:full_complete.grep_pattern || :
685 ( cd "${DBDIR}/requires" && \
686 find . -depth 3 -type f -name requirements.${tag}.direct | sed 's|^./||;s|/[^/]*$||' ) \
687 | grep -v -E -f "${TMPDIR}/convert_requirements_list:full_complete.grep_pattern" \
688 > ${DBDIR}/stage.loop_list/complete_${tag}time_reqlists || :
690 for inspected_level_tmp in direct node
692 cat "${DBDIR}/ports.inspected.${inspected_level_tmp}.list" || :
693 done 2> /dev/null | sort -u > ${DBDIR}/stage.loop_list/trim_dependency_lists_rm_uninspected_ports
694 find "${DBDIR}/requires" -depth 2 -type d > ${DBDIR}/stage.loop_list/inspect_dependent
695 [ -e "${DBDIR}/dependents_files" ] && \
696 mv "${DBDIR}/dependents_files" "${DBDIR}/dependents_files.prev"
697 rm -f "${DBDIR}/stage.loop_list/make_dependents_lists_unique.tmp" "${DBDIR}/dependents_files.tmp"
700 program_exec_and_record_completion CONVERT_REQUIREMENTS_LIST
702 # Completion of recursive requirement lists
703 for _REQUIREMENT_LISTS_tag in all run build
705 PROGRAM_DEPENDS='CONVERT_REQUIREMENTS_LIST'
706 _program_exec_restartable_loop_operation__routine ()
708 local tag dbpath origin
709 tag=${_REQUIREMENT_LISTS_tag}
711 origin=`str_dirpath_to_origin "$dbpath"`
712 database_build_get_complete_recursive_dependency requirements.${tag} "$origin" > /dev/null
714 _program_exec_and_record_completion__operation ()
717 tag=${_REQUIREMENT_LISTS_tag}
718 message_section_title "Completion of ${tag}-time requirement lists"
719 program_exec_restartable_loop_operation complete_${tag}time_reqlists
722 program_exec_and_record_completion REQUIREMENT_LISTS:${_REQUIREMENT_LISTS_tag}
725 # Trim dependency lists by removing uninspected ports
726 if [ $opt_only_target_scope = yes ]
728 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES CONVERT_REQUIREMENTS_LIST'
729 _program_exec_restartable_loop_operation__routine ()
731 local dbpath tag level srcdb
733 for tag in all run build
735 for level in direct full
737 srcdb=requirements.${tag}.${level}
738 [ -e "$dbpath/$srcdb" ] || continue
739 grep -E -f "${DBDIR}/inspected_ports.grep_pattern" "$dbpath/$srcdb" \
740 > $dbpath/$srcdb.tmp || :
741 mv "$dbpath/$srcdb.tmp" "$dbpath/$srcdb"
745 _program_exec_and_record_completion__operation ()
747 message_section_title "Trimming dependency lists by removing uninspected ports"
748 program_exec_restartable_loop_operation trim_dependency_lists_rm_uninspected_ports
751 program_exec_and_record_completion TRIM_DEPENDENCY_LISTS_RM_UNINSPECTED_PORTS
754 # Inspection of dependents
755 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES CONVERT_REQUIREMENTS_LIST TRIM_DEPENDENCY_LISTS_RM_UNINSPECTED_PORTS'
756 _program_exec_restartable_loop_operation__routine ()
758 local dbpath origin tag level srcdb dstdb
760 origin=`str_dirpath_to_origin "$dbpath"`
761 for tag in all run build
763 for level in direct full
765 srcdb=requirements.${tag}.${level}
766 dstdb=dependents.${tag}.${level}
767 [ -e "$dbpath/$srcdb" ] || continue
768 while read origin_requirement
770 dstpath=${DBDIR}/requires/$origin_requirement
771 echo "$dstpath/$dstdb" >> ${DBDIR}/dependents_files.tmp
772 [ "$dstpath/$dstdb" -nt "$dbpath/$srcdb" ] && continue
773 [ -d "$dstpath" ] || mkdir -p "$dstpath"
774 echo "$origin" >> $dstpath/$dstdb.raw
775 echo "$dstpath/$dstdb" >> ${DBDIR}/stage.loop_list/make_dependents_lists_unique.tmp
776 done < $dbpath/$srcdb
780 _program_exec_and_record_completion__operation ()
782 local dbrequires_valesc
783 message_section_title "Inspection of dependents"
784 dbrequires_valesc=`str_escape_replaceval "${DBDIR}/requires/"`
785 program_exec_restartable_loop_operation inspect_dependent
786 sort -u "${DBDIR}/stage.loop_list/make_dependents_lists_unique.tmp" 2> /dev/null \
787 > ${DBDIR}/stage.loop_list/make_dependents_lists_unique || :
788 sort -u "${DBDIR}/dependents_files.tmp" 2> /dev/null > ${DBDIR}/dependents_files || :
789 [ -e "${DBDIR}/make_dependents_lists_unique.prev" ] && \
790 fileedit_manipulate_old_lines "${DBDIR}/dependents_files.prev" "${DBDIR}/dependents_files" \
794 program_exec_and_record_completion INSPECT_DEPENDENTS
796 # Remove duplicated lines in dependents lists
797 PROGRAM_DEPENDS='CONVERT_REQUIREMENTS_LIST INSPECT_DEPENDENTS'
798 _program_exec_restartable_loop_operation__routine ()
800 local dbpath tag level dstdb
802 cat "$dstdb" "$dstdb.raw" 2> /dev/null | sort -u > $dstdb.tmp
803 mv "$dstdb.tmp" "$dstdb"
806 _program_exec_and_record_completion__operation ()
808 local dbrequires_valesc
809 message_section_title "Removing duplicated items in dependents lists"
810 program_exec_restartable_loop_operation make_dependents_lists_unique
813 program_exec_and_record_completion MAKE_DEPENDENTS_LISTS_UNIQUE
815 # Preparation of target attribute information
816 for _TARGET_ATTR_INFO_table in requirements dependents itself
818 [ `cat "${DBDIR}/stage.loop_list/target_${_TARGET_ATTR_INFO_table}.replaced.specified" 2> /dev/null \
819 | wc -l` -gt 0 ] || continue
820 PROGRAM_DEPENDS='DETERMINE_SPECIFIED_TARGETS CONVERT_REQUIREMENTS_LIST'
821 _program_exec_restartable_loop_operation__routine ()
823 local origin dbtargets_valesc table
825 dbtargets_valesc=`str_escape_replaceval "${DBDIR}/targets/"`
826 table=${_TARGET_ATTR_INFO_table}
827 for database in requires initial
829 dbpath=${DBDIR}/$database/$origin
830 dstpath=${DBDIR}/targets/$origin
831 [ -d "$dstpath" ] || mkdir -p "$dstpath"
832 touch "$dstpath/target_itself"
833 echo "$origin" >> ${DBDIR}/all_targets.lst
834 [ $table = itself ] && continue
835 for tag in all run build
837 for level in direct full
839 srcdb=${table}.${tag}.${level}
840 dstdb=target_${database}_${table}.${tag}.${level}
841 [ -e "$dbpath/$srcdb" ] || continue
842 cat "$dbpath/$srcdb" >> ${DBDIR}/all_targets.lst
843 sed -E "s/^/$dbtargets_valesc/; s|$|/$dstdb|" "$dbpath/$srcdb" \
844 | fileedit_add_a_line_to_files_if_new "$origin"
849 _program_exec_and_record_completion__operation ()
852 table=${_TARGET_ATTR_INFO_table}
853 message_section_title "Preparation of target attribute information for dependency [$table]"
854 program_exec_restartable_loop_operation target_$table.replaced.specified
857 program_exec_and_record_completion TARGET_ATTR_INFO:${_TARGET_ATTR_INFO_table}
860 # Post-process after the preparation of target attribute information
861 PROGRAM_DEPENDS='MAKE_DEPENDENTS_LISTS_UNIQUE TARGET_ATTR_INFO:requirements TARGET_ATTR_INFO:dependents'
862 _program_exec_and_record_completion__operation ()
864 message_section_title "Post-process after the preparation of target attribute information"
865 sort -u "${DBDIR}/all_targets.lst" 2> /dev/null \
866 | grep -E -f "${DBDIR}/inspected_ports.grep_pattern" \
867 | sed -E -f "${DBDIR}/REPLACE.complete_sed_pattern" \
868 > ${DBDIR}/all_targets.lst.tmp || :
869 mv "${DBDIR}/all_targets.lst.tmp" "${DBDIR}/all_targets.lst"
870 find "${DBDIR}/targets" -depth 2 -type d > ${DBDIR}/stage.loop_list/build_complement_to_new_dependents_for_targets 2> /dev/null || :
872 cat "${DBDIR}/all_targets.lst" "${DBDIR}/need.with_replaced.list" 2> /dev/null || :
873 find "${DBDIR}/requires" -depth 3 -type f -name installed_version \
874 | sed -E 's|.*/([^/]+/[^/]+)/[^/]*$|\1|'
875 } | sort -u > ${DBDIR}/stage.loop_list/inspect_necessity
876 cp /dev/null "${DBDIR}/stage.loop_list/parse_target_attr_info"
877 find -E "${DBDIR}/requires" -depth 3 -type f -regex '.*/necessary_port\.(direct|full)$' -delete
880 program_exec_and_record_completion TARGET_ATTR_INFO_POSTPROCESS
882 # Build of data on complement to new dependents for target attribute information
883 PROGRAM_DEPENDS='TARGET_ATTR_INFO_POSTPROCESS TARGET_ATTR_INFO:requirements TARGET_ATTR_INFO:dependents CONVERT_REQUIREMENTS_LIST'
884 _program_exec_restartable_loop_operation__routine ()
888 origin=`str_dirpath_to_origin "$dbpath"`
889 database_build_complement_to_new_dependents_for_targets "$origin"
891 _program_exec_and_record_completion__operation ()
893 message_section_title "Build of data on complement to new dependents for target attribute information"
894 program_exec_restartable_loop_operation build_complement_to_new_dependents_for_targets
895 sort -u "${DBDIR}/stage.loop_list/parse_target_attr_info" > ${DBDIR}/stage.loop_list/parse_target_attr_info.tmp
896 mv "${DBDIR}/stage.loop_list/parse_target_attr_info.tmp" "${DBDIR}/stage.loop_list/parse_target_attr_info"
899 program_exec_and_record_completion COMPLEMENT_TO_NEW_DEPENDENTS_FOR_TARGET_ATTR_INFO
901 # Parse target attribute information
902 PROGRAM_DEPENDS='COMPLEMENT_TO_NEW_DEPENDENTS_FOR_TARGET_ATTR_INFO'
903 _program_exec_restartable_loop_operation__routine ()
907 origin=`str_dirpath_to_origin "$dbpath"`
908 database_build_target_attributes "$origin"
910 _program_exec_and_record_completion__operation ()
912 message_section_title "Parsing target attribute information"
913 program_exec_restartable_loop_operation parse_target_attr_info
916 program_exec_and_record_completion PARSE_TARGET_ATTR_INFO
918 # Inspection of necessity
919 PROGRAM_DEPENDS='TARGET_ATTR_INFO_POSTPROCESS REQUIREMENT_LISTS:run-time REQUIREMENT_LISTS:build-time INSPECT_ALL_DEPENDENCIES'
920 _program_exec_restartable_loop_operation__routine ()
924 for level in direct full
926 database_build_inspect_necessity_for_only_new_upgrade "$origin" "$level"
929 _program_exec_and_record_completion__operation ()
931 message_section_title "Inspection of necessity"
932 program_exec_restartable_loop_operation inspect_necessity
933 for level in direct full
935 find "${DBDIR}/requires" -depth 3 -type f -name "necessary_port.${level}" \
936 > ${DBDIR}/stage.loop_list/necessary_ports.${level}
940 program_exec_and_record_completion INSPECT_NECESSITY
942 # Inspection of necessary upgrades
943 for _NECESSARY_UPDATES_level in direct full
945 PROGRAM_DEPENDS='INSPECT_NECESSITY INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE'
946 _program_exec_restartable_loop_operation__routine ()
948 local markerpath level dbpath origin tag
950 level=${_NECESSARY_UPDATES_level}
951 dbpath=`dirname "$markerpath"`
952 origin=`str_dirpath_to_origin "$dbpath"`
953 database_query_does_a_port_need_update "$origin" || return 0
954 for tag in all run build none
956 touch "$dbpath/necessary_upgrade.$tag.${level}"
957 [ -e "$dbpath/dependents.$tag.${level}" ] || continue
958 while read origin_dependent
960 touch "${DBDIR}/requires/$origin_dependent/necessary_upgrade.$tag.${level}"
961 done < $dbpath/dependents.$tag.${level}
964 _program_exec_and_record_completion__operation ()
967 level=${_NECESSARY_UPDATES_level}
968 message_section_title "Inspection of necessary upgrades at the $level level"
969 program_exec_restartable_loop_operation necessary_ports.${level}
972 program_exec_and_record_completion NECESSARY_UPDATES:${_NECESSARY_UPDATES_level}
975 # Preparation for inspection of new leaf ports
976 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
978 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE PARSE_CONF'
979 _program_exec_and_record_completion__operation ()
981 message_section_title "Preparation for inspection of new leaf ports"
982 find "${DBDIR}/requires" -depth 3 -type f -name dependents.all.full \
983 | sed -E 's|.*/([^/]+/[^/]+)/[^/]+$|\1|' \
984 | sort -u > ${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:nonleaf_ports
985 sort -u "${DBDIR}/inspected_ports" > ${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:inspected_ports
986 fileedit_manipulate_new_lines \
987 "${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:nonleaf_ports" \
988 "${TMPDIR}/PREPARE_INSPECT_LEAF_PORTS:inspected_ports" \
989 | grep -v -E -f "${DBDIR}/conf/HOLD_PORTS.grep_pattern" \
990 > ${DBDIR}/stage.loop_list/leaf_ports_primary_candidates || :
991 cp /dev/null "${DBDIR}/grep.leaf_ports.pattern"
992 cp /dev/null "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates"
995 program_exec_and_record_completion PREPARE_INSPECT_LEAF_PORTS
998 # Inspection of new primary leaf ports
999 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1001 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE PREPARE_INSPECT_LEAF_PORTS PARSE_CONF'
1002 _program_exec_restartable_loop_operation__routine ()
1004 local origin origin_ini origin_esc dbpath origin_req
1006 pkgsys_is_pkgtool "$origin" && return
1007 dbpath=${DBDIR}/requires/$origin
1008 origin_esc=`str_escape_regexp "$origin"`
1009 grep -q -E "^$origin_esc$" "${DBDIR}/need.with_replaced.list" 2> /dev/null && return
1010 if ! grep -q -E "^$origin_esc$" "${DBDIR}/noneed.list" 2> /dev/null
1012 if [ -e "$dbpath/initial_orig" ]
1014 origin_ini=`cat "$dbpath/initial_orig"`
1015 [ -e "${DBDIR}/initial/$origin_ini/installed_version" \
1016 -a `cat "${DBDIR}/initial/$origin_ini/dependents.all.full" 2> /dev/null | wc -l` -eq 0 ] \
1019 [ -e "${DBDIR}/initial/$origin/installed_version" \
1020 -a `cat "${DBDIR}/initial/$origin/dependents.all.full" 2> /dev/null | wc -l` -eq 0 ] \
1023 if [ -e "$dbpath/requirements.all.full" ]
1025 grep -v -E -f "${DBDIR}/conf/HOLD_PORTS.grep_pattern" "$dbpath/requirements.all.full" | \
1026 fileedit_add_lines_if_new "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates" || :
1028 fileedit_add_a_line_if_new "^$origin_esc$" "${DBDIR}/grep.leaf_ports.pattern"
1030 _program_exec_and_record_completion__operation ()
1032 local num_leaves num_leaves_prev
1033 message_section_title "Inspection of new primary leaf ports"
1034 program_exec_restartable_loop_operation leaf_ports_primary_candidates
1035 wc -l < ${DBDIR}/grep.leaf_ports.pattern | tr -d ' ' > ${DBDIR}/num_leaves
1036 cp /dev/null "${DBDIR}/leaf_ports_secondary_candidates.new_requirements"
1037 message_echo " `cat "${DBDIR}/num_leaves"` primary leaf port(s) is/are found."
1040 program_exec_and_record_completion INSPECT_PRIMARY_LEAF_PORTS
1043 # Inspection of requirements of new leaf ports
1044 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1046 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES MAKE_DEPENDENTS_LISTS_UNIQUE INSPECT_PRIMARY_LEAF_PORTS PARSE_CONF'
1047 _program_exec_and_record_completion__operation ()
1049 local num_leaves num_leaves_prev num_inspect num_leaves_new
1050 message_section_title "Inspection of requirements of new leaf ports"
1051 message_echo "INFO: The inspection proceeds by iterative method."
1054 _program_exec_restartable_loop_operation__routine ()
1056 local origin origin_esc dbpath
1058 pkgsys_is_pkgtool "$origin" && return
1059 dbpath=${DBDIR}/requires/$origin
1060 origin_esc=`str_escape_regexp "$origin"`
1061 grep -q -E "^$origin_esc$" "${DBDIR}/need.with_replaced.list" 2> /dev/null && return
1062 grep -E -v -f "${DBDIR}/grep.leaf_ports.pattern" \
1063 "$dbpath/dependents.all.full" > /dev/null 2>&1 && return
1064 cat "$dbpath/requirements.all.full" 2> /dev/null \
1065 >> ${DBDIR}/leaf_ports_secondary_candidates.new_requirements || :
1066 fileedit_add_a_line_if_new "^$origin_esc$" "${DBDIR}/grep.leaf_ports.pattern"
1068 program_exec_restartable_loop_operation leaf_ports_secondary_candidates
1069 num_leaves_prev=`cat "${DBDIR}/num_leaves"`
1070 num_leaves=`wc -l < ${DBDIR}/grep.leaf_ports.pattern | tr -d ' '`
1071 num_leaves_new=`echo $(($num_leaves-$num_leaves_prev)) | tr -d ' '`
1072 if [ $num_leaves_new -eq 0 ]
1074 message_echo " No more leaf port is found."
1075 message_echo " $num_leaves leaf port(s) is/are found in total."
1079 grep -E -v -f "${DBDIR}/grep.leaf_ports.pattern" \
1080 "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates" || :
1081 cat "${DBDIR}/leaf_ports_secondary_candidates.new_requirements" || :
1082 } | grep -v -E -f "${DBDIR}/conf/HOLD_PORTS.grep_pattern" | sort -u \
1083 > ${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates.tmp || :
1084 program_reset_loop_for_stage INSPECT_REQUIREMENTS_OF_LEAF_PORTS
1085 mv "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates.tmp" \
1086 "${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates"
1087 cp /dev/null "${DBDIR}/leaf_ports_secondary_candidates.new_requirements"
1088 echo "$num_leaves" > ${DBDIR}/num_leaves
1089 num_inspect=`wc -l < ${DBDIR}/stage.loop_list/leaf_ports_secondary_candidates | tr -d ' '`
1090 message_echo " $num_leaves_new leaf port(s) is/are newly found; continue for $num_inspect candidate(s)."
1092 grep -E -f "${DBDIR}/grep.leaf_ports.pattern" "${DBDIR}/inspected_ports" | sort -u > ${DBDIR}/leaf_ports || :
1095 program_exec_and_record_completion INSPECT_REQUIREMENTS_OF_LEAF_PORTS
1098 # Order the ports considering dependencies
1099 PROGRAM_DEPENDS='CONVERT_REQUIREMENTS_LIST'
1100 _program_exec_and_record_completion__operation ()
1102 message_section_title "Ordering dependencies"
1103 if ! database_build_order_ports_considering_dependencies
1105 message_echo "ERROR: Unsatisfied dependencies are remained:" >&2
1106 message_cat "${DBDIR}/unsatisfied.list"
1107 message_echo "*** Aborted by ${APPNAME}"
1108 message_echo "The ports tree seems broken. You might have caught an incomplete version."
1109 message_echo "You are encouraged to update the ports tree by portsnap(8)."
1110 message_echo "Then execute"
1111 message_echo " ${APPNAME} clean"
1112 message_echo "before restart."
1113 temp_terminate_process () { :; }
1118 program_exec_and_record_completion ORDER_ALL_DEPENDENCIES
1120 # Selection of removing leaf ports
1121 PROGRAM_DEPENDS='INSPECT_REQUIREMENTS_OF_LEAF_PORTS'
1122 _program_exec_and_record_completion__operation ()
1124 message_section_title "Selection of removing leaf ports"
1125 deinstall_select_leaf_ports_to_delete
1128 program_exec_and_record_completion SELECT_LEAF_PORTS
1130 # Selection of removing obsolete ports
1131 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES PARSE_CONF'
1132 _program_exec_and_record_completion__operation ()
1134 message_section_title "Selection of removing obsolete ports"
1135 deinstall_select_obsolete_ports_to_delete
1138 program_exec_and_record_completion SELECT_OBSOLETE_PORTS
1140 # Collection of leaf ports to delete
1141 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1143 PROGRAM_DEPENDS='SELECT_LEAF_PORTS'
1144 _program_exec_and_record_completion__operation ()
1146 local src src_unselected reqptn_file src_with_initial_origins
1147 message_section_title "Collecting leaf ports to delete"
1148 src=${DBDIR}/leaf_ports
1149 src_unselected=${DBDIR}/leaf_ports_to_delete.unselected
1150 src_with_initial_origins=${DBDIR}/leaf_ports.with_ini
1151 reqptn_file=${DBDIR}/leaf_ports.requirements_of_unselected.grep_pattern
1152 cat "$src_unselected" 2> /dev/null | while read origin
1154 cat "${DBDIR}/requires/$origin/requirements.all.full" || :
1155 done | sort -u | str_escape_regexp_filter \
1156 | sed 's/^/^/;s/$/$/' > $reqptn_file
1157 database_query_add_initial_origins < $src > $src_with_initial_origins
1160 program_exec_and_record_completion COLLECT_LEAF_PORTS_TO_DELETE
1163 # Collection of obsolete ports to delete
1164 PROGRAM_DEPENDS='SELECT_OBSOLETE_PORTS'
1165 _program_exec_and_record_completion__operation ()
1167 local src src_selected src_unselected dst_selected reqptn_file
1168 message_section_title "Collecting obsolete ports to delete"
1169 src=${DBDIR}/obsolete_ports.can_be_deleted
1170 src_selected=${DBDIR}/obsolete_ports_to_delete.selected
1171 src_unselected=${DBDIR}/obsolete_ports_to_delete.unselected
1172 dst_selected=${DBDIR}/obsolete_ports_to_delete
1173 reqptn_file=${DBDIR}/obsolete_ports.requirements_of_unselected.grep_pattern
1174 cat "$src_unselected" 2> /dev/null | while read origin
1176 cat "${DBDIR}/initial/$origin/requirements.run.full" || :
1177 cat "${DBDIR}/obsolete/$origin/requirements.run.full" || :
1178 done | sort -u | str_escape_regexp_filter \
1179 | sed 's/^/^/;s/$/$/' > $reqptn_file
1180 grep -v -E -f "$reqptn_file" "$src_selected" > $dst_selected 2> /dev/null || :
1183 program_exec_and_record_completion COLLECT_OBSOLETE_PORTS_TO_DELETE
1185 # Set up the list of ports to reinstall
1186 PROGRAM_DEPENDS='ORDER_ALL_DEPENDENCIES'
1187 _program_exec_and_record_completion__operation ()
1189 message_section_title "Setting up the list of ports to reinstall"
1190 cp -p "${DBDIR}/reinst_order.list" "${DBDIR}/stage.loop_list/reinst_todo"
1193 program_exec_and_record_completion SETUP_REINST_TODO
1195 # Composition of a list for deinstallation of obsolete and leaf packages
1196 PROGRAM_DEPENDS='COLLECT_LEAF_PORTS_TO_DELETE COLLECT_OBSOLETE_PORTS_TO_DELETE'
1197 _program_exec_and_record_completion__operation ()
1199 local reqptn_leaf reqptn_obs leaf_selected leaf_selected_src obs_selected obs_selected_src grepptn preserved
1200 message_section_title "Composing a list for deinstallation of obsolete and leaf packages"
1201 reqptn_leaf=${DBDIR}/leaf_ports.requirements_of_unselected.grep_pattern
1202 reqptn_obs=${DBDIR}/obsolete_ports.requirements_of_unselected.grep_pattern
1203 leaf_selected_src=${DBDIR}/leaf_ports_to_delete.selected
1204 leaf_selected=${DBDIR}/leaf_ports_to_delete
1205 obs_selected_src=${DBDIR}/obsolete_ports_to_delete.selected
1206 obs_selected=${DBDIR}/obsolete_ports_to_delete
1207 grepptn=${DBDIR}/ports_to_delete.grep_pattern
1208 grepptn_col1=${DBDIR}/ports_to_delete.grep_pattern_col1
1209 preserved=${TMPDIR}/LIST_DEINST_PKGS::preserved
1210 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ]
1212 cat "$reqptn_leaf" "$reqptn_obs" 2> /dev/null | sort -u > $grepptn
1213 grep -v -E -f "$grepptn" "$leaf_selected_src" 2> /dev/null \
1214 | database_query_add_initial_origins > $leaf_selected || :
1215 cat "$obs_selected" "$leaf_selected" 2> /dev/null || :
1217 rm -f "$leaf_selected"
1218 cat "$obs_selected" 2> /dev/null
1219 fi | sort -u > ${DBDIR}/stage.loop_list/ports_to_delete
1220 str_escape_regexp_filter < ${DBDIR}/stage.loop_list/ports_to_delete \
1221 | sed 's/^/^/;s/$/$/' > $grepptn
1222 str_escape_regexp_filter < ${DBDIR}/stage.loop_list/ports_to_delete \
1223 | sed 's/^/^/;s/$/[[:space:]]/' > $grepptn_col1
1224 cat "${DBDIR}/leaf_ports.with_ini" "${DBDIR}/obsolete_ports" 2> /dev/null \
1225 | grep -E -v -f "$grepptn" > ${DBDIR}/stage.loop_list/ports_to_restore || :
1226 if [ $opt_batch_mode = no ]
1228 if [ ! -e "${DBDIR}/inspected_ports_only_partially" ] && \
1229 grep -v -E -f "$grepptn" "$leaf_selected_src" > $preserved 2> /dev/null
1231 message_echo "INFO: Following leaf ports are preserved because required by other preserved leaf/obsolete ports."
1232 message_echo "----------------"
1235 pkgtag=`cat "${DBDIR}/required/$origin/pkgtag" 2> /dev/null` || :
1238 echo "$origin" "($pkgtag)"
1243 message_echo "----------------"
1245 if grep -v -E -f "$grepptn" "$obs_selected_src" > $preserved 2> /dev/null
1247 message_echo "INFO: Following obsolete ports are preserved because required by other obsolete ports."
1248 message_echo "----------------"
1251 pkgtag=`cat "${DBDIR}/initial/$origin/installed_version" 2> /dev/null` || :
1254 echo "$origin" "($pkgtag)"
1259 message_echo "----------------"
1264 program_exec_and_record_completion LIST_DEINST_PKGS
1266 # Collect entire distfiles list
1267 if [ $opt_suppress_inspect_entire_distinfo = yes ]
1270 _program_exec_and_record_completion__operation ()
1272 message_section_title "Collecting entire distfiles list"
1273 find "${PORTSDIR}" -depth 3 -name distinfo -exec cat {} \; \
1274 | grep '^SHA256 ' | sed -E 's/^SHA256 \(([^)]*)\).*/\1/' \
1275 | sort -u > ${DBDIR}/distfiles.entire.tmp
1276 mv "${DBDIR}/distfiles.entire.tmp" "${DBDIR}/distfiles.entire"
1279 program_exec_and_record_completion COLLECT_ALL_DISTFILES_LIST
1282 # Inspection of all required distfiles
1283 PROGRAM_DEPENDS='INSPECT_ALL_DEPENDENCIES COLLECT_ALL_DISTFILES_LIST'
1284 _program_exec_and_record_completion__operation ()
1286 message_section_title "Summarizing distfiles list"
1287 cat "${DBDIR}/distfiles.entire" "${DBDIR}/distfiles.inspected" 2> /dev/null \
1288 | sort -u | str_escape_regexp_filter \
1289 | sed 's|^|^\\.\\/|; s|$|$|' > ${DBDIR}/distfiles.grep.pattern || :
1292 program_exec_and_record_completion DISTFILES_LIST
1294 # Clean up of reinstallation status for preparation
1295 PROGRAM_DEPENDS='REDO_INIT INSPECT_ALL_DEPENDENCIES'
1296 _program_exec_and_record_completion__operation ()
1298 message_section_title "Cleaning up of reinstallation status for preparation"
1299 rm -rf "${DBDIR}/status.ports"
1302 program_exec_and_record_completion CLEANUP_REINST_STATUS
1304 # Completion of building the temporary database
1305 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'
1306 _program_exec_and_record_completion__operation ()
1308 message_section_title "The temporary database is completely built up"
1311 program_exec_and_record_completion PREPARATION
1314 # ==================================================
1315 # ====================== MAIN ======================
1316 # ==================================================
1318 # Execute command operations which must be done before actual (re/de)installation processes
1319 command_exec_before_actual_re_de_installation "$@"
1321 # Set termination messages
1322 temp_terminate_process ()
1324 temp_terminate_process_common
1327 # Reinstallation of remained ports
1328 PROGRAM_DEPENDS='PREPARATION'
1329 _program_exec_restartable_loop_operation__routine ()
1333 _program_exec_and_record_completion__operation ()
1335 local _MSG_CURRENT_STAGE_general
1336 _MSG_CURRENT_STAGE_general="reinstallation"
1337 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1338 message_section_title "Reinstallation"
1339 program_exec_restartable_loop_operation reinst_todo
1340 reinstall_restore_conflicts
1343 program_exec_and_record_completion REINSTALLATION
1345 # Restoration of obsolete and leaf packages which have been deinstalled but unselected from the deletion list again
1346 PROGRAM_DEPENDS='REDO_INIT LIST_DEINST_PKGS'
1347 _program_exec_restartable_loop_operation__routine ()
1349 deinstall_restore "$@"
1351 _program_exec_and_record_completion__operation ()
1353 local _MSG_CURRENT_STAGE_general
1354 _MSG_CURRENT_STAGE_general="restoration of unselected obsolete/leaf packages"
1355 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1356 message_section_title "Restoration of unselected obsolete/leaf packages"
1357 program_exec_restartable_loop_operation ports_to_restore
1358 temp_set_msg_current_stage
1361 program_exec_and_record_completion RESTORE_ONCE_DEINST_PKGS
1363 # Deinstallation of unused obsolete and leaf packages
1364 PROGRAM_DEPENDS='REDO_INIT LIST_DEINST_PKGS'
1365 _program_exec_restartable_loop_operation__routine ()
1369 _program_exec_and_record_completion__operation ()
1371 local _MSG_CURRENT_STAGE_general
1372 _MSG_CURRENT_STAGE_general="deinstallation of obsolete/leaf packages"
1373 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1374 message_section_title "Deinstallation of unused obsolete/leaf packages"
1375 program_exec_restartable_loop_operation ports_to_delete
1376 temp_set_msg_current_stage
1379 program_exec_and_record_completion DEINST_UNUSED_PKGS
1381 # Clean up obsolete or unused distfiles
1382 if [ $opt_only_target_scope = no -a $opt_keep_distfiles = no ]
1384 PROGRAM_DEPENDS='REINSTALLATION DISTFILES_LIST'
1385 _program_exec_and_record_completion__operation ()
1387 local tmp_distfiles_exists
1388 message_section_title "Cleaning up obsolete or unused distfiles"
1389 tmp_distfiles_exists=${TMPDIR}/CLEANUP_OBSLETE_DISTFILES::distfiles_exists
1390 [ $opt_dry_run = yes ] && message_echo "INFO: The operations are not actually carried out."
1391 ( set -e; cd "${DISTDIR}" && find . -type f ) \
1392 | sed 's|^\./||' | sort -u > $tmp_distfiles_exists
1393 fileedit_manipulate_old_lines "$tmp_distfiles_exists" "${DBDIR}/distfiles.entire" \
1394 | while read distfile
1396 if [ $opt_batch_mode = no ]
1400 [ $opt_dry_run = yes ] && continue
1401 rm -f "${DISTDIR}/$distfile"
1405 program_exec_and_record_completion CLEANUP_OBSLETE_DISTFILES
1408 # Rebuild of package database
1409 PROGRAM_DEPENDS='REINSTALLATION RESTORE_ONCE_DEINST_PKGS DEINST_UNUSED_PKGS'
1410 _program_exec_and_record_completion__operation ()
1412 which -s pkgdb || return 0
1413 message_section_title "Rebuilding package database for portupgrade"
1417 program_exec_and_record_completion REBUILD_PKGDB
1420 # ==================================================
1421 # ================ ENDING MESSAGES =================
1422 # ==================================================
1424 # Notice of failures
1425 exists_unresolved_ports=
1426 message_summary_dependents_of_failed_reinstallation failure || exists_unresolved_ports=y
1427 message_summary_dependents_of_failed_reinstallation redo || exists_unresolved_ports=y
1428 message_summary_dependents_of_failed_reinstallation conflict || exists_unresolved_ports=y
1429 [ -n "$exists_unresolved_ports" ] && message_summary_advice_on_manual_solution
1432 temp_terminate_process () { :; }
1434 if [ -z "$exists_unresolved_ports" ]
1436 message_section_title "COMPLETELY DONE"
1437 message_echo "- E N D -"
1439 message_warn_no_achieved_progress || :
1440 message_section_title "Done with some unresolved problems"
1441 message_echo "- To be continued -"