summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.am16
-rw-r--r--scripts/makepkg.sh.in493
-rw-r--r--scripts/repo-add.sh.in101
3 files changed, 382 insertions, 228 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 10e179e1..d6d9bb93 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -37,6 +37,7 @@ edit = sed \
-e 's|@PACKAGE_BUGREPORT[@]|$(PACKAGE_BUGREPORT)|g' \
-e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \
-e 's|@DBEXT[@]|$(DBEXT)|g' \
+ -e 's|@BUILDSCRIPT[@]|$(BUILDSCRIPT)|g' \
-e 's|@SIZECMD[@]|$(SIZECMD)|g' \
-e 's|@configure_input[@]|Generated from $@.in; do not edit by hand.|g'
@@ -46,13 +47,14 @@ edit = sed \
# two 'test' lines- make sure we can handle both sh and py type scripts
# third 'test' line- make sure one of the two checks succeeded
$(OURSCRIPTS): Makefile
- rm -f $@ $@.tmp
- test -f $(srcdir)/$@.sh.in && $(edit) $(srcdir)/$@.sh.in >$@.tmp || true
- test -f $(srcdir)/$@.py.in && $(edit) $(srcdir)/$@.py.in >$@.tmp || true
- test -f $@.tmp || false
- chmod +x $@.tmp
- chmod a-w $@.tmp
- mv $@.tmp $@
+ @echo ' ' GEN $@;
+ @rm -f $@ $@.tmp
+ @test -f $(srcdir)/$@.sh.in && $(edit) $(srcdir)/$@.sh.in >$@.tmp || true
+ @test -f $(srcdir)/$@.py.in && $(edit) $(srcdir)/$@.py.in >$@.tmp || true
+ @test -f $@.tmp || false
+ @chmod +x $@.tmp
+ @chmod a-w $@.tmp
+ @mv $@.tmp $@
makepkg: $(srcdir)/makepkg.sh.in
pacman-optimize: $(srcdir)/pacman-optimize.sh.in
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index d05d2403..52e80d17 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -38,11 +38,16 @@ export COMMAND_MODE='legacy'
myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@'
+BUILDSCRIPT='@BUILDSCRIPT@'
startdir="$PWD"
srcdir="$startdir/src"
pkgdir="$startdir/pkg"
-known_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'ccache' 'distcc' 'makeflags' 'force')
-readonly -a known_options
+
+packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge')
+other_options=('ccache' 'distcc' 'makeflags' 'force')
+splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \
+ 'conflicts' 'replaces' 'backup' 'options' 'install')
+readonly -a packaging_options other_options splitpkg_overrides
# Options
ASROOT=0
@@ -62,6 +67,8 @@ LOGGING=0
SOURCEONLY=0
IGNOREARCH=0
HOLDVER=0
+PKGFUNC=0
+SPLITPKG=0
# Forces the pkgver of the current PKGBUILD. Used by the fakeroot call
# when dealing with svn/cvs/etc PKGBUILDs.
@@ -122,7 +129,7 @@ error() {
# the fakeroot call, the error message will be printed by the main call.
##
trap_exit() {
- if [ "$INFAKEROOT" = "0" ]; then
+ if [ "$INFAKEROOT" -eq 0 ]; then
echo
error "$@"
fi
@@ -136,16 +143,16 @@ trap_exit() {
clean_up() {
local EXIT_CODE=$?
- if [ "$INFAKEROOT" = "1" ]; then
+ if [ "$INFAKEROOT" -eq 1 ]; then
# Don't clean up when leaving fakeroot, we're not done yet.
return
fi
- if [ $EXIT_CODE -eq 0 -a "$CLEANUP" = "1" ]; then
+ if [ $EXIT_CODE -eq 0 -a "$CLEANUP" -eq 1 ]; then
# If it's a clean exit and -c/--clean has been passed...
msg "$(gettext "Cleaning up...")"
rm -rf "$pkgdir" "$srcdir"
- if [ "$pkgname" != "" ]; then
+ if [ -n "$pkgname" ]; then
# Can't do this unless the BUILDSCRIPT has been sourced.
rm -f "${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log*"
fi
@@ -270,7 +277,7 @@ get_downloadclient() {
local i
for i in "${DLAGENTS[@]}"; do
local handler=$(echo $i | sed 's|::.*||')
- if [ "$proto" == "$handler" ]; then
+ if [ "$proto" = "$handler" ]; then
agent=$(echo $i | sed 's|^.*::||')
break
fi
@@ -278,7 +285,7 @@ get_downloadclient() {
# if we didn't find an agent, return an error
if [ -z "$agent" ]; then
- error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$confdir/makepkg.conf"
+ error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
plain "$(gettext "Aborting...")"
exit 1 # $E_CONFIG_ERROR
fi
@@ -346,16 +353,16 @@ handledeps() {
local deplist="$*"
- if [ "$DEP_BIN" = "0" ]; then
+ if [ "$DEP_BIN" -eq 0 ]; then
return $R_DEPS_MISSING
fi
- if [ "$DEP_BIN" = "1" ]; then
+ if [ "$DEP_BIN" -eq 1 ]; then
# install missing deps from binary packages (using pacman -S)
msg "$(gettext "Installing missing dependencies...")"
local ret=0
- if [ "$ASROOT" = 0 ]; then
+ if [ "$ASROOT" -eq 0 ]; then
sudo pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
else
pacman $PACMAN_OPTS -S --asdeps $deplist || ret=$?
@@ -382,7 +389,7 @@ resolve_deps() {
local R_DEPS_MISSING=1
local deplist="$(check_deps $*)"
- if [ "$deplist" = "" ]; then
+ if [ -z "$deplist" ]; then
return $R_DEPS_SATISFIED
fi
@@ -390,8 +397,8 @@ resolve_deps() {
pkgdeps="$pkgdeps $deplist"
# check deps again to make sure they were resolved
deplist="$(check_deps $*)"
- [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
- elif [ "$DEP_BIN" = "1" ]; then
+ [ -z "$deplist" ] && return $R_DEPS_SATISFIED
+ elif [ "$DEP_BIN" -eq 1 ]; then
error "$(gettext "Failed to install all missing dependencies.")"
fi
@@ -407,8 +414,8 @@ resolve_deps() {
# fix flyspray bug #5923
remove_deps() {
# $pkgdeps is a GLOBAL variable, set by resolve_deps()
- [ "$RMDEPS" = "0" ] && return
- [ "$pkgdeps" = "" ] && return
+ [ "$RMDEPS" -eq 0 ] && return
+ [ -z "$pkgdeps" ] && return
local dep depstrip deplist
deplist=""
@@ -419,7 +426,7 @@ remove_deps() {
msg "Removing installed dependencies..."
local ret=0
- if [ "$ASROOT" = "0" ]; then
+ if [ "$ASROOT" -eq 0 ]; then
sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$?
else
pacman $PACMAN_OPTS -Rns $deplist || ret=$?
@@ -488,6 +495,11 @@ generate_checksums() {
msg "$(gettext "Generating checksums for source files...")"
plain ""
+ if [ ! $(type -p openssl) ]; then
+ error "$(gettext "Cannot find openssl.")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+
local integ
for integ in ${INTEGRITY_CHECK[@]}; do
integ="$(echo $integ | tr '[:upper:]' '[:lower:]')"
@@ -498,11 +510,6 @@ generate_checksums() {
exit 1;; # $E_CONFIG_ERROR
esac
- if [ ! $(type -p openssl) ]; then
- error "$(gettext "Cannot find openssl.")"
- exit 1 # $E_MISSING_PROGRAM
- fi
-
local ct=0
local numsrc=${#source[@]}
echo -n "${integ}sums=("
@@ -540,24 +547,18 @@ generate_checksums() {
}
check_checksums() {
- local integ
- for integ in ${INTEGRITY_CHECK[@]}; do
- integ="$(echo $integ | tr '[:upper:]' '[:lower:]')"
- case "$integ" in
- md5|sha1|sha256|sha384|sha512) : ;;
- *)
- error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ"
- exit 1;; # $E_CONFIG_ERROR
- esac
-
- if [ ! $(type -p openssl) ]; then
- error "$(gettext "Cannot find openssl.")"
- exit 1 # $E_MISSING_PROGRAM
- fi
+ if [ ! $(type -p openssl) ]; then
+ error "$(gettext "Cannot find openssl.")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+ local correlation=0
+ local integ required
+ for integ in md5 sha1 sha256 sha384 sha512; do
local integrity_sums=($(eval echo "\${${integ}sums[@]}"))
if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
msg "$(gettext "Validating source files with %s...")" "${integ}sums"
+ correlation=1
local errors=0
local idx=0
local file
@@ -591,10 +592,16 @@ check_checksums() {
error "$(gettext "One or more files did not pass the validity check!")"
exit 1 # TODO: error code
fi
- else
- warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ"
+ elif [ ${#integrity_sums[@]} -gt 0 ]; then
+ error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
+ exit 1 # TODO: error code
fi
done
+
+ if [ $correlation -eq 0 ]; then
+ error "$(gettext "Integrity checks are missing.")"
+ exit 1 # TODO: error code
+ fi
}
extract_sources() {
@@ -674,13 +681,13 @@ run_build() {
cd "$srcdir"
# ensure all necessary build variables are exported
- export CFLAGS CXXFLAGS MAKEFLAGS CHOST
+ export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
# save our shell options so build() can't override what we need
local shellopts=$(shopt -p)
local ret=0
- if [ "$LOGGING" = "1" ]; then
- BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log"
+ if [ "$LOGGING" -eq 1 ]; then
+ BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log"
if [ -f "$BUILDLOG" ]; then
local i=1
while true; do
@@ -708,21 +715,88 @@ run_build() {
fi
}
+run_package() {
+ if [ -z "$1" ]; then
+ pkgfunc="package"
+ nameofpkg="$pkgname"
+ else
+ pkgfunc="package_$1"
+ nameofpkg="$1"
+ fi
+
+ # clear user-specified makeflags if requested
+ if [ "$(check_option makeflags)" = "n" ]; then
+ MAKEFLAGS=""
+ fi
+
+ msg "$(gettext "Starting %s()...")" "$pkgfunc"
+ cd "$srcdir"
+
+ # ensure all necessary build variables are exported
+ export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
+
+ local ret=0
+ if [ "$LOGGING" -eq 1 ]; then
+ BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
+ if [ -f "$BUILDLOG" ]; then
+ local i=1
+ while true; do
+ if [ -f "$BUILDLOG.$i" ]; then
+ i=$(($i +1))
+ else
+ break
+ fi
+ done
+ mv "$BUILDLOG" "$BUILDLOG.$i"
+ fi
+
+ # ensure overridden package variables suvrive tee with split packages
+ logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX")
+ mknod "$logpipe" p
+ exec 3>&1
+ tee "$BUILDLOG" < "$logpipe" &
+ exec 1>"$logpipe" 2>"$logpipe"
+ $pkgfunc 2>&1 || ret=$?
+ sync
+ exec 1>&3 2>&3 3>&-
+ rm "$logpipe"
+ else
+ $pkgfunc 2>&1 || ret=$?
+ fi
+
+ if [ $ret -gt 0 ]; then
+ error "$(gettext "Packaging Failed.")"
+ plain "$(gettext "Aborting...")"
+ remove_deps
+ exit 2 # $E_BUILD_FAILED
+ fi
+}
+
tidy_install() {
cd "$pkgdir"
msg "$(gettext "Tidying install...")"
- if [ "$(check_option docs)" = "n" ]; then
- msg2 "$(gettext "Removing info/doc files...")"
- #fix flyspray bug #5021
+ if [ "$(check_option docs)" = "n" -a -n "${DOC_DIRS[*]}" ]; then
+ msg2 "$(gettext "Removing doc files...")"
rm -rf ${DOC_DIRS[@]}
fi
- if [ "$(check_option zipman)" = "y" ]; then
- msg2 "$(gettext "Compressing man pages...")"
- local manpage mandirs ext file link hardlinks hl
- mandirs="usr/man usr/share/man usr/local/man usr/local/share/man opt/*/man"
- find ${mandirs} -type f 2>/dev/null |
+ if [ "$(check_option purge)" = "y" -a -n "${PURGE_TARGETS[*]}" ]; then
+ msg2 "$(gettext "Purging other files...")"
+ local pt
+ for pt in "${PURGE_TARGETS[@]}"; do
+ if [ "${pt}" = "${pt//\/}" ]; then
+ find . -type f -name "${pt}" -exec rm -f -- '{}' \;
+ else
+ rm -f ${pt}
+ fi
+ done
+ fi
+
+ if [ "$(check_option zipman)" = "y" -a -n "${MAN_DIRS[*]}" ]; then
+ msg2 "$(gettext "Compressing man and info pages...")"
+ local manpage ext file link hardlinks hl
+ find ${MAN_DIRS[@]} -type f 2>/dev/null |
while read manpage ; do
# check file still exists (potentially compressed with hard link)
if [ -f ${manpage} ]; then
@@ -730,7 +804,7 @@ tidy_install() {
file="${manpage##*/}"
if [ "$ext" != "gz" -a "$ext" != "bz2" ]; then
# update symlinks to this manpage
- find ${mandirs} -lname "$file" 2>/dev/null |
+ find ${MAN_DIRS[@]} -lname "$file" 2>/dev/null |
while read link ; do
rm -f "$link"
ln -sf "${file}.gz" "${link}.gz"
@@ -738,7 +812,7 @@ tidy_install() {
# find hard links and remove them
# the '|| true' part keeps the script from bailing if find returned an
# error, such as when one of the man directories doesn't exist
- hardlinks="$(find ${mandirs} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
+ hardlinks="$(find ${MAN_DIRS[@]} \! -name "$file" -samefile "$manpage" 2>/dev/null)" || true
for hl in ${hardlinks}; do
rm -f "${hl}";
done
@@ -754,15 +828,9 @@ tidy_install() {
done
fi
-
- if [ "$(check_option strip)" = "y" ]; then
+ if [ "$(check_option strip)" = "y" -a -n "${STRIP_DIRS[*]}" ]; then
msg2 "$(gettext "Stripping debugging symbols from binaries and libraries...")"
local binary
- if [ -z "${STRIP_DIRS[*]}" ]; then
- # fall back to default value
- STRIP_DIRS=(bin lib sbin usr/{bin,lib,sbin,local/{bin,lib,sbin}}
- opt/*/{bin,lib,sbin})
- fi
find ${STRIP_DIRS[@]} -type f 2>/dev/null | while read binary ; do
case "$(file -biz "$binary")" in
*application/x-sharedlib*) # Libraries (.so)
@@ -787,6 +855,12 @@ tidy_install() {
}
create_package() {
+ if [ -z "$1" ]; then
+ nameofpkg="$pkgname"
+ else
+ nameofpkg="$1"
+ fi
+
if [ ! -d "$pkgdir" ]; then
error "$(gettext "Missing pkg/ directory.")"
plain "$(gettext "Aborting...")"
@@ -797,7 +871,7 @@ create_package() {
msg "$(gettext "Creating package...")"
local builddate=$(date -u "+%s")
- if [ "$PACKAGER" != "" ]; then
+ if [ -n "$PACKAGER" ]; then
local packager="$PACKAGER"
else
local packager="Unknown Packager"
@@ -807,18 +881,18 @@ create_package() {
# write the .PKGINFO file
msg2 "$(gettext "Generating .PKGINFO file...")"
echo "# Generated by makepkg $myver" >.PKGINFO
- if [ "$INFAKEROOT" = "1" ]; then
+ if [ "$INFAKEROOT" -eq 1 ]; then
echo "# using $(fakeroot -v)" >>.PKGINFO
fi
echo "# $(LC_ALL=C date -u)" >>.PKGINFO
- echo "pkgname = $pkgname" >>.PKGINFO
+ echo "pkgname = $nameofpkg" >>.PKGINFO
echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
echo "pkgdesc = $pkgdesc" >>.PKGINFO
echo "url = $url" >>.PKGINFO
echo "builddate = $builddate" >>.PKGINFO
echo "packager = $packager" >>.PKGINFO
echo "size = $size" >>.PKGINFO
- if [ "$CARCH" != "" ]; then
+ if [ -n "$CARCH" ]; then
echo "arch = $CARCH" >>.PKGINFO
fi
if [ "$(check_option force)" = "y" ]; then
@@ -850,10 +924,20 @@ create_package() {
for it in "${backup[@]}"; do
echo "backup = $it" >>.PKGINFO
done
+ for it in "${packaging_options[@]}"; do
+ local ret="$(check_option $it)"
+ if [ "$ret" != "?" ]; then
+ if [ "$ret" = "y" ]; then
+ echo "makepkgopt = $it" >>.PKGINFO
+ else
+ echo "makepkgopt = !$it" >>.PKGINFO
+ fi
+ fi
+ done
# TODO maybe remove this at some point
# warn if license array is not present or empty
- if [ "$license" = "" ]; then
+ if [ -z "$license" ]; then
warning "$(gettext "Please add a license line to your %s!")" "$BUILDSCRIPT"
plain "$(gettext "Example for GPL'ed software: license=('GPL').")"
fi
@@ -861,7 +945,7 @@ create_package() {
local comp_files=".PKGINFO"
# check for an install script
- if [ "$install" != "" ]; then
+ if [ -n "$install" ]; then
msg2 "$(gettext "Adding install script...")"
cp "$startdir/$install" .INSTALL
comp_files="$comp_files .INSTALL"
@@ -877,13 +961,21 @@ create_package() {
# tar it up
msg2 "$(gettext "Compressing package...")"
- local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
+ local TAR_OPT
+ case "$PKGEXT" in
+ *tar.gz) TAR_OPT="z" ;;
+ *tar.bz2) TAR_OPT="j" ;;
+ *) warning "$(gettext "'%s' is not a valid archive extension.")" \
+ "$PKGEXT" ;;
+ esac
+
+ local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
# when fileglobbing, we want * in an empty directory to expand to
# the null string rather than itself
shopt -s nullglob
- if ! bsdtar -czf "$pkg_file" $comp_files *; then
+ if ! bsdtar -c${TAR_OPT}f "$pkg_file" $comp_files *; then
error "$(gettext "Failed to create package file.")"
exit 1 # TODO: error code
fi
@@ -923,7 +1015,7 @@ create_xdelta() {
rm -f "$pkginfo"
- if [ "$base_file" != "" ]; then
+ if [ -n "$base_file" ]; then
msg "$(gettext "Making delta from version %s...")" "$latest_version"
local delta_file="$PKGDEST/$pkgname-${latest_version}_to_$pkgver-$pkgrel-$CARCH.delta"
local ret=0
@@ -956,7 +1048,7 @@ create_xdelta() {
create_srcpackage() {
cd "$startdir"
- if [ "$SOURCEONLY" = "2" ]; then
+ if [ "$SOURCEONLY" -eq 2 ]; then
# get back to our src directory so we can begin with sources
mkdir -p "$srcdir"
cd "$srcdir"
@@ -972,7 +1064,7 @@ create_srcpackage() {
msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
ln -s "${startdir}/${BUILDSCRIPT}" "${srclinks}/${pkgname}/"
- if [ "$install" != "" ]; then
+ if [ -n "$install" ]; then
if [ -f $install ]; then
msg2 "$(gettext "Adding install script...")"
ln -s "${startdir}/$install" "${srclinks}/${pkgname}/"
@@ -992,18 +1084,26 @@ create_srcpackage() {
if [ -f "$netfile" ]; then
msg2 "$(gettext "Adding %s...")" "$netfile"
ln -s "${startdir}/$netfile" "${srclinks}/${pkgname}"
- elif [ "$SOURCEONLY" = "2" -a -f "$SRCDEST/$file" ]; then
+ elif [ "$SOURCEONLY" -eq 2 -a -f "$SRCDEST/$file" ]; then
msg2 "$(gettext "Adding %s...")" "$file"
ln -s "$SRCDEST/$file" "${srclinks}/${pkgname}/"
fi
done
+ local TAR_OPT
+ case "$SRCEXT" in
+ *tar.gz) TAR_OPT="z" ;;
+ *tar.bz2) TAR_OPT="j" ;;
+ *) warning "$(gettext "'%s' is not a valid archive extension.")" \
+ "$SRCEXT" ;;
+ esac
+
local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}"
# tar it up
msg2 "$(gettext "Compressing source package...")"
cd "${srclinks}"
- if ! bsdtar -czLf "$pkg_file" ${pkgname}; then
+ if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgname}; then
error "$(gettext "Failed to create source package file.")"
exit 1 # TODO: error code
fi
@@ -1012,9 +1112,9 @@ create_srcpackage() {
}
install_package() {
- [ "$INSTALL" = "0" ] && return
+ [ "$INSTALL" -eq 0 ] && return
msg "$(gettext "Installing package ${pkgname} with pacman -U...")"
- if [ "$ASROOT" = "0" ]; then
+ if [ "$ASROOT" -eq 0 ]; then
sudo pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
else
pacman $PACMAN_OPTS -U $PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} || exit $?
@@ -1024,10 +1124,14 @@ install_package() {
devel_check() {
newpkgver=""
# Only update pkgver if --holdver is not set
- if [ "$HOLDVER" = "1" ]; then
+ if [ "$HOLDVER" -eq 1 ]; then
+ return
+ fi
+ # Cannot update pkgver/pkgrel if reading PKGBUILD from pipe
+ if [ ! -f "./$BUILDSCRIPT" ]; then
return
fi
- if [ "$FORCE_VER" = "" ]; then
+ if [ -z "$FORCE_VER" ]; then
# Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
# This will only be used on the first call to makepkg; subsequent
# calls to makepkg via fakeroot will explicitly pass the version
@@ -1070,7 +1174,7 @@ devel_check() {
cd ../../
fi
- if [ "$newpkgver" != "" ]; then
+ if [ -n "$newpkgver" ]; then
msg2 "$(gettext "Version found: %s")" "$newpkgver"
fi
@@ -1090,15 +1194,35 @@ devel_update() {
# ...
# _foo=pkgver
#
- if [ "$newpkgver" != "" ]; then
+ if [ -n "$newpkgver" ]; then
if [ "$newpkgver" != "$pkgver" ]; then
- sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
- sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
- source "$BUILDSCRIPT"
+ if [ -f "./$BUILDSCRIPT" ]; then
+ sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
+ sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
+ source "$BUILDSCRIPT"
+ fi
fi
fi
}
+backup_package_variables() {
+ for var in ${splitpkg_overrides[@]}; do
+ indirect="${var}_backup"
+ eval "${indirect}=\"${!var}\""
+ done
+}
+
+restore_package_variables() {
+ for var in ${splitpkg_overrides[@]}; do
+ indirect="${var}_backup"
+ if [ -n "${!indirect}" ]; then
+ eval "${var}=\"${!indirect}\""
+ else
+ unset ${var}
+ fi
+ done
+}
+
# getopt like parser
parse_options() {
local short_options=$1; shift;
@@ -1195,6 +1319,7 @@ usage() {
printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT"
echo "$(gettext " -c, --clean Clean up work files after build")"
echo "$(gettext " -C, --cleancache Clean up source files from the cache")"
+ printf "$(gettext " --config <config> Use an alternate config file (instead of '%s')")\n" "$confdir/makepkg.conf"
echo "$(gettext " -d, --nodeps Skip all dependency checks")"
echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")"
echo "$(gettext " -f, --force Overwrite existing package")"
@@ -1242,36 +1367,12 @@ fi
ARGLIST=$@
-#preserve environment variables
-_PKGDEST=${PKGDEST}
-_SRCDEST=${SRCDEST}
-
-# Source makepkg.conf; fail if it is not found
-if [ -r "$confdir/makepkg.conf" ]; then
- source "$confdir/makepkg.conf"
-else
- error "$(gettext "%s not found.")" "$confdir/makepkg.conf"
- plain "$(gettext "Aborting...")"
- exit 1 # $E_CONFIG_ERROR
-fi
-
-# Source user-specific makepkg.conf overrides
-if [ -r ~/.makepkg.conf ]; then
- source ~/.makepkg.conf
-fi
-
-# override settings with an environment variable for batch processing
-PKGDEST=${_PKGDEST:-$PKGDEST}
-PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
-SRCDEST=${_SRCDEST:-$SRCDEST}
-SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
-
# Parse Command Line Options.
OPT_SHORT="AbcCdefFghiLmop:rRsV"
OPT_LONG="allsource,asroot,ignorearch,builddeps,clean,cleancache,nodeps"
OPT_LONG="$OPT_LONG,noextract,force,forcever:,geninteg,help,holdver"
OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source"
-OPT_LONG="$OPT_LONG,syncdeps,version"
+OPT_LONG="$OPT_LONG,syncdeps,version,config:"
# Pacman Options
OPT_LONG="$OPT_LONG,noconfirm,noprogressbar"
OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')"
@@ -1294,6 +1395,7 @@ while true; do
-A|--ignorearch) IGNOREARCH=1 ;;
-c|--clean) CLEANUP=1 ;;
-C|--cleancache) CLEANCACHE=1 ;;
+ --config) shift; MAKEPKG_CONF=$1 ;;
-d|--nodeps) NODEPS=1 ;;
-e|--noextract) NOEXTRACT=1 ;;
-f|--force) FORCE=1 ;;
@@ -1321,13 +1423,41 @@ while true; do
shift
done
-if [ "$HOLDVER" = "1" -a "$FORCE_VER" != "" ]; then
+#preserve environment variables
+_PKGDEST=${PKGDEST}
+_SRCDEST=${SRCDEST}
+
+# default config is makepkg.conf
+MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
+
+# Source the config file; fail if it is not found
+if [ -r "$MAKEPKG_CONF" ]; then
+ source "$MAKEPKG_CONF"
+else
+ error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_CONFIG_ERROR
+fi
+
+# Source user-specific makepkg.conf overrides
+if [ -r ~/.makepkg.conf ]; then
+ source ~/.makepkg.conf
+fi
+
+# override settings with an environment variable for batch processing
+PKGDEST=${_PKGDEST:-$PKGDEST}
+PKGDEST=${PKGDEST:-$startdir} #default to $startdir if undefined
+SRCDEST=${_SRCDEST:-$SRCDEST}
+SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined
+
+
+if [ "$HOLDVER" -eq 1 -a -n "$FORCE_VER" ]; then
# The '\\0' is here to prevent gettext from thinking --holdver is an option
error "$(gettext "\\0--holdver and --forcever cannot both be specified" )"
exit 1
fi
-if [ "$CLEANCACHE" = "1" ]; then
+if [ "$CLEANCACHE" -eq 1 ]; then
#fix flyspray feature request #5223
if [ -n "$SRCDEST" -a "$SRCDEST" != "$startdir" ]; then
msg "$(gettext "Cleaning up ALL files from %s.")" "$SRCDEST"
@@ -1352,25 +1482,25 @@ if [ "$CLEANCACHE" = "1" ]; then
fi
else
# $SRCDEST is $startdir, two possibilities
- error "$(gettext "Source destination must be defined in makepkg.conf.")"
+ error "$(gettext "Source destination must be defined in %s.")" "$MAKEPKG_CONF"
plain "$(gettext "In addition, please run makepkg -C outside of your cache directory.")"
exit 1
fi
fi
if [ -z "$BUILDSCRIPT" ]; then
- error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$confdir/makepkg.conf"
+ error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$MAKEPKG_CONF"
exit 1
fi
-if [ "$INFAKEROOT" = "0" ]; then
- if [ $EUID -eq 0 -a "$ASROOT" = "0" ]; then
+if [ "$INFAKEROOT" -eq 0 ]; then
+ if [ $EUID -eq 0 -a "$ASROOT" -eq 0 ]; then
# Warn those who like to live dangerously.
error "$(gettext "Running makepkg as root is a BAD idea and can cause")"
plain "$(gettext "permanent, catastrophic damage to your system. If you")"
plain "$(gettext "wish to run as root, please use the --asroot option.")"
exit 1 # $E_USER_ABORT
- elif [ $EUID -gt 0 -a "$ASROOT" = "1" ]; then
+ elif [ $EUID -gt 0 -a "$ASROOT" -eq 1 ]; then
# Warn those who try to use the --asroot option when they are not root
error "$(gettext "The --asroot option is meant for the root user only.")"
plain "$(gettext "Please rerun makepkg without the --asroot flag.")"
@@ -1378,25 +1508,25 @@ if [ "$INFAKEROOT" = "0" ]; then
elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then
if [ ! $(type -p fakeroot) ]; then
error "$(gettext "Fakeroot must be installed if using the 'fakeroot' option")"
- plain "$(gettext "in the BUILDENV array in %s.")" "$confdir/makepkg.conf"
+ plain "$(gettext "in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
exit 1
fi
elif [ $EUID -gt 0 ]; then
warning "$(gettext "Running makepkg as an unprivileged user will result in non-root")"
plain "$(gettext "ownership of the packaged files. Try using the fakeroot environment by")"
- plain "$(gettext "placing 'fakeroot' in the BUILDENV array in makepkg.conf.")"
+ plain "$(gettext "placing 'fakeroot' in the BUILDENV array in %s.")" "$MAKEPKG_CONF"
sleep 1
fi
else
- if [ "$FAKEROOTKEY" = "" ]; then
+ if [ -z "$FAKEROOTKEY" ]; then
error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")"
exit 1 # TODO: error code
fi
fi
# check for sudo if we will need it during makepkg execution
-if [ "$ASROOT" = "0" -a \( "$DEP_BIN" = "1" \
- -o "$RMDEPS" = "1" -o "$INSTALL" = "1" \) ]; then
+if [ "$ASROOT" -eq 0 \
+ -a \( "$DEP_BIN" -eq 1 -o "$RMDEPS" -eq 1 -o "$INSTALL" -eq 1 \) ]; then
if [ ! "$(type -p sudo)" ]; then
error "$(gettext "Cannot find the sudo binary! Is sudo installed?")"
plain "$(gettext "Missing dependencies cannot be installed or removed as a normal user")"
@@ -1410,13 +1540,24 @@ unset replaces depends conflicts backup source install build makedepends
unset optdepends options noextract
if [ ! -f "$BUILDSCRIPT" ]; then
- error "$(gettext "%s does not exist.")" "$BUILDSCRIPT"
- exit 1
+ if [ -t 0 ]; then
+ error "$(gettext "%s does not exist.")" "$BUILDSCRIPT"
+ exit 1
+ else
+ # PKGBUILD passed through a pipe
+ BUILDSCRIPT=/dev/stdin
+ fi
+else
+ crlftest=$(file $BUILDSCRIPT | grep -F 'CRLF' || true)
+ if [ -n "$crlftest" ]; then
+ error "$(gettext "%s contains CRLF characters and cannot be sourced.")" "$BUILDSCRIPT"
+ exit 1
+ fi
fi
source "$BUILDSCRIPT"
-if [ "$GENINTEG" = "1" ]; then
+if [ "$GENINTEG" -eq 1 ]; then
mkdir -p "$srcdir"
cd "$srcdir"
download_sources
@@ -1424,6 +1565,14 @@ if [ "$GENINTEG" = "1" ]; then
exit 0 # $E_OK
fi
+if [ "$(type -t package)" = "function" ]; then
+ PKGFUNC=1
+fi
+
+if [ "${#pkgname[@]}" -gt "1" ]; then
+ SPLITPKG=1
+fi
+
# check for no-no's in the build script
if [ -z "$pkgname" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgname"
@@ -1451,15 +1600,11 @@ if [ "$arch" = 'any' ]; then
fi
if ! in_array $CARCH ${arch[@]}; then
- if [ "$IGNOREARCH" = "0" ]; then
+ if [ "$IGNOREARCH" -eq 0 ]; then
error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH"
plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
plain "$(gettext "such as arch=('%s').")" "$CARCH"
exit 1
- else
- warning "$(gettext "%s is not available for the '%s' architecture.")" "$pkgname" "$CARCH"
- plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
- plain "$(gettext "such as arch=('%s').")" "$CARCH"
fi
fi
@@ -1480,7 +1625,7 @@ valid_options=1
for opt in ${options[@]}; do
known=0
# check if option matches a known option or its inverse
- for kopt in ${known_options[@]}; do
+ for kopt in ${packaging_options[@]} ${other_options[@]}; do
if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
known=1
fi
@@ -1503,8 +1648,8 @@ devel_check
devel_update
if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
- -a "$FORCE" = "0" -a "$SOURCEONLY" = "0" -a "$NOBUILD" = "0" ]; then
- if [ "$INSTALL" = "1" ]; then
+ -a "$FORCE" -eq 0 -a "$SOURCEONLY" -eq 0 -a "$NOBUILD" -eq 0 ]; then
+ if [ "$INSTALL" -eq 1 ]; then
warning "$(gettext "A package has already been built, installing existing package...")"
install_package
exit $?
@@ -1515,31 +1660,40 @@ if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" \
fi
# Run the bare minimum in fakeroot
-# fix flyspray bug 6208 -- using makepkg with fakeroot gives an error
-if [ "$INFAKEROOT" = "1" ]; then
- if [ "$REPKG" = "1" ]; then
- warning "$(gettext "Skipping build.")"
+if [ "$INFAKEROOT" -eq 1 ]; then
+ if [ "$SPLITPKG" -eq 0 ]; then
+ if [ "$PKGFUNC" -eq 0 ]; then
+ if [ "$REPKG" -eq 0 ]; then
+ run_build
+ fi
+ else
+ run_package
+ tidy_install
+ fi
+ create_package
else
- run_build
- tidy_install
+ for pkg in ${pkgname[@]}; do
+ pkgdir="$pkgdir/$pkg"
+ mkdir -p "$pkgdir"
+ backup_package_variables
+ run_package $pkg
+ tidy_install
+ create_package $pkg
+ restore_package_variables
+ pkgdir="${pkgdir%/*}"
+ done
fi
- create_package
-
msg "$(gettext "Leaving fakeroot environment.")"
exit 0 # $E_OK
fi
msg "$(gettext "Making package: %s")" "$pkgname $pkgver-$pkgrel $CARCH ($(date))"
-if [ $EUID -eq 0 ]; then
- warning "$(gettext "Running makepkg as root...")"
-fi
-
# if we are creating a source-only package, go no further
-if [ "$SOURCEONLY" != "0" ]; then
+if [ "$SOURCEONLY" -ne 0 ]; then
if [ -f "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}${SRCEXT}" \
- -a "$FORCE" = "0" ]; then
+ -a "$FORCE" -eq 0 ]; then
error "$(gettext "A package has already been built. (use -f to overwrite)")"
exit 1
fi
@@ -1549,11 +1703,11 @@ if [ "$SOURCEONLY" != "0" ]; then
fi
# fix flyspray bug #5973
-if [ "$NODEPS" = "1" -o "$NOBUILD" = "1" -o "$REPKG" = "1" ]; then
- if [ "$NODEPS" = "1" ]; then
+if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then
+ # no warning message needed for nobuild, repkg
+ if [ "$NODEPS" -eq 1 ]; then
warning "$(gettext "Skipping dependency checks.")"
fi
- # skip printing a warning message for the others: nobuild, repkg
elif [ $(type -p pacman) ]; then
unset pkgdeps # Set by resolve_deps() and used by remove_deps()
deperr=0
@@ -1579,16 +1733,19 @@ umask 0022
mkdir -p "$srcdir"
cd "$srcdir"
-if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
+if [ "$NOEXTRACT" -eq 1 ]; then
warning "$(gettext "Skipping source retrieval -- using existing src/ tree")"
warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
warning "$(gettext "Skipping source extraction -- using existing src/ tree")"
- if [ "$NOEXTRACT" = "1" -a "$(ls "$srcdir" 2>/dev/null)" = "" ]; then
+ if [ "$NOEXTRACT" -eq 1 -a -z "$(ls "$srcdir" 2>/dev/null)" ]; then
error "$(gettext "The source directory is empty, there is nothing to build!")"
plain "$(gettext "Aborting...")"
exit 1
- elif [ "$REPKG" = "1" -a \( ! -d "$pkgdir" -o "$(ls "$pkgdir" 2>/dev/null)" = "" \) ]; then
+ fi
+elif [ "$REPKG" -eq 1 ]; then
+ if [ "$PKGFUNC" -eq 0 -a "$SPLITPKG" -eq 0 \
+ -a \( ! -d "$pkgdir" -o -z "$(ls "$pkgdir" 2>/dev/null)" \) ]; then
error "$(gettext "The package directory is empty, there is nothing to repackage!")"
plain "$(gettext "Aborting...")"
exit 1
@@ -1599,33 +1756,55 @@ else
extract_sources
fi
-if [ "$NOBUILD" = "1" ]; then
+if [ "$NOBUILD" -eq 1 ]; then
msg "$(gettext "Sources are ready.")"
exit 0 #E_OK
else
# check for existing pkg directory; don't remove if we are repackaging
- if [ -d "$pkgdir" -a "$REPKG" = "0" ]; then
+ if [ -d "$pkgdir" \
+ -a \( "$REPKG" -eq 0 -o "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then
msg "$(gettext "Removing existing pkg/ directory...")"
rm -rf "$pkgdir"
fi
mkdir -p "$pkgdir"
cd "$startdir"
+ # if we are root or if fakeroot is not enabled, then we don't use it
if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then
- # if we are root or if fakeroot is not enabled, then we don't use it
- if [ "$REPKG" = "1" ]; then
- warning "$(gettext "Skipping build.")"
+ if [ "$REPKG" -eq 0 ]; then
+ devel_update
+ run_build
+ fi
+ if [ "$SPLITPKG" -eq 0 ]; then
+ if [ "$PKGFUNC" -eq 1 ]; then
+ run_package
+ tidy_install
+ elif [ "$REPKG" -eq 0 ]; then
+ tidy_install
+ fi
+ create_package
else
+ for pkg in ${pkgname[@]}; do
+ pkgdir="$pkgdir/$pkg"
+ mkdir -p "$pkgdir"
+ backup_package_variables
+ run_package $pkg
+ tidy_install
+ create_package $pkg
+ restore_package_variables
+ pkgdir="${pkgdir%/*}"
+ done
+ fi
+ else
+ if [ "$REPKG" -eq 0 -a \( "$PKGFUNC" -eq 1 -o "$SPLITPKG" -eq 1 \) ]; then
devel_update
run_build
- tidy_install
+ cd "$startdir"
fi
- create_package
- else
msg "$(gettext "Entering fakeroot environment...")"
- if [ "$newpkgver" != "" ]; then
+ if [ -n "$newpkgver" ]; then
fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $?
else
fakeroot -- $0 -F $ARGLIST || exit $?
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 32e3a301..c6d25aac 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -34,7 +34,6 @@ REPO_DB_FILE=""
umask 0022
msg() {
- [ $QUIET -ne 0 ] && return
local mesg=$1; shift
printf "==> ${mesg}\n" "$@" >&1
}
@@ -68,8 +67,8 @@ repo-remove will update a package database by removing the package name\n\
specified on the command line from the given repo database. Multiple\n\
packages to remove can be specified on the command line.\n\n")"
printf "$(gettext "\
-The -q/--quiet flag to either program will force silent running except\n\
-in the case of warnings or errors.\n\n")"
+Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\
+and errors\n\n")"
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
}
@@ -83,15 +82,6 @@ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")"
}
-# test if a file is a repository DB
-test_repo_db_file () {
- if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
- return 0 # YES
- else
- return 1 # NO
- fi
-}
-
# write a list entry
# arg1 - Entry name
# arg2 - List
@@ -107,8 +97,8 @@ write_list_entry() {
# arg1 - path to delta
db_write_delta()
{
- # blank out all variables and set deltafile to absolute path
- local deltafile=$($realpath "$1")
+ # blank out all variables
+ local deltafile="$1"
local filename=$(basename "$deltafile")
local deltavars pkgname fromver tover arch csize md5sum
@@ -138,12 +128,12 @@ db_write_delta()
# arg1 - path to package
db_write_entry()
{
- # blank out all variables and set pkgfile to an absolute path
- local pkgfile=$($realpath "$1")
+ # blank out all variables
+ local pkgfile="$1"
local pkgname pkgver pkgdesc url builddate packager csize size \
group depend backup license replaces provides conflict force \
_groups _depends _backups _licenses _replaces _provides _conflicts \
- startdir optdepend _optdepends
+ startdir optdepend _optdepends md5sum
local OLDIFS="$IFS"
# IFS (field separator) is only the newline character
@@ -172,22 +162,22 @@ db_write_entry()
IFS=$OLDIFS
- # get compressed size of package
+ # get md5sum and compressed size of package
+ md5sum="$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')"
csize=$(@SIZECMD@ "$pkgfile")
- startdir=$(pwd)
- pushd "$gstmpdir" 2>&1 >/dev/null
-
# ensure $pkgname and $pkgver variables were found
if [ -z "$pkgname" -o -z "$pkgver" ]; then
error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
- popd 2>&1 >/dev/null
return 1
fi
# remove an existing entry if it exists, ignore failures
db_remove_entry "$pkgname"
+ startdir=$(pwd)
+ pushd "$gstmpdir" 2>&1 >/dev/null
+
# create package directory
mkdir "$pkgname-$pkgver"
cd "$pkgname-$pkgver"
@@ -204,7 +194,7 @@ db_write_entry()
# compute checksums
msg2 "$(gettext "Computing md5 checksums...")"
- echo -e "%MD5SUM%\n$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')\n" >>desc
+ echo -e "%MD5SUM%\n$md5sum\n" >>desc
[ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
write_list_entry "LICENSE" "$_licenses" "desc"
@@ -222,6 +212,7 @@ db_write_entry()
write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
# create deltas entry if there are delta files
+ # Xav : why should deltas be in $startdir?
for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do
# This for loop also pulls in all files that start with the current package
# name and are followed by a -whatever. For instance, running this loop for
@@ -247,11 +238,15 @@ db_write_entry()
# add the final newline
[ -f "deltas" ] && echo -e "" >>deltas
+ popd 2>&1 >/dev/null
+
# preserve the modification time
- touch -r "$pkgfile" desc depends
- [ -f "deltas" ] && touch -r "$pkgfile" deltas
+ # Xav : what for?
+ pkgdir="$gstmpdir/$pkgname-$pkgver"
+ touch -r "$pkgfile" "$pkgdir/desc" "$pkgdir/depends"
+ [ -f "$pkgdir/deltas" ] && touch -r "$pkgfile" "$pkgdir/deltas"
- popd 2>&1 >/dev/null
+ return 0
} # end db_write_entry
# remove existing entries from the DB
@@ -298,28 +293,6 @@ if [ $# -lt 2 ]; then
exit 1
fi
-# check for and store the name of a realpath-like program
-if [ $(type -t realpath) ]; then
- realpath='realpath'
-elif [ $(type -t readlink) ]; then
- realpath='readlink -f'
-else
- error "$(gettext "Either realpath or readlink are required by repo-add.")"
- exit 1 # $E_MISSING_PROGRAM
-fi
-
-# source system and user makepkg.conf
-if [ -r "$confdir/makepkg.conf" ]; then
- source "$confdir/makepkg.conf"
-else
- error "$(gettext "%s not found. Cannot continue.")" "$confdir/makepkg.conf"
- exit 1 # $E_CONFIG_ERROR
-fi
-
-if [ -r ~/.makepkg.conf ]; then
- source ~/.makepkg.conf
-fi
-
# main routine
gstmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
error "$(gettext "Cannot create temp directory for database building.")"; \
@@ -341,10 +314,9 @@ for arg in "$@"; do
elif [ "$arg" == "--quiet" -o "$arg" == "-q" ]; then
QUIET=1
elif [ -z "$REPO_DB_FILE" ]; then
- # store absolute path to repo DB
- REPO_DB_FILE=$($realpath "$arg")
+ REPO_DB_FILE="$arg"
if [ -f "$REPO_DB_FILE" ]; then
- if ! test_repo_db_file $cmd; then
+ if ! (bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"); then
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
exit 1
fi
@@ -384,26 +356,27 @@ done
# if all operations were a success, re-zip database
if [ $success -eq 1 ]; then
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
- pushd "$gstmpdir" 2>&1 >/dev/null
- if [ -n "$(ls)" ]; then
- [ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old"
- [ -f "$REPO_DB_FILE" ] && mv "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ case "$REPO_DB_FILE" in
+ *tar.gz) TAR_OPT="z" ;;
+ *tar.bz2) TAR_OPT="j" ;;
+ *) warning "$(gettext "'%s' does not have a valid archive extension.")" \
+ "$REPO_DB_FILE" ;;
+ esac
- case "$DB_COMPRESSION" in
- gz) TAR_OPT="z" ;;
- bz2) TAR_OPT="j" ;;
- *) warning "$(gettext "No compression set.")" ;;
- esac
+ filename=$(basename "$REPO_DB_FILE")
- bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" *
+ pushd "$gstmpdir" 2>&1 >/dev/null
+ if [ -n "$(ls)" ]; then
+ bsdtar -c${TAR_OPT}f "$filename" *
else
- # we should only end up with an empty db after a remove of the last package in the database
+ # the database will be moved to .old below, and there will be no new one to replace it
error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE"
- rm "$REPO_DB_FILE"
fi
-
popd 2>&1 >/dev/null
+
+ [ -f "$REPO_DB_FILE" ] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ [ -f "$gstmpdir/$filename" ] && mv "$gstmpdir/$filename" "$REPO_DB_FILE"
else
msg "$(gettext "No packages modified, nothing to do.")"
fi