OSDN Git Service

Fixed a bug that obsolete or moved ports were not inspected. For this purpose, the...
[portsreinstall/current.git] / lib / chroot / libcommand.sh
1 #!/bin/sh -e
2 # ==============================================================================
3 # portsreinstall library script
4 # Overlay onto lib/libcommand.sh for portsreinstall-chroot
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 the necessity of opening notice =============
11 command_all_chk_need_opening_notice ()
12 {
13         false
14 }
15
16 # ============= Execute command operations before getting the temporary database ready =============
17 command_all_exec_before_db_creation ()
18 {
19         local COMMAND_RESTART COMMAND_MODE COMMAND_OPERATION
20         COMMAND_RESTART="$@"
21         COMMAND_MODE=${1:-do}
22         shift || :
23         case $COMMAND_MODE in
24         clean )
25                 COMMAND_OPERATION=${1:-normal}
26                 shift || :
27                 _command_parse_args__chk_no_arg $#
28                 case $COMMAND_OPERATION in
29                 force )
30                         database_maintain_clean_force
31                         exit
32                         ;;
33                 esac
34                 ;;
35         esac
36 }
37
38 # ============= Check and parse command line arguments =============
39 command_all_parse_args ()
40 {
41         local num_args_init
42         num_args_init=$#
43         COMMAND_RESTART="$@"
44         COMMAND_MODE=${1:-do}
45         shift || :
46         case $COMMAND_MODE in
47         clean )
48                 COMMAND_OPERATION=${1:-normal}
49                 shift || :
50                 case $COMMAND_OPERATION in
51                 normal )
52                         misc_chk_privilege
53                         ;;
54                 esac
55                 _command_parse_args__chk_no_arg $#
56                 ;;
57         auto )
58                 COMMAND_RESTART=$COMMAND_MODE
59                 misc_chk_privilege
60                 ;;
61         enter )
62                 fs_inspect_fs_privilege
63                 if ! fs_chk_mount > /dev/null && ! ( misc_chk_privilege )
64                 then
65                         message_echo "ERROR: The file system of the builder chroot environment is not yet ready." >&2
66                         exit 1
67                 fi
68                 _command_parse_args__chk_no_arg $#
69                 ;;
70         mount )
71                 fs_inspect_fs_privilege
72                 if fs_chk_mount > /dev/null
73                 then
74                         message_echo "INFO: Already mounted"
75                         exit
76                 fi
77                 misc_chk_privilege
78                 _command_parse_args__chk_no_arg $#
79                 ;;
80         unmount )
81                 fs_inspect_fs_privilege
82                 if fs_chk_unmount > /dev/null
83                 then
84                         message_echo "INFO: Already unmounted"
85                         exit
86                 fi
87                 misc_chk_privilege
88                 _command_parse_args__chk_no_arg $#
89                 ;;
90         do | sync | destroy )
91                 misc_chk_privilege
92                 _command_parse_args__chk_no_arg $#
93                 ;;
94         options )
95                 _command_parse_args__chk_no_arg $#
96                 ;;
97         *)
98                 message_echo "ERROR: Invalid command [$COMMAND_MODE]." >&2
99                 exit 1
100                 ;;
101         esac
102         COMMAND_SHIFT=$(($num_args_init - $#))
103 }
104
105 # ============= Execute command operations which should be done without upgrade of tools =============
106 command_all_exec_before_tools_upgrade ()
107 {
108         case $COMMAND_MODE in
109         clean )
110                 database_maintain_clean
111                 [ $opt_no_opening_message = yes ] || message_echo "Done"
112                 exit
113                 ;;
114         destroy )
115                 database_maintain_destroy
116                 [ $opt_no_opening_message = yes ] || message_echo "Done"
117                 exit
118                 ;;
119         unmount )
120                 fs_unmount
121                 exit
122                 ;;
123         mount )
124                 command_do_chroot_cleanup
125                 fs_build_chroot
126                 fs_mount
127                 temp_reset_termination_messages_common
128                 [ $opt_no_opening_message = yes ] || message_echo "Done"
129                 exit
130                 ;;
131         enter )
132                 if misc_chk_privilege
133                 then
134                         command_do_chroot_cleanup
135                         fs_build_chroot
136                         fs_mount
137                 elif ! fs_chk_mount > /dev/null
138                 then
139                         message_echo "ERROR: The file system of the builder chroot environment is not ready." >&2
140                         exit 1
141                 fi
142                 command_do_chroot_enter_shell
143                 if misc_chk_privilege
144                 then
145                         message_echo "Exited successfully"
146                         program_deregister_stage_complete UPGRADE_GUEST
147                 fi
148                 exit
149                 ;;
150         sync )
151                 command_do_chroot_cleanup
152                 fs_build_chroot
153                 fs_mount
154                 command_do_update_host_files
155                 [ $opt_no_opening_message = yes ] || message_echo "Done"
156                 exit
157                 ;;
158         esac
159 }
160
161 # ============= Execute command operations as the main process =============
162 command_all_exec_main ()
163 {
164         case $COMMAND_MODE in
165         do | auto )
166                 command_do_chroot_cleanup
167                 command_do_starter_portsnap
168                 command_do_starter_pkg
169                 command_do_pre
170                 command_do_starter_clean
171                 command_do_main_init_resinst
172                 command_do_chroot_enter_if_incomplete "$@"
173                 command_do_post
174                 command_do_ending_process
175                 ;;
176         esac
177 }