mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
bacman: bashify using [[ ]] and (( ))
Another style change. The [[ expression ]] form is particularly cleaner, safer and more powerful than the [ expression ] form. Signed-off-by: lolilolicon <lolilolicon@gmail.com>
This commit is contained in:
parent
3f937c8404
commit
7e5bbf0387
@ -26,23 +26,23 @@ readonly progver="0.2.1"
|
|||||||
#
|
#
|
||||||
# User Friendliness
|
# User Friendliness
|
||||||
#
|
#
|
||||||
function usage(){
|
usage() {
|
||||||
echo "This program recreates a package using pacman's db and system files"
|
echo "This program recreates a package using pacman's db and system files"
|
||||||
echo "Usage: $progname <installed package name>"
|
echo "Usage: $progname <installed package name>"
|
||||||
echo "Example: $progname kernel26"
|
echo "Example: $progname kernel26"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -ne 1 ] ; then
|
if (( $# != 1 )); then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "--help" -o "$1" = "-h" ] ; then
|
if [[ $1 == "--help" || $1 == "-h" ]]; then
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "--version" -o "$1" = "-v" ]; then
|
if [[ $1 == "--version" || $1 == "-v" ]]; then
|
||||||
echo "$progname version $progver"
|
echo "$progname version $progver"
|
||||||
echo "Copyright (C) 2008 locci"
|
echo "Copyright (C) 2008 locci"
|
||||||
exit 0
|
exit 0
|
||||||
@ -51,11 +51,11 @@ fi
|
|||||||
#
|
#
|
||||||
# Fakeroot support
|
# Fakeroot support
|
||||||
#
|
#
|
||||||
if [ $EUID -gt 0 ]; then
|
if (( EUID )); then
|
||||||
if [ -f /usr/bin/fakeroot ]; then
|
if [[ -f /usr/bin/fakeroot ]]; then
|
||||||
echo "Entering fakeroot environment"
|
echo "Entering fakeroot environment"
|
||||||
export INFAKEROOT="1"
|
export INFAKEROOT="1"
|
||||||
/usr/bin/fakeroot -u -- $0 $1
|
/usr/bin/fakeroot -u -- "$0" "$@"
|
||||||
exit $?
|
exit $?
|
||||||
else
|
else
|
||||||
echo "WARNING: installing fakeroot or running ${progname} as root is required to"
|
echo "WARNING: installing fakeroot or running ${progname} as root is required to"
|
||||||
@ -67,7 +67,7 @@ fi
|
|||||||
#
|
#
|
||||||
# Setting environmental variables
|
# Setting environmental variables
|
||||||
#
|
#
|
||||||
if [ ! -r @sysconfdir@/pacman.conf ]; then
|
if [[ ! -r @sysconfdir@/pacman.conf ]]; then
|
||||||
echo "ERROR: unable to read @sysconfdir@/pacman.conf"
|
echo "ERROR: unable to read @sysconfdir@/pacman.conf"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -75,13 +75,13 @@ fi
|
|||||||
eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
|
eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
|
||||||
pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
|
pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
|
||||||
|
|
||||||
if [ ! -r @sysconfdir@/makepkg.conf ]; then
|
if [[ ! -r @sysconfdir@/makepkg.conf ]]; then
|
||||||
echo "ERROR: unable to read @sysconfdir@/makepkg.conf"
|
echo "ERROR: unable to read @sysconfdir@/makepkg.conf"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source "@sysconfdir@/makepkg.conf"
|
source "@sysconfdir@/makepkg.conf"
|
||||||
if [ -r ~/.makepkg.conf ]; then
|
if [[ -r ~/.makepkg.conf ]]; then
|
||||||
source ~/.makepkg.conf
|
source ~/.makepkg.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -96,12 +96,12 @@ pkg_namver="${pkg_dir##*/}"
|
|||||||
#
|
#
|
||||||
# Checks everything is in place
|
# Checks everything is in place
|
||||||
#
|
#
|
||||||
if [ ! -d "$pac_db" ] ; then
|
if [[ ! -d $pac_db ]]; then
|
||||||
echo "ERROR: pacman database directory ${pac_db} not found"
|
echo "ERROR: pacman database directory ${pac_db} not found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "$pkg_dir" ] ; then
|
if [[ ! -d $pkg_dir ]]; then
|
||||||
echo "ERROR: package ${pkg_name} not found in pacman database"
|
echo "ERROR: package ${pkg_name} not found in pacman database"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -120,11 +120,11 @@ echo "Copying package files..."
|
|||||||
|
|
||||||
cat "$pkg_dir"/files |
|
cat "$pkg_dir"/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
|
||||||
@ -132,11 +132,11 @@ while read i; do
|
|||||||
case $current in
|
case $current in
|
||||||
%FILES%)
|
%FILES%)
|
||||||
ret=0
|
ret=0
|
||||||
if [ -e "/$i" ]; then
|
if [[ -e /$i ]]; then
|
||||||
bsdtar -cnf - "/$i" 2> /dev/null | bsdtar -xpf -
|
bsdtar -cnf - "/$i" 2> /dev/null | bsdtar -xpf -
|
||||||
|
|
||||||
# Workaround to bsdtar not reporting a missing file as an error
|
# Workaround to bsdtar not reporting a missing file as an error
|
||||||
if [ ! -e "$work_dir/$i" -a ! -L "$work_dir/$i" ]; then
|
if ! [[ -e $work_dir/$i || -L $work_dir/$i ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "ERROR: unable to add /$i to the package"
|
echo "ERROR: unable to add /$i to the package"
|
||||||
echo " If your user does not have permssion to read this file then"
|
echo " If your user does not have permssion to read this file then"
|
||||||
@ -154,7 +154,7 @@ while read i; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
ret=$?
|
ret=$?
|
||||||
if [ $ret -ne 0 ]; then
|
if (( ret )); then
|
||||||
rm -rf "$work_dir"
|
rm -rf "$work_dir"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -166,7 +166,7 @@ pkg_size=$(du -sk | awk '{print $1 * 1024}')
|
|||||||
#
|
#
|
||||||
echo Generating .PKGINFO metadata...
|
echo Generating .PKGINFO metadata...
|
||||||
echo "# Generated by $progname $progver" > .PKGINFO
|
echo "# Generated by $progname $progver" > .PKGINFO
|
||||||
if [ "$INFAKEROOT" = "1" ]; then
|
if [[ $INFAKEROOT == "1" ]]; then
|
||||||
echo "# Using $(fakeroot -v)" >> .PKGINFO
|
echo "# Using $(fakeroot -v)" >> .PKGINFO
|
||||||
fi
|
fi
|
||||||
echo "# $(LC_ALL=C date)" >> .PKGINFO
|
echo "# $(LC_ALL=C date)" >> .PKGINFO
|
||||||
@ -178,7 +178,7 @@ 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
|
||||||
@ -241,11 +241,11 @@ done
|
|||||||
|
|
||||||
comp_files=".PKGINFO"
|
comp_files=".PKGINFO"
|
||||||
|
|
||||||
if [ -f "$pkg_dir/install" ] ; then
|
if [[ -f $pkg_dir/install ]]; then
|
||||||
cp "$pkg_dir/install" "$work_dir/.INSTALL"
|
cp "$pkg_dir/install" "$work_dir/.INSTALL"
|
||||||
comp_files+=" .INSTALL"
|
comp_files+=" .INSTALL"
|
||||||
fi
|
fi
|
||||||
if [ -f $pkg_dir/changelog ] ; then
|
if [[ -f $pkg_dir/changelog ]]; then
|
||||||
cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
|
cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
|
||||||
comp_files+=" .CHANGELOG"
|
comp_files+=" .CHANGELOG"
|
||||||
fi
|
fi
|
||||||
@ -286,7 +286,7 @@ case "$PKGEXT" in
|
|||||||
*tar) cat ;;
|
*tar) cat ;;
|
||||||
esac > ${pkg_file} || ret=$?
|
esac > ${pkg_file} || ret=$?
|
||||||
|
|
||||||
if [ $ret -ne 0 ]; then
|
if (( ret )); then
|
||||||
echo "ERROR: unable to write package to $pkg_dest"
|
echo "ERROR: unable to write package to $pkg_dest"
|
||||||
echo " Maybe the disk is full or you do not have write access"
|
echo " Maybe the disk is full or you do not have write access"
|
||||||
rm -rf "$work_dir"
|
rm -rf "$work_dir"
|
||||||
|
Loading…
Reference in New Issue
Block a user