[pacman-dev] Bacman patch
Hi, I have updated bacman with the following changes: * added option "--pacnew" to include unmodified .pacnew BACKUP files in package archive when available (instead of locally modified version) * added warning when modified BACKUP files are included * fixed bug in fakeroot invocation (fakeroot was invoked with shifted argument array, so the --nocolor (and --pacnew) options were lost * removed one unnecessary "cat <file> |" I cloned the pacman git repo to format a patch, but pacman/contrib/bacman.sh.in appears to be outdated (e.g. the shebang is still "#!/bin/bash", even though the current bacman uses "#!/usr/bin/bash"). So, where is the current bacman source? Regards, Xyne
On Mon, Sep 16, 2013 at 04:46:33PM +0000, Xyne wrote:
Hi,
I have updated bacman with the following changes:
* added option "--pacnew" to include unmodified .pacnew BACKUP files in package archive when available (instead of locally modified version)
* added warning when modified BACKUP files are included
* fixed bug in fakeroot invocation (fakeroot was invoked with shifted argument array, so the --nocolor (and --pacnew) options were lost
* removed one unnecessary "cat <file> |"
I cloned the pacman git repo to format a patch, but pacman/contrib/bacman.sh.in appears to be outdated (e.g. the shebang is still "#!/bin/bash", even though the current bacman uses "#!/usr/bin/bash").
So, where is the current bacman source?
Regards, Xyne
You've found the current source. We change the shebang during the build process.
Here is the patch with the aforementioned changes. This allows the optional creation of packages with the unmodified pacnew files when they are available. This is the first time that I'm using git send-email. Let me know what I need to fix if anything is incorrect. Xyne (1): bacman: optionally include unmodified BACKUP files and fix other errors contrib/bacman.sh.in | 85 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 22 deletions(-) -- 1.8.4
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@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 + 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 - 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 + + # 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" + 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 -- 1.8.4
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@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
On 17/09/13 06:49, Xyne wrote:
Here is the patch with the aforementioned changes. This allows the optional creation of packages with the unmodified pacnew files when they are available.
This is the first time that I'm using git send-email. Let me know what I need to fix if anything is incorrect.
I will give your patch a review next, but a few tips for you: 1) If you are sending a single patch, there is no need for a cover letter. Just put comments below the "---" line in the patch. 2) A patch should try and do one thing. That makes them easier to review. It also means we can accept parts while waiting on other parts to be revised if necessary. 3) Careful with whitespace.
Xyne (1): bacman: optionally include unmodified BACKUP files and fix other errors
contrib/bacman.sh.in | 85 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 22 deletions(-)
Take 2. The previous patch has been split in 3. All of Allan's suggestions have been included. Xyne (3): bacman: pass unshifted arguments to fakeroot bacman: update copyright information in version function bacman: optionally include unmodified backup files when available contrib/bacman.sh.in | 85 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 22 deletions(-) -- 1.8.4
--- contrib/bacman.sh.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 5435e40..30db686 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -27,6 +27,8 @@ shopt -s nullglob declare -r myname='bacman' declare -r myver='@PACKAGE_VERSION@' USE_COLOR='y' +# Required for fakeroot because options are shifted off the array. +ARGS=("$@") m4_include(../scripts/library/output_format.sh) @@ -71,7 +73,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" -- 1.8.4
--- contrib/bacman.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index 30db686..ca4d88d 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -44,6 +44,7 @@ usage() { 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@archlinux.org>' } if [[ $1 == "--nocolor" ]]; then -- 1.8.4
--- contrib/bacman.sh.in | 80 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in index ca4d88d..5d2210a 100644 --- a/contrib/bacman.sh.in +++ b/contrib/bacman.sh.in @@ -27,6 +27,7 @@ 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=("$@") @@ -37,7 +38,7 @@ 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" } @@ -47,10 +48,17 @@ version() { echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev@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) @@ -143,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 @@ -156,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 + 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 - 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 + + # 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 permission to read this file then" + plain " you will need to run $myname as root" + rm -rf "$work_dir" + exit 1 + fi +done < "$pkg_dir"/files ret=$? if (( ret )); then @@ -256,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 -- 1.8.4
On 17/09/13 19:19, Xyne wrote:
Take 2. The previous patch has been split in 3. All of Allan's suggestions have been included.
Xyne (3): bacman: pass unshifted arguments to fakeroot bacman: update copyright information in version function bacman: optionally include unmodified backup files when available
contrib/bacman.sh.in | 85 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 22 deletions(-)
Changes all like fine to me now. A
On 09/16/13 at 04:46pm, Xyne wrote:
Hi,
I have updated bacman with the following changes:
* added option "--pacnew" to include unmodified .pacnew BACKUP files in package archive when available (instead of locally modified version)
* added warning when modified BACKUP files are included
* fixed bug in fakeroot invocation (fakeroot was invoked with shifted argument array, so the --nocolor (and --pacnew) options were lost
* removed one unnecessary "cat <file> |"
I cloned the pacman git repo to format a patch, but pacman/contrib/bacman.sh.in appears to be outdated (e.g. the shebang is still "#!/bin/bash", even though the current bacman uses "#!/usr/bin/bash").
So, where is the current bacman source?
Regards, Xyne
contrib/bacman.sh.in is it. The shebang is changed in the Makefil. apg
participants (4)
-
Allan McRae
-
Andrew Gregory
-
Dave Reisner
-
Xyne