From: "Jan Alexander Steffens (heftig)" <[email protected]>

Steal some functions from makepkg in order to parse the PKGBUILD
---
 makechrootpkg.in | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 8 deletions(-)

diff --git a/makechrootpkg.in b/makechrootpkg.in
index 7796298..f69660f 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -237,14 +237,53 @@ export CARCH
 # Copy PKGBUILD and sources
 cp PKGBUILD "$copydir/build/"
 (
+       # extract the protocol from a source entry - return "local" for local 
sources
+       get_protocol() {
+               if [[ $1 = *://* ]]; then
+                       # strip leading filename
+                       local proto="${1##*::}"
+                       printf "%s\n" "${proto%%://*}"
+               else
+                       printf "%s\n" local
+               fi
+       }
+
+       # extract the filename from a source entry
+       get_filename() {
+               local netfile=$1
+
+               # if a filename is specified, use it
+               if [[ $netfile = *::* ]]; then
+                       printf "%s\n" ${netfile%%::*}
+                       return
+               fi
+
+               local proto=$(get_protocol "$netfile")
+
+               case $proto in
+                       bzr*|git*|hg*|svn*)
+                               filename=${netfile%%#*}
+                               filename=${filename%/}
+                               filename=${filename##*/}
+                               if [[ $proto = git* ]]; then
+                                       filename=${filename%%.git*}
+                               fi
+                               ;;
+                       *)
+                               # if it is just an URL, we only keep the last 
component
+                               filename="${netfile##*/}"
+                               ;;
+               esac
+               printf "%s\n" "${filename}"
+       }
+
        source PKGBUILD
        for file in "${source[@]}"; do
-               file="${file%%::*}"
-               file="${file##*://*/}"
-               if [[ -f $file ]]; then
-                       cp "$file" "$copydir/srcdest/"
-               elif [[ -f $SRCDEST/$file ]]; then
-                       cp "$SRCDEST/$file" "$copydir/srcdest/"
+               file="$(get_filename "$file")"
+               if [[ -e $file ]]; then
+                       cp -a "$file" "$copydir/srcdest/"
+               elif [[ -e $SRCDEST/$file ]]; then
+                       cp -a "$SRCDEST/$file" "$copydir/srcdest/"
                fi
        done
 
@@ -312,8 +351,9 @@ else
 fi
 
 for f in "$copydir"/srcdest/*; do
-       chown "$src_owner" "$f"
-       mv "$f" "$SRCDEST"
+       chown -R "$src_owner" "$f"
+       cp -af "$f" "$SRCDEST/"
+       rm -rf "$f"
 done
 
 if $temp_chroot; then
-- 
1.8.2.1

Reply via email to