2 # ==============================================================================
3 # portsreinstall library script
4 # Overlay onto lib/libcommand.sh
5 # - Operations of commands as well as check of command line arguments -
6 # Copyright (C) 2013-2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
7 # This software is distributed under the 2-Clause BSD License.
8 # ==============================================================================
10 # ============= Check the necessity of opening notice =============
11 command_all_chk_need_opening_notice ()
13 [ $COMMAND_MODE = do -o $COMMAND_MODE = redo -o $COMMAND_MODE = forget ]
16 # ============= Execute command operations before getting the temporary database ready =============
17 command_all_exec_before_db_creation ()
19 local COMMAND_RESTART COMMAND_MODE COMMAND_OPERATION
25 COMMAND_OPERATION=${1:-normal}
27 _command_parse_args__chk_no_arg $#
28 case $COMMAND_OPERATION in
30 message_echo "INFO: The temporary database is tried to be cleaned up without checking the privilege."
31 database_maintain_clean_all
40 # ============= Check and parse command line arguments =============
41 command_all_parse_args ()
50 COMMAND_OPERATION=${1:-normal}
52 case $COMMAND_OPERATION in
57 _command_parse_args__chk_no_arg $#
61 COMMAND_OPERATION=${1:-all}
63 case $COMMAND_OPERATION in
64 all | keepopts | keepstatus )
67 message_echo "ERROR: Invalid operation [$COMMAND_OPERATION]; it must be empty, \"all\" or \"keepopts\"." >&2
71 _command_parse_args__chk_no_arg $#
73 ok | taboo | freeze | need | noneed )
75 [ $COMMAND_MODE = ok ] && database_query_chk_preparation_completion
76 temp_warn_obsolete_temp_db >&2
79 case $COMMAND_OPERATION in
83 message_echo "ERROR: Missing operation which must be \"add\" or \"del\"." >&2
87 message_echo "ERROR: Invalid operation [$COMMAND_OPERATION]; it must be \"add\" or \"del\"." >&2
91 _command_parse_args__chk_glob_args $#
95 database_query_chk_preparation_completion
96 temp_warn_obsolete_temp_db >&2
99 case $COMMAND_OPERATION in
101 if [ -e "${DBDIR}/inspected_ports_only_partially" ]
103 message_echo "ERROR: Leaf ports cannot be analyzed because the dependency inspection is partial." >&2
104 message_echo "Executing redo command with -N option by disabling -o option fixes this situation." >&2
111 message_echo "ERROR: Missing operation which must be \"leaves\" or \"obsolete\"." >&2
115 message_echo "ERROR: Invalid operation [$COMMAND_OPERATION]; it must be \"leaves\" or \"obsolete\"." >&2
119 _command_parse_args__chk_glob_args $#
123 if [ ! -d "${DBDIR}" ]
125 message_echo "ERROR: The temporary database has not been created yet." >&2
130 _command_parse_args__chk_no_arg $#
131 if [ -z "$COMMAND_SAVE_DIR" ]
133 message_echo "ERROR: Directory to save the temporary database archive is not specified." >&2
136 if [ ! -d "$COMMAND_SAVE_DIR" ]
138 message_echo "ERROR: Directory [$COMMAND_SAVE_DIR] is not found." >&2
144 if database_maintain_chk_use
146 message_echo "ERROR: A temporary database exists." >&2
147 message_echo "You must execute" >&2
148 message_echo " ${APPNAME} clean" >&2
149 message_echo "before executing \"load\" command." >&2
154 _command_parse_args__chk_no_arg $#
155 if [ -z "$COMMAND_LOAD_FILE" ]
157 message_echo "ERROR: No temporary database archive is specified." >&2
160 if [ ! -f "$COMMAND_LOAD_FILE" ]
162 message_echo "ERROR: No such temporary database archive is found." >&2
165 COMMAND_LOAD_FILE=`realpath "$COMMAND_LOAD_FILE"`
168 _command_parse_args__chk_glob_args $#
171 _command_parse_args__chk_no_arg $#
173 reconf | rmconf | forget | escape | restore | make )
175 temp_warn_obsolete_temp_db >&2
176 _command_parse_args__chk_glob_args $#
180 temp_warn_obsolete_temp_db >&2
186 case $COMMAND_OPERATION in
188 _command_parse_args__chk_no_arg $#
191 COMMAND_PACKUPGRADE_SAVEPATH=${1:-${PROGRAM}-upgrade.tar.gz}
193 _command_parse_args__chk_no_arg $#
194 [ ! -d "${COMMAND_PACKUPGRADE_SAVEPATH}" ] || COMMAND_PACKUPGRADE_SAVEPATH=${COMMAND_PACKUPGRADE_SAVEPATH}/${PROGRAM}-upgrade.tar.gz
197 message_echo "ERROR: Invalid operation [$COMMAND_OPERATION]; it must be \"create\" \"crop\" or \"clean\"." >&2
203 case $COMMAND_SHOW_SUBJECT in
204 todo | done | redo | resolved | failure | deleted | restored | conflict | leaves | obsolete )
205 database_query_chk_preparation_completion;;
207 temp_warn_obsolete_temp_db >&2
208 if ! expr "$1" : '@.*' > /dev/null
210 COMMAND_SHOW_SUBJECT=${1:-todo}
213 COMMAND_SHOW_SUBJECT=todo
215 COMMAND_SHOW_OPTIONS=$1
216 if expr "$COMMAND_SHOW_OPTIONS" : '@.*' > /dev/null
218 COMMAND_SHOW_DEPTAG=`expr "$COMMAND_SHOW_OPTIONS," : '@\(.*\)' | cut -d , -f 1` || :
219 COMMAND_SHOW_LEVEL=`expr "$COMMAND_SHOW_OPTIONS," : '@\(.*\)' | cut -d , -f 2` || :
220 case $COMMAND_SHOW_DEPTAG in
221 all | run | build | '' ) ;;
223 message_echo "ERROR: Invalid show option [$COMMAND_SHOW_OPTIONS]." >&2
227 case $COMMAND_SHOW_LEVEL in
228 full | direct | '' ) ;;
230 message_echo "ERROR: Invalid show option [$COMMAND_SHOW_OPTIONS]." >&2
236 case $COMMAND_SHOW_SUBJECT in
237 todo | done | redo | resolved | failure | taboo | freeze | need | noneed | restored | deleted | conflict )
238 _command_parse_args__chk_no_arg $#
241 COMMAND_SHOW_KEYWORD=$1
242 case $COMMAND_SHOW_KEYWORD in
243 '' | selected | unselected ) ;;
245 message_echo "ERROR: Invalid show $COMMAND_SHOW_SUBJECT keyword [$COMMAND_SHOW_KEYWORD]." >&2
250 _command_parse_args__chk_no_arg $#
252 initrequirements | requirements | initdependents | dependents | conflict_files | status | errormessage )
253 _command_parse_args__chk_glob_args $#
256 message_echo "ERROR: Invalid subject [$COMMAND_SHOW_SUBJECT]." >&2
262 COMMAND_DO_MODE=$COMMAND_MODE
265 temp_warn_obsolete_temp_db >&2
266 _command_parse_args__chk_no_arg $#
269 COMMAND_DO_MODE=${1:-all}
271 case $COMMAND_DO_MODE in
274 message_echo "ERROR: Invalid operation mode [$COMMAND_DO_MODE]." >&2
279 temp_warn_obsolete_temp_db >&2
280 _command_parse_args__chk_no_arg $#
281 if [ "$COMMAND_DO_MODE" = prepare ]
283 COMMAND_RESTART=prepare
289 message_echo "ERROR: Invalid command [$COMMAND_MODE]." >&2
293 COMMAND_SHIFT=$(($num_args_init - $#))
296 # ============= Notify that option settings are reset =============
297 command_exec_without_pkgtools__notify_reset_options ()
299 message_echo "NOTE: Option settings are ignored (because of no effect) and reset."
302 # ============= Execute command operations which do not need package tools =============
303 command_all_exec_without_pkgtools ()
306 case $COMMAND_MODE in
308 command_exec_without_pkgtools__notify_reset_options
309 case $COMMAND_MODE in
311 message_echo "Starting to clean up the temporary database..."
312 database_maintain_clean_all
315 message_echo "Starting to load the temporary database from the archive..."
316 database_maintain_load "$COMMAND_LOAD_FILE"
325 # ============= Execute command operations which are irrespective of option settings =============
326 command_all_exec_irrespective_of_saved_options ()
328 local arcfile origins_match pkgs_match
330 case $COMMAND_MODE in
332 _command_exec_irrespective_of_saved_options__notify_ignored_options
333 command_flexconf_update_ok "$@"
336 taboo | freeze | need | noneed )
337 _command_exec_irrespective_of_saved_options__notify_ignored_options
338 mkdir -p "${DBDIR}/journal"
339 echo "$@" >> ${DBDIR}/journal/$COMMAND_MODE
340 case $COMMAND_MODE in
342 command_flexconf_update_taboo "$@"
345 command_flexconf_update_freeze "$@"
348 program_deregister_stage_complete DETERMINE_SPECIFIED_TARGETS
349 program_deregister_stage_complete ALL_COMPLETE
350 command_flexconf_update_need "$@"
353 program_deregister_stage_complete INSPECT_PRIMARY_LEAF_PORTS
354 program_deregister_stage_complete ALL_COMPLETE
355 command_flexconf_update_noneed "$@"
361 case $COMMAND_OPERATION in
363 if ! deinstall_select_leaf_ports_to_delete force
367 message_echo "INFO: No leaf port is found."
370 message_echo "INFO: Leaf ports are undefined because requirements of some ports are not fully inspected."
374 program_deregister_stage_complete COLLECT_LEAF_PORTS_TO_DELETE
375 program_deregister_stage_complete ALL_COMPLETE
379 if ! deinstall_select_obsolete_ports_to_delete force
383 message_echo "INFO: No obsolete package is found."
387 program_deregister_stage_complete COLLECT_OBSOLETE_PORTS_TO_DELETE
388 program_deregister_stage_complete ALL_COMPLETE
395 _command_exec_irrespective_of_saved_options__notify_ignored_options
396 arcfile=`realpath "$COMMAND_SAVE_DIR"`/${APPNAME}_`date +%Y%m%d_%H%M%S`.tar.gz
397 message_echo "Starting to save the temporary database as [$arcfile]..."
398 database_maintain_save "$arcfile"
403 _command_exec_irrespective_of_saved_options__notify_ignored_options
404 message_echo "Evaluated flavored port origins are as follows:"
405 origins_match=`pkgsys_eval_ports_glob "$@"`
406 if [ -n "$origins_match" ]
408 message_echo "Evaluated flavored port origins are as follows:"
410 message_echo "No matching flavored port origin is found."
412 echo "$origins_match"
416 _command_exec_irrespective_of_saved_options__notify_ignored_options
417 message_echo "Evaluated installed package are as follows:"
418 pkgs_match=`pkgsys_eval_ports_glob "$@" | while read origin
420 pkgsys_get_installed_pkg_from_origin "$origin"
422 if [ -n "$pkgs_match" ]
424 message_echo "Evaluated installed package are as follows:"
427 message_echo "ERROR: No matching package is installed." >&2
432 reconf | rmconf | forget | escape | restore | pkgsanity | packupgrade )
433 _command_exec_irrespective_of_saved_options__notify_ignored_options
434 case $COMMAND_MODE in
436 command_pkgs_port_option_conf "$@"
442 command_pkgs_escape "$@"
445 command_pkgs_restore "$@"
448 command_pkgs_pkgsanity "$@"
451 command_pkgs_packupgrade
458 command_do_redo__command_all_exec_irrespective_of_saved_options
463 # ============= Execute command operations which should be done without upgrade of tools =============
464 command_all_exec_before_tools_upgrade ()
466 local glob origins errno
468 case $COMMAND_MODE in
470 message_echo "Starting to reset the temporary database by preserving the initial snapshot of installed packages..."
471 if [ ! -d "${DBDIR}" ]
473 message_echo "INFO: No temporary database is built yet."
475 database_maintain_reset "$COMMAND_OPERATION"
476 message_echo "INFO: Option settings and taboo/freeze/need/noneed lists are preserved."
490 command_pkgs_make_ports "$@"
495 # ============= Execute command operations which must be done before the database construction =============
496 command_all_exec_before_build_database ()
498 case $COMMAND_MODE in
500 command_do_do__command_all_exec_before_build_database
503 command_do_redo__command_all_exec_before_build_database
508 # ============= Execute command operations of database construction =============
509 command_all_exec_build_database ()
511 case $COMMAND_MODE in
518 # ============= Execute command operations which must be done before the main process =============
519 command_all_exec_before_main ()
521 case $COMMAND_MODE in
523 case $COMMAND_DO_MODE in
525 command_do_end_at_prepare_complete
533 # ============= Execute command operations as the main process =============
534 command_all_exec_main ()
536 case $COMMAND_MODE in
539 command_do_ending_process