Last active
December 30, 2021 03:14
-
-
Save jfut/a02909aa58e91daf3da0 to your computer and use it in GitHub Desktop.
rpmnew-merge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Merge tool for rpmnew file | |
| # | |
| # @author Jun Futagawa | |
| RPMNEW_FILE="$1" | |
| DEFAULT_FILE="$2" | |
| if [[ -z "${RPMNEW_FILE}" ]]; then | |
| cat << _EOF_ | |
| Usage: | |
| ${0} RPMNEW_FILE [DEFAULT_FILE] | |
| 1. locate .rpmnew | |
| 2. ex) ${0} /etc/sudoers.rpmnew | |
| 3. Copy and paste | |
| _EOF_ | |
| exit 1 | |
| fi | |
| # /etc/sudoers.rpmnew -> /etc/sudoers | |
| TARGET_FILE=$(echo "${RPMNEW_FILE}" | sed "s/.rpmnew$//") | |
| # /etc/sudoers -> sudoers | |
| FILE_NAME=$(echo "${TARGET_FILE}" | xargs basename) | |
| # sudoers -> sudoers.patch | |
| PATCH_NAME="${FILE_NAME}.patch" | |
| if [[ ! -f "${RPMNEW_FILE}" ]]; then | |
| echo "Error: rpmnew file not found: ${RPMNEW_FILE}" | |
| exit 1 | |
| fi | |
| if [[ -z "${DEFAULT_FILE}" ]]; then | |
| # /etc/sudoers.rpmnew | |
| # -> /etc/sudoers.default | |
| DEFAULT_FILE="${TARGET_FILE}.default" | |
| # /etc/sudoers.rpmnew | |
| # -> /etc/logrotate.d.default/sudoers | |
| TEST_FILE="$(dirname "${TARGET_FILE}").default/$(basename "${TARGET_FILE}")" | |
| if [[ -f "${TEST_FILE}" ]]; then | |
| DEFAULT_FILE="${TEST_FILE}" | |
| fi | |
| fi | |
| if [[ ! -f "${DEFAULT_FILE}" ]]; then | |
| echo "Error .default file not found: ${DEFAULT_FILE}" | |
| exit 1 | |
| fi | |
| cat << _EOF_ | |
| # | |
| # current diff | |
| # | |
| # diff "${DEFAULT_FILE}" "${TARGET_FILE}" | |
| _EOF_ | |
| diff "${DEFAULT_FILE}" "${TARGET_FILE}" | |
| echo "" | |
| cat << _EOF_ | |
| # | |
| # diff default rpmnew | |
| # | |
| # diff "${DEFAULT_FILE}" "${TARGET_FILE}.rpmnew" | |
| _EOF_ | |
| diff "${DEFAULT_FILE}" "${TARGET_FILE}.rpmnew" | |
| echo "" | |
| cat << _EOF_ | |
| # | |
| # Start copy and paste | |
| # | |
| # backup | |
| yes | cp -ai "${TARGET_FILE}"{,.prev} | |
| yes | cp -ai "${DEFAULT_FILE}"{,.prev} | |
| yes | cp -ai "${RPMNEW_FILE}"{,.prev} | |
| # patch | |
| diff -urN "${DEFAULT_FILE}" "${TARGET_FILE}" > ~/"${PATCH_NAME}" | |
| yes | mv "${RPMNEW_FILE}" "${DEFAULT_FILE}" | |
| yes | cp -ai "${DEFAULT_FILE}" "${TARGET_FILE}" | |
| patch "${TARGET_FILE}" < ~/"${PATCH_NAME}" | |
| # new diff | |
| diff "${DEFAULT_FILE}" "${TARGET_FILE}" | |
| # | |
| # Stop copy and paste | |
| # | |
| # Failed: restore file | |
| yes | cp -ai "${TARGET_FILE}"{.prev,} | |
| yes | cp -ai "${DEFAULT_FILE}"{.prev,} | |
| yes | cp -ai "${RPMNEW_FILE}"{.prev,} | |
| rm "${TARGET_FILE}"{.orig,.prev,.rej} -f | |
| rm ~/"${PATCH_NAME}" -f | |
| # Success: delete work file | |
| rm "${TARGET_FILE}.prev" -f | |
| rm "${DEFAULT_FILE}.prev" -f | |
| rm "${RPMNEW_FILE}.prev" -f | |
| rm "${RPMNEW_FILE}.orig" -f | |
| rm ~/"${PATCH_NAME}" -f | |
| _EOF_ | |
| echo "" | |
| echo "# Update locate database" | |
| if [[ -f "/etc/cron.daily/mlocate" ]]; then | |
| echo /etc/cron.daily/mlocate | |
| elif [[ -f "/usr/lib/systemd/system/mlocate-updatedb.service" ]]; then | |
| echo systemctl start mlocate-updatedb.service | |
| fi | |
| echo locate .rpmnew | |
| echo rpmnew-merge NEXT_RPMNEW |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment