[arch-projects] [devtools] [PATCH 1/5] checkpkg: Proper quoting, use double brackets
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- checkpkg | 52 ++++++++++++++++++++++++++-------------------------- 1 files changed, 26 insertions(+), 26 deletions(-) diff --git a/checkpkg b/checkpkg index c0b2ceb..ddc14dd 100755 --- a/checkpkg +++ b/checkpkg @@ -1,7 +1,7 @@ #!/bin/bash # Source makepkg.conf; fail if it is not found -if [ -r '/etc/makepkg.conf' ]; then +if [[ -r '/etc/makepkg.conf' ]]; then source '/etc/makepkg.conf' else echo '/etc/makepkg.conf not found!' @@ -9,86 +9,86 @@ else fi # Source user-specific makepkg.conf overrides -if [ -r ~/.makepkg.conf ]; then +if [[ -r ~/.makepkg.conf ]]; then source ~/.makepkg.conf fi strip_url() { - echo $1 | sed 's|^.*://.*/||g' + echo "$1" | sed 's|^.*://.*/||g' } -if [ ! -f PKGBUILD ]; then +if [[ ! -f PKGBUILD ]]; then echo 'This must be run in the directory of a built package.' exit 1 fi . PKGBUILD -if [ "$arch" == 'any' ]; then +if [[ $arch == 'any' ]]; then CARCH='any' fi STARTDIR=$(pwd) TEMPDIR=$(mktemp -d /tmp/checkpkg-script.XXXX) -cd $TEMPDIR +cd "$TEMPDIR" -for _pkgname in ${pkgname[@]}; do - if [ -z ${epoch} ] ; then +for _pkgname in "${pkgname[@]}"; do + if [[ -z ${epoch} ]] ; then pkgfile=${_pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} else pkgfile=${_pkgname}-${epoch}:${pkgver}-${pkgrel}-${CARCH}${PKGEXT} fi - if [ -f "$STARTDIR/$pkgfile" ]; then + if [[ -f "$STARTDIR/$pkgfile" ]]; then ln -s "$STARTDIR/$pkgfile" "$pkgfile" - elif [ -f "$PKGDEST/$pkgfile" ]; then + elif [[ -f "$PKGDEST/$pkgfile" ]]; then ln -s "$PKGDEST/$pkgfile" "$pkgfile" else echo "File \"$pkgfile\" doesn't exist" exit 1 fi - tmp=$(pacman -Spdd --noconfirm $_pkgname) + tmp=$(pacman -Spdd --noconfirm "$_pkgname") - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then echo "Couldn't download previous package for $_pkgname." exit 1 fi pkgurl=$(echo $tmp | rev | cut -d ' ' -f 1 | rev) - oldpkg=$(strip_url $pkgurl) + oldpkg=$(strip_url "$pkgurl") - if [ "$(basename $oldpkg)" = "$(basename $pkgfile)" ]; then + if [[ "$(basename $oldpkg)" = "$(basename $pkgfile)" ]]; then echo "The built package ($_pkgname) is the one in the repo right now!" exit 1 fi - if [ ! -f $oldpkg ]; then + if [[ ! -f $oldpkg ]]; then if echo $pkgurl | grep '^file:///' > /dev/null 2>&1; then ln -s "${pkgurl#file://}" $(basename "${pkgurl#file://}") - elif [ -f "$PKGDEST/$oldpkg" ]; then + elif [[ -f "$PKGDEST/$oldpkg" ]]; then ln -s "$PKGDEST/$oldpkg" "$oldpkg" - elif [ -f "$STARTDIR/$oldpkg" ]; then + elif [[ -f "$STARTDIR/$oldpkg" ]]; then ln -s "$STARTDIR/$oldpkg" "$oldpkg" else - wget --quiet $pkgurl + wget --quiet "$pkgurl" fi fi - bsdtar tf $oldpkg > filelist-$_pkgname-old - bsdtar tf "$pkgfile" > filelist-$_pkgname + bsdtar tf "$oldpkg" > "filelist-$_pkgname-old" + bsdtar tf "$pkgfile" > "filelist-$_pkgname" - sort -o filelist-$_pkgname filelist-$_pkgname - sort -o filelist-$_pkgname-old filelist-$_pkgname-old + sort -o "filelist-$_pkgname" "filelist-$_pkgname" + sort -o "filelist-$_pkgname-old" "filelist-$_pkgname-old" - sdiff -s filelist-$_pkgname-old filelist-$_pkgname + sdiff -s "filelist-$_pkgname-old" "filelist-$_pkgname" - if diff filelist-$_pkgname-old filelist-$_pkgname | grep '\.so' > /dev/null 2>&1; then + if diff "filelist-$_pkgname-old" "filelist-$_pkgname" | grep '\.so' > /dev/null 2>&1; then mkdir -p pkg cd pkg bsdtar xf ../"$pkgfile" > /dev/null - for i in $(diff ../filelist-$_pkgname-old ../filelist-$_pkgname | grep \> | grep '\.so' | awk '{print $2}'); do - echo "${i}: " "$(objdump -p $i | grep SONAME)" + for i in $(diff "../filelist-$_pkgname-old" "../filelist-$_pkgname" | grep \> | grep '\.so' | awk '{print $2}'); do + echo "${i}: " "$(objdump -p "$i" | grep SONAME)" done cd .. else -- 1.7.6
We already use `pacman -Sddp` here which should always only return a single package URL for regular packages. No need to extract the first field of the last line. Also, specify "--print-format '%l'" explicitly to make this consistent even if pacman(8)'s default value changes some day. Use bash parameter expansion instead of sed(1) to extract the file name from the URL. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- checkpkg | 10 ++-------- 1 files changed, 2 insertions(+), 8 deletions(-) diff --git a/checkpkg b/checkpkg index ddc14dd..9d379b7 100755 --- a/checkpkg +++ b/checkpkg @@ -13,10 +13,6 @@ if [[ -r ~/.makepkg.conf ]]; then source ~/.makepkg.conf fi -strip_url() { - echo "$1" | sed 's|^.*://.*/||g' -} - if [[ ! -f PKGBUILD ]]; then echo 'This must be run in the directory of a built package.' exit 1 @@ -47,16 +43,14 @@ for _pkgname in "${pkgname[@]}"; do exit 1 fi - tmp=$(pacman -Spdd --noconfirm "$_pkgname") + pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") if [[ $? -ne 0 ]]; then echo "Couldn't download previous package for $_pkgname." exit 1 fi - pkgurl=$(echo $tmp | rev | cut -d ' ' -f 1 | rev) - - oldpkg=$(strip_url "$pkgurl") + oldpkg=${pkgurl##*://*/} if [[ "$(basename $oldpkg)" = "$(basename $pkgfile)" ]]; then echo "The built package ($_pkgname) is the one in the repo right now!" -- 1.7.6
Use parameter expansion instead of invoking external binaries here. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- checkpkg | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/checkpkg b/checkpkg index 9d379b7..f408267 100755 --- a/checkpkg +++ b/checkpkg @@ -52,14 +52,14 @@ for _pkgname in "${pkgname[@]}"; do oldpkg=${pkgurl##*://*/} - if [[ "$(basename $oldpkg)" = "$(basename $pkgfile)" ]]; then + if [[ ${oldpkg##*/} = ${pkgfile##*/} ]]; then echo "The built package ($_pkgname) is the one in the repo right now!" exit 1 fi if [[ ! -f $oldpkg ]]; then - if echo $pkgurl | grep '^file:///' > /dev/null 2>&1; then - ln -s "${pkgurl#file://}" $(basename "${pkgurl#file://}") + if [[ $pkgurl = file://* ]]; then + ln -s "${pkgurl#file://}" "${pkgurl##file://*/}" elif [[ -f "$PKGDEST/$oldpkg" ]]; then ln -s "$PKGDEST/$oldpkg" "$oldpkg" elif [[ -f "$STARTDIR/$oldpkg" ]]; then -- 1.7.6
The read shell builtin is the proper way to read single lines. Also, simplify grep(1) and awk(1) invocations and use a single awk(1) expression, that supports extracting file names with spaces, instead. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- checkpkg | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/checkpkg b/checkpkg index f408267..2f442c9 100755 --- a/checkpkg +++ b/checkpkg @@ -81,7 +81,7 @@ for _pkgname in "${pkgname[@]}"; do mkdir -p pkg cd pkg bsdtar xf ../"$pkgfile" > /dev/null - for i in $(diff "../filelist-$_pkgname-old" "../filelist-$_pkgname" | grep \> | grep '\.so' | awk '{print $2}'); do + diff "../filelist-$_pkgname-old" "../filelist-$_pkgname" | awk '/>.*\.so/{$1 = ""; print $0}' | while read i; do echo "${i}: " "$(objdump -p "$i" | grep SONAME)" done cd .. -- 1.7.6
No need to do this after we already wrote the package list to a file. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- checkpkg | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-) diff --git a/checkpkg b/checkpkg index 2f442c9..94a7529 100755 --- a/checkpkg +++ b/checkpkg @@ -69,11 +69,8 @@ for _pkgname in "${pkgname[@]}"; do fi fi - bsdtar tf "$oldpkg" > "filelist-$_pkgname-old" - bsdtar tf "$pkgfile" > "filelist-$_pkgname" - - sort -o "filelist-$_pkgname" "filelist-$_pkgname" - sort -o "filelist-$_pkgname-old" "filelist-$_pkgname-old" + bsdtar tf "$oldpkg" | sort > "filelist-$_pkgname-old" + bsdtar tf "$pkgfile" | sort > "filelist-$_pkgname" sdiff -s "filelist-$_pkgname-old" "filelist-$_pkgname" -- 1.7.6
participants (1)
-
Lukas Fleischer