#!/bin/bash
# extract the protocol from a source entry - return "local" for local sources
get_protocol() {
if [[ $1 = *://* ]]; then
# strip leading filename
local proto="${1#*::}"
proto="${proto%%://*}"
# strip proto+uri://
printf "%s\n" "${proto%%+*}"
elif [[ $1 = *lp:* ]]; then
local proto="${1#*::}"
printf "%s\n" "${proto%%+lp:*}"
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|fossil|git|hg|svn)
filename=${netfile%%#*}
filename=${filename%%\?*}
filename=${filename%/}
filename=${filename##*/}
if [[ $proto = bzr ]]; then
filename=${filename#*lp:}
fi
if [[ $proto = fossil ]]; then
filename=$filename.fossil
fi
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}"
}
for arg; do
if [ ! -e $arg/PKGBUILD ]; then
continue
fi
(cd $arg;
DEST=/sources/archives/kde5/$(basename `pwd`)
mkdir -p $DEST
chown builder:builder $DEST
for src in $(su builder -c "makepkg --printsrcinfo" | grep "^ source = " | cut -d ' ' -f 3-); do
p=$(get_protocol "$src")
if [ "$p" = "local" ]; then
continue
fi
name=$(get_filename "$src")
if [ -e "$name" ]; then
mv -v $name $DEST/
else
echo "$arg:$name does not exist"
fi
done
)
done