2 # ==============================================================================
3 # portsreinstall library script
4 # - Reinstallation processes -
5 # Copyright (C) 2013-2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
9 # ============= Variables =============
10 # The following variables are available only within reinstall_exec and functions invoked by it.
11 REINSTALL_PKGTAG= # Tag indicating version changes by reinstallation of the current port
12 REINSTALL_ORIGPKGTAG= # Tag indicating the flavored port origin and version changes by reinstallation of the current port
13 REINSTALL_CURRENTPKG= # Currently installed package name of the current port
14 REINSTALL_ORIGIN= # Flavored port origin of the current port
15 REINSTALL_DBNODE_DIR= # Path of the "requires" section of the temporary database for the current port
16 REINSTALL_IS_CURRENTPKG_LATEST= # Currently installed package name of the current port
17 REINSTALL_DBSUFFIX= # Database suffix for the evaluation method of dependencies
19 # ============= Skip reinstallation by showing messages =============
24 message_echo "($message)"
25 message_target_relations "$REINSTALL_ORIGIN"
26 fileedit_rm_a_line "$REINSTALL_ORIGIN" "${DBDIR}/stage.loop_list/reinst_todo.remain"
29 # ============= Check whether a package is forbidden due to conflict =============
30 reinstall_quick_chk_forbidden_conflicts ()
32 local pkg pkg_regexp_esc
34 pkg_regexp_esc=`str_escape_regexp "$pkg"`
35 grep -qE "^$pkg_regexp_esc:" "${DBDIR}/forbidden_conflicts" 2> /dev/null
38 # ============= Check whether a package is forbidden due to conflict =============
39 reinstall_chk_forbidden_conflicts ()
41 local pkg tmp_forbidden pkg_regexp_esc
43 tmp_forbidden=${TMPDIR}/reinstall_chk_forbidden_conflicts:forbidden
44 pkg_regexp_esc=`str_escape_regexp "$pkg"`
45 grep -E "^$pkg_regexp_esc:" "${DBDIR}/forbidden_conflicts" > $tmp_forbidden 2> /dev/null || return
46 pkg_info_e `cut -d : -f 3 "$tmp_forbidden"`
49 # ============= Restore a package if it is temporarily deinstalled =============
50 reinstall_restore_if_temporarily_deinstalled ()
53 [ $opt_fetch_only = no -a $opt_dry_run = no ] || return 0
54 [ -n "$REINSTALL_CURRENTPKG" ] && return
55 tmp_list=${TMPDIR}/reinstall_restore_if_temporarily_deinstalled
57 [ -e "$REINSTALL_FROMNODE_DIR/backedup_pkgfile" ] || return 0
60 [ -z "$backup_pkg" -o ! -e "$backup_pkg" ] && continue
61 echo "$backup_pkg" >> $tmp_list.backedup
62 pkg=`pkgsys_pkgarc_to_pkgname "$backup_pkg"`
63 if reinstall_chk_forbidden_conflicts "$pkg"
65 echo "$backup_pkg" >> $tmp_list.avoid
67 echo "$backup_pkg" >> $tmp_list.restore
69 done < $REINSTALL_FROMNODE_DIR/backedup_pkgfile
70 [ -e "$tmp_list.backedup" ] || return 0
71 message_echo "INFO: This port is temporarily deinstalled, so restoration will be attempted."
72 if [ -e "$tmp_list.avoid" ]
74 message_echo "INFO: The following backup(s) are avoided because of conflict with installed packages."
75 message_cat < $tmp_list.avoid
77 if [ -e "$tmp_list.restore" ]
79 message_echo "INFO: The following backup(s) will be restored."
80 message_cat < $tmp_list.restore
83 pkg_add_fF "$backup_pkg" || echo "$backup_pkg" >> $tmp_list.failed
84 done < $tmp_list.restore
85 if [ -e "$tmp_list.failed" ]
87 message_echo "WARNING: Failed to restore the following backup, but continuing anyway." >&2
88 message_cat < $tmp_list.failed
94 # ============= Skip reinstallation by showing messages if a flavored origin is in a list =============
95 reinstall_skip_if_in_a_list ()
97 local message list mode
101 grep -q -Fx "$REINSTALL_ORIGIN" "${DBDIR}/$list" 2> /dev/null || return
102 [ "x$mode" = xrestore ] && reinstall_restore_if_temporarily_deinstalled
103 reinstall_skip "$message" || :
106 # ============= Get the make arguments =============
107 reinstall_setup_make_args ()
112 for key in LOCALBASE LINUXBASE PORT_DBDIR PORTSDIR DISTDIR PACKAGES PKGREPOSITORY
114 eval echo $key=\$$key
116 [ $opt_avoid_vulner = yes ] || echo 'DISABLE_VULNERABILITIES=yes'
121 [ $opt_batch_ports_only = yes ] && echo 'BATCH=yes'
122 [ $opt_interactive_ports_only = yes ] && echo 'INTERACTIVE=yes'
125 if [ $opt_apply_default_config = yes ]
127 pkgsys_is_dialog4ports_used && echo 'NO_DIALOG=yes'
129 dbdir=$REINSTALL_DBNODE_DIR
130 [ -d "$dbdir" ] || dbdir=${DBDIR}/conf/each_port/$origin
131 cat "$dbdir/MARG.conf" 2> /dev/null || :
132 flavor=`pkgsys_get_flavor_from_origin "$REINSTALL_ORIGIN"`
133 [ -z "$flavor" ] || echo "FLAVOR=$flavor"
137 # ============= Get the make environment variables =============
138 reinstall_setup_make_envs ()
140 database_build_setup_make_envs "$REINSTALL_ORIGIN"
143 # ============= Common comand to execute make command =============
144 _reinstall_make_common ()
146 local mode port_path MAKE_ARGS MAKE_ENVS
149 MAKE_ARGS=`reinstall_setup_make_args $mode`
150 MAKE_ENVS=`reinstall_setup_make_envs`
151 port_path=`pkgsys_get_portpath_from_origin "$REINSTALL_ORIGIN"`
152 fs_fix_unionfs_image_if_hidden "$port_path"
153 env $MAKE_ENVS make -C "$port_path" "$@" $MAKE_ARGS
156 # ============= Execute make command without restricting for BATCH or INTERACTIVE ports =============
157 reinstall_make_anymode ()
159 _reinstall_make_common anymode "$@"
162 # ============= Execute make command =============
165 _reinstall_make_common '' "$@"
168 # ============= Error process during reinstallation =============
171 local position msg port_path
174 database_build_update_pkgname "$REINSTALL_ORIGIN" > /dev/null
175 message_echo "ERROR: In $position." >&2
176 message_echo "The port/package in concern is $REINSTALL_ORIGPKGTAG." >&2
177 [ -n "$msg" ] && message_echo "($msg)" >&2
179 port_path=`pkgsys_get_portpath_from_origin "$REINSTALL_ORIGIN"`
180 { fs_fix_unionfs_image_if_hidden "$port_path" \
181 && pkgsys_chk_ports_tree_implementation; } || exit 1
182 mkdir -p "${DBDIR}/notes/$REINSTALL_ORIGIN"
183 echo "$position" > ${DBDIR}/notes/$REINSTALL_ORIGIN/note_failtre
184 database_record_failure "$REINSTALL_ORIGIN" noclean
185 fileedit_rm_a_line "$REINSTALL_ORIGIN" "${DBDIR}/stage.loop_list/reinst_todo.remain"
186 message_report_failure_for_a_port "$REINSTALL_ORIGIN"
189 # ============= Check the latest stage for a port =============
190 reinstall_chk_stage ()
194 [ -e "${DBDIR}/status.ports/$REINSTALL_ORIGIN/$stagetag" ]
197 # ============= Check completion of a stage for a port =============
198 reinstall_chk_stage_complete ()
202 [ -e "${DBDIR}/status.ports/$REINSTALL_ORIGIN/complete/$stagetag" ]
205 # ============= Register the latest stage for a port =============
206 reinstall_register_stage ()
208 local stagetag parentdir
210 parentdir=${DBDIR}/status.ports/$REINSTALL_ORIGIN
211 mkdir -p "$parentdir"
212 touch "$parentdir/$stagetag"
215 # ============= Register completion of a stage for a port =============
216 reinstall_register_stage_complete ()
218 local stagetag parentdir
220 parentdir=${DBDIR}/status.ports/$REINSTALL_ORIGIN/complete
221 mkdir -p "$parentdir"
222 touch "$parentdir/$stagetag"
225 # ============= Deregister the latest stage for a port =============
226 reinstall_deregister_stage ()
230 rm -f "${DBDIR}/status.ports/$REINSTALL_ORIGIN/$stagetag"
233 # ============= Deregister completion of a stage for a port =============
234 reinstall_deregister_stage_complete ()
238 rm -f "${DBDIR}/status.ports/$REINSTALL_ORIGIN/complete/$stagetag"
241 # ============= Back up and delete conflict =============
242 # Package names of conflict are given via stdin.
243 reinstall_backup_and_delete_conflicts ()
245 local pkg origin origin_regexp_esc backup_pkgdir backup_pkg
246 message_echo "INFO: Deinstalling conflicting packages for $REINSTALL_ORIGPKGTAG."
249 origin=`pkg_info_flavored_origin "$pkg"`
250 message_echo "INFO: Backing up and deleting a conflict, $origin ($pkg)."
251 origin_regexp_esc=`str_escape_regexp "$origin"`
252 if [ -d "${DBDIR}/requires/$origin" ]
254 backup_pkgdir=${DBDIR}/backup_packages
256 backup_pkgdir=${PKGREPOSITORY}
258 mkdir -p "$backup_pkgdir"
259 if backup_pkg=`pkgsys_get_backup_pkg "$origin"`
261 message_echo "INFO: backup package already exists as $backup_pkg"
262 elif ! backup_pkg=`pkgsys_create_backup_pkg "$pkg" "$backup_pkgdir"`
264 message_echo "WARNING: Failed to create the backup package, the conflict is kept installed." >&2
267 grep -v -E "^${origin_regexp_esc}[[:space:]]" "${DBDIR}/deleted_conflicts" \
268 > ${DBDIR}/deleted_conflicts.tmp 2> /dev/null || :
269 printf '%s\t%s\n' "$origin" "$pkg" >> ${DBDIR}/deleted_conflicts.tmp
270 mv "${DBDIR}/deleted_conflicts.tmp" "${DBDIR}/deleted_conflicts"
271 pkg_delete_f "$pkg" || \
273 message_echo "WARNING: Failed to deinstall $pkg by $PKGSYS_CMD_PKG_DELETE." >&2
276 cat "${DBDIR}/deleted_conflicts" 2> /dev/null | sort -u > ${DBDIR}/deleted_conflicts.tmp
277 mv "${DBDIR}/deleted_conflicts.tmp" "${DBDIR}/deleted_conflicts"
280 # ============= Back up and delete remaining actual install conflict (for installation by package) =============
281 reinstall_backup_and_delete_remaining_install_conflicts__by_pkg ()
283 local pkg tmp_conflicts
285 tmp_conflicts=${TMPDIR}/reinstall_backup_and_delete_remaining_install_conflicts__by_pkg
286 message_echo "(Checking installation conflict...)"
287 pkgsys_get_conflicting_installed_pkgs install "$REINSTALL_ORIGIN" > $tmp_conflicts.pkgs || :
288 while read pkg_conflict
290 fileedit_add_a_line_if_new "$pkg_conflict:$REINSTALL_ORIGIN:$pkg" \
291 "${DBDIR}/forbidden_conflicts"
292 done < $tmp_conflicts.pkgs
293 reinstall_backup_and_delete_conflicts < $tmp_conflicts.pkgs
296 # ============= Back up and delete remaining actual install conflict (for installation by port) =============
297 reinstall_backup_and_delete_remaining_install_conflicts ()
299 local stagedir tmp_conflicts db_conflict
300 tmp_conflicts=${TMPDIR}/reinstall_backup_and_delete_remaining_install_conflicts
301 db_conflict=$REINSTALL_DBNODE_DIR/possible_additional_conflist.csv
302 message_echo "(Checking installation conflict...)"
303 rm -rf "$db_conflict.tmp" "$tmp_conflicts".*
304 stagedir=`database_query_get_makevar_val "$REINSTALL_ORIGIN" STAGEDIR`
305 pkgsys_get_conflicting_installed_pkgs install "$REINSTALL_ORIGIN" > $tmp_conflicts.pkgs || :
309 ) | sed 's|^\.||' | while read filepath
311 [ ! -e "$filepath" ] && continue
312 pkg=`pkg_which "$filepath" || :`
313 [ -z "$pkg" ] && continue
314 grep -qFx "$pkg" "$tmp_conflicts.pkgs" && continue
315 origin=`pkg_info_flavored_origin "$pkg"`
316 [ x"$origin" = x"$REINSTALL_ORIGIN" ] && continue
317 printf '%s\t%s\n' "$pkg" "$filepath" >> $db_conflict.tmp
319 if [ -e "$db_conflict.tmp" ]
321 while read pkg filepath
323 message_echo "INFO: Possible additional conflict with $pkg: $filepath"
324 done < $db_conflict.tmp
325 message_echo "INFO: The possible additional conflict packages will be escaped just in case."
326 mv "$db_conflict.tmp" "$db_conflict"
327 cut -f 1 "$db_conflict" >> $tmp_conflicts.pkgs
329 rm -f "$db_conflict.tmp" "$db_conflict"
331 while read pkg_conflict
333 fileedit_add_a_line_if_new "$pkg_conflict:$REINSTALL_ORIGIN:$REINSTALL_NEWPKGNAME" \
334 "${DBDIR}/forbidden_conflicts"
335 done < $tmp_conflicts.pkgs
336 reinstall_backup_and_delete_conflicts < $tmp_conflicts.pkgs
339 # ============= Remove needless possible additional conflict =============
340 # Use after installation of the target port and before restoration of its possible additional conflict.
341 reinstall_remove_needless_possible_conflict ()
343 local db_conflict db_forbidden suffix tmp_db
344 db_conflict=$REINSTALL_DBNODE_DIR/possible_additional_conflist.csv
345 db_forbidden=${DBDIR}/forbidden_conflicts
346 tmp_db=${TMPDIR}/reinstall_remove_needless_possible_conflict:db
347 [ -e "$db_conflict" ] || return 0
348 if [ ! -e "$db_forbidden" ]
350 rm -fr "$db_conflict"
353 rm -rf "$db_conflict".*
354 touch $db_conflict.tmp
355 while read pkg filepath
357 if which -s "$filepath"
359 echo printf '%s\t%s\n' "$pkg" "$filepath" >> $db_conflict.tmp
360 message_echo "WARNING: Unregistered additional conflict with $pkg: $filepath" >&2
362 message_echo "INFO: The above notice of the possible additional conflict was needless: $pkg: $filepath"
365 cut -f 1 "$db_conflict" | sort -u > $tmp_db.conflict_pkg.old
366 cut -f 1 "$db_conflict.tmp" | sort -u > $tmp_db.conflict_pkg.new
367 suffix=`echo ":$REINSTALL_ORIGIN:$REINSTALL_NEWPKGNAME" | str_escape_replaceval_filter`
368 grep -vFx -f "$tmp_db.conflict_pkg.new" "$tmp_db.conflict_pkg.old" | \
369 sed -E "s/$/$suffix/" > $tmp_db.conflict_pkg.needless.filter
370 grep -vFx -f "$tmp_db.conflict_pkg.needless.filter" "$db_forbidden" > $db_forbidden.tmp || :
371 mv "$db_forbidden.tmp" "$db_forbidden"
372 mv "$db_conflict.tmp" "$db_conflict"
373 [ `wc -l < $db_conflict` -gt 0 ] || rm "$db_conflict"
376 # ============= Restoration of backed up conflict =============
377 reinstall_restore_conflicts ()
379 local origin_current tmpsrc
381 [ $opt_fetch_only = no -a $opt_dry_run = no ] || return 0
382 [ -e "${DBDIR}/deleted_conflicts" ] || return 0
383 tmpsrc=${TMPDIR}/reinstall_restore_conflicts::deleted_conflicts
384 cp "${DBDIR}/deleted_conflicts" "$tmpsrc"
385 while read origin pkg
387 pkg_regexp_esc=`str_escape_regexp "$pkg"`
388 origins_init=`database_query_initial_orgins "$origin" | grep -vFx "$origin" || :`
389 origin_replace=`echo "$origin" \
390 | sed -E -f "${DBDIR}/REPLACE.complete_sed_pattern"`
391 [ "x$origin_replace" = "x$origin" ] && origin_replace=
392 is_to_dereg_from_list=no
393 if [ -n "$origin_current" -a "x$origin" = "x$origin_current" ] || \
394 pkg_info_e "$pkg" || pkgsys_exists_from_orig "$origin"
396 is_to_dereg_from_list=yes
398 for origin_orig in $origins_init $origin_replace
400 if [ -n "$origin_orig" ] && pkgsys_exists_from_orig "$origin_orig"
402 is_to_dereg_from_list=yes
407 if pkgsys_chk_conflict_by_a_pkg install "$REINSTALL_ORIGIN" "$pkg"
409 fileedit_add_a_line_if_new "$pkg:$REINSTALL_ORIGIN:$REINSTALL_NEWPKGNAME" "${DBDIR}/forbidden_conflicts"
411 elif reinstall_chk_forbidden_conflicts "$pkg"
417 if [ $is_skipped = yes ]
419 message_echo "INFO: Restoration of a conflict, $origin ($pkg), is avoided because it conflicts with installed packages."
421 if [ $is_to_dereg_from_list = yes ]
425 for origin_trial in $origin $origins_init $origin_replace
427 pkg_trial=`pkgsys_get_installed_pkg_from_origin "$origin_trial" || :`
428 [ -z "$pkg_trial" ] && continue
429 pkg_current="$pkg_current, $pkg_trial"
430 origin_current="$origin_current, $origin_trial"
432 pkg_current=`expr "$pkg_current" : ', \(.*\)'` || pkg_current=none
433 origin_current=`expr "$origin_current" : ', \(.*\)'` || origin_current=none
436 [ "x$pkg_current" = "x$pkg" ] || pkgname_msg="$pkg => $pkg_current"
437 [ "x$origin_current" = "x$origin" ] || origin_msg="$origin => $origin_current"
438 if [ $is_skipped = yes ]
440 message_echo "WARNING: Conflicting package is installed: $origin_msg ($pkgname_msg)"
442 message_echo "INFO: $origin_msg ($pkgname_msg) is already restored."
443 grep -v -E "[[:space:]]$pkg_regexp_esc$" "${DBDIR}/deleted_conflicts" \
444 > ${DBDIR}/deleted_conflicts.tmp || :
445 mv "${DBDIR}/deleted_conflicts.tmp" "${DBDIR}/deleted_conflicts"
449 [ $is_skipped = yes ] && continue
450 if grep -q -Fx -e "$origin" -e "$origin_replace" "${DBDIR}/taboo.all.list" 2> /dev/null
452 message_echo "INFO: Restoration of a conflict, $origin ($pkg), is avoided because it is taboo."
455 message_echo "INFO: Restoring a former conflict, $origin ($pkg)."
456 if ! backup_pkg=`pkgsys_get_backup_pkg "$origin"`
458 message_echo "WARNING: No backup exists, gave up." >&2
461 if pkg_add_fF "$backup_pkg"
463 grep -v -E "[[:space:]]$pkg_regexp_esc$" "${DBDIR}/deleted_conflicts" \
464 > ${DBDIR}/deleted_conflicts.tmp || :
465 mv "${DBDIR}/deleted_conflicts.tmp" "${DBDIR}/deleted_conflicts"
467 message_echo "WARNING: Failed to restore. Note that your system may experience troubles by this error." >&2
472 # ============= Check whether the all non-looped requirements are installed =============
473 reinstall_are_requirements_ready ()
475 [ -e "$REINSTALL_DBNODE_DIR/requirements.all.direct" ] || return 0
478 pkgsys_exists_from_orig "$origin" || return 1
479 done < $REINSTALL_DBNODE_DIR/requirements.all.direct
482 # ============= Get the all non-looped requirements ready for a port by restarting them if deinstalled =============
483 reinstall_chk_and_restore_requirements ()
485 local tmp_restore tmp_isfailed
486 tmp_restore=${TMPDIR}/reinstall_setup_requirements:restore
487 tmp_isfailed=${TMPDIR}/reinstall_setup_requirements:isfailed
488 cp /dev/null "$tmp_restore"
489 rm -f "$tmp_isfailed"
490 cat "$REINSTALL_DBNODE_DIR/requirements.all.direct" 2> /dev/null \
493 pkgsys_exists_from_orig "$origin" && continue
494 if grep -q -Fx "$origin" "${DBDIR}/taboo.all.list" 2> /dev/null
496 message_echo "INFO: Restoration of a requirement [$origin] is avoided because it is set taboo."
497 touch "$tmp_isfailed"
500 origins_init=`database_query_initial_orgins "$origin" | grep -vFx "$origin" || :`
501 origin_replace=`echo "$origin" \
502 | sed -E -f "${DBDIR}/REPLACE.complete_sed_pattern"`
503 [ "x$origin_replace" = "x$origin" ] && origin_replace=
505 for origin_orig in $origins_init $origin_replace
507 [ "x$origin_orig" = "x$origin" ] && continue
508 if pkgsys_exists_from_orig "$origin_orig"
513 if grep -q -Fx "$origin_orig" "${DBDIR}/taboo.all.list" 2> /dev/null
515 message_echo "INFO: Restoration of a requirement [$origin_orig] is avoided because it is set taboo."
516 touch "$tmp_isfailed"
521 [ $is_installed = yes ] && continue
522 [ $is_installed = taboo ] && break
523 for origin_orig in $origin $origins_init $origin_replace
525 pkgarc=`pkgsys_get_backup_pkg "$origin_orig"` && break
529 if grep -q -Fx "$origin" "${DBDIR}/failed.list" 2> /dev/null
531 touch "$tmp_isfailed"
536 printf '%s\t%s\n' "$origin_orig" "$pkgarc" >> $tmp_restore
538 [ -e "$tmp_isfailed" ] && return 1
539 while read origin pkgarc
541 pkg=`pkgsys_pkgarc_to_pkgname "$pkgarc"`
542 pkg_regexp_esc=`str_escape_regexp "$pkg"`
543 if reinstall_chk_forbidden_conflicts "$pkg"
545 message_echo "INFO: Restoration of a requirement [$origin ($pkg)] is avoided because it conflicts with installed packages."
548 message_echo "INFO: Restoring a backed-up requirement [$origin ($pkg)]."
549 if pkg_add_fF "$pkgarc"
551 grep -v -E "[[:space:]]$pkg_regexp_esc$" "${DBDIR}/deleted_conflicts" \
552 > ${DBDIR}/deleted_conflicts.tmp 2> /dev/null || :
553 mv "${DBDIR}/deleted_conflicts.tmp" "${DBDIR}/deleted_conflicts"
555 message_echo "WARNING: Failed to restore by the backed-up package." >&2
562 # ============= Back-up of the currently installed package =============
563 reinstall_pkg_backup ()
566 reinstall_chk_stage_complete PKG_BACKUP && return
567 pkg=`echo "$REINSTALL_CURRENTPKG" | tr ' ' '\n' | grep -v '^$' | tail -n 1`
570 message_echo "-- (Creating temporary backup package for $REINSTALL_ORIGPKGTAG)"
571 if backup_pkg=`pkgsys_create_backup_pkg "$pkg" "${DBDIR}/backup_packages"`
573 fileedit_add_a_line_if_new "$pkg" "$REINSTALL_FROMNODE_DIR/backedup_version"
574 fileedit_add_a_line_if_new "$backup_pkg" "$REINSTALL_FROMNODE_DIR/backedup_pkgfile"
576 message_echo "WARNING: Failed to create the backup package, but ignored by hoping success." >&2
580 reinstall_register_stage_complete PKG_BACKUP
583 # ============= Deinstallation of the currently installed package =============
584 reinstall_deinstall ()
586 local tmp_installedpkg installed_pkgs
587 tmp_installedpkg=${TMPDIR}/reinstall_deinstall:installedpkg
588 pkgsys_get_installed_pkg_from_origin "$REINSTALL_ORIGIN" > $tmp_installedpkg
589 [ `wc -l < $tmp_installedpkg` -gt 0 ] || return 0
590 installed_pkgs=`tr '\n' ' ' < $tmp_installedpkg | sed 's/ *$//'`
591 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
593 message_echo "INFO: Deinstalling $installed_pkgs by $PKGSYS_CMD_PKG_DELETE."
594 pkg_delete_f $installed_pkgs || \
596 message_echo "WARNING: Failed to deinstall." >&2
601 message_echo "INFO: Deinstalling $pkg by $PKGSYS_CMD_PKG_DELETE." >&2
602 pkg_delete_f "$pkg" || \
604 message_echo "WARNING: Failed to deinstall." >&2
606 done < $tmp_installedpkg
608 message_echo "-- (Trying to deinstall by ports to make sure. This may cause negligible warnings.)"
609 reinstall_make deinstall || \
611 message_echo "WARNING: Failed to deinstall $REINSTALL_CURRENTPKG by make deinstall." >&2
615 # ============= Deinstallation of installed packages for old ports of the current one =============
616 reinstall_deinstall_old_ports ()
618 [ -e "$REINSTALL_FROMNODE_DIR/old_origs" ] || return 0
619 while read origin_old
621 pkgsys_get_installed_pkg_from_origin "$origin_old"
622 done < $REINSTALL_FROMNODE_DIR/old_origs | reinstall_backup_and_delete_conflicts
625 # ============= Recovery after failure of installation of the new package =============
626 reinstall_failed_install_recover ()
628 local backedup_version backup_pkg
629 reinstall_chk_stage_complete FAILED_INSTALL.RECOVER && return
630 message_echo "INFO: Trying to deinstall the failed/terminated installation (Ignore failures)."
631 if [ -n "$REINSTALL_CURRENTPKG" ]
633 pkg_delete_f "$REINSTALL_CURRENTPKG" || :
635 message_echo "INFO: Trying to deinstall by ports to make sure (This may cause negligible warnings)."
636 reinstall_make deinstall || :
637 backedup_version=`cat "$REINSTALL_FROMNODE_DIR/backedup_version" 2> /dev/null || :`
638 if grep -q -Fx "$REINSTALL_ORIGIN" "${DBDIR}/taboo.all.list" 2> /dev/null
640 message_echo "INFO: Restoration of the backup of $backedup_version is avoided because it is taboo."
641 elif [ -n "$backedup_version" ]
643 if reinstall_chk_forbidden_conflicts "$backedup_version"
645 message_echo "INFO: Restoration of the backup of $backedup_version, is avoided because it conflicts with installed packages."
647 message_echo "INFO: Restoring the backup of $backedup_version."
648 if [ -e "$REINSTALL_FROMNODE_DIR/backedup_pkgfile" ]
650 while read backup_pkg
652 if [ ! -e "$backup_pkg" ]
654 message_echo "WARNING: The backup file $backup_pkg doesn't exist, gave up." >&2
655 elif ! pkg_add_fF "$backup_pkg"
657 message_echo "WARNING: Failed to restore $backedup_version. Note that your system may experience troubles by this error." >&2
659 done < $REINSTALL_FROMNODE_DIR/backedup_pkgfile
661 message_echo "WARNING: No backup was saved, gave up." >&2
665 reinstall_register_stage_complete FAILED_INSTALL.RECOVER
668 # ============= Report an installation success to the all dependents =============
669 reinstall_tell_update_to_depandents ()
671 local tag level dbsuffix
672 pkgsys_is_pkgtool "$REINSTALL_ORIGIN" && return
673 reinstall_chk_stage_complete TELL_UPDATE_TO_DEPANDENTSL && return
674 for tag in all run build none
676 for level in full direct
678 dbsuffix=${tag}.${level}
680 cat "$REINSTALL_DBNODE_DIR/dependents.$dbsuffix" "$REINSTALL_DBNODE_DIR/dependents.$dbsuffix.orig"
681 [ -e "$REINSTALL_DBNODE_DIR/succeeded_once" ] || cat "$REINSTALL_DBNODE_DIR/ignored_dependents.$tag" "$REINSTALL_DBNODE_DIR/ignored_dependents.$tag.orig"
684 | while read origin_dependent
686 [ -d "${DBDIR}/requires/$origin_dependent" ] || continue
687 touch "${DBDIR}/requires/$origin_dependent/need_reinstall_due_to_upgraded_requirements.$dbsuffix"
688 fileedit_rm_a_line "$origin_dependent" \
689 "${DBDIR}/success.$dbsuffix.list"
690 fileedit_rm_a_line "$origin_dependent" \
691 "${DBDIR}/todo_after_requirements_succeed.$dbsuffix.list"
695 reinstall_register_stage_complete TELL_UPDATE_TO_DEPANDENTS
698 # ============= Closing operations after an installation success =============
699 reinstall_closing_operations_after_successful_install ()
702 reinstall_chk_stage_complete CLOSING_OPERATIONS_AFTER_SUCCESSFUL_INSTALL && return
703 database_build_update_pkgname "$REINSTALL_ORIGIN" > /dev/null
704 database_build_update_pkgtag "$REINSTALL_ORIGIN"
705 for tag in all run build none
707 for level in full direct
709 rm -f "$REINSTALL_DBNODE_DIR/need_reinstall_due_to_upgraded_requirements.${tag}.${level}"
710 [ -e "$REINSTALL_DBNODE_DIR/failed_requirements.${tag}.${level}" ] || continue
711 cp "$REINSTALL_DBNODE_DIR/failed_requirements.${tag}.${level}" \
712 "$REINSTALL_DBNODE_DIR/failed_requirements.${tag}.${level}.previous"
716 echo "$REINSTALL_ORIGIN"
717 database_query_initial_orgins "$REINSTALL_ORIGIN"
718 } | sort -u | while read initial_orig
720 initial_orig_regexp=`str_escape_regexp "$initial_orig"`
721 grep -E "^${initial_orig_regexp}[[:space:]]" "${DBDIR}/deleted_conflicts" 2> /dev/null \
722 | cut -f 2 | while read initial_pkg
724 pkg_regexp=`str_escape_regexp "$initial_pkg"`
725 grep -v -E "^${pkg_regexp}:" "${DBDIR}/forbidden_conflicts" \
726 > ${DBDIR}/forbidden_conflicts.tmp 2> /dev/null || :
727 mv "${DBDIR}/forbidden_conflicts.tmp" "${DBDIR}/forbidden_conflicts"
729 grep -v -E "^${initial_orig_regexp}[[:space:]]" "${DBDIR}/deleted_conflicts" \
730 > ${DBDIR}/deleted_conflicts.tmp 2> /dev/null || :
731 mv "${DBDIR}/deleted_conflicts.tmp" "${DBDIR}/deleted_conflicts"
732 pkgsys_delete_backup_pkg "$initial_orig"
734 rm -f "$REINSTALL_FROMNODE_DIR/backedup_pkgfile"
735 database_record_success "$REINSTALL_ORIGIN"
736 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
737 message_echo "===> Done successfully"
738 reinstall_register_stage_complete CLOSING_OPERATIONS_AFTER_SUCCESSFUL_INSTALL
741 # ============= Fetch missing distfiles of a port without sanity check =============
742 reinstall_fetch_missing_distfiles ()
744 local port_path tmp_fetch
745 port_path=`pkgsys_get_portpath_from_origin "$REINSTALL_ORIGIN"` || return
746 tmp_fetch=${TMPDIR}/reinstall_fetch_missing_distfiles:fetch.sh
747 tmp_missing_fetch=${TMPDIR}/reinstall_fetch_missing_distfiles:missing_fetch.sh
748 rm -rf "$tmp_fetch.pre"
749 reinstall_make_anymode fetch-list 2> /dev/null > $tmp_fetch.src || return
750 grep '^SHA256[[:space:]]' "$port_path/distinfo" | \
751 sed -E 's/^SHA256[[:space:]]+\(([^)]*)\).*/\1/' | \
752 while read relative_distfile_path
754 if ! { testhash=`( cd "${DISTDIR}" && sha256 "$relative_distfile_path" ) 2> /dev/null` && \
755 grep -qxF "$testhash" "$port_path/distinfo"; }
757 relative_distfile_path_ptn=`str_escape_regexp "|| echo \"$relative_distfile_path\" not fetched; }"`
758 if grep -E "$relative_distfile_path_ptn$" "$tmp_fetch.src"
760 subdir_distfile=`dirname "$relative_distfile_path"`
761 [ "x$subdir_distfile" = x. ] || echo "mkdir -p \"${DISTDIR}/$subdir_distfile\"" >> $tmp_fetch.pre
764 done | grep -v '^[[:space:]]*$' > $tmp_fetch.main || :
765 [ -e "$tmp_fetch.pre" ] && sort -u "$tmp_fetch.pre"
766 cat "$tmp_fetch.main"
769 # ============= Execute a command by recording the standard output and error output into a file in case of error =============
770 reinstall_execcmd_tee_errlog ()
774 tmp_err=${TMPDIR}/reinstall_execcmd_tee_errlog::error
778 } 2>&1 || touch "$tmp_err"; } | tee "$REINSTALL_DBNODE_DIR/error.log"
779 [ -e "$tmp_err" ] && return 1
780 rm -f "$REINSTALL_DBNODE_DIR/error.log"
784 # ============= Execute a command to output to stdout by recording the error output into a file in case of error =============
785 reinstall_execcmd_getstdout_errlog ()
789 if $func 2> $REINSTALL_DBNODE_DIR/error.log
791 rm -f "$REINSTALL_DBNODE_DIR/error.log"
794 cat "$REINSTALL_DBNODE_DIR/error.log" >&2
798 # ============= Check whether any required package is missing or too old for build by ports =============
799 # Return status 0 for no problem about missing ports
800 reinstall_chk_missing_requirement ()
802 local tmp_filter tmp_miising
803 tmp_filter=${TMPDIR}/reinstall_chk_missing_requirement::requirements.all_but_test.unflavored
804 tmp_miising=${TMPDIR}/reinstall_chk_missing_requirement::missing_requirements
805 message_echo "Checking whether any required package is missing or too old..."
806 sed 's/@.*//' "$REINSTALL_DBNODE_DIR/requirements.all.full" > $tmp_filter || :
807 if reinstall_make missing 2> /dev/null | grep -Fx -f "$tmp_filter" > $tmp_miising
809 message_echo "Found missing/too old requirements:"
810 message_cat < $tmp_miising
812 echo "Found missing/too old requirements:"
814 } > "$REINSTALL_DBNODE_DIR/error.log"
815 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
816 reinstall_restore_if_temporarily_deinstalled
817 reinstall_errproc 'check of missing/too old packages'
818 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
823 # ============= Check whether the current port is marked to skip =============
824 # Return status 1 for port to skip
825 reinstall_exec_chk_skip ()
828 local currentorigin_is_all currentorigin_is_target currentorigin_is_requires_requirements
829 local currentorigin_is_initial_requirements currentorigin_is_requires_dependents
830 local currentorigin_is_initial_dependents currentorigin_is_requires_requirements_complement
831 local currentorigin_is_relevant
832 database_query_get_target_attributes currentorigin "$REINSTALL_ORIGIN"
833 if [ -z "${currentorigin_is_all}" -a -z "${currentorigin_is_relevant}" ]
835 reinstall_skip 'Skipped because being irrelevant'
838 reinstall_skip_if_in_a_list 'Skipped because being a leaf port' leaf_ports_to_delete && return 1
839 rm -f "$REINSTALL_DBNODE_DIR/this_is_skipped_build_requirement"
840 if expr "$REINSTALL_CURRENTPKG" : '.* .*' > /dev/null
842 message_echo "WARNING: Multiple packages are registered for this port. Reinstallation is needed to fix it." >&2
843 elif grep -q -Fx "$REINSTALL_ORIGIN" "${DBDIR}/damaged_package" 2> /dev/null
845 message_echo "WARNING: Installed files have invalid checksums for this port. Reinstallation is needed to fix it." >&2
847 if [ -e "${DBDIR}/target_all" ]
849 if [ $REINSTALL_IS_CURRENTPKG_LATEST = yes ]
851 reinstall_restore_if_temporarily_deinstalled
852 reinstall_skip 'Skipped because being already latest' "$REINSTALL_ORIGIN"
855 elif [ ! -e "$REINSTALL_DBNODE_DIR/conf_updated" ]
857 if [ -e "$REINSTALL_DBNODE_DIR/installed_by_pkg" ] && database_query_is_default_conf "$REINSTALL_ORIGIN" quiet
859 reinstall_restore_if_temporarily_deinstalled
860 reinstall_skip 'Skipped because already upgraded with a prebuilt package'
863 reinstall_skip_if_in_a_list 'Skipped because the reinstallation has been already completed' \
864 "success.${REINSTALL_DBSUFFIX}.list" restore && return 1
865 if [ $opt_skip_unchanged = yes ]
867 if [ ! -e "$REINSTALL_DBNODE_DIR/necessary_upgrade.${REINSTALL_DBSUFFIX}" ]
869 reinstall_restore_if_temporarily_deinstalled
870 if [ -e "$REINSTALL_FROMNODE_DIR/installed_version" ]
872 reinstall_skip 'Skipped because being already latest as well as the all requirements'
874 touch "$REINSTALL_DBNODE_DIR/this_is_skipped_build_requirement"
875 reinstall_skip 'Skipped because being an only-build-time dependency of already latest packages'
880 if [ \( $opt_skip_unchanged = no -a -e "$REINSTALL_DBNODE_DIR/succeeded_once" \) \
881 -o \( $opt_skip_unchanged = yes -a $REINSTALL_IS_CURRENTPKG_LATEST = yes \) ]
883 if [ ! -e "$REINSTALL_DBNODE_DIR/need_reinstall_due_to_upgraded_requirements.${REINSTALL_DBSUFFIX}" ]
885 if ! database_query_is_necessary_upgrade "$REINSTALL_ORIGIN"
887 reinstall_restore_if_temporarily_deinstalled
888 fileedit_add_a_line_if_new "$REINSTALL_ORIGIN" \
889 "${DBDIR}/todo_after_requirements_succeed.${REINSTALL_DBSUFFIX}.list"
890 reinstall_skip 'Skipped because being already latest or failed as well as the all requirements'
896 reinstall_skip_if_in_a_list 'Marked to be manually-done' manually_done.list restore && return 1
898 reinstall_skip_if_in_a_list 'Skipped because being a hold package' conf/HOLD:PORTS.parsed restore && return 1
899 if database_query_is_a_port_suppressed "$REINSTALL_ORIGIN"
901 reinstall_restore_if_temporarily_deinstalled
902 reinstall_skip 'Skipped because being suppressed'
905 reinstall_skip_if_in_a_list 'Ignored because being taboo' taboo.all.list && return 1
906 if [ $opt_fetch_only = no ] && \
907 ! reinstall_are_requirements_ready && \
908 ! reinstall_chk_and_restore_requirements
910 reinstall_restore_if_temporarily_deinstalled
911 for tag in all run build none
913 for level in full direct
915 fileedit_add_a_line_if_new "$REINSTALL_ORIGIN" \
916 "${DBDIR}/todo_after_requirements_succeed.${tag}.${level}.list"
919 reinstall_skip 'Skipped because the requirements cannot be ready'
924 # ============= Reinstallation of the current origin: Check sanity =============
925 # Return status 0 for no sanity problem
926 reinstall_exec_reinstall_check_sanity ()
928 local check_sanity_msg func_pkg_inst_remote_verify_fetch func_pkg_inst_verify_pkg tmp_fetch_dir tmp_fetch_missing
929 if ! reinstall_chk_stage_complete CHECK_SANITY
931 message_echo "Sanity Check..."
932 _reinstall_exec__tmpcmd () { reinstall_make_anymode check-sanity; }
933 if ! check_sanity_msg=`reinstall_execcmd_getstdout_errlog _reinstall_exec__tmpcmd`
935 echo "$check_sanity_msg"
936 reinstall_restore_if_temporarily_deinstalled
937 reinstall_errproc 'check sanity'
938 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
939 if [ $opt_fetch_only = yes ]
941 if [ $opt_inst_by_pkg_if_can = yes ]
943 if ! reinstall_chk_stage_complete FAILOVER_FETCH_PKG && \
944 database_query_is_default_conf "$REINSTALL_ORIGIN"
946 message_echo "INFO: The configuration of this port is default, so use of a prebuilt package is attempted."
947 func_pkg_inst_remote_verify_fetch=pkg_inst_remote_verify_fetch
948 func_pkg_inst_verify_pkg=pkg_inst_verify_pkg
949 if [ $opt_use_legacy_pkg_for_missing_pkgng = yes ]
951 func_pkg_inst_remote_verify_fetch=pkg_inst_remote_wild_verify_fetch
952 func_pkg_inst_verify_pkg=pkg_inst_wild_verify_pkg
954 if ! $func_pkg_inst_verify_pkg "$REINSTALL_NEWPKGNAME"
956 message_echo "Trying to fetch the package because of the fetch only mode..."
957 if $func_pkg_inst_remote_verify_fetch "$REINSTALL_NEWPKGNAME"
959 reinstall_register_stage_complete FAILOVER_FETCH_PKG
961 message_echo "WARNING: Failed to fetch package for $REINSTALL_NEWPKGNAME"
966 if ! reinstall_chk_stage_complete FAILOVER_FETCH
968 tmp_fetch_missing=${TMPDIR}/reinstall_exec:fetch.sh
969 reinstall_fetch_missing_distfiles > $tmp_fetch_missing
970 if [ `wc -l < $tmp_fetch_missing` -gt 0 ]
972 message_echo "Trying to fetch the distfiles because of the fetch only mode..."
973 tmp_fetch_dir=${TMPDIR}/reinstall_exec:fetch_dir
974 rm -rf "$tmp_fetch_dir"
975 mkdir -p "$tmp_fetch_dir"
976 if ( cd "$tmp_fetch_dir" && sh "$tmp_fetch_missing" )
978 reinstall_register_stage_complete FAILOVER_FETCH
980 message_echo "WARNING: Failed to fetch distfiles"
989 reinstall_register_stage_complete CHECK_SANITY
993 # ============= Reinstallation of the current origin: Installation by package =============
994 # Return status 0 for success
995 reinstall_exec_reinstall_by_pkg ()
997 local pkg func_pkg_inst_remote_verify_fetch func_pkg_inst_remote
998 if [ $REINSTALL_IS_FROZEN = yes ] || [ $opt_inst_by_pkg_if_can = yes ] && database_query_is_default_conf "$REINSTALL_ORIGIN"
1000 if [ $REINSTALL_IS_FROZEN = yes ]
1002 pkg=`pkg_get_remote_repository_version "$REINSTALL_ORIGIN" || :`
1004 pkg=$REINSTALL_NEWPKGNAME
1006 message_echo "INFO: The configuration of this port is default, so use of a prebuilt package is attempted."
1007 if reinstall_chk_stage in_bypkg
1009 message_echo "(Restarting the previously terminated (re)installation-by-package process...)"
1011 reinstall_register_stage in_bypkg
1013 if ! reinstall_chk_stage_complete INSTALL_BY_PKG
1015 if ! reinstall_chk_stage FAILED_INSTALL_BY_PKG
1017 if [ $opt_fetch_only = no -a "x$PKGSYS_USE_PKGNG" = xyes ] \
1018 && pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1020 if reinstall_deinstall && pkg_is_tool_available && pkg_info_e "$pkg"
1022 reinstall_register_stage_complete INSTALL_BY_PKG
1024 reinstall_register_stage FAILED_INSTALL_BY_PKG
1027 func_pkg_inst_remote_verify_fetch=pkg_inst_remote_verify_fetch
1028 func_pkg_inst_remote=pkg_inst_remote
1029 if [ $opt_use_legacy_pkg_for_missing_pkgng = yes ]
1031 func_pkg_inst_remote_verify_fetch=pkg_inst_remote_wild_verify_fetch
1032 func_pkg_inst_remote=pkg_inst_remote_wild
1034 if $func_pkg_inst_remote_verify_fetch "$pkg"
1036 if [ $opt_fetch_only = yes ]
1040 reinstall_backup_and_delete_remaining_install_conflicts__by_pkg "$pkg"
1041 reinstall_pkg_backup || :
1042 reinstall_register_stage in_add_pkg
1043 reinstall_deinstall_old_ports
1045 if $func_pkg_inst_remote "$pkg"
1047 if database_query_dependency_matching "$REINSTALL_ORIGIN"
1049 reinstall_register_stage_complete INSTALL_BY_PKG
1051 message_echo "INFO: The requirements of the package mismatch the configuration."
1052 message_echo "INFO: The installed package will be deleted and installation by port will be attempted instead."
1053 pkg_delete_f "$pkg" || :
1054 reinstall_register_stage FAILED_INSTALL_BY_PKG
1057 reinstall_register_stage FAILED_INSTALL_BY_PKG
1059 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1061 pkg_is_tool_available || pkg_rescue_tools
1065 reinstall_register_stage FAILED_INSTALL_BY_PKG
1069 if [ $opt_fetch_only = no ]
1071 if reinstall_chk_stage FAILED_INSTALL_BY_PKG && \
1072 reinstall_chk_stage in_add_pkg
1074 reinstall_failed_install_recover
1078 if [ $opt_fetch_only = no ] && reinstall_chk_stage_complete INSTALL_BY_PKG
1080 touch "$REINSTALL_DBNODE_DIR/installed_timestamp"
1081 touch "$REINSTALL_DBNODE_DIR/installed_by_pkg"
1082 reinstall_deregister_stage in_bypkg
1083 reinstall_tell_update_to_depandents
1084 reinstall_closing_operations_after_successful_install
1087 reinstall_deregister_stage in_bypkg
1088 if [ $opt_fetch_only = yes ]
1090 message_echo "INFO: Continue to fetch distfiles in case of installation by port."
1092 message_echo "WARNING: (Re)installation-by-package is unsuccessful, so retrying by using port." >&2
1098 # ============= Reinstallation of the current origin: Freeze the port =============
1099 # Return status 0 for no need of freezing
1100 reinstall_exec_reinstall_freeze_if_necessary ()
1102 local pkg pkg_current
1103 message_echo "(Port to freeze)"
1104 _reinstall_exec__tmpcmd () { pkg_get_remote_repository_version "$REINSTALL_ORIGIN"; }
1105 if ! pkg=`reinstall_execcmd_getstdout_errlog _reinstall_exec__tmpcmd` || [ -z "$pkg" ]
1107 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1108 reinstall_restore_if_temporarily_deinstalled
1109 reinstall_errproc 'freezing'
1110 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1111 reinstall_skip "ERROR: Failed to get the repository version."
1114 pkg_current=`pkgsys_get_installed_pkg_from_origin "$REINSTALL_ORIGIN"`
1115 if [ "x$pkg" = "x$pkg_current" ]
1117 message_echo "INFO: The latest repository version $pkg installed, deemed success."
1118 message_echo "WARNING: This action may cause problems due to the version/option mismatch." >&2
1119 reinstall_tell_update_to_depandents
1120 reinstall_closing_operations_after_successful_install
1123 message_echo "INFO: The latest repository version $pkg will be installed."
1124 reinstall_pkg_backup || :
1125 reinstall_deinstall_old_ports
1127 reinstall_backup_and_delete_remaining_install_conflicts__by_pkg "$pkg"
1128 _reinstall_exec__tmpcmd () { pkg_inst_remote "$pkg"; }
1129 if reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1131 message_echo "INFO: Deemed success."
1132 message_echo "WARNING: This action may cause problems due to the version/option mismatch." >&2
1133 reinstall_tell_update_to_depandents
1134 reinstall_closing_operations_after_successful_install
1137 message_echo "ERROR: Failed install the version in the repository for a port to freeze. Dependents are locked." >&2
1138 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1139 reinstall_restore_if_temporarily_deinstalled
1140 reinstall_errproc 'freezing'
1141 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1142 reinstall_skip 'Skipped because being a port to freeze.'
1146 # ============= Reinstallation of the current origin: Avoid build if any requirement port to freeze is unfrozen =============
1147 # Return status 0 for no concern about freezing requirements
1148 reinstall_exec_reinstall_avoid_if_any_unfrozen_requirements_exists ()
1150 if grep -qFx "$REINSTALL_DBNODE_DIR/requirements.all.full" "${DBDIR}/freeze.all.list" 2> /dev/null
1152 reinstall_restore_conflicts
1154 pkgsys_get_conflicting_installed_pkgs build "$REINSTALL_ORIGIN" || :
1155 pkgsys_get_conflicting_installed_pkgs install "$REINSTALL_ORIGIN" || :
1156 } | reinstall_backup_and_delete_conflicts
1157 if ! database_query_are_requirements_not_locked "$REINSTALL_ORIGIN"
1159 reinstall_skip 'Skipped because of missing requirements to freeze.'
1165 # ============= Reinstallation of the current origin: Prebuild process =============
1166 # Return status 1 for error end
1167 reinstall_exec_reinstall_prebuild ()
1169 if [ $opt_fetch_only = no ]
1171 if reinstall_chk_stage in_prebuild
1173 message_echo "(Restarting the previously terminated pre-build process...)"
1175 reinstall_restore_conflicts
1176 reinstall_register_stage in_prebuild
1179 if [ $opt_fetch_only = no -a -e "$REINSTALL_DBNODE_DIR/BEFOREBUILD.conf" ] && \
1180 ! reinstall_chk_stage_complete BEFOREBUILD
1182 message_echo "-- BEFOREBUILD operations (start)"
1183 _reinstall_exec__tmpcmd () { sh -e "$REINSTALL_DBNODE_DIR/BEFOREBUILD.conf"; }
1184 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1186 reinstall_restore_if_temporarily_deinstalled
1187 reinstall_errproc 'BEFOREBUILD operations'
1188 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1191 message_echo "-- BEFOREBUILD operations (end)"
1192 reinstall_register_stage_complete BEFOREBUILD
1194 if [ $opt_fetch_only = no ] && ! reinstall_chk_stage_complete CLEAN_BEFORE_BUILD
1196 _reinstall_exec__tmpcmd () { reinstall_make_anymode clean NOCLEANDEPENDS=yes; }
1197 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1199 reinstall_restore_if_temporarily_deinstalled
1200 reinstall_errproc 'clean before build'
1201 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1205 reinstall_register_stage_complete CLEAN_BEFORE_BUILD
1207 reinstall_deregister_stage in_prebuild
1210 # ============= Reinstallation of the current origin: Fetch process =============
1211 # Return status 1 for error end
1212 reinstall_exec_reinstall_fetch ()
1214 if ! reinstall_chk_stage_complete FETCH
1216 if ! reinstall_chk_stage FAILED_FETCH
1218 reinstall_make_anymode checksum || \
1219 reinstall_register_stage FAILED_FETCH
1221 if reinstall_chk_stage FAILED_FETCH
1223 if ! reinstall_chk_stage_complete FAILED_FETCH.RETRIAL_1
1225 message_echo "INFO: Refetching distfiles for $REINSTALL_ORIGPKGTAG."
1227 reinstall_make_anymode fetch FETCH_ARGS=-Ap &&
1228 reinstall_make_anymode checksum
1229 } || reinstall_register_stage FAILED_REFETCH_1
1230 reinstall_register_stage_complete FAILED_FETCH.RETRIAL_1
1232 if reinstall_chk_stage FAILED_REFETCH_1
1234 if ! reinstall_chk_stage_complete FAILED_FETCH.RETRIAL_2.DISTCLEAN
1236 message_echo "INFO: Cleaning distfiles for the second refetch for $REINSTALL_ORIGPKGTAG."
1237 reinstall_make_anymode distclean || :
1238 reinstall_register_stage_complete FAILED_FETCH.RETRIAL_2.DISTCLEAN
1240 if ! reinstall_chk_stage_complete FAILED_FETCH.RETRIAL_2
1242 message_echo "INFO: Refetching distfiles as the second retrial for $REINSTALL_ORIGPKGTAG."
1243 _reinstall_exec__tmpcmd () { reinstall_make_anymode fetch FETCH_ARGS=-Ap; }
1244 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1246 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1247 reinstall_restore_if_temporarily_deinstalled
1248 reinstall_errproc 'fetch'
1249 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1252 _reinstall_exec__tmpcmd () { reinstall_make_anymode checksum; }
1253 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1255 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1256 reinstall_restore_if_temporarily_deinstalled
1257 reinstall_errproc 'checksum'
1258 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1261 reinstall_register_stage_complete FAILED_FETCH.RETRIAL_2
1265 reinstall_register_stage_complete FETCH
1269 # ============= Reinstallation of the current origin: Check matching of interactive or non-interactive mode=============
1270 # Return status 1 for error end
1271 reinstall_exec_reinstall_chk_interactive_mode ()
1273 local to_skip msg_is_interactive
1274 if [ $opt_batch_ports_only = yes -o $opt_interactive_ports_only = yes ]
1277 case `database_query_get_makevar_val "$REINSTALL_ORIGIN" IS_INTERACTIVE` in
1278 yes ) msg_is_interactive='interactive'
1279 [ $opt_batch_ports_only = yes ] && to_skip=yes
1281 '' ) msg_is_interactive='not interactive'
1282 [ $opt_interactive_ports_only = yes ] && to_skip=yes
1285 if [ $to_skip = yes ]
1287 reinstall_restore_if_temporarily_deinstalled
1288 database_build_update_pkgname "$REINSTALL_ORIGIN" > /dev/null
1289 message_echo "INFO: Further processes for this port are skipped because it is $msg_is_interactive."
1290 fileedit_rm_a_line "$REINSTALL_ORIGIN" "${DBDIR}/stage.loop_list/reinst_todo.remain"
1291 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1297 # ============= Reinstallation of the current origin: Build process=============
1298 # Return status 1 for error end
1299 reinstall_exec_reinstall_build ()
1301 local flag_restarted_build build_args is_build_env_modified conflicts_install
1302 if reinstall_chk_stage in_build
1304 message_echo "(Restarting the previously terminated build process...)"
1305 flag_restarted_build=yes
1307 reinstall_register_stage in_build
1308 flag_restarted_build=no
1310 if reinstall_chk_stage in_retrial_build
1312 message_echo "(Restarting the previously terminated retrial build process...)"
1313 build_args='MAKE_JOBS_UNSAFE=yes'
1317 if ! reinstall_chk_stage_complete BUILD
1319 pkgsys_get_conflicting_installed_pkgs build "$REINSTALL_ORIGIN" \
1320 | reinstall_backup_and_delete_conflicts
1321 reinstall_chk_missing_requirement || return
1322 if ! reinstall_make build $build_args
1324 reinstall_register_stage in_retrial_build
1325 [ $flag_restarted_build = yes ] && message_echo "INFO: This failure may be due to restarting from a terminated build."
1326 is_build_env_modified=no
1327 if conflicts_install=`pkgsys_get_conflicting_installed_pkgs install "$REINSTALL_ORIGIN"`
1329 message_echo "INFO: Install-only conflicts are deinstalled for retrial because they may have effects on build."
1330 echo "$conflicts_install" | reinstall_backup_and_delete_conflicts
1331 is_build_env_modified=yes
1333 if pkgsys_exists_from_orig "$REINSTALL_ORIGIN"
1335 message_echo "INFO: The currently installed package for this port is deinstalled for retrial because it may have effects on build."
1336 reinstall_pkg_backup || :
1337 reinstall_deinstall_old_ports
1339 is_build_env_modified=yes
1341 reinstall_deregister_stage_complete CLEAN_BEFORE_BUILD
1342 message_echo "INFO: Retrying the build process after cleaning for $REINSTALL_ORIGPKGTAG."
1343 _reinstall_exec__tmpcmd () { reinstall_make clean; }
1344 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1346 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1348 pkg_is_tool_available || pkg_rescue_tools
1350 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1351 reinstall_restore_if_temporarily_deinstalled
1352 reinstall_errproc 'build and clean after build failure'
1353 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1356 reinstall_register_stage_complete CLEAN_BEFORE_BUILD
1357 _reinstall_exec__tmpcmd () { reinstall_make build MAKE_JOBS_UNSAFE=yes; }
1358 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1360 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1362 pkg_is_tool_available || pkg_rescue_tools
1364 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1365 reinstall_restore_if_temporarily_deinstalled
1366 reinstall_errproc 'retrial of build after failure'
1367 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1370 reinstall_deregister_stage in_retrial_build
1372 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1374 pkg_is_tool_available || pkg_rescue_tools
1376 reinstall_register_stage_complete BUILD
1378 reinstall_deregister_stage in_retrial_build
1379 reinstall_deregister_stage in_build
1382 # ============= Reinstallation of the current origin: Stage process=============
1383 # Return status 1 for error end
1384 reinstall_exec_reinstall_stage ()
1386 if reinstall_chk_stage in_stage
1388 message_echo "(Restarting the previously terminated staging process...)"
1390 reinstall_register_stage in_stage
1392 if ! reinstall_chk_stage_complete STAGE
1394 _reinstall_exec__tmpcmd () { reinstall_make stage; }
1395 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1397 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1398 reinstall_restore_if_temporarily_deinstalled
1399 reinstall_errproc 'STAGE operations'
1400 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1403 reinstall_register_stage_complete STAGE
1405 reinstall_deregister_stage in_stage
1408 # ============= Reinstallation of the current origin: Install process=============
1409 # Return status 1 for error end
1410 reinstall_exec_reinstall_install ()
1413 if [ -e "$REINSTALL_FROMNODE_DIR/installed_version" ]
1415 insttarget=reinstall
1419 if reinstall_chk_stage in_install
1421 message_echo "(Restarting the previously terminated installation process...)"
1423 reinstall_register_stage in_install
1425 reinstall_pkg_backup || :
1426 if [ -e "$REINSTALL_DBNODE_DIR/BEFOREDEINSTALL.conf" ] && ! reinstall_chk_stage_complete BEFOREDEINSTALL
1428 message_echo "-- BEFOREDEINSTALL operations (start)"
1429 _reinstall_exec__tmpcmd () { sh -e "$REINSTALL_DBNODE_DIR/BEFOREDEINSTALL.conf"; }
1430 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1432 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1433 reinstall_restore_if_temporarily_deinstalled
1434 reinstall_errproc 'BEFOREDEINSTALL operations'
1435 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1438 message_echo "-- BEFOREDEINSTALL operations (end)"
1439 reinstall_register_stage_complete BEFOREDEINSTALL
1441 if ! reinstall_chk_stage_complete INSTALL
1443 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1445 reinstall_backup_and_delete_remaining_install_conflicts
1446 reinstall_deinstall_old_ports
1449 reinstall_deinstall_old_ports
1451 reinstall_backup_and_delete_remaining_install_conflicts
1453 if ! reinstall_chk_stage FAILED_INSTALL
1455 if reinstall_make $insttarget || \
1457 message_echo "INFO: Cleaning up for retrial."
1458 reinstall_make deinstall \
1459 || message_echo "WARNING: Continuing by hoping a success." >&2
1460 message_echo "INFO: Retrying the installation."
1461 _reinstall_exec__tmpcmd () { reinstall_make $insttarget MAKE_JOBS_UNSAFE=yes; }
1462 reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1465 touch "$REINSTALL_DBNODE_DIR/installed_timestamp"
1466 reinstall_register_stage_complete INSTALL
1468 reinstall_register_stage FAILED_INSTALL
1471 if reinstall_chk_stage FAILED_INSTALL
1473 if pkgsys_is_necessary_pkgtool "$REINSTALL_ORIGIN"
1475 pkg_is_tool_available || pkg_rescue_tools
1477 reinstall_failed_install_recover
1479 if [ -e "$REINSTALL_DBNODE_DIR/AFTERINSTALL.conf" ] && \
1480 ! reinstall_chk_stage_complete FAILED_INSTALL.AFTERINSTALL
1482 message_echo "-- AFTERINSTALL operations (start)"
1483 if ! sh -e "$REINSTALL_DBNODE_DIR/AFTERINSTALL.conf"
1485 message_echo "WARNING: Failed in AFTERINSTALL operations." >&2
1486 message_echo "---- (The process is continued anyway)"
1488 message_echo "-- AFTERINSTALL operations (end)"
1489 reinstall_register_stage_complete FAILED_INSTALL.AFTERINSTALL
1491 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1492 reinstall_restore_if_temporarily_deinstalled
1493 reinstall_errproc 'install'
1494 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1498 reinstall_remove_needless_possible_conflict
1499 reinstall_restore_if_temporarily_deinstalled
1500 if ! reinstall_chk_stage_complete UPDATE_CONFLICTS
1502 pkg_info_qL "$REINSTALL_NEWPKGNAME" > ${TMPDIR}/reinstall_exec:currently_installed_files
1503 cat "${DBDIR}/backup_pkgarcs.lst" 2> /dev/null \
1504 | while read origin_bak pkgpath_bak
1506 pkg_bak=`pkgsys_pkgarc_to_pkgname "$pkgpath_bak"`
1507 if [ "$origin_bak" = "$REINSTALL_ORIGIN" ]
1509 [ "$pkg_bak" = "$REINSTALL_NEWPKGNAME" ] && continue
1510 elif reinstall_quick_chk_forbidden_conflicts "$pkg_bak"
1513 elif ! pkgsys_chk_match_to_restored_files_by_backup_pkg \
1514 "$origin_bak" "${TMPDIR}/reinstall_exec:currently_installed_files"
1518 fileedit_add_a_line_if_new "$pkg_bak:$REINSTALL_ORIGIN:$REINSTALL_NEWPKGNAME" \
1519 "${DBDIR}/forbidden_conflicts"
1521 reinstall_register_stage_complete UPDATE_CONFLICTS
1523 if [ -e "$REINSTALL_DBNODE_DIR/AFTERINSTALL.conf" ] && ! reinstall_chk_stage_complete AFTERINSTALL
1525 message_echo "-- AFTERINSTALL operations (start)"
1526 _reinstall_exec__tmpcmd () { sh -e "$REINSTALL_DBNODE_DIR/AFTERINSTALL.conf"; }
1527 if ! reinstall_execcmd_tee_errlog _reinstall_exec__tmpcmd
1529 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1530 reinstall_errproc 'AFTERINSTALL operations'
1531 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1534 message_echo "-- AFTERINSTALL operations (end)"
1535 reinstall_register_stage_complete AFTERINSTALL
1537 reinstall_deregister_stage in_install
1540 # ============= Reinstallation of the current origin: Closing process after successful install =============
1541 reinstall_exec_reinstall_close ()
1543 reinstall_restore_conflicts "$REINSTALL_ORIGIN"
1544 if ! reinstall_chk_stage_complete CLEAN_AFTER_INSTALL
1546 if ! reinstall_make clean
1548 message_echo "WARNING: Failed to clean $REINSTALL_ORIGPKGTAG." >&2
1550 reinstall_register_stage_complete CLEAN_AFTER_INSTALL
1552 reinstall_tell_update_to_depandents
1553 reinstall_closing_operations_after_successful_install
1556 # ============= Reinstallation of the current origin =============
1557 # Return status 1 for error or incomplete end
1558 reinstall_exec_reinstall ()
1560 local insttarget instdesc
1561 if [ -e "$REINSTALL_FROMNODE_DIR/installed_version" ]
1563 insttarget=reinstall
1564 instdesc='a reinstallation'
1567 instdesc='an installation'
1569 temp_set_msg_current_stage "$instdesc process for $REINSTALL_ORIGPKGTAG $PROGRAM_STEP_COUNTER"
1570 message_target_relations "$REINSTALL_ORIGIN"
1571 message_echo "------- Starting $instdesc process --------"
1572 reinstall_exec_reinstall_check_sanity || return
1573 if [ $opt_dry_run = yes ]
1576 temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
1579 reinstall_exec_reinstall_by_pkg && return
1580 if [ $REINSTALL_IS_FROZEN = yes ]
1582 reinstall_exec_reinstall_freeze_if_necessary || return
1584 reinstall_exec_reinstall_avoid_if_any_unfrozen_requirements_exists || return
1585 reinstall_exec_reinstall_prebuild || return
1586 reinstall_exec_reinstall_fetch || return
1587 if [ $opt_fetch_only = yes ]
1592 reinstall_exec_reinstall_chk_interactive_mode || return
1593 reinstall_exec_reinstall_build || return
1594 reinstall_exec_reinstall_stage || return
1595 reinstall_exec_reinstall_install || return
1596 reinstall_exec_reinstall_close_successful_install
1599 # ============= Reinstallation for a flavored origin =============
1602 local REINSTALL_ORIGIN REINSTALL_DBNODE_DIR REINSTALL_FROMNODE_DIR
1603 local REINSTALL_CURRENTPKG REINSTALL_IS_CURRENTPKG_LATEST
1604 local REINSTALL_PKGTAG REINSTALL_ORIGPKGTAG REINSTALL_DBSUFFIX
1605 local REINSTALL_NEWPKGNAME REINSTALL_IS_FROZEN
1607 REINSTALL_DBNODE_DIR=${DBDIR}/requires/$REINSTALL_ORIGIN
1608 REINSTALL_FROMNODE_DIR=${DBDIR}/moved_from/$REINSTALL_ORIGIN
1609 REINSTALL_CURRENTPKG=`database_build_update_pkgname "$REINSTALL_ORIGIN" | tr '\n' ' ' | sed 's/ *$//'`
1610 REINSTALL_IS_CURRENTPKG_LATEST=no
1611 database_build_is_currentpkg_latest "$REINSTALL_ORIGIN" && REINSTALL_IS_CURRENTPKG_LATEST=yes
1612 database_build_update_pkgtag "$REINSTALL_ORIGIN"
1613 REINSTALL_PKGTAG=`cat "$REINSTALL_FROMNODE_DIR/pkgtag"`
1614 REINSTALL_ORIGPKGTAG="$REINSTALL_ORIGIN ($REINSTALL_PKGTAG)"
1615 REINSTALL_DBSUFFIX=`options_get_dependency_type`.`options_get_dependency_level`
1616 REINSTALL_NEWPKGNAME=`database_build_get_new_pkgname "$REINSTALL_ORIGIN"`
1617 REINSTALL_IS_FROZEN=no
1618 grep -qFx "$REINSTALL_ORIGIN" "${DBDIR}/freeze.all.list" 2> /dev/null && REINSTALL_IS_FROZEN=yes
1619 message_stage_title "$PROGRAM_STEP_COUNTER $REINSTALL_ORIGPKGTAG"
1620 reinstall_exec_chk_skip && reinstall_exec_reinstall || :
1624 # ============= Indivisual make of a port for user command operations =============
1625 reinstall_make_individual ()
1627 local REINSTALL_ORIGIN REINSTALL_DBNODE_DIR
1629 REINSTALL_DBNODE_DIR=${DBDIR}/requires/$REINSTALL_ORIGIN
1631 reinstall_make_anymode "$@"