1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-12 04:15:06 -05:00

bacman: optionally include unmodified backup files when available

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Xyne 2013-09-17 09:19:26 +00:00 committed by Allan McRae
parent 8561ad2256
commit 5ef0c3caa5

View File

@ -27,6 +27,7 @@ shopt -s nullglob
declare -r myname='bacman' declare -r myname='bacman'
declare -r myver='@PACKAGE_VERSION@' declare -r myver='@PACKAGE_VERSION@'
USE_COLOR='y' USE_COLOR='y'
INCLUDE_PACNEW='n'
# Required for fakeroot because options are shifted off the array. # Required for fakeroot because options are shifted off the array.
ARGS=("$@") ARGS=("$@")
@ -37,7 +38,7 @@ m4_include(../scripts/library/output_format.sh)
# #
usage() { usage() {
echo "This program recreates a package using pacman's db and system files" echo "This program recreates a package using pacman's db and system files"
echo "Usage: $myname [--nocolor] <installed package name>" echo "Usage: $myname [--nocolor] [--pacnew] <installed package name>"
echo "Example: $myname kernel26" echo "Example: $myname kernel26"
} }
@ -47,10 +48,17 @@ version() {
echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>' echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>'
} }
if [[ $1 == "--nocolor" ]]; then while [[ ! -z $1 ]]; do
if [[ $1 == "--nocolor" ]]; then
USE_COLOR='n' USE_COLOR='n'
shift shift
fi elif [[ $1 == "--pacnew" ]]; then
INCLUDE_PACNEW='y'
shift
else
break
fi
done
m4_include(../scripts/library/term_colors.sh) m4_include(../scripts/library/term_colors.sh)
@ -143,7 +151,6 @@ cd "$work_dir" || exit 1
# #
msg2 "Copying package files..." msg2 "Copying package files..."
cat "$pkg_dir"/files |
while read i; do while read i; do
if [[ -z $i ]]; then if [[ -z $i ]]; then
continue continue
@ -156,24 +163,55 @@ while read i; do
case "$current" in case "$current" in
%FILES%) %FILES%)
local_file="/$i"
package_file="$work_dir/$i"
if [[ ! -e $local_file ]]; then
warning "package file $local_file is missing"
continue
fi
;;
%BACKUP%)
# Get the MD5 checksum.
original_md5="${i##*$'\t'}"
# Strip the md5sum after the tab.
i="${i%$'\t'*}"
local_file="/$i.pacnew"
package_file="$work_dir/$i"
# Include unmodified .pacnew files.
local_md5="$(md5sum "$local_file" | cut -d' ' -f1)"
if [[ $INCLUDE_PACNEW == 'n' ]] \
|| [[ ! -e $local_file ]] \
|| [[ $local_md5 != $original_md5 ]]; then
# Warn about modified files.
local_md5="$(md5sum "/$i" | cut -d' ' -f1)"
if [[ $local_md5 != $original_md5 ]]; then
warning "package file /$i has been modified"
fi
# Let the normal file be included in the %FILES% list.
continue
fi
;;
*)
continue
;;
esac
ret=0 ret=0
if [[ -e /$i ]]; then bsdtar -cnf - -s'/.pacnew$//' "$local_file" 2> /dev/null | bsdtar -xpf - 2> /dev/null
bsdtar -cnf - "/$i" 2> /dev/null | bsdtar -xpf -
# Workaround to bsdtar not reporting a missing file as an error # Workaround to bsdtar not reporting a missing file as an error
if ! [[ -e $work_dir/$i || -L $work_dir/$i ]]; then if ! [[ -e $package_file || -L $package_file ]]; then
error "unable to add /$i to the package" error "unable to add $local_file to the package"
plain " If your user does not have permssion to read this file then" plain " If your user does not have permission to read this file then"
plain " you will need to run $myname as root" plain " you will need to run $myname as root"
rm -rf "$work_dir" rm -rf "$work_dir"
exit 1 exit 1
fi fi
else done < "$pkg_dir"/files
warning "package file /$i is missing"
fi
;;
esac
done
ret=$? ret=$?
if (( ret )); then if (( ret )); then
@ -256,7 +294,7 @@ while read i; do
# files # files
%BACKUP%) %BACKUP%)
# strip the md5sum after the tab # Strip the md5sum after the tab
echo "backup = ${i%%$'\t'*}" >> .PKGINFO echo "backup = ${i%%$'\t'*}" >> .PKGINFO
;; ;;
esac esac