2012-11-04 20:52:19 +01:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
own_dir="$(cd "$(dirname "$0")"; pwd)"
|
|
|
|
|
2014-07-01 09:28:35 +02:00
|
|
|
URL_WAS_SET=
|
2014-07-01 09:48:46 +02:00
|
|
|
DL_URL_RE=
|
2012-11-04 20:52:19 +01:00
|
|
|
CURRENT_URL=
|
2013-10-29 07:56:33 +01:00
|
|
|
CURRENT_REV=
|
|
|
|
PREFETCH_COMMAND=
|
2012-11-25 20:57:49 +01:00
|
|
|
NEED_TO_CHOOSE_URL=1
|
2012-11-04 20:52:19 +01:00
|
|
|
|
|
|
|
url () {
|
2014-07-01 09:28:35 +02:00
|
|
|
URL_WAS_SET=1
|
2012-11-04 20:52:19 +01:00
|
|
|
CURRENT_URL="$1"
|
|
|
|
}
|
|
|
|
|
2014-07-01 09:48:46 +02:00
|
|
|
dl_url_re () {
|
|
|
|
DL_URL_RE="$1"
|
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
version_unpack () {
|
|
|
|
sed -re '
|
|
|
|
s/[.]/ /g;
|
|
|
|
s@/@ / @g
|
|
|
|
s/-(rc|pre)/ -1 \1 /g;
|
|
|
|
s/-(gamma)/ -2 \1 /g;
|
|
|
|
s/-(beta)/ -3 \1 /g;
|
|
|
|
s/-(alpha)/ -4 \1 /g;
|
2012-11-10 11:38:53 +01:00
|
|
|
s/[-]/ - /g;
|
2012-11-04 20:52:19 +01:00
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
version_repack () {
|
|
|
|
sed -re '
|
2012-11-10 11:38:53 +01:00
|
|
|
s/ - /-/g;
|
2012-11-04 20:52:19 +01:00
|
|
|
s/ -[0-9]+ ([a-z]+) /-\1/g;
|
|
|
|
s@ / @/@g
|
|
|
|
s/ /./g;
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
version_sort () {
|
|
|
|
version_unpack |
|
2012-11-10 11:38:53 +01:00
|
|
|
sort -t ' ' -n $(for i in $(seq 30); do echo " -k${i}n" ; done) | tac |
|
2012-11-04 20:52:19 +01:00
|
|
|
version_repack
|
|
|
|
}
|
|
|
|
|
|
|
|
position_choice () {
|
|
|
|
head -n "${1:-1}" | tail -n "${2:-1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
matching_links () {
|
|
|
|
"$own_dir"/urls-from-page.sh "$CURRENT_URL" | grep -E "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
link () {
|
|
|
|
CURRENT_URL="$(matching_links "$1" | position_choice "$2" "$3")"
|
2012-11-25 20:57:49 +01:00
|
|
|
unset NEED_TO_CHOOSE_URL
|
2012-11-04 20:52:19 +01:00
|
|
|
echo "Linked by: $*"
|
|
|
|
echo "URL: $CURRENT_URL" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
version_link () {
|
|
|
|
CURRENT_URL="$(matching_links "$1" | version_sort | position_choice "$2" "$3")"
|
2012-11-25 20:57:49 +01:00
|
|
|
unset NEED_TO_CHOOSE_URL
|
2012-11-04 20:52:19 +01:00
|
|
|
echo "Linked version by: $*"
|
|
|
|
echo "URL: $CURRENT_URL" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
redirect () {
|
|
|
|
CURRENT_URL="$(curl -I -L --max-redirs "${1:-99}" "$CURRENT_URL" |
|
|
|
|
grep -E '^Location: ' | position_choice "${2:-999999}" "$3" |
|
|
|
|
sed -e 's/^Location: //; s/\r//')"
|
|
|
|
echo "Redirected: $*"
|
|
|
|
echo "URL: $CURRENT_URL" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
replace () {
|
|
|
|
sed -re "s $1 $2 g"
|
|
|
|
}
|
|
|
|
|
|
|
|
process () {
|
|
|
|
CURRENT_URL="$(echo "$CURRENT_URL" | replace "$1" "$2")"
|
|
|
|
echo "Processed: $*"
|
|
|
|
echo "URL: $CURRENT_URL" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
version () {
|
|
|
|
CURRENT_VERSION="$(echo "$CURRENT_URL" | replace "$1" "$2")"
|
|
|
|
echo "Version: $CURRENT_VERSION" >&2
|
|
|
|
}
|
|
|
|
|
2012-11-08 08:38:34 +01:00
|
|
|
ensure_version () {
|
2012-12-04 06:56:38 +01:00
|
|
|
echo "Ensuring version. CURRENT_VERSION: $CURRENT_VERSION" >&2
|
2012-11-08 08:38:34 +01:00
|
|
|
[ -z "$CURRENT_VERSION" ] && version '.*-([0-9.]+)[-._].*' '\1'
|
|
|
|
}
|
|
|
|
|
2012-11-10 11:38:53 +01:00
|
|
|
ensure_target () {
|
2012-12-04 06:56:38 +01:00
|
|
|
echo "Ensuring target. CURRENT_TARGET: $CURRENT_TARGET" >&2
|
2012-12-22 10:59:02 +01:00
|
|
|
[ -z "$CURRENT_TARGET" ] && target "$(basename "$CONFIG_NAME" .upstream).nix"
|
2012-11-10 11:38:53 +01:00
|
|
|
}
|
|
|
|
|
2012-11-25 20:57:49 +01:00
|
|
|
ensure_name () {
|
2012-12-04 06:56:38 +01:00
|
|
|
echo "Ensuring name. CURRENT_NAME: $CURRENT_NAME" >&2
|
2012-11-25 20:57:49 +01:00
|
|
|
[ -z "$CURRENT_NAME" ] && name "$(basename "$CONFIG_DIR")"
|
|
|
|
echo "Resulting name: $CURRENT_NAME"
|
|
|
|
}
|
|
|
|
|
2012-12-08 10:05:43 +01:00
|
|
|
ensure_attribute_name () {
|
|
|
|
echo "Ensuring attribute name. CURRENT_ATTRIBUTE_NAME: $CURRENT_ATTRIBUTE_NAME" >&2
|
2014-07-01 09:28:35 +02:00
|
|
|
ensure_name
|
2012-12-08 10:05:43 +01:00
|
|
|
[ -z "$CURRENT_ATTRIBUTE_NAME" ] && attribute_name "$CURRENT_NAME"
|
|
|
|
echo "Resulting attribute name: $CURRENT_ATTRIBUTE_NAME"
|
|
|
|
}
|
|
|
|
|
2014-07-01 09:28:35 +02:00
|
|
|
ensure_url () {
|
|
|
|
echo "Ensuring starting URL. CURRENT_URL: $CURRENT_URL" >&2
|
|
|
|
ensure_attribute_name
|
|
|
|
[ -z "$CURRENT_URL" ] && CURRENT_URL="$(retrieve_meta downloadPage)"
|
|
|
|
[ -z "$CURRENT_URL" ] && CURRENT_URL="$(retrieve_meta downloadpage)"
|
|
|
|
[ -z "$CURRENT_URL" ] && CURRENT_URL="$(retrieve_meta homepage)"
|
|
|
|
echo "Resulting URL: $CURRENT_URL"
|
|
|
|
}
|
|
|
|
|
2012-11-25 20:57:49 +01:00
|
|
|
ensure_choice () {
|
2012-12-04 06:56:38 +01:00
|
|
|
echo "Ensuring that choice is made." >&2
|
|
|
|
echo "NEED_TO_CHOOSE_URL: [$NEED_TO_CHOOSE_URL]." >&2
|
|
|
|
echo "CURRENT_URL: $CURRENT_URL" >&2
|
2014-07-01 09:28:35 +02:00
|
|
|
[ -z "$URL_WAS_SET" ] && [ -z "$CURRENT_URL" ] && ensure_url
|
2012-12-04 06:56:38 +01:00
|
|
|
[ -n "$NEED_TO_CHOOSE_URL" ] && {
|
2014-07-01 10:01:11 +02:00
|
|
|
version_link "${DL_URL_RE:-[.]tar[.]([^./])+\$}"
|
2012-11-25 20:57:49 +01:00
|
|
|
unset NEED_TO_CHOOSE_URL
|
|
|
|
}
|
|
|
|
[ -z "$CURRENT_URL" ] && {
|
|
|
|
echo "Error: empty CURRENT_URL"
|
|
|
|
echo "Error: empty CURRENT_URL" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-30 23:59:45 +01:00
|
|
|
revision () {
|
2013-10-29 07:56:33 +01:00
|
|
|
CURRENT_REV="$1"
|
2013-10-30 23:59:45 +01:00
|
|
|
echo "CURRENT_REV: $CURRENT_REV"
|
2013-10-29 07:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
prefetch_command () {
|
|
|
|
PREFETCH_COMMAND="$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
prefetch_command_rel () {
|
|
|
|
PREFETCH_COMMAND="$(dirname "$0")/$1"
|
|
|
|
}
|
|
|
|
|
2012-12-04 06:56:38 +01:00
|
|
|
ensure_hash () {
|
|
|
|
echo "Ensuring hash. CURRENT_HASH: $CURRENT_HASH" >&2
|
|
|
|
[ -z "$CURRENT_HASH" ] && hash
|
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
hash () {
|
2013-10-29 07:56:33 +01:00
|
|
|
CURRENT_HASH="$(${PREFETCH_COMMAND:-nix-prefetch-url} "$CURRENT_URL" $CURRENT_REV)"
|
2012-12-04 06:56:38 +01:00
|
|
|
echo "CURRENT_HASH: $CURRENT_HASH" >&2
|
2012-11-04 20:52:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
name () {
|
|
|
|
CURRENT_NAME="$1"
|
2012-12-04 06:56:38 +01:00
|
|
|
echo "CURRENT_NAME: $CURRENT_NAME" >&2
|
2012-11-04 20:52:19 +01:00
|
|
|
}
|
|
|
|
|
2012-12-08 10:05:43 +01:00
|
|
|
attribute_name () {
|
|
|
|
CURRENT_ATTRIBUTE_NAME="$1"
|
|
|
|
echo "CURRENT_ATTRIBUTE_NAME: $CURRENT_ATTRIBUTE_NAME" >&2
|
|
|
|
}
|
|
|
|
|
2014-07-01 09:28:35 +02:00
|
|
|
retrieve_meta () {
|
|
|
|
nix-instantiate --eval-only '<nixpkgs>' -A "$CURRENT_ATTRIBUTE_NAME".meta."$1" | xargs
|
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
retrieve_version () {
|
2014-07-01 09:28:35 +02:00
|
|
|
PACKAGED_VERSION="$(retrieve_meta version)"
|
2012-11-04 20:52:19 +01:00
|
|
|
}
|
|
|
|
|
2014-07-01 09:48:46 +02:00
|
|
|
ensure_dl_url_re () {
|
|
|
|
echo "Ensuring DL_URL_RE. DL_URL_RE: $DL_URL_RE" >&2
|
|
|
|
[ -z "$DL_URL_RE" ] && dl_url_re "$(retrieve_meta downloadURLRegexp)"
|
|
|
|
echo "DL_URL_RE: $DL_URL_RE" >&2
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:44:18 +01:00
|
|
|
directory_of () {
|
|
|
|
cd "$(dirname "$1")"; pwd
|
|
|
|
}
|
|
|
|
|
|
|
|
full_path () {
|
|
|
|
echo "$(directory_of "$1")/$(basename "$1")"
|
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
target () {
|
|
|
|
CURRENT_TARGET="$1"
|
2012-12-22 11:14:48 +01:00
|
|
|
{ [ "$CURRENT_TARGET" = "${CURRENT_TARGET#/}" ] && CURRENT_TARGET="$CONFIG_DIR/$CURRENT_TARGET"; }
|
2012-11-08 19:44:18 +01:00
|
|
|
echo "Target set to: $CURRENT_TARGET"
|
2012-11-04 20:52:19 +01:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:59:57 +01:00
|
|
|
marker () {
|
|
|
|
BEGIN_EXPRESSION="$1"
|
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
update_found () {
|
|
|
|
echo "Compare: $CURRENT_VERSION vs $PACKAGED_VERSION"
|
|
|
|
[ "$CURRENT_VERSION" != "$PACKAGED_VERSION" ]
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:59:57 +01:00
|
|
|
do_write_expression () {
|
|
|
|
echo "${1}rec {"
|
|
|
|
echo "${1} baseName=\"$CURRENT_NAME\";"
|
|
|
|
echo "${1} version=\"$CURRENT_VERSION\";"
|
2012-12-08 10:05:43 +01:00
|
|
|
echo "${1} name=\"\${baseName}-\${version}\";"
|
2012-11-08 19:59:57 +01:00
|
|
|
echo "${1} hash=\"$CURRENT_HASH\";"
|
|
|
|
echo "${1} url=\"$CURRENT_URL\";"
|
2013-10-29 07:56:33 +01:00
|
|
|
[ -n "$CURRENT_REV" ] && echo "${1} rev=\"$CURRENT_REV\";"
|
2012-11-08 19:59:57 +01:00
|
|
|
echo "${1} sha256=\"$CURRENT_HASH\";"
|
|
|
|
echo "$2"
|
|
|
|
}
|
|
|
|
|
2012-11-10 11:38:53 +01:00
|
|
|
line_position () {
|
|
|
|
file="$1"
|
|
|
|
regexp="$2"
|
|
|
|
count="${3:-1}"
|
|
|
|
grep -E "$regexp" -m "$count" -B 999999 "$file" | wc -l
|
|
|
|
}
|
|
|
|
|
|
|
|
replace_once () {
|
|
|
|
file="$1"
|
|
|
|
regexp="$2"
|
|
|
|
replacement="$3"
|
|
|
|
instance="${4:-1}"
|
|
|
|
|
2012-12-22 11:14:48 +01:00
|
|
|
echo "Replacing once:"
|
|
|
|
echo "file: [[$file]]"
|
|
|
|
echo "regexp: [[$regexp]]"
|
|
|
|
echo "replacement: [[$replacement]]"
|
|
|
|
echo "instance: [[$instance]]"
|
|
|
|
|
2012-11-10 11:38:53 +01:00
|
|
|
position="$(line_position "$file" "$regexp" "$instance")"
|
|
|
|
sed -re "${position}s $regexp $replacement " -i "$file"
|
|
|
|
}
|
|
|
|
|
|
|
|
set_var_value () {
|
|
|
|
var="${1}"
|
|
|
|
value="${2}"
|
|
|
|
instance="${3:-1}"
|
|
|
|
file="${4:-$CURRENT_TARGET}"
|
|
|
|
no_quotes="${5:-0}"
|
|
|
|
|
|
|
|
quote='"'
|
|
|
|
let "$no_quotes" && quote=""
|
|
|
|
|
2012-12-22 11:14:48 +01:00
|
|
|
replace_once "$file" "${var} *= *.*" "${var} = ${quote}${value}${quote};" "$instance"
|
2012-11-10 11:38:53 +01:00
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
do_regenerate () {
|
2012-11-08 19:59:57 +01:00
|
|
|
BEFORE="$(cat "$1" | grep -F "$BEGIN_EXPRESSION" -B 999999;)"
|
|
|
|
AFTER_EXPANDED="$(cat "$1" | grep -F "$BEGIN_EXPRESSION" -A 999999 | grep -E '^ *[}] *; *$' -A 999999;)"
|
|
|
|
AFTER="$(echo "$AFTER_EXPANDED" | tail -n +2)"
|
|
|
|
CLOSE_BRACE="$(echo "$AFTER_EXPANDED" | head -n 1)"
|
|
|
|
SPACING="$(echo "$CLOSE_BRACE" | sed -re 's/[^ ].*//')"
|
|
|
|
|
|
|
|
echo "$BEFORE"
|
|
|
|
do_write_expression "$SPACING" "$CLOSE_BRACE"
|
|
|
|
echo "$AFTER"
|
2012-11-04 20:52:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do_overwrite () {
|
2012-12-04 06:56:38 +01:00
|
|
|
ensure_hash
|
2012-11-04 20:52:19 +01:00
|
|
|
do_regenerate "$1" > "$1.new.tmp"
|
|
|
|
mv "$1.new.tmp" "$1"
|
|
|
|
}
|
|
|
|
|
2014-06-13 11:35:00 +02:00
|
|
|
do_overwrite_just_version () {
|
|
|
|
ensure_hash
|
|
|
|
set_var_value version $CURRENT_VERSION
|
|
|
|
set_var_value sha256 $CURRENT_HASH
|
|
|
|
}
|
|
|
|
|
2014-09-02 11:08:18 +02:00
|
|
|
minimize_overwrite() {
|
|
|
|
do_overwrite(){
|
|
|
|
do_overwrite_just_version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
process_config () {
|
2012-11-08 19:44:18 +01:00
|
|
|
CONFIG_DIR="$(directory_of "$1")"
|
2012-12-22 10:59:02 +01:00
|
|
|
CONFIG_NAME="$(basename "$1")"
|
2012-11-08 19:59:57 +01:00
|
|
|
BEGIN_EXPRESSION='# Generated upstream information';
|
2014-07-01 09:28:35 +02:00
|
|
|
if [ -f "$CONFIG_DIR/$CONFIG_NAME" ] &&
|
|
|
|
[ "${CONFIG_NAME}" = "${CONFIG_NAME%.nix}" ]; then
|
|
|
|
source "$CONFIG_DIR/$CONFIG_NAME"
|
|
|
|
else
|
|
|
|
CONFIG_NAME="${CONFIG_NAME%.nix}"
|
|
|
|
ensure_attribute_name
|
|
|
|
[ -n "$(retrieve_meta updateWalker)" ] ||
|
|
|
|
[ -n "$FORCE_UPDATE_WALKER" ] || {
|
|
|
|
echo "Error: package not marked as safe for update-walker" >&2
|
|
|
|
echo "Set FORCE_UPDATE_WALKER=1 to override" >&2
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
[ -z "$(retrieve_meta fullRegenerate)" ] && eval "
|
2014-09-02 11:08:18 +02:00
|
|
|
minimize_overwrite
|
2014-07-01 09:28:35 +02:00
|
|
|
"
|
|
|
|
fi
|
2012-12-08 10:05:43 +01:00
|
|
|
ensure_attribute_name
|
2012-11-04 20:52:19 +01:00
|
|
|
retrieve_version
|
2014-07-01 09:48:46 +02:00
|
|
|
ensure_dl_url_re
|
2012-11-25 20:57:49 +01:00
|
|
|
ensure_choice
|
2012-11-08 08:38:34 +01:00
|
|
|
ensure_version
|
2012-11-10 11:38:53 +01:00
|
|
|
ensure_target
|
2012-11-04 20:52:19 +01:00
|
|
|
update_found && do_overwrite "$CURRENT_TARGET"
|
|
|
|
}
|
|
|
|
|
2012-11-10 11:38:53 +01:00
|
|
|
source "$own_dir/update-walker-service-specific.sh"
|
|
|
|
|
2012-11-04 20:52:19 +01:00
|
|
|
process_config "$1"
|