summaryrefslogtreecommitdiffstats
path: root/contrib/bacman.in
diff options
context:
space:
mode:
authorlolilolicon <lolilolicon@gmail.com>2011-10-06 08:14:44 +0200
committerDan McGee <dan@archlinux.org>2011-10-06 09:10:25 +0200
commit273cc66a8a3173e41b68fd07a0944887a1eb80b9 (patch)
treeb1977e8a443f2fd3633a04de60b8b62b43a55ec7 /contrib/bacman.in
parent7e5bbf0387203a078bf901d730f063f10c7c1f2c (diff)
downloadpacman-273cc66a8a3173e41b68fd07a0944887a1eb80b9.tar.gz
pacman-273cc66a8a3173e41b68fd07a0944887a1eb80b9.tar.xz
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 <lolilolicon@gmail.com>
Diffstat (limited to 'contrib/bacman.in')
-rwxr-xr-xcontrib/bacman.in21
1 files changed, 11 insertions, 10 deletions
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 <http://www.gnu.org/licenses/>.
#
+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"