2020-05-07 10:21:39 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# This script takes a deps.list file and builds a Nix expression
|
|
|
|
# that can be used by maven-repo-builder.nix to produce a path to
|
|
|
|
# a local Maven repository.
|
|
|
|
#
|
|
|
|
|
|
|
|
CUR_DIR=$(cd "${BASH_SOURCE%/*}" && pwd)
|
|
|
|
|
2020-05-22 18:24:47 +00:00
|
|
|
# This defines URLs of Maven repos we know about and use.
|
|
|
|
declare -a REPOS=(
|
|
|
|
"https://repo.maven.apache.org/maven2"
|
|
|
|
"https://dl.google.com/dl/android/maven2"
|
2021-06-30 13:43:05 +00:00
|
|
|
"https://plugins.gradle.org/m2"
|
|
|
|
"https://jitpack.io"
|
2020-05-22 18:24:47 +00:00
|
|
|
)
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
function nix_fetch() {
|
|
|
|
nix-prefetch-url --print-path --type sha256 "${1}" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2020-05-14 09:13:06 +00:00
|
|
|
function get_nix_path() { echo "${1}" | tail -n1; }
|
|
|
|
function get_nix_sha() { echo "${1}" | head -n1; }
|
|
|
|
function get_sha1() { sha1sum "${1}" | cut -d' ' -f1; }
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
# Assumes REPOS from repos.sh is available
|
|
|
|
function match_repo_url() {
|
|
|
|
for REPO_URL in "${REPOS[@]}"; do
|
|
|
|
if [[ "$1" = ${REPO_URL}* ]]; then
|
|
|
|
echo "${REPO_URL}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo " ! Failed to match a repo for: ${1}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z "${1}" ]]; then
|
|
|
|
echo "Required argument not given!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-24 13:44:15 +00:00
|
|
|
POM_URL=${1}
|
|
|
|
# Drop the POM extension
|
|
|
|
OBJ_REL_URL=${POM_URL%.pom}
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2020-05-24 13:44:15 +00:00
|
|
|
echo -en "${CLR} - Nix entry for: ${1##*/}\r" >&2
|
2020-05-07 10:21:39 +00:00
|
|
|
|
|
|
|
REPO_URL=$(match_repo_url "${OBJ_REL_URL}")
|
|
|
|
|
|
|
|
if [[ -z "${REPO_URL}" ]]; then
|
|
|
|
echo "\r\n ? REPO_URL: ${REPO_URL}" >&2
|
|
|
|
fi
|
|
|
|
# Get the relative path without full URL
|
|
|
|
OBJ_REL_NAME="${OBJ_REL_URL#${REPO_URL}/}"
|
|
|
|
|
2020-05-14 09:13:06 +00:00
|
|
|
OBJ_NIX_FETCH_OUT=$(nix_fetch "${OBJ_REL_URL}.jar")
|
2020-05-07 10:21:39 +00:00
|
|
|
# Dependency might be a JAR or an AAR
|
2020-05-14 09:13:06 +00:00
|
|
|
if [[ ${?} -eq 0 ]]; then
|
|
|
|
# Some deps have only a POM, nor JAR or AAR
|
2020-05-07 10:21:39 +00:00
|
|
|
OBJ_TYPE="jar"
|
2020-05-14 09:13:06 +00:00
|
|
|
OBJ_PATH=$(get_nix_path "${OBJ_NIX_FETCH_OUT}")
|
|
|
|
OBJ_SHA256=$(get_nix_sha "${OBJ_NIX_FETCH_OUT}")
|
2020-05-07 10:21:39 +00:00
|
|
|
OBJ_SHA1=$(get_sha1 "${OBJ_PATH}")
|
2020-05-14 09:13:06 +00:00
|
|
|
else
|
|
|
|
OBJ_NIX_FETCH_OUT=$(nix_fetch "${OBJ_REL_URL}.aar")
|
|
|
|
if [[ ${?} -eq 0 ]]; then
|
|
|
|
OBJ_TYPE="aar"
|
|
|
|
OBJ_PATH=$(get_nix_path "${OBJ_NIX_FETCH_OUT}")
|
|
|
|
OBJ_SHA256=$(get_nix_sha "${OBJ_NIX_FETCH_OUT}")
|
|
|
|
OBJ_SHA1=$(get_sha1 "${OBJ_PATH}")
|
|
|
|
else
|
|
|
|
OBJ_TYPE="pom"
|
|
|
|
fi
|
2020-05-07 10:21:39 +00:00
|
|
|
fi
|
|
|
|
|
2020-05-14 09:13:06 +00:00
|
|
|
# Both JARs and AARs have a POM
|
|
|
|
POM_NIX_FETCH_OUT=$(nix_fetch "${OBJ_REL_URL}.pom")
|
|
|
|
POM_PATH=$(get_nix_path "${POM_NIX_FETCH_OUT}")
|
2020-05-07 10:21:39 +00:00
|
|
|
if [[ -z "${POM_PATH}" ]]; then
|
|
|
|
echo " ! Failed to fetch: ${OBJ_REL_URL}.pom" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-14 09:13:06 +00:00
|
|
|
POM_SHA256=$(get_nix_sha "${POM_NIX_FETCH_OUT}")
|
2020-05-07 10:21:39 +00:00
|
|
|
POM_SHA1=$(get_sha1 "${POM_PATH}")
|
|
|
|
|
|
|
|
# Format into a Nix attrset entry
|
2020-05-14 09:13:06 +00:00
|
|
|
echo -ne "
|
2020-05-07 10:21:39 +00:00
|
|
|
{
|
2020-05-14 09:13:06 +00:00
|
|
|
\"path\": \"${OBJ_REL_NAME}\",
|
|
|
|
\"host\": \"${REPO_URL}\",
|
|
|
|
\"type\": \"${OBJ_TYPE}\","
|
2020-05-07 10:21:39 +00:00
|
|
|
if [[ -n "${POM_SHA256}" ]]; then
|
|
|
|
echo -n "
|
2020-05-14 09:13:06 +00:00
|
|
|
\"pom\": {
|
|
|
|
\"sha1\": \"${POM_SHA1}\",
|
|
|
|
\"sha256\": \"${POM_SHA256}\"
|
|
|
|
}";[[ -n "${OBJ_SHA256}" ]] && echo -n ","
|
2020-05-07 10:21:39 +00:00
|
|
|
fi
|
|
|
|
if [[ -n "${OBJ_SHA256}" ]]; then
|
|
|
|
echo -n "
|
2020-05-14 09:13:06 +00:00
|
|
|
\"jar\": {
|
|
|
|
\"sha1\": \"${OBJ_SHA1}\",
|
|
|
|
\"sha256\": \"${OBJ_SHA256}\"
|
|
|
|
}"
|
2020-05-07 10:21:39 +00:00
|
|
|
fi
|
2020-05-14 09:13:06 +00:00
|
|
|
echo -e "\n },"
|