mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-21 23:38:49 -05:00
bacman: allow for multiple packages as arguments
To enable the creation of multiple packages with one command move the assembly process into its own function. Signed-off-by: Gordian Edenhofer <gordian.edenhofer@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
45b6a3074a
commit
7568928e71
@ -66,7 +66,8 @@ done
|
|||||||
|
|
||||||
m4_include(../scripts/library/term_colors.sh)
|
m4_include(../scripts/library/term_colors.sh)
|
||||||
|
|
||||||
if (( $# != 1 )); then
|
# Break if no argument was given
|
||||||
|
if (( $# < 1 )); then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -118,10 +119,6 @@ fi
|
|||||||
pkg_dest="${PKGDEST:-$PWD}"
|
pkg_dest="${PKGDEST:-$PWD}"
|
||||||
pkg_pkger=${PACKAGER:-'Unknown Packager'}
|
pkg_pkger=${PACKAGER:-'Unknown Packager'}
|
||||||
|
|
||||||
pkg_name="$1"
|
|
||||||
pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
|
|
||||||
pkg_namver=("${pkg_dir[@]##*/}")
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Checks everything is in place
|
# Checks everything is in place
|
||||||
#
|
#
|
||||||
@ -130,31 +127,32 @@ if [[ ! -d $pac_db ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Assemble a single package: $1 = pkgname
|
||||||
|
fakebuild() {
|
||||||
|
pkg_name="$1"
|
||||||
|
pkg_dir=("$pac_db/$pkg_name"-+([^-])-+([^-]))
|
||||||
|
pkg_namver=("${pkg_dir[@]##*/}")
|
||||||
|
|
||||||
|
# Checks database for specified package
|
||||||
if (( ${#pkg_dir[@]} != 1 )); then
|
if (( ${#pkg_dir[@]} != 1 )); then
|
||||||
error "%d entries for package %s found in pacman database" \
|
error "%d entries for package %s found in pacman database" \
|
||||||
${#pkg_dir[@]} "${pkg_name}"
|
${#pkg_dir[@]} "${pkg_name}"
|
||||||
msg2 "%s" "${pkg_dir[@]}"
|
msg2 "%s" "${pkg_dir[@]}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -d $pkg_dir ]]; then
|
if [[ ! -d $pkg_dir ]]; then
|
||||||
error "package %s is found in pacman database," "${pkg_name}"
|
error "package %s is found in pacman database," "${pkg_name}"
|
||||||
plain " but '%s' is not a directory" "${pkg_dir}"
|
plain " but '%s' is not a directory" "${pkg_dir}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
# Create working directory
|
||||||
# Begin
|
|
||||||
#
|
|
||||||
msg "Package: ${pkg_namver}"
|
msg "Package: ${pkg_namver}"
|
||||||
work_dir=$(mktemp -d "${TMPDIR:-/tmp}/bacman.XXXXXXXXXX")
|
work_dir=$(mktemp -d "${work_dir_root}.XXXXXXXXXX")
|
||||||
cd "$work_dir" || exit 1
|
cd "$work_dir" || exit 1
|
||||||
|
|
||||||
#
|
# Assemble list of files which belong to the package and tar them
|
||||||
# File copying
|
|
||||||
#
|
|
||||||
msg2 "Copying package files..."
|
msg2 "Copying package files..."
|
||||||
|
|
||||||
while read i; do
|
while read i; do
|
||||||
if [[ -z $i ]]; then
|
if [[ -z $i ]]; then
|
||||||
continue
|
continue
|
||||||
@ -204,9 +202,9 @@ while read i; do
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Tar files
|
||||||
ret=0
|
ret=0
|
||||||
bsdtar -cnf - -s'/.pacnew$//' "$local_file" 2> /dev/null | bsdtar -xpf - 2> /dev/null
|
bsdtar -cnf - -s'/.pacnew$//' "$local_file" 2> /dev/null | bsdtar -xpf - 2> /dev/null
|
||||||
|
|
||||||
# Workaround to bsdtar not reporting a missing file as an error
|
# Workaround to bsdtar not reporting a missing file as an error
|
||||||
if ! [[ -e $package_file || -L $package_file ]]; then
|
if ! [[ -e $package_file || -L $package_file ]]; then
|
||||||
error "unable to add $local_file to the package"
|
error "unable to add $local_file to the package"
|
||||||
@ -223,12 +221,11 @@ if (( ret )); then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Calculate package size
|
||||||
pkg_size=$(du -sk | awk '{print $1 * 1024}')
|
pkg_size=$(du -sk | awk '{print $1 * 1024}')
|
||||||
|
|
||||||
#
|
# Reconstruct .PKGINFO from database
|
||||||
# .PKGINFO stuff
|
|
||||||
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
|
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
|
||||||
#
|
|
||||||
msg2 "Generating .PKGINFO metadata..."
|
msg2 "Generating .PKGINFO metadata..."
|
||||||
echo "# Generated by $myname $myver" > .PKGINFO
|
echo "# Generated by $myname $myver" > .PKGINFO
|
||||||
if [[ $INFAKEROOT == "1" ]]; then
|
if [[ $INFAKEROOT == "1" ]]; then
|
||||||
@ -236,12 +233,10 @@ if [[ $INFAKEROOT == "1" ]]; then
|
|||||||
fi
|
fi
|
||||||
echo "# $(LC_ALL=C date)" >> .PKGINFO
|
echo "# $(LC_ALL=C date)" >> .PKGINFO
|
||||||
echo "#" >> .PKGINFO
|
echo "#" >> .PKGINFO
|
||||||
|
|
||||||
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
|
||||||
@ -295,8 +290,6 @@ while read i; do
|
|||||||
%PROVIDES%)
|
%PROVIDES%)
|
||||||
echo "provides = $i" >> .PKGINFO
|
echo "provides = $i" >> .PKGINFO
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# files
|
|
||||||
%BACKUP%)
|
%BACKUP%)
|
||||||
# Strip the md5sum after the tab
|
# Strip the md5sum after the tab
|
||||||
echo "backup = ${i%%$'\t'*}" >> .PKGINFO
|
echo "backup = ${i%%$'\t'*}" >> .PKGINFO
|
||||||
@ -306,6 +299,7 @@ done < <(cat "$pkg_dir"/{desc,files})
|
|||||||
|
|
||||||
comp_files=".PKGINFO"
|
comp_files=".PKGINFO"
|
||||||
|
|
||||||
|
# Add instal file if present
|
||||||
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"
|
||||||
@ -315,15 +309,11 @@ if [[ -f $pkg_dir/changelog ]]; then
|
|||||||
comp_files+=" .CHANGELOG"
|
comp_files+=" .CHANGELOG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
|
||||||
# Fixes owner:group and permissions for .PKGINFO, .CHANGELOG, .INSTALL
|
# Fixes owner:group and permissions for .PKGINFO, .CHANGELOG, .INSTALL
|
||||||
#
|
|
||||||
chown root:root "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
|
chown root:root "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
|
||||||
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
|
chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
|
||||||
|
|
||||||
#
|
|
||||||
# Generate the package
|
# Generate the package
|
||||||
#
|
|
||||||
msg2 "Generating the package..."
|
msg2 "Generating the package..."
|
||||||
|
|
||||||
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
|
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
|
||||||
@ -342,6 +332,7 @@ case "$PKGEXT" in
|
|||||||
"$PKGEXT"; cat ;;
|
"$PKGEXT"; cat ;;
|
||||||
esac > "${pkg_file}"; ret=$?
|
esac > "${pkg_file}"; ret=$?
|
||||||
|
|
||||||
|
# Move compressed package to destination
|
||||||
if (( ret )); then
|
if (( ret )); then
|
||||||
error "Unable to write package to $pkg_dest"
|
error "Unable to write package to $pkg_dest"
|
||||||
plain " Maybe the disk is full or you do not have write access"
|
plain " Maybe the disk is full or you do not have write access"
|
||||||
@ -349,8 +340,12 @@ if (( ret )); then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clean up working directory
|
||||||
rm -rf "$work_dir"
|
rm -rf "$work_dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for PKG in $@; do fakebuild $PKG; done
|
||||||
msg "Done."
|
msg "Done."
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user