OSDN Git Service

Fixed bugs related to command_do_complete_necessary_upgrades_for_build ().
[portsreinstall/current.git] / lib / libmain.sh
1 #!/bin/sh -e
2 # ==============================================================================
3 # portsreinstall library script
4 # - Common functions of main programs -
5 # Copyright (C) 2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
8
9 # ============= Define the software version =============
10 main_set_version ()
11 {
12         MYVERSION=4.1.0
13         COMPATIBLE_VERSIONS='^(4\.[1]\.[0-9])$'
14         # Template for development versions
15         MYVERSION=4.0.0+toward_4.1.0_20180920012630
16         COMPATIBLE_VERSIONS='^(4\.[0-1]\.[0-9]]|4\.[0]\.[0]+(|\+toward_4\.[0-1]\.[0-9]+_[0-9]+))$'
17 }
18
19 # ============= Parse options, arguments and control parameters =============
20 # All arguments/options of the main program must be passed.
21 main_parse_options_arguments ()
22 {
23         # ============= Save arguments for upgraded restart =============
24         options_dump_args "$@" > ${TMPDIR}/restart_command.sh
25
26         # ============= Option check =============
27         options_set_default
28
29         options_getopts "$@" || :
30         if [ $OPTIONS_ERRNO -eq 2 ]
31         then
32                 message_echo "INTERNAL ERROR: In parsing options" >&2
33                 exit 1
34         fi
35         shift "${OPTIONS_SHIFT}"
36         
37         options_regularize
38         
39         # ============= Argument check for no-command options =============
40         if [ $opt_help_mode -ne 0 -o $opt_show_version = yes ]
41         then
42                 if [ $# -gt 0 ]
43                 then
44                         message_echo "SYNTAX ERROR: No command is allowed for showing Help or Version" >&2
45                         OPTIONS_ERRNO=1
46                 fi
47         fi
48         
49         # ============= Output usage if the case of a help mode or option/argument errors =============
50         if [ $OPTIONS_ERRNO -ne 0 ]
51         then
52                 exit $OPTIONS_ERRNO
53         elif [ $opt_help_mode -eq 1 ]
54         then
55                 usage_short
56                 exit
57         elif [ $opt_help_mode -eq 2 ]
58         then
59                 usage_long | less -r
60                 exit
61         fi
62         
63         # ============= Output version number =============
64         if [ $opt_show_version = yes ]
65         then
66                 message_version
67                 exit
68         fi
69
70         # ============= Set up variables for environment of ports and packages =============
71         conf_setup_ports_envs
72         conf_setup_packages_envs
73
74         # ============= Execute command operations before getting the temporary database ready =============
75         command_all_exec_before_db_creation "$@"
76
77         # ============= Creation of temporary database directory =============
78         database_maintain_create
79
80         # ============= Argument check for conventional runs =============
81         command_all_parse_args "$@"
82 }
83
84 # ============= Define the common termination messages =============
85 main_define_common_termination_messages ()
86 {
87         temp_terminate_process_common ()
88         {
89                 local errno msg_where
90                 errno=${1:-0}
91                 [ $opt_batch_mode = yes -o $errno -eq 0 ] && return
92                 msg_where=`temp_get_msg_current_stage`
93                 [ -n "$msg_where" ] && msg_where=" during $msg_where"
94                 message_echo
95                 if [ $errno -eq 130 ]
96                 then
97                         message_echo "INFO: Terminated at `message_timestamp`$msg_where."
98                         message_echo
99                         [ $opt_no_opening_message = yes ] && return
100                         message_echo " You can restart this process from the terminated point by"
101                 else
102                         message_echo "INFO: Aborted at `message_timestamp`$msg_where."
103                         message_echo
104                         [ $opt_no_opening_message = yes ] && return
105                         message_echo " You may restart this process from the aborted point by"
106                 fi
107                 message_echo "executing without options or arguments as:"
108                 if [ -n "$COMMAND_RESTART" ]
109                 then
110                         message_echo "  ${APPNAME} $COMMAND_RESTART"
111                 else
112                         message_echo "  ${APPNAME}"
113                 fi
114         }
115 }
116
117 # ============= Set termination messages for special commands =============
118 main_set_termination_messages_special ()
119 {
120 }
121
122 # ============= Option settings =============
123 main_option_settings ()
124 {
125         local optcomb_err
126         # Load, renew and save option values
127         optcomb_err=0
128         if [ \( "x$opt_reload_conf" = xyes -o "x$opt_reset_targets" = xyes \) -a "x$COMMAND_MODE" != xredo ]
129         then
130                 message_echo "ERROR: Options -L and -N are available only in the initial run of redo command." >&2
131                 message_echo >&2
132                 optcomb_err=1
133         fi
134         if [ "x$opt_batch_ports_only" = xyes -a "x$opt_interactive_ports_only" = xyes ]
135         then
136                 message_echo "ERROR: Options -A and -I conflict with each other." >&2
137                 message_echo >&2
138                 optcomb_err=1
139         fi
140         if [ -e "${DBDIR}/saved_options.sh" ]
141         then
142                 options_chk_invalid_optvals_renewal non_renewable || optcomb_err=$?
143                 {
144                         options_renewed_optvals M renewable_anytime || optcomb_err=$?
145                         options_renewed_optvals N renewable_in_redo_on_target || optcomb_err=$?
146                         options_renewed_optvals L renewable_in_redo_on_conf || optcomb_err=$?
147                 } > ${TMPDIR}/renewed_optvals.sh
148                 [ $optcomb_err -eq 0 ] || exit $optcomb_err
149                 . "${DBDIR}/saved_options.sh"
150                 . "${TMPDIR}/renewed_optvals.sh"
151         fi
152         misc_is_superuser_privilege && misc_get_all_vardefs | options_filter saved > ${DBDIR}/saved_options.sh
153         :
154 }
155
156 # ============= Save the previous configuration if exists =============
157 main_save_prev_conf ()
158 {
159         local PROGRAM_DEPENDS
160         PROGRAM_DEPENDS=''
161         _program_exec_and_record_completion__operation ()
162         {
163                 rm -rf "${DBDIR}/conf.prev"
164                 [ -d "${DBDIR}/conf" ] && \
165                         cp -Rp "${DBDIR}/conf" "${DBDIR}/conf.prev"
166                 :
167         }
168         program_exec_and_record_completion SAVE_PREV_CONF
169 }
170
171 # ============= Load the saved configuration =============
172 main_load_conf ()
173 {
174         . "${DBDIR}/conf/setenv.sh"
175 }
176
177 # ============= Get complete configuration variable definitions by importing pkgtools.conf(5) if available =============
178 main_get_complete_conf ()
179 {
180         local PROGRAM_DEPENDS
181         PROGRAM_DEPENDS='SAVE_PREV_CONF'
182         _program_exec_and_record_completion__operation ()
183         {
184                 local need_msg
185                 need_msg=no
186                 rm -rf "${DBDIR}/conf"
187                 mkdir -p "${DBDIR}/conf"
188                 [ "x`options_get_effective_opt_load_pkgtoolsconf 2> /dev/null`" != xno -a $opt_batch_mode = no ] \
189                         && need_msg=yes
190                 [ $need_msg = yes ] && \
191                         message_section_title "Parsing pkgtools.conf (by using installed portupgrade)"
192                 conf_get_complete_var_defs > ${DBDIR}/conf/complete_setup.sh
193                 [ $need_msg = yes ] &&  { message_echo "===> ok"; message_echo; }
194                 :
195         }
196         program_exec_and_record_completion GET_COMPLETE_CONF_VAR_DEF
197 }
198
199 # ============= Parse the configuration =============
200 main_parse_conf ()
201 {
202         local PROGRAM_DEPENDS
203         PROGRAM_DEPENDS='GET_COMPLETE_CONF_VAR_DEF'
204         _program_exec_and_record_completion__operation ()
205         {
206                 message_section_title "Parsing the configuration"
207                 conf_manipulate_available_var_defs
208                 . "${DBDIR}/conf/manipulated_defs.sh"
209                 # ALT_MOVED_*
210                 conf_build_effective_MOVED
211                 # Environmental variables
212                 conf_setup_effective_env > ${DBDIR}/conf/setenv.sh
213                 . "${DBDIR}/conf/setenv.sh"
214                 # HOLD_*
215                 conf_parse_vars_for_each_port_glob HOLD
216                 # TABOO_*
217                 conf_parse_vars_for_each_port_glob TABOO
218                 fileedit_combine_lists "${DBDIR}/conf/TABOO:PORTS.parsed" "${DBDIR}/taboo.list" \
219                         > ${DBDIR}/taboo.all.list
220                 # FREEZE_*
221                 conf_parse_vars_for_each_port_glob FREEZE
222                 fileedit_combine_lists "${DBDIR}/conf/FREEZE:PORTS.parsed" "${DBDIR}/freeze.list" \
223                         > ${DBDIR}/freeze.all.list
224                 # REBUILD_*
225                 conf_parse_vars_for_each_port_glob NOPKG
226                 # REPLACE_*
227                 conf_build_replacement_patterns_from_REPLACE
228                 # CONFLICT_*
229                 conf_parse_vars_for_each_port_glob_with_bound_val CONFLICT TARGET DEF
230                 # BUILDCONFLICT_*
231                 conf_parse_vars_for_each_port_glob_with_bound_val BUILDCONFLICT TARGET DEF
232                 # INSTCONFLICT_*
233                 conf_parse_vars_for_each_port_glob_with_bound_val INSTCONFLICT TARGET DEF
234                 # MARG_*
235                 conf_parse_vars_for_each_port_glob_with_bound_val MARG TARGET DEF
236                 # MENV_*
237                 conf_parse_vars_for_each_port_glob_with_bound_val MENV TARGET DEF
238                 # BEFOREBUILD_*
239                 conf_parse_vars_for_each_port_glob_with_bound_val BEFOREBUILD TARGET COMMAND
240                 # BEFOREDEINSTALL_*
241                 conf_parse_vars_for_each_port_glob_with_bound_val BEFOREDEINSTALL TARGET COMMAND
242                 # AFTERINSTALL_*
243                 conf_parse_vars_for_each_port_glob_with_bound_val AFTERINSTALL TARGET COMMAND
244                 message_echo
245         }
246         program_exec_and_record_completion PARSE_CONF
247 }
248
249 # ============= Set up parameters based on options, arguments, environment =============
250 main_setup_parameters ()
251 {
252         # ============= Termination messages during construction of the temporary database =============
253         main_define_common_termination_messages
254         temp_reset_termination_messages_common
255         main_set_termination_messages_special
256         
257         # ============= Opening title =============
258         
259         message_credit
260         command_all_chk_need_opening_notice && message_opening_notice
261         message_echo
262         
263         # ============= Execute command operations which do not need package tools =============
264         
265         command_all_exec_without_pkgtools "$@"
266         misc_is_superuser_privilege && database_maintain_mark_use
267         # ============= Definition of environment dependent functions =============
268         
269         pkgsys_def_pkgtools
270         
271         # ============= Option settings =============
272         
273         # Execute command operations which are not affected by saved option settings
274         command_all_exec_irrespective_of_saved_options "$@"
275         
276         # Load, renew and save option values
277         main_option_settings
278         
279         # Show option values
280         message_show_option_settings
281         
282         # Execute command operations which should be carried out just after completing the option settings
283         command_all_exec_just_after_option_settings "$@"
284
285         # ============= Command-specific pre-configuration =============
286         
287         # Execute command operations which must be done before the database construction
288         command_all_exec_command_specific_preconfiguration "$@"
289         
290         # ============= Configurations =============
291         
292         # Save the previous configuration if exists
293         main_save_prev_conf
294         
295         # Get complete configuration variable definitions by importing pkgtools.conf(5) if available
296         main_get_complete_conf
297         
298         # Parse the configuration
299         main_parse_conf
300         
301         # Load the saved configuration
302         main_load_conf
303         if [ $opt_just_save_options = yes ]
304         then
305                 message_echo "(Save-options-only mode)"
306                 exit
307         fi
308 }
309
310 # ============= Operation without packages management tools =============
311 main_operation_without_pkg_management_tools ()
312 {
313         # Execute command operations which should be done without upgrade of tools
314         command_all_exec_before_tools_upgrade "$@"
315
316         # Check whether the temporary database is newer than the ports tree and refresh if so
317         database_maintain_refresh_if_obsolete
318 }
319
320 # ============= Collect all installed packages =============
321 main_collect_all_installed_packages ()
322 {
323         local PROGRAM_DEPENDS
324         PROGRAM_DEPENDS=''
325         _program_exec_and_record_completion__operation ()
326         {
327                 local fossil_path
328                 message_section_title "Collecting all installed packages"
329                 mkdir -p "${DBDIR}/fossil_pkgs"
330                 fossil_path=${DBDIR}/fossil_pkgs/fossil_since_`pkgsys_get_timestamp_portstree`
331                 if [ ! -e "$fossil_path" ]
332                 then
333                         pkg_info_all_flavored_origins > $fossil_path.tmp
334                         mv "$fossil_path.tmp" "$fossil_path"
335                 fi
336                 if [ ! -e "${DBDIR}/installed_ports" ]
337                 then
338                         cp "$fossil_path" "${DBDIR}/installed_ports.tmp"
339                         mv "${DBDIR}/installed_ports.tmp" "${DBDIR}/installed_ports"
340                 fi
341                 pkgsys_gen_init_pkg_origin_table
342                 message_echo
343         }
344         program_exec_and_record_completion COLLECT_ALL_INSTALLED_PACKAGES
345 }
346
347 # ============= Determine all target ports of tools which have to be up-to-date =============
348 main_determine_all_target_ports_of_tools ()
349 {
350         local PROGRAM_DEPENDS
351         PROGRAM_DEPENDS=
352         _program_exec_and_record_completion__operation ()
353         {
354                 message_section_title "Determining all target ports of tools which have to be up-to-date"
355                 {
356                         [ "$PKGSYS_USE_PKGNG" = yes ] && pkgsys_portsmgmt_pkg
357                         pkgsys_is_dialog4ports_used && pkgsys_portsmgmt_dialog4ports
358                         [ -n "$MYPORTORIGIN" ] && echo "$MYPORTORIGIN"
359                 } 2> /dev/null > ${DBDIR}/stage.loop_list/tools_to_inspect
360                 cp "${DBDIR}/stage.loop_list/tools_to_inspect" "${DBDIR}/stage.loop_list/tools_to_inspect_initial"
361                 message_echo
362         }
363         program_exec_and_record_completion DETERMINE_ALL_TARGET_PORTS_OF_TOOLS
364 }
365
366 # ============= Preliminary inspection of initially installed tools which have to be up-to-date =============
367 # (No need depend on PARSE_CONF because INSPECT_ALL_DEPENDENCIES will take the task.)
368 main_preliminary_inspection_of_initial_tools ()
369 {
370         local PROGRAM_DEPENDS
371         PROGRAM_DEPENDS='DETERMINE_ALL_TARGET_PORTS_OF_TOOLS'
372         _program_exec_restartable_loop_operation__routine ()
373         {
374                 local origin
375                 origin=$1
376                 database_build_setup_initial_node "$origin"
377         }
378         _program_exec_and_record_completion__operation ()
379         {
380                 local DEPTH_INDEX
381                 message_section_title "Preliminary inspection of initially installed tools which have to be up-to-date"
382                 program_exec_restartable_loop_operation tools_to_inspect_initial
383                 database_build_post_inspect_initial_dependencies
384                 message_echo
385         }
386         program_exec_and_record_completion PRELIMINARY_INSPECTION_OF_INITIAL_TOOLS
387 }
388
389 # ============= Preliminary inspection of tools which have to be up-to-date =============
390 # (No need depend on PARSE_CONF because INSPECT_ALL_DEPENDENCIES will take the task.)
391 main_preliminary_inspection_of_tools ()
392 {
393         local PROGRAM_DEPENDS
394         PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_INITIAL_TOOLS'
395         _program_exec_restartable_loop_operation__routine ()
396         {
397                 local origin
398                 origin=$1
399                 database_build_inspect_dependencies "$origin"
400         }
401         _program_exec_and_record_completion__operation ()
402         {
403                 local DEPTH_INDEX
404                 message_section_title "Preliminary inspection of tools which have to be up-to-date"
405                 cp /dev/null "${DBDIR}/done_required_ports_to_inspect"
406                 DEPTH_INDEX='--'
407                 program_exec_restartable_loop_operation tools_to_inspect
408                 database_build_post_inspect_dependencies
409                 message_echo
410         }
411         program_exec_and_record_completion PRELIMINARY_INSPECTION_OF_TOOLS
412 }
413
414 # ============= Upgrade of pkg(8) if new =============
415 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
416 main_upgrade_pkg8_if_new ()
417 {
418         local PROGRAM_DEPENDS
419         if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
420                 -a $opt_dry_run = no -a $opt_suppress_pkgtools_upadte = no \
421                 -a "$PKGSYS_USE_PKGNG" = yes ]
422         then
423                 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
424                 _program_exec_and_record_completion__operation ()
425                 {
426                         local _MSG_CURRENT_STAGE_general origin
427                         _MSG_CURRENT_STAGE_general="pkg(8) upgrade"
428                         origin=`pkgsys_portsmgmt_pkg`
429                         temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
430                         message_section_title "Upgrade of $origin if new"
431                         touch "${DBDIR}/target_all"
432                         cp "${DBDIR}/requires/$origin/requirements.all.direct.src" "${DBDIR}/requires/$origin/requirements.all.full"
433                         reinstall_exec "$origin"
434                         reinstall_restore_conflicts
435                         rm -f "${DBDIR}/target_all"
436                         temp_set_msg_current_stage
437                         message_echo
438                 }
439                 program_exec_and_record_completion UPGRADE_PKGNG
440         fi
441 }
442
443 # ============= Upgrade of dialog4ports(1) if new =============
444 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
445 main_upgrade_dialog4ports1_if_new ()
446 {
447         local PROGRAM_DEPENDS
448         if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
449                 -a $opt_dry_run = no -a $opt_suppress_pkgtools_upadte = no ] \
450                 && pkgsys_is_dialog4ports_used
451         then
452                 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
453                 _program_exec_and_record_completion__operation ()
454                 {
455                         local _MSG_CURRENT_STAGE_general origin
456                         _MSG_CURRENT_STAGE_general="dialog4ports(1) upgrade"
457                         origin=`pkgsys_portsmgmt_dialog4ports`
458                         temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
459                         message_section_title "Upgrade of $origin if new"
460                         touch "${DBDIR}/target_all"
461                         cp "${DBDIR}/requires/$origin/requirements.all.direct.src" "${DBDIR}/requires/$origin/requirements.all.full"
462                         reinstall_exec "$origin"
463                         reinstall_restore_conflicts
464                         rm -f "${DBDIR}/target_all"
465                         temp_set_msg_current_stage
466                         message_echo
467                 }
468                 program_exec_and_record_completion UPGRADE_DIALOG4PORTS
469         fi
470 }
471
472 # ============= Upgrade of this utility if new =============
473 # (No need depend on PARSE_CONF because REINSTALLATION will take the task.)
474 main_self_upgrade ()
475 {
476         local PROGRAM_DEPENDS
477         if [ \( "$COMMAND_MODE" = do -o "$COMMAND_MODE" = redo \) \
478                 -a $opt_dry_run = no -a $opt_suppress_self_upadte = no \
479                 -a -n "$MYPORTORIGIN" ]
480         then
481                 PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
482                 _program_exec_and_record_completion__operation ()
483                 {
484                         local _MSG_CURRENT_STAGE_general
485                         _MSG_CURRENT_STAGE_general="pkgng upgrade"
486                         temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
487                         message_section_title "Upgrade of this utility if new"
488                         touch "${DBDIR}/target_all"
489                         cp "${DBDIR}/requires/$MYPORTORIGIN/requirements.all.direct.src" "${DBDIR}/requires/$MYPORTORIGIN/requirements.all.full"
490                         reinstall_exec "$MYPORTORIGIN"
491                         reinstall_restore_conflicts
492                         rm -f "${DBDIR}/target_all"
493                         temp_set_msg_current_stage
494                         message_echo
495                 }
496                 program_exec_and_record_completion UPGRADE_SELF
497         fi
498         if [ "x`${APPNAME} -aV 2> /dev/null`" != "x$MYVERSION" ]
499         then
500                 message_echo "INFO: ${APPNAME} is upgraded and the temporary database needs refresh."
501                 database_maintain_clean_for_self_upgrade || :
502                 message_echo "INFO: Restarting with the new version."
503                 message_echo
504                 temp_trap_for_invoking_new_version
505                 . "${TMPDIR}"/restart_command.sh
506                 exit
507         fi
508 }
509
510 # ============= Overlay onto the temporary database by reflecting changes in configuration =============
511 main_reflect_conf_changes ()
512 {
513         local PROGRAM_DEPENDS
514         PROGRAM_DEPENDS='PARSE_CONF'
515         _program_exec_and_record_completion__operation ()
516         {
517                 local tmpfile_diff tmpfile_old tmpfile_new key
518                 [ -d "${DBDIR}/conf.prev" ] || return 0
519                 message_section_title "Overlay onto the temporary database by reflecting changes in configuration"
520                 tmpfile_old=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::old
521                 tmpfile_new=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::new
522                 tmpfile_updated_ports=${TMPDIR}/PATCH_TO_TMPDB_REFLECT_CONF_CHANGES::updated_ports
523                 if fileedit_manipulate_old_new_lines \
524                         "${DBDIR}/conf.prev/setenv.sh" "${DBDIR}/conf/setenv.sh" "$tmpfile_old" "$tmpfile_new"
525                 then
526                         if grep -q -e ^LOCALBASE= -e ^LINUXBASE= -e ^PORTSDIR= "$tmpfile_old" "$tmpfile_new"
527                         then
528                                 message_echo "ERROR: Migration of the temporary database is unavailable because LOCALBASE, LINUXBASE or PORTSDIR was changed." >&2
529                                 message_echo "        ${APPNAME} clean" >&2
530                                 message_echo "must be executed in advance." >&2
531                                 exit 1
532                         fi
533                 fi
534                 cut -s -d '|' -f 1,2 "${DBDIR}/conf.prev/MOVED_ALT.parsed" | tr '|' '\t' > ${TMPDIR}/MOVED_ALT.old
535                 cut -s -d '|' -f 1,2 "${DBDIR}/conf/MOVED_ALT.parsed" | tr '|' '\t' > ${TMPDIR}/MOVED_ALT.new
536                 if fileedit_manipulate_old_new_lines \
537                         "${TMPDIR}/MOVED_ALT.old" "${TMPDIR}/MOVED_ALT.new" "$tmpfile_old" "$tmpfile_new"
538                 then
539                         cat "$tmpfile_old" "$tmpfile_new" | while read from to
540                         do
541                                 echo "$from"
542                                 [ -n "$to" ] && echo "$to"
543                         done
544                 fi > $tmpfile_updated_ports
545                 sort -u "${DBDIR}/conf/NOPKG:PORTS.parsed" 2> /dev/null > ${TMPDIR}/NOPKG:PORTS.parsed.new || :
546                 sort -u "${DBDIR}/conf.prev/NOPKG:PORTS.parsed" 2> /dev/null > ${TMPDIR}/NOPKG:PORTS.parsed.old || :
547                 diff "${TMPDIR}/NOPKG:PORTS.parsed.old" "${TMPDIR}/NOPKG:PORTS.parsed.new" | sed -n 's/^[<>] //p' >> $tmpfile_updated_ports
548                 if fileedit_manipulate_old_new_lines \
549                         "${DBDIR}/conf.prev/REPLACE.csv" "${DBDIR}/conf/REPLACE.csv" "$tmpfile_old" "$tmpfile_new"
550                 then
551                         cat "$tmpfile_old" "$tmpfile_new" | while read from to
552                         do
553                                 echo "$from"
554                                 [ -n "$to" ] && echo "$to"
555                         done
556                 fi >> $tmpfile_updated_ports
557                 [ `wc -l < $tmpfile_updated_ports` -gt 0 ] && rm -f "${DBDIR}/REPLACE.complete_sed_pattern"
558                 [ -d "${DBDIR}/conf/each_port" ] && find "${DBDIR}/conf/each_port" -depth 2 \
559                         | while read dbpath
560                 do
561                         origin=`str_dirpath_to_origin "$dbpath"`
562                         dbpath_prev=${DBDIR}/conf.prev/each_port/$origin
563                         diff -r "$dbpath_prev" "$dbpath" > /dev/null 2>&1 && continue
564                         echo "$origin"
565                 done >> $tmpfile_updated_ports
566                 [ -d "${DBDIR}/conf.prev/each_port" ] && find "${DBDIR}/conf.prev/each_port" -depth 2 \
567                         | while read dbpath_prev
568                 do
569                         origin=`str_dirpath_to_origin "$dbpath_prev"`
570                         dbpath=${DBDIR}/conf/each_port/$origin
571                         [ -d "$dbpath" ] && continue
572                         echo "$origin"
573                 done >> $tmpfile_updated_ports
574                 if [ `wc -l < $tmpfile_updated_ports` -gt 0 ]
575                 then
576                         sort -u "$tmpfile_updated_ports" | while read origin
577                         do
578                                 message_echo "Reset for $origin"
579                                 database_build_patch_reconf "$origin"
580                         done
581                         program_deregister_stage_complete PREPARE_FOR_INSPECT_ALL_DEPENDENCIES
582                         program_deregister_stage_complete ALL_COMPLETE
583                 fi
584                 message_echo
585         }
586         program_exec_and_record_completion PATCH_TO_TMPDB_REFLECT_CONF_CHANGES
587 }