diff --git a/leaf b/leaf index 2f8e8f0..996c099 100755 --- a/leaf +++ b/leaf @@ -403,10 +403,21 @@ leaf_remove_package() { leaf_error "Package ${PKG_PREFIX}/${PKG_NAME} is NOT installed" } src_preremove - local _file _link _directory + local _file _link _directory _etc_backup_path _relative_path _backup_etc=false + _etc_backup_path="/etc/.leaf_backup/${PKGNAME}_$(date +%Y%m%d%H%M%S)" cat "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/FILES" | while read -r _file; do - rm -fv "${_file}" + if [[ "${_file}" == /etc/* && -f "${_file}" ]]; then + _backup_etc=true + _relative_path="${_file#/etc/}" + mkdir -pv "${_etc_backup_path}/$(dirname "${_relative_path}")" + mv -v "${_file}" "${_etc_backup_path}/${_relative_path}" + else + rm -fv "${file}" + fi done + if [[ "${_backup_etc}" == true ]]; then + leaf_record_message "Found files in /etc, backuped to ${_etc_backup_path}." + fi cat "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/LINKS" | while read -r _link; do [ ! -L "${_link}" ] || rm -fv "${_link}" done