From 3f722d851657d53aed215ed87e3f432977b0696f Mon Sep 17 00:00:00 2001 From: Mamoru Sakaue / MwGhennndo Date: Wed, 25 Jul 2018 17:49:55 +0800 Subject: [PATCH] [NEW] auto command is added to portsreinstall-chroot(8). Changes to be committed: modified: bin/portsreinstall modified: bin/portsreinstall-chroot modified: lib/chroot/libcommand.sh modified: lib/chroot/libcommand_do.sh modified: lib/chroot/libusage.sh modified: lib/libdatabase_maintain.sh modified: lib/libfs.sh modified: lib/libmain.sh modified: man/portsreinstall-chroot.8 modified: man/portsreinstall.8 modified: share/bin/portsreinstall-chroot-mount modified: share/bin/portsreinstall-upgrade --- bin/portsreinstall | 1 + bin/portsreinstall-chroot | 1 + lib/chroot/libcommand.sh | 13 +++- lib/chroot/libcommand_do.sh | 108 +++++++++++++++++++++++++++------- lib/chroot/libusage.sh | 2 +- lib/libdatabase_maintain.sh | 6 ++ lib/libfs.sh | 3 +- lib/libmain.sh | 2 +- man/portsreinstall-chroot.8 | 8 ++- man/portsreinstall.8 | 2 + share/bin/portsreinstall-chroot-mount | 1 + share/bin/portsreinstall-upgrade | 1 + 12 files changed, 123 insertions(+), 25 deletions(-) diff --git a/bin/portsreinstall b/bin/portsreinstall index 0f9bcc1..ac02883 100755 --- a/bin/portsreinstall +++ b/bin/portsreinstall @@ -56,6 +56,7 @@ PKGTOOLSCONF=${ETCDIR}/pkgtools.conf main_set_version misc_init_vardefs temp_trap_init +database_maintain_reset_execflag # ================================================== # ========= PARSING OPTIONS AND ARGUMENTS ========== diff --git a/bin/portsreinstall-chroot b/bin/portsreinstall-chroot index 07f267a..2d0caeb 100755 --- a/bin/portsreinstall-chroot +++ b/bin/portsreinstall-chroot @@ -61,6 +61,7 @@ PKGTOOLSCONF=${ETCDIR}/pkgtools.conf main_set_version misc_init_vardefs temp_trap_init +database_maintain_reset_execflag # ================================================== # ========= PARSING OPTIONS AND ARGUMENTS ========== diff --git a/lib/chroot/libcommand.sh b/lib/chroot/libcommand.sh index 884907b..b9133eb 100644 --- a/lib/chroot/libcommand.sh +++ b/lib/chroot/libcommand.sh @@ -54,6 +54,8 @@ command_all_parse_args () esac _command_parse_args__chk_no_arg $# ;; + auto ) + ;; do | mount | unmount | enter | sync | options ) misc_chk_privilege _command_parse_args__chk_no_arg $# @@ -119,7 +121,16 @@ command_all_exec_main () { case $COMMAND_MODE in do) - command_do_main + command_do_pre + command_do_chroot_enter_if_incomplete + command_do_post + command_do_ending_process + ;; + auto) + shift || : + command_do_pre + command_do_auto_if_incomplete "$@" + command_do_post command_do_ending_process ;; esac diff --git a/lib/chroot/libcommand_do.sh b/lib/chroot/libcommand_do.sh index 20efd64..f7dea4e 100644 --- a/lib/chroot/libcommand_do.sh +++ b/lib/chroot/libcommand_do.sh @@ -13,10 +13,22 @@ command_do_chk_build_completion () [ -e "$opt_basedir/builder/${DBDIR_PROG}"/stage.complete/ALL_COMPLETE ] } +# ============= Check whether the termination of portsreinstall at the chroot environment was a unionfs error ============= +command_do_chk_unionfs_error_at_chroot () +{ + [ -e "$opt_basedir/builder/${DBDIR_PROG}"/execflag/unionfs_error ] +} + +# ============= Get the recent chroot exit status of the builder chroot environment ============= +command_do_get_recent_chroot_exit_status () +{ + cat "${DBDIR}/recent_exit_status" +} + # ============= Enter the guest ============= command_do_chroot_enter () { - local shellcmd + local shellcmd exitstatus message_cat < ${DBDIR}/recent_exit_status + return $exitstatus +} + +# ============= Enter the guest and execute portsreinstall(8) automatically ============= +command_do_chroot_auto () +{ + local exitstatus + [ $opt_batch_mode = yes ] && opt_quiet='-a ' + message_cat < ${DBDIR}/recent_exit_status + return $exitstatus } # ============= Update of the files affecting package installation of the host environment ============= @@ -99,20 +132,9 @@ command_do_chroot_cleanup () program_exec_and_record_completion CLEANUP_GUEST } -# ============= Enter the chroot environment ============= -command_do_chroot_enter_if_incomplete () +# ============= Common process after exiting from the chroot environment ============= +command_do_chroot_postprocess () { - local PROGRAM_DEPENDS - command_do_chk_build_completion || program_deregister_stage_complete UPGRADE_GUEST - PROGRAM_DEPENDS='CLEANUP_GUEST' - _program_exec_and_record_completion__operation () - { - message_echo - if ! command_do_chroot_enter - then - message_echo "INFO: The last exit status in the builder chroot environment was non-zero." >&2 - exit 1 - fi if ! command_do_chk_build_completion then message_echo "ERROR: Exited from the builder chroot environment without completing the build." >&2 @@ -125,10 +147,55 @@ command_do_chroot_enter_if_incomplete () message_echo "INFO: Terminated because the continuation is stopped by the user." exit 1 fi +} + +# ============= Enter the chroot environment ============= +command_do_chroot_enter_if_incomplete () +{ + local PROGRAM_DEPENDS + command_do_chk_build_completion || program_deregister_stage_complete UPGRADE_GUEST + PROGRAM_DEPENDS='CLEANUP_GUEST' + _program_exec_and_record_completion__operation () + { + local exitstatus + message_echo + if ! command_do_chroot_enter + then + exitstatus=`command_do_get_recent_chroot_exit_status` + message_echo "INFO: The last exit status in the builder chroot environment was non-zero." >&2 + command_do_chk_unionfs_error_at_chroot && \ + message_echo "INFO: Executing ${APPNAME} again may be sufficient for the troubleshooting." >&2 + exit $exitstatus + fi + command_do_chroot_postprocess } program_exec_and_record_completion UPGRADE_GUEST } +# ============= Enter the chroot environment and execute portsreinstall automatically ============= +command_do_auto_if_incomplete () +{ + local PROGRAM_DEPENDS + command_do_chk_build_completion || program_deregister_stage_complete UPGRADE_GUEST + PROGRAM_DEPENDS='CLEANUP_GUEST' + _program_exec_and_record_completion__operation () + { + local exitstatus + message_echo + until command_do_chroot_auto "$@" || command_do_chk_unionfs_error_at_chroot + do + message_echo "INFO: Retrying by re-mounting the file systems for the builder chroot environment." >&2 + fs_terminate_if_unmount_unavailable + fs_unmount + fs_mount + done + exitstatus=`command_do_get_recent_chroot_exit_status` + [ "$exitstatus" -gt 0 ] && exit $exitstatus + command_do_chroot_postprocess + } + program_exec_and_record_completion UPGRADE_GUEST "$@" +} + # ============= Pack (re)installed packages at the chroot environment ============= command_do_chroot_pack_update () { @@ -196,8 +263,8 @@ command_do_chroot_update_host_pkgs () program_exec_and_record_completion UPGRADE_HOST } -# ============= Main operation of do/redo ============= -command_do_main () +# ============= Main pre-operation of do/auto ============= +command_do_pre () { # Initial clean up command_do_chroot_cleanup @@ -206,10 +273,11 @@ command_do_main () fs_build_chroot fs_terminate_if_mount_unavailable fs_mount - - # Enter the guest - command_do_chroot_enter_if_incomplete - +} + +# ============= Main post-operation of do/auto ============= +command_do_post () +{ # Pack (re)installed packages at the guest command_do_chroot_pack_update diff --git a/lib/chroot/libusage.sh b/lib/chroot/libusage.sh index dd4f195..91b8a24 100644 --- a/lib/chroot/libusage.sh +++ b/lib/chroot/libusage.sh @@ -34,7 +34,7 @@ USAGE: portsreinstall-chroot [OPTIONS] [--] [command] [ARGUMENTS] command: - do (default) + do (default) | auto [options] [arguments] | enter | mount | unmount | sync diff --git a/lib/libdatabase_maintain.sh b/lib/libdatabase_maintain.sh index 5ee2453..a20f9af 100644 --- a/lib/libdatabase_maintain.sh +++ b/lib/libdatabase_maintain.sh @@ -18,6 +18,12 @@ database_maintain_clean_all () rm -rf "${DBDIR}" } +# ============= Reset the execution result flags ============= +database_maintain_reset_execflag () +{ + rm -rf "${DBDIR}/execflag" +} + # ============= Load a temporary database from an archive ============= database_maintain_load () { diff --git a/lib/libfs.sh b/lib/libfs.sh index 9dc703a..13f6383 100644 --- a/lib/libfs.sh +++ b/lib/libfs.sh @@ -190,7 +190,8 @@ fs_fix_unionfs_image_if_hidden () if [ -n "$needlepath_lowest_exist" ] && df "$needlepath_lowest_exist" | sed 1d | grep -q '^:' then message_echo "ERROR: Failed to recover a lost mandatory file, probably due to the bug of unionfs: $needlepath" >&2 - message_echo "Reboot, or umount -A in the single user mode may be needed for the troubleshooting." >&2 + mkdir -p "${DBDIR}/execflag" + touch "${DBDIR}/execflag/unionfs_error" else message_echo "ERROR: Failed to recover a lost mandatory file due to unknown reasons: $needlepath" >&2 fi diff --git a/lib/libmain.sh b/lib/libmain.sh index 0266c3e..6c32522 100644 --- a/lib/libmain.sh +++ b/lib/libmain.sh @@ -12,7 +12,7 @@ main_set_version () MYVERSION=4.0.1 COMPATIBLE_VERSIONS='^(4\.[0]\.[0-1])$' # Template for development versions - MYVERSION=4.0.0+toward_4.0.1_20180724234945 + MYVERSION=4.0.0+toward_4.0.1_20180725174853 COMPATIBLE_VERSIONS='^(4\.[0]\.[0-1]]|4\.[0]\.[0]+(|\+toward_4\.[0]\.[1]+_[0-9]+))$' } diff --git a/man/portsreinstall-chroot.8 b/man/portsreinstall-chroot.8 index 6511bee..3fb5890 100644 --- a/man/portsreinstall-chroot.8 +++ b/man/portsreinstall-chroot.8 @@ -65,7 +65,13 @@ The original configuration file is backed up as \fB/root/.cshrc.bak\-portsreinst One of the following \fIcommands\fR can be given for optional operations or confirmation. .TP \fBdo\fR -(Default) Execute the whole process from creation of a \fBchroot\fR(8) environment to package update of the host system. +(Default) Execute the whole process from creation of a builder \fBchroot\fR(8) environment to package update of the host system. +.TP +\fBauto\fR [\fIoptions\fR] [\fIarguments\fR] +Automatically execute \fBportsreinstall\fR(8) in the whole process from creation of a builder \fBchroot\fR(8) environment to package update of the host system. +If given, \fIoptions\fR and \fIarguments\fR are passed to \fBportsreinstall\fR(8). +If the reinstallation inside the builder \fBchroot\fR(8) environment is marked complete at the exit with zero status from \fBportsreinstall\fR(8) regardless of the options or arguments, the following processes toward the package update of the host system are automatically carried out. +In case of the lost of the lower layer image of unionfs by its bug, the file system will be automatically recovered by re-mounting. .TP \fBenter\fR Just (create, if not yet, and) enter the builder \fBchroot\fR(8) environment. diff --git a/man/portsreinstall.8 b/man/portsreinstall.8 index c50794a..d3e369c 100644 --- a/man/portsreinstall.8 +++ b/man/portsreinstall.8 @@ -1079,6 +1079,8 @@ Configuration file of \fBportupgrade\fR(1). .PP [NEW] Option \fB\-s\fR is added to \fBportsreinstall\-chroot\fR(8). .PP +[NEW] \fBauto\fR command is added to \fBportsreinstall\-chroot\fR(8). +.PP [NEW] BUILDCONFLICT and INSTCONFLICT sections are added to ${LOCALBASE}/etc/portsreinstall.conf. .PP [IMPROVED] The (Re)installation scheme is changed to skip ports whose requirements are not installed at their turns . diff --git a/share/bin/portsreinstall-chroot-mount b/share/bin/portsreinstall-chroot-mount index 90f4bc2..319dd16 100755 --- a/share/bin/portsreinstall-chroot-mount +++ b/share/bin/portsreinstall-chroot-mount @@ -62,6 +62,7 @@ main_set_version misc_init_vardefs temp_trap_init main_load_conf +database_maintain_reset_execflag # ================================================== # ========= PARSING OPTIONS AND ARGUMENTS ========== diff --git a/share/bin/portsreinstall-upgrade b/share/bin/portsreinstall-upgrade index 533152a..9de8537 100644 --- a/share/bin/portsreinstall-upgrade +++ b/share/bin/portsreinstall-upgrade @@ -57,6 +57,7 @@ SAVEDCONF=${ETCDIR}/complete_setup.sh main_set_version misc_init_vardefs temp_trap_init +database_maintain_reset_execflag . "${SAVEDENV}" -- 2.11.0