OSDN Git Service

[BUG FIX] Packages for which the flavor mechanism is newly introduced sometimes had...
[portsreinstall/current.git] / lib / libmain.sh
index 572d264..23dbc45 100644 (file)
@@ -2,18 +2,18 @@
 # ==============================================================================
 # portsreinstall library script
 # - Common functions of main programs -
-# Copyright (C) 2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
+# Copyright (C) 2018-2022 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
 # This software is distributed under the 2-Clause BSD License.
 # ==============================================================================
 
 # ============= Define the software version =============
 main_set_version ()
 {
-       MYVERSION=4.0.1
-       COMPATIBLE_VERSIONS='^(4\.[0]\.[0-1])$'
+       MYVERSION=4.1.2
+       COMPATIBLE_VERSIONS='^(4\.[1]\.[0-9])$'
        # Template for development versions
-       MYVERSION=4.0.0+toward_4.0.1_20180715175555
-       COMPATIBLE_VERSIONS='^(4\.[0]\.[0-1]]|4\.[0]\.[0]+(|\+toward_4\.[0]\.[1]+_[0-9]+))$'
+       MYVERSION=4.1.1+toward_4.1.2_20220508155922
+       COMPATIBLE_VERSIONS='^(4\.[0-1]\.[0-9]]|4\.[0-1]\.[0-1]+(|\+toward_4\.[0-1]\.[0-9]+_[0-9]+))$'
 }
 
 # ============= Parse options, arguments and control parameters =============
@@ -35,16 +35,17 @@ main_parse_options_arguments ()
        shift "${OPTIONS_SHIFT}"
        
        options_regularize
-
+       
        # ============= Argument check for no-command options =============
        if [ $opt_help_mode -ne 0 -o $opt_show_version = yes ]
        then
                if [ $# -gt 0 ]
                then
+                       message_echo "SYNTAX ERROR: No command is allowed for showing Help or Version" >&2
                        OPTIONS_ERRNO=1
                fi
        fi
-
+       
        # ============= Output usage if the case of a help mode or option/argument errors =============
        if [ $OPTIONS_ERRNO -ne 0 ]
        then
@@ -58,7 +59,7 @@ main_parse_options_arguments ()
                usage_long | less -r
                exit
        fi
-
+       
        # ============= Output version number =============
        if [ $opt_show_version = yes ]
        then
@@ -78,7 +79,6 @@ main_parse_options_arguments ()
 
        # ============= Argument check for conventional runs =============
        command_all_parse_args "$@"
-       shift "${COMMAND_SHIFT}"
 }
 
 # ============= Define the common termination messages =============
@@ -96,10 +96,12 @@ main_define_common_termination_messages ()
                then
                        message_echo "INFO: Terminated at `message_timestamp`$msg_where."
                        message_echo
+                       [ $opt_no_opening_message = yes ] && return
                        message_echo " You can restart this process from the terminated point by"
                else
                        message_echo "INFO: Aborted at `message_timestamp`$msg_where."
                        message_echo
+                       [ $opt_no_opening_message = yes ] && return
                        message_echo " You may restart this process from the aborted point by"
                fi
                message_echo "executing without options or arguments as:"
@@ -115,20 +117,6 @@ main_define_common_termination_messages ()
 # ============= Set termination messages for special commands =============
 main_set_termination_messages_special ()
 {
-       temp_terminate_process ()
-       {
-               local errno tmp_msg
-               errno=${1:-0}
-               tmp_msg=${TMPDIR}/temp_terminate_process:msg
-               [ $errno -eq 0 -o $opt_batch_mode = yes ] && return
-               temp_terminate_process_common "$errno"
-               [ -n "$COMMAND_RESTART" ] && return
-               cat > $tmp_msg << eof
-Instead, if you only want to construct the temporary database so as to stop before the actual reinstallation, execute as:
-${APPNAME} prepare
-eof
-               message_cat "$tmp_msg"
-       }
 }
 
 # ============= Option settings =============
@@ -233,7 +221,7 @@ main_parse_conf ()
                conf_parse_vars_for_each_port_glob FREEZE
                fileedit_combine_lists "${DBDIR}/conf/FREEZE:PORTS.parsed" "${DBDIR}/freeze.list" \
                        > ${DBDIR}/freeze.all.list
-               # NOPKG_*
+               # REBUILD_*
                conf_parse_vars_for_each_port_glob NOPKG
                # REPLACE_*
                conf_build_replacement_patterns_from_REPLACE
@@ -265,45 +253,58 @@ main_setup_parameters ()
        main_define_common_termination_messages
        temp_reset_termination_messages_common
        main_set_termination_messages_special
-
+       
        # ============= Opening title =============
-
+       
        message_credit
        command_all_chk_need_opening_notice && message_opening_notice
        message_echo
-
+       
        # ============= Execute command operations which do not need package tools =============
-
+       
        command_all_exec_without_pkgtools "$@"
        misc_is_superuser_privilege && database_maintain_mark_use
        # ============= Definition of environment dependent functions =============
-
+       
        pkgsys_def_pkgtools
-
+       
        # ============= Option settings =============
-
+       
        # Execute command operations which are not affected by saved option settings
        command_all_exec_irrespective_of_saved_options "$@"
-
+       
        # Load, renew and save option values
        main_option_settings
-
+       
        # Show option values
        message_show_option_settings
+       
+       # Execute command operations which should be carried out just after completing the option settings
+       command_all_exec_just_after_option_settings "$@"
 
+       # ============= Command-specific pre-configuration =============
+       
+       # Execute command operations which must be done before the database construction
+       command_all_exec_command_specific_preconfiguration "$@"
+       
        # ============= Configurations =============
-
+       
        # Save the previous configuration if exists
        main_save_prev_conf
-
+       
        # Get complete configuration variable definitions by importing pkgtools.conf(5) if available
        main_get_complete_conf
-
+       
        # Parse the configuration
        main_parse_conf
-
+       
        # Load the saved configuration
        main_load_conf
+       if [ $opt_just_save_options = yes ]
+       then
+               message_echo "(Save-options-only mode)"
+               exit
+       fi
 }
 
 # ============= Operation without packages management tools =============
@@ -323,25 +324,74 @@ main_collect_all_installed_packages ()
        PROGRAM_DEPENDS=''
        _program_exec_and_record_completion__operation ()
        {
-               local tmp_installed_ports tmp_installed_pkgs
+               local fossil_path
                message_section_title "Collecting all installed packages"
+               mkdir -p "${DBDIR}/fossil_pkgs"
+               fossil_path=${DBDIR}/fossil_pkgs/fossil_since_`pkgsys_get_timestamp_portstree`
+               if [ ! -e "$fossil_path" ]
+               then
+                       pkg_info_all_flavored_origins > $fossil_path.tmp
+                       mv "$fossil_path.tmp" "$fossil_path"
+               fi
                if [ ! -e "${DBDIR}/installed_ports" ]
                then
-                       pkg_info_all_flavored_origins > ${DBDIR}/installed_ports.tmp
-                       pkg_info_gen_pkg_origin_table
+                       cp "$fossil_path" "${DBDIR}/installed_ports.tmp"
                        mv "${DBDIR}/installed_ports.tmp" "${DBDIR}/installed_ports"
                fi
+               pkgsys_gen_init_pkg_origin_table
                message_echo
        }
        program_exec_and_record_completion COLLECT_ALL_INSTALLED_PACKAGES
 }
 
+# ============= Determine all target ports of tools which have to be up-to-date =============
+main_determine_all_target_ports_of_tools ()
+{
+       local PROGRAM_DEPENDS
+       PROGRAM_DEPENDS=
+       _program_exec_and_record_completion__operation ()
+       {
+               message_section_title "Determining all target ports of tools which have to be up-to-date"
+               {
+                       [ "$PKGSYS_USE_PKGNG" = yes ] && pkgsys_portsmgmt_pkg
+                       pkgsys_is_dialog4ports_used && pkgsys_portsmgmt_dialog4ports
+                       [ -n "$MYPORTORIGIN" ] && echo "$MYPORTORIGIN"
+               } 2> /dev/null > ${DBDIR}/stage.loop_list/tools_to_inspect
+               cp "${DBDIR}/stage.loop_list/tools_to_inspect" "${DBDIR}/stage.loop_list/tools_to_inspect_initial"
+               message_echo
+       }
+       program_exec_and_record_completion DETERMINE_ALL_TARGET_PORTS_OF_TOOLS
+}
+
+# ============= Preliminary inspection of initially installed tools which have to be up-to-date =============
+# (No need depend on PARSE_CONF because INSPECT_ALL_DEPENDENCIES will take the task.)
+main_preliminary_inspection_of_initial_tools ()
+{
+       local PROGRAM_DEPENDS
+       PROGRAM_DEPENDS='DETERMINE_ALL_TARGET_PORTS_OF_TOOLS'
+       _program_exec_restartable_loop_operation__routine ()
+       {
+               local origin
+               origin=$1
+               database_build_setup_initial_node "$origin"
+       }
+       _program_exec_and_record_completion__operation ()
+       {
+               local DEPTH_INDEX
+               message_section_title "Preliminary inspection of initially installed tools which have to be up-to-date"
+               program_exec_restartable_loop_operation tools_to_inspect_initial
+               database_build_post_inspect_initial_dependencies
+               message_echo
+       }
+       program_exec_and_record_completion PRELIMINARY_INSPECTION_OF_INITIAL_TOOLS
+}
+
 # ============= Preliminary inspection of tools which have to be up-to-date =============
 # (No need depend on PARSE_CONF because INSPECT_ALL_DEPENDENCIES will take the task.)
 main_preliminary_inspection_of_tools ()
 {
        local PROGRAM_DEPENDS
-       PROGRAM_DEPENDS=
+       PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_INITIAL_TOOLS'
        _program_exec_restartable_loop_operation__routine ()
        {
                local origin
@@ -352,11 +402,6 @@ main_preliminary_inspection_of_tools ()
        {
                local DEPTH_INDEX
                message_section_title "Preliminary inspection of tools which have to be up-to-date"
-               {
-                       [ "$PKGSYS_USE_PKGNG" = yes ] && pkgsys_portsmgmt_pkg
-                       pkgsys_is_dialog4ports_used && pkgsys_portsmgmt_dialog4ports
-                       [ -n "$MYPORTORIGIN" ] && echo "$MYPORTORIGIN"
-               } 2> /dev/null > ${DBDIR}/stage.loop_list/tools_to_inspect
                cp /dev/null "${DBDIR}/done_required_ports_to_inspect"
                DEPTH_INDEX='--'
                program_exec_restartable_loop_operation tools_to_inspect
@@ -378,12 +423,14 @@ main_upgrade_pkg8_if_new ()
                PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
                _program_exec_and_record_completion__operation ()
                {
-                       local _MSG_CURRENT_STAGE_general
+                       local _MSG_CURRENT_STAGE_general origin
                        _MSG_CURRENT_STAGE_general="pkg(8) upgrade"
+                       origin=`pkgsys_portsmgmt_pkg`
                        temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
-                       message_section_title "Upgrade of `pkgsys_portsmgmt_pkg` if new"
+                       message_section_title "Upgrade of $origin if new"
                        touch "${DBDIR}/target_all"
-                       reinstall_exec `pkgsys_portsmgmt_pkg`
+                       cp "${DBDIR}/requires/$origin/requirements.all.direct.src" "${DBDIR}/requires/$origin/requirements.all.full"
+                       reinstall_exec "$origin"
                        reinstall_restore_conflicts
                        rm -f "${DBDIR}/target_all"
                        temp_set_msg_current_stage
@@ -405,12 +452,14 @@ main_upgrade_dialog4ports1_if_new ()
                PROGRAM_DEPENDS='PRELIMINARY_INSPECTION_OF_TOOLS'
                _program_exec_and_record_completion__operation ()
                {
-                       local _MSG_CURRENT_STAGE_general
+                       local _MSG_CURRENT_STAGE_general origin
                        _MSG_CURRENT_STAGE_general="dialog4ports(1) upgrade"
+                       origin=`pkgsys_portsmgmt_dialog4ports`
                        temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
-                       message_section_title "Upgrade of `pkgsys_portsmgmt_dialog4ports` if new"
+                       message_section_title "Upgrade of $origin if new"
                        touch "${DBDIR}/target_all"
-                       reinstall_exec `pkgsys_portsmgmt_dialog4ports`
+                       cp "${DBDIR}/requires/$origin/requirements.all.direct.src" "${DBDIR}/requires/$origin/requirements.all.full"
+                       reinstall_exec "$origin"
                        reinstall_restore_conflicts
                        rm -f "${DBDIR}/target_all"
                        temp_set_msg_current_stage
@@ -437,6 +486,7 @@ main_self_upgrade ()
                        temp_set_msg_current_stage "${_MSG_CURRENT_STAGE_general}"
                        message_section_title "Upgrade of this utility if new"
                        touch "${DBDIR}/target_all"
+                       cp "${DBDIR}/requires/$MYPORTORIGIN/requirements.all.direct.src" "${DBDIR}/requires/$MYPORTORIGIN/requirements.all.full"
                        reinstall_exec "$MYPORTORIGIN"
                        reinstall_restore_conflicts
                        rm -f "${DBDIR}/target_all"
@@ -473,7 +523,7 @@ main_reflect_conf_changes ()
                if fileedit_manipulate_old_new_lines \
                        "${DBDIR}/conf.prev/setenv.sh" "${DBDIR}/conf/setenv.sh" "$tmpfile_old" "$tmpfile_new"
                then
-                       if grep -q -e ^LOCALBASE= -e ^LINUXBASE= -e ^PORTSDIR= "$tmpfile_old" "$tmpfile_new"
+                       if env LANG=C grep -q -e ^LOCALBASE= -e ^LINUXBASE= -e ^PORTSDIR= "$tmpfile_old" "$tmpfile_new"
                        then
                                message_echo "ERROR: Migration of the temporary database is unavailable because LOCALBASE, LINUXBASE or PORTSDIR was changed." >&2
                                message_echo "        ${APPNAME} clean" >&2