OSDN Git Service

[BUG FIX] Adding packages sometimes failed due to lack of required packages.
[portsreinstall/current.git] / lib / upgrade / libcommand.sh
1 #!/bin/sh -e
2 # ==============================================================================
3 # portsreinstall library script
4 # Overlay onto lib/libcommand.sh for portsreinstall-upgrade
5 # - Operations of commands as well as check of command line arguments -
6 # Copyright (C) 2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
7 # This software is distributed under the 2-Clause BSD License.
8 # ==============================================================================
9
10 # ============= Check and parse command line arguments =============
11 command_all_parse_args ()
12 {
13         local num_args_init
14         num_args_init=$#
15         COMMAND_RESTART="$@"
16         COMMAND_MODE=${1:-do}
17         shift || :
18         case $COMMAND_MODE in
19         clean )
20                 COMMAND_OPERATION=${1:-normal}
21                 shift || :
22                 case $COMMAND_OPERATION in
23                 normal )
24                         misc_chk_privilege
25                         ;;
26                 esac
27                 _command_parse_args__chk_no_arg $#
28                 ;;
29         do )
30                 misc_chk_privilege
31                 _command_parse_args__chk_no_arg $#
32                 ;;
33         options )
34                 _command_parse_args__chk_no_arg $#
35                 ;;
36         *)
37                 message_echo "ERROR: Invalid command [$COMMAND_MODE]." >&2
38                 exit 1
39                 ;;
40         esac
41         COMMAND_SHIFT=$(($num_args_init - $#))
42 }
43
44 # ============= Execute command operations which do not need package tools =============
45 command_all_exec_without_pkgtools ()
46 {
47         local dbdir_parent 
48         case $COMMAND_MODE in
49         clean )
50                 command_exec_without_pkgtools__notify_reset_options
51                 message_echo "Starting to clean up the temporary database..."
52                 database_maintain_clean_all
53                 message_echo "Done"
54                 exit
55                 ;;
56         esac
57 }
58
59 # ============= Execute command operations which are irrespective of option settings =============
60 command_all_exec_irrespective_of_saved_options ()
61 {
62         case $COMMAND_MODE in
63         options )
64                 options_show_all
65                 exit
66                 ;;
67         esac
68 }
69
70 # ============= Execute command operations as the main process =============
71 command_all_exec_main ()
72 {
73         case $COMMAND_MODE in
74         do )
75                 command_do_main
76                 command_do_ending_process
77                 ;;
78         esac
79 }
80