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>
This commit is contained in:
parent
7e5bbf0387
commit
273cc66a8a
|
@ -20,6 +20,9 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
shopt -s extglob
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
readonly progname="bacman"
|
readonly progname="bacman"
|
||||||
readonly progver="0.2.1"
|
readonly progver="0.2.1"
|
||||||
|
|
||||||
|
@ -109,8 +112,8 @@ fi
|
||||||
#
|
#
|
||||||
# Begin
|
# Begin
|
||||||
#
|
#
|
||||||
echo Package: ${pkg_namver}
|
echo "Package: ${pkg_namver}"
|
||||||
work_dir=$(mktemp -d -p /tmp)
|
work_dir=$(mktemp -d --tmpdir bacman.XXXXXXXXXX)
|
||||||
cd "$work_dir" || exit 1
|
cd "$work_dir" || exit 1
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -124,12 +127,12 @@ while read i; do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$i" =~ %[A-Z]*% ]]; then
|
if [[ $i == %+([A-Z])% ]]; then
|
||||||
current=$i
|
current=$i
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $current in
|
case "$current" in
|
||||||
%FILES%)
|
%FILES%)
|
||||||
ret=0
|
ret=0
|
||||||
if [[ -e /$i ]]; then
|
if [[ -e /$i ]]; then
|
||||||
|
@ -163,6 +166,7 @@ pkg_size=$(du -sk | awk '{print $1 * 1024}')
|
||||||
|
|
||||||
#
|
#
|
||||||
# .PKGINFO stuff
|
# .PKGINFO stuff
|
||||||
|
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
|
||||||
#
|
#
|
||||||
echo Generating .PKGINFO metadata...
|
echo Generating .PKGINFO metadata...
|
||||||
echo "# Generated by $progname $progver" > .PKGINFO
|
echo "# Generated by $progname $progver" > .PKGINFO
|
||||||
|
@ -174,11 +178,11 @@ echo "#" >> .PKGINFO
|
||||||
|
|
||||||
cat "$pkg_dir"/{desc,files} |
|
cat "$pkg_dir"/{desc,files} |
|
||||||
while read i; do
|
while read i; do
|
||||||
if [[ -z "$i" ]]; then
|
if [[ -z $i ]]; then
|
||||||
continue;
|
continue;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$i" =~ %[A-Z]*% ]]; then
|
if [[ $i == %+([A-Z])% ]]; then
|
||||||
current=$i
|
current=$i
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
@ -273,9 +277,6 @@ esac
|
||||||
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
|
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
|
||||||
ret=0
|
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
|
# TODO: Maybe this can be set globally for robustness
|
||||||
shopt -s -o pipefail
|
shopt -s -o pipefail
|
||||||
bsdtar -cf - $comp_files * |
|
bsdtar -cf - $comp_files * |
|
||||||
|
@ -284,7 +285,7 @@ case "$PKGEXT" in
|
||||||
*tar.bz2) bzip2 -c -f ;;
|
*tar.bz2) bzip2 -c -f ;;
|
||||||
*tar.xz) xz -c -z - ;;
|
*tar.xz) xz -c -z - ;;
|
||||||
*tar) cat ;;
|
*tar) cat ;;
|
||||||
esac > ${pkg_file} || ret=$?
|
esac > "${pkg_file}"; ret=$?
|
||||||
|
|
||||||
if (( ret )); then
|
if (( ret )); then
|
||||||
echo "ERROR: unable to write package to $pkg_dest"
|
echo "ERROR: unable to write package to $pkg_dest"
|
||||||
|
|
Loading…
Reference in New Issue