From 273cc66a8a3173e41b68fd07a0944887a1eb80b9 Mon Sep 17 00:00:00 2001 From: lolilolicon Date: Thu, 6 Oct 2011 14:14:44 +0800 Subject: bacman: small code cleanup This includes: - Quoting fixes. - Drop deprecated mktemp option -p. - Set extglob nullglob shell options at the top. - Use extended globbing instead of regex to match %HEADER% in pacman db. Signed-off-by: lolilolicon --- contrib/bacman.in | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'contrib') diff --git a/contrib/bacman.in b/contrib/bacman.in index 93145e48..89d7f619 100755 --- a/contrib/bacman.in +++ b/contrib/bacman.in @@ -20,6 +20,9 @@ # along with this program. If not, see . # +shopt -s extglob +shopt -s nullglob + readonly progname="bacman" readonly progver="0.2.1" @@ -109,8 +112,8 @@ fi # # Begin # -echo Package: ${pkg_namver} -work_dir=$(mktemp -d -p /tmp) +echo "Package: ${pkg_namver}" +work_dir=$(mktemp -d --tmpdir bacman.XXXXXXXXXX) cd "$work_dir" || exit 1 # @@ -124,12 +127,12 @@ while read i; do continue fi - if [[ "$i" =~ %[A-Z]*% ]]; then + if [[ $i == %+([A-Z])% ]]; then current=$i continue fi - case $current in + case "$current" in %FILES%) ret=0 if [[ -e /$i ]]; then @@ -163,6 +166,7 @@ pkg_size=$(du -sk | awk '{print $1 * 1024}') # # .PKGINFO stuff +# TODO adopt makepkg's write_pkginfo() into this or scripts/library # echo Generating .PKGINFO metadata... echo "# Generated by $progname $progver" > .PKGINFO @@ -174,11 +178,11 @@ echo "#" >> .PKGINFO cat "$pkg_dir"/{desc,files} | while read i; do - if [[ -z "$i" ]]; then + if [[ -z $i ]]; then continue; fi - if [[ "$i" =~ %[A-Z]*% ]]; then + if [[ $i == %+([A-Z])% ]]; then current=$i continue fi @@ -273,9 +277,6 @@ esac pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}" ret=0 -# when fileglobbing, we want * in an empty directory to expand to -# the null string rather than itself -shopt -s nullglob # TODO: Maybe this can be set globally for robustness shopt -s -o pipefail bsdtar -cf - $comp_files * | @@ -284,7 +285,7 @@ case "$PKGEXT" in *tar.bz2) bzip2 -c -f ;; *tar.xz) xz -c -z - ;; *tar) cat ;; -esac > ${pkg_file} || ret=$? +esac > "${pkg_file}"; ret=$? if (( ret )); then echo "ERROR: unable to write package to $pkg_dest" -- cgit v1.2.3-24-g4f1b