[pacman-dev] [PATCH] bacman: optionally include unmodified BACKUP files and fix other errors

Allan McRae allan at archlinux.org
Mon Sep 16 23:20:12 EDT 2013


On 17/09/13 06:49, Xyne wrote:
> Add option "--pacnew" to include unmodified .pacnew BACKUP files in package archive when available (instead of locally modified version).
> 
> Add warning when modified BACKUP files are included.
> 
> Fix bug in fakeroot invocation. During argument parsing, option flags are
> shifted off of the argument array. This shifted array was previously passed to
> fakeroot resulting in the omission of options such as "--nocolor". Avoid this by
> passing an unshifted copy of the argument array.
> 
> Replace unnecessary "cat ... |" with "< ..."
> 
> Update "version" function to match copyright data at top of file.
> ---
>  contrib/bacman.sh.in | 85 ++++++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 63 insertions(+), 22 deletions(-)
> 
> diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
> index 5435e40..bcc0e73 100644
> --- a/contrib/bacman.sh.in
> +++ b/contrib/bacman.sh.in
> @@ -27,6 +27,9 @@ shopt -s nullglob
>  declare -r myname='bacman'
>  declare -r myver='@PACKAGE_VERSION@'
>  USE_COLOR='y'
> +INCLUDE_PACNEW='n'
> +# Required for fakeroot because options are shifted off the array.
> +ARGS=("$@")
>  
>  m4_include(../scripts/library/output_format.sh)
>  
> @@ -35,19 +38,27 @@ m4_include(../scripts/library/output_format.sh)
>  #
>  usage() {
>  	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"
>  }
>  
>  version() {
>  	printf "%s %s\n" "$myname" "$myver"
>  	echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>'
> +	echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev at archlinux.org>'
>  }
>  
> -if [[ $1 == "--nocolor" ]]; then
> -	USE_COLOR='n'
> -	shift
> -fi
> +while [[ ! -z $1 ]]; do
> +	if [[ $1 == "--nocolor" ]]; then
> +		USE_COLOR='n'
> +		shift
> +	elif [[ $1 == "--pacnew" ]]; then
> +		INCLUDE_PACNEW='y'
> +		shift
> +	else
> +		break
> +	fi
> +done
>  
>  m4_include(../scripts/library/term_colors.sh)
>  
> @@ -71,7 +82,7 @@ if (( EUID )); then
>  	if [[ -f /usr/bin/fakeroot ]]; then
>  		msg "Entering fakeroot environment"
>  		export INFAKEROOT="1"
> -		/usr/bin/fakeroot -u -- "$0" "$@"
> +		/usr/bin/fakeroot -u -- "$0" "${ARGS[@]}"
>  		exit $?
>  	else
>  		warning "installing fakeroot or running $myname as root is required to"
> @@ -140,7 +151,6 @@ cd "$work_dir" || exit 1
>  #
>  msg2 "Copying package files..."
>  
> -cat "$pkg_dir"/files |
>  while read i; do
>  	if [[ -z $i ]]; then
>  		continue
> @@ -153,24 +163,55 @@ while read i; do
>  
>  	case "$current" in
>  		%FILES%)
> -			ret=0
> -			if [[ -e /$i ]]; then
> -				bsdtar -cnf - "/$i" 2> /dev/null | bsdtar -xpf -
> -
> -				# Workaround to bsdtar not reporting a missing file as an error
> -				if ! [[ -e $work_dir/$i || -L $work_dir/$i ]]; then
> -					error "unable to add /$i to the package"
> -					plain "       If your user does not have permssion to read this file then"
> -					plain "       you will need to run $myname as root"
> -					rm -rf "$work_dir"
> -					exit 1
> +			local_file="/$i"
> +			package_file="$work_dir/$i"
> +
> +			if [[ ! -e $local_file ]]; then
> +				warning "package file $local_file is missing"
> +        continue

Whitespace

> +			fi
> +			;;
> +
> +		%BACKUP%)
> +			# Get the MD5 checksum.
> +			original_md5="${i##*$'\t'}"
> +			# Strip the md5sum after the tab.
> +			i="${i%%$'\t'*}"

You only want one "%" here.

> +			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
> -			else
> -				warning "package file /$i is missing"
> +				# Let the normal file be included in the %FILES% list.
> +				continue
>  			fi
>  			;;
> +
> +		*)
> +			continue
> +			;;
>  	esac
> -done
> +
> +	ret=0
> +	bsdtar -cnf - -s'/.pacnew//' "$local_file" 2> /dev/null | bsdtar -xpf - 2> /dev/null

-s'/.pacnew$//'

> +
> +	# Workaround to bsdtar not reporting a missing file as an error
> +	if ! [[ -e $package_file || -L $package_file ]]; then
> +		error "unable to add $local_file to the package"
> +		plain "       If your user does not have permssion to read this file then"

Can you fix the typo here too.

> +		plain "       you will need to run $myname as root"
> +		rm -rf "$work_dir"
> +		exit 1
> +	fi
> +done < "$pkg_dir"/files
>  
>  ret=$?
>  if (( ret )); then
> @@ -253,7 +294,7 @@ while read i; do
>  
>  		# files
>  		%BACKUP%)
> -			# strip the md5sum after the tab
> +			# Strip the md5sum after the tab
>  			echo "backup = ${i%%$'\t'*}"   >> .PKGINFO
>  			;;
>  	esac
> 



More information about the pacman-dev mailing list