2009-08-24 00:10:08 +02:00
|
|
|
#! /bin/sh
|
|
|
|
|
2009-08-26 13:13:36 +02:00
|
|
|
set -x
|
|
|
|
|
2009-08-24 00:10:08 +02:00
|
|
|
own_dir="$(cd "$(dirname "$0")"; sh -c pwd)"
|
|
|
|
|
2009-08-26 13:13:36 +02:00
|
|
|
source "$own_dir/snippets.sh"
|
|
|
|
|
2010-06-05 23:14:01 +02:00
|
|
|
[ -z "$1" ] && {
|
|
|
|
echo "Specify main expression filename."
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2009-08-24 00:10:08 +02:00
|
|
|
main_file="$1"
|
|
|
|
main_dir="$(cd "$(dirname "$main_file")" ; sh -c pwd)"
|
|
|
|
file_name="$(basename "$main_file")"
|
|
|
|
defs_file="$main_dir"/src-info-for-"$file_name"
|
|
|
|
src_file="$main_dir"/src-for-"$file_name"
|
2009-08-26 13:13:36 +02:00
|
|
|
# OK, [vcs] revert is always possible
|
|
|
|
new_src_file="$main_dir"/src-for-"$file_name"
|
2009-08-24 00:10:08 +02:00
|
|
|
|
2009-08-24 06:55:55 +02:00
|
|
|
forcedUrl="$2"
|
|
|
|
|
2009-08-24 00:10:08 +02:00
|
|
|
defs_dir="$("$own_dir"/attrset-to-dir.sh "$defs_file")"
|
|
|
|
src_defs_dir="$("$own_dir"/attrset-to-dir.sh "$src_file")"
|
|
|
|
|
|
|
|
getAttr () {
|
|
|
|
file="$defs_dir"/"$1"
|
|
|
|
data="$( ( [ -f "$file" ] && cat "$file" ) || echo "$2" )"
|
|
|
|
echo "attribute $1 obtained as: [[$data]]" >&2
|
|
|
|
echo "$data"
|
|
|
|
}
|
|
|
|
|
2009-09-08 11:35:21 +02:00
|
|
|
method="$(getAttr method fetchurl)"
|
|
|
|
baseName="$(getAttr baseName 'unnamed-package')"
|
|
|
|
commonPrefetchVars=" version name hash"
|
|
|
|
|
|
|
|
prefetchClause=""
|
2011-12-13 22:00:26 +01:00
|
|
|
[ fetchSFdirs = "$method" ] && {
|
|
|
|
if [ -z "$forcedUrl" ]; then
|
|
|
|
freshUrl="$("$own_dir"/urls-from-page.sh "$(getAttr downloadPage)" |
|
|
|
|
eval "egrep '$(getAttr sourceRegexp '[-][0-9.]+/$')'" |
|
|
|
|
eval "egrep -v '$(getAttr blacklistRegexp '^$')'" |
|
|
|
|
eval "$(getAttr choiceCommand 'head -n 1')" |
|
|
|
|
eval "$(getAttr versionToFileCommand "sed -re 's@/([^/]*-[0-9.]+)/@/\1/\1$(getAttr fileSuffix .tar.gz)@'")"
|
|
|
|
)"
|
|
|
|
|
|
|
|
if ! egrep ':' <<< "$freshUrl" ; then
|
|
|
|
freshUrl="$(dirname "$(getAttr downloadPage).")/$freshUrl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found download link: $freshUrl" >&2
|
|
|
|
else
|
|
|
|
freshUrl="$forcedUrl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
freshUrl="$(echo "$freshUrl" | sed -re "$skipRedirectSF")"
|
|
|
|
echo "Sourceforge-corrected URL: $freshUrl" >&2
|
|
|
|
|
|
|
|
version="$(echo "$freshUrl" |
|
|
|
|
sed -re "$(getAttr versionExtractorSedScript "$extractVersionSF")")"
|
|
|
|
baseName="$(getAttr baseName "$(echo "$freshUrl" | sed -re 's@.*/project/([^/]+)/.*@\1@')")"
|
|
|
|
url="$freshUrl"
|
|
|
|
name="$baseName-$version"
|
|
|
|
advertisedUrl="$freshUrl"
|
|
|
|
|
|
|
|
if [ x"$freshUrl" = x"$(cat "$src_defs_dir"/advertisedUrl)" ]; then
|
|
|
|
echo "Source link not changed" >&2
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
hash=$(nix-prefetch-url "$freshUrl")
|
|
|
|
|
|
|
|
prefetchVars="url advertisedUrl";
|
|
|
|
}
|
2010-06-23 06:39:21 +02:00
|
|
|
[ fetchSF = "$method" ] && {
|
|
|
|
if [ -z "$forcedUrl" ]; then
|
|
|
|
freshUrl="$("$own_dir"/urls-from-page.sh "$(getAttr downloadPage)" |
|
|
|
|
eval "egrep \"$(getAttr sourceRegexp '.*[.]tar[.].*|.*[.]tgz$|.*[.]tbz2$')\"" |
|
|
|
|
eval "egrep -v \"$(getAttr blacklistRegexp '^$')\"" |
|
|
|
|
eval "$(getAttr choiceCommand 'head -1')")"
|
|
|
|
|
|
|
|
if ! egrep ':' <<< "$freshUrl" ; then
|
|
|
|
freshUrl="$(dirname "$(getAttr downloadPage).")/$freshUrl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found download link: $freshUrl" >&2
|
|
|
|
else
|
|
|
|
freshUrl="$forcedUrl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
freshUrl="$(echo "$freshUrl" | sed -re "$skipRedirectSF")"
|
|
|
|
echo "Sourceforge-corrected URL: $freshUrl" >&2
|
|
|
|
|
|
|
|
version="$(echo "$freshUrl" |
|
2010-06-23 12:05:57 +02:00
|
|
|
sed -re "$(getAttr versionExtractorSedScript "$extractVersionSF")")"
|
2010-06-23 06:58:07 +02:00
|
|
|
baseName="$(getAttr baseName "$(echo "$freshUrl" | sed -re 's@.*/project/([^/]+)/.*@\1@')")"
|
2010-06-23 06:39:21 +02:00
|
|
|
url="$freshUrl"
|
|
|
|
name="$baseName-$version"
|
|
|
|
advertisedUrl="$freshUrl"
|
|
|
|
|
|
|
|
if [ x"$freshUrl" = x"$(cat "$src_defs_dir"/advertisedUrl)" ]; then
|
|
|
|
echo "Source link not changed" >&2
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
hash=$(nix-prefetch-url "$freshUrl")
|
|
|
|
|
|
|
|
prefetchVars="url advertisedUrl";
|
|
|
|
}
|
2009-09-08 11:35:21 +02:00
|
|
|
[ fetchurl = "$method" ] && {
|
|
|
|
if [ -z "$forcedUrl" ] ; then
|
|
|
|
freshUrl="$("$own_dir"/urls-from-page.sh "$(getAttr downloadPage)" |
|
2010-06-23 06:39:21 +02:00
|
|
|
eval "egrep \"$(getAttr sourceRegexp '.*[.]tar[.].*|.*[.]tgz$|.*[.]tbz2$')\"" |
|
2009-11-06 11:13:00 +01:00
|
|
|
eval "egrep -v \"$(getAttr blacklistRegexp '^$')\"" |
|
2009-09-08 11:35:21 +02:00
|
|
|
eval "$(getAttr choiceCommand 'head -1')")"
|
|
|
|
|
2009-09-13 20:31:33 +02:00
|
|
|
if ! egrep ':' <<< "$freshUrl" ; then
|
2009-09-08 11:35:21 +02:00
|
|
|
freshUrl="$(dirname "$(getAttr downloadPage).")/$freshUrl"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Found download link: $freshUrl" >&2
|
|
|
|
else
|
|
|
|
freshUrl="$forcedUrl"
|
2009-08-26 13:13:36 +02:00
|
|
|
fi
|
2009-09-08 11:35:21 +02:00
|
|
|
|
|
|
|
version="$(echo "$freshUrl" |
|
|
|
|
eval "sed -re \"$(getAttr versionExtractorSedScript \
|
|
|
|
's/.*-([0-9.]+)[.].*/\1/')\"")"
|
|
|
|
|
|
|
|
mirrorUrl="$(echo "$freshUrl" |
|
|
|
|
eval "sed -r -e \"$(getAttr versionReferenceCreator \
|
2009-09-17 07:18:19 +02:00
|
|
|
's/-'"${version}"'[.]/-\${version}./')\"" |
|
2009-09-08 11:35:21 +02:00
|
|
|
eval "sed -r -e \"$(getAttr mirrorSedScript)\"")"
|
2009-09-13 20:31:33 +02:00
|
|
|
url="$mirrorUrl"
|
2009-09-08 11:35:21 +02:00
|
|
|
|
|
|
|
name="$baseName-$version"
|
|
|
|
|
|
|
|
advertisedUrl="$freshUrl"
|
|
|
|
url="$mirrorUrl"
|
|
|
|
|
|
|
|
if [ x"$freshUrl" = x"$(cat "$src_defs_dir"/advertisedUrl)" ]; then
|
|
|
|
echo "Source link not changed" >&2
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
hash=$(nix-prefetch-url "$freshUrl")
|
2009-08-24 00:10:08 +02:00
|
|
|
|
2009-09-08 11:35:21 +02:00
|
|
|
prefetchVars="url advertisedUrl";
|
|
|
|
}
|
|
|
|
[ "fetchgit" = "$method" ] && {
|
|
|
|
repoUrl="$(getAttr repoUrl)"
|
|
|
|
export NIX_PREFETCH_GIT_CHECKOUT_HOOK="
|
|
|
|
cat .git/HEAD
|
|
|
|
"
|
|
|
|
export NIX_HASH_ALGO=sha256
|
|
|
|
rev="$(getAttr rev '')";
|
2009-09-11 15:16:18 +02:00
|
|
|
rev_and_hash="$("$own_dir"/../fetchgit/nix-prefetch-git "$repoUrl" "$rev" | tee /dev/stderr | tail -2)"
|
2009-09-08 11:35:21 +02:00
|
|
|
|
|
|
|
rev="$(echo "$rev_and_hash" | head -1)"
|
|
|
|
url="$repoUrl";
|
|
|
|
hash="$(echo "$rev_and_hash" | tail -1)"
|
|
|
|
version="$rev"
|
|
|
|
name="$baseName-$version"
|
|
|
|
|
|
|
|
prefetchVars="rev url";
|
|
|
|
}
|
2009-08-26 13:13:36 +02:00
|
|
|
|
2009-09-08 11:35:21 +02:00
|
|
|
prefetchAssignments="";
|
|
|
|
for i in $commonPrefetchVars $prefetchVars; do
|
|
|
|
prefetchAssignments="$prefetchAssignments $i=\"$(eval echo \"\$$i\")\";$(echo -e '\n ')"
|
|
|
|
done;
|
2009-08-26 13:13:36 +02:00
|
|
|
|
|
|
|
extraAssignments=""
|
|
|
|
for i in $(getAttr extraVars ''); do
|
|
|
|
eval "$(getAttr "eval_$i" 'i=""')"
|
2009-09-08 11:35:21 +02:00
|
|
|
extraAssignments="$extraAssignments $i=\"$(eval echo \"\$$i\")\";$(echo -e '\n ')"
|
2009-08-26 13:13:36 +02:00
|
|
|
done
|
|
|
|
|
2009-08-24 00:10:08 +02:00
|
|
|
cat << EOF > "$new_src_file"
|
|
|
|
rec {
|
2009-09-08 11:35:21 +02:00
|
|
|
$prefetchAssignments
|
2009-08-26 13:13:36 +02:00
|
|
|
$extraAssignments
|
2009-08-24 00:10:08 +02:00
|
|
|
}
|
|
|
|
EOF
|