2020-01-04 10:34:52 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i bash -p coreutils git nix curl
|
2021-12-25 15:52:54 +00:00
|
|
|
# shellcheck shell=bash enable=all
|
2020-01-04 10:34:52 +00:00
|
|
|
|
2020-03-17 07:45:20 +00:00
|
|
|
set -e
|
2021-12-25 15:52:54 +00:00
|
|
|
shopt -s inherit_errexit
|
2020-03-17 07:45:20 +00:00
|
|
|
|
2020-01-04 10:34:52 +00:00
|
|
|
# this script will generate versions.nix in the right location
|
|
|
|
# this should contain the versions' revs and hashes
|
|
|
|
# the stable revs are stored only for ease of skipping
|
|
|
|
|
2020-01-11 10:29:55 +00:00
|
|
|
# by default nix-prefetch-url uses XDG_RUNTIME_DIR as tmp
|
|
|
|
# which is /run/user/1000, which defaults to 10% of your RAM
|
|
|
|
# unless you have over 64GB of ram that'll be insufficient
|
|
|
|
# resulting in "tar: no space left on device" for packages3d
|
|
|
|
# hence:
|
|
|
|
export TMPDIR=/tmp
|
2020-01-04 10:34:52 +00:00
|
|
|
|
|
|
|
# if something goes unrepairably wrong, run 'update.sh all clean'
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# support parallel instances for each pname
|
|
|
|
# currently risks reusing old data
|
|
|
|
# no getting around manually checking if the build product works...
|
2020-01-11 10:29:55 +00:00
|
|
|
# if there is, default to commiting?
|
|
|
|
# won't work when running in parallel?
|
2020-01-04 10:34:52 +00:00
|
|
|
# remove items left in /nix/store?
|
|
|
|
|
|
|
|
# get the latest tag that isn't an RC or *.99
|
2021-12-25 15:52:54 +00:00
|
|
|
latest_tags="$(git ls-remote --tags --sort -version:refname https://gitlab.com/kicad/code/kicad.git)"
|
|
|
|
# using a scratch variable to ensure command failures get caught (SC2312)
|
|
|
|
scratch="$(grep -o 'refs/tags/[0-9]*\.[0-9]*\.[0-9]*$' <<< "${latest_tags}")"
|
|
|
|
scratch="$(grep -ve '\.99' -e '\.9\.9' <<< "${scratch}")"
|
|
|
|
scratch="$(head -n 1 <<< "${scratch}")"
|
|
|
|
latest_tag="$(cut -d '/' -f 3 <<< "${scratch}")"
|
2020-01-04 10:34:52 +00:00
|
|
|
|
|
|
|
all_versions=( "${latest_tag}" master )
|
|
|
|
|
|
|
|
prefetch="nix-prefetch-url --unpack --quiet"
|
|
|
|
|
|
|
|
clean=""
|
|
|
|
check_stable=""
|
|
|
|
check_unstable=1
|
|
|
|
commit=""
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
case "${arg}" in
|
|
|
|
help|-h|--help) echo "Read me!" >&2; exit 1; ;;
|
|
|
|
kicad|release|tag|stable|*small|5*|6*) check_stable=1; check_unstable="" ;;
|
|
|
|
all|both|full) check_stable=1; check_unstable=1 ;;
|
|
|
|
commit) commit=1 ;;
|
|
|
|
clean|fix|*fuck) check_stable=1; check_unstable=1; clean=1 ;;
|
|
|
|
master|*unstable|latest|now|today) check_unstable=1 ;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
2020-03-17 07:45:20 +00:00
|
|
|
now=$(date --iso-8601 --utc)
|
2020-01-04 10:34:52 +00:00
|
|
|
|
|
|
|
file="${here}/versions.nix"
|
|
|
|
# just in case this runs in parallel
|
2020-03-17 07:45:20 +00:00
|
|
|
tmp="${here}/,versions.nix.${RANDOM}"
|
2020-01-04 10:34:52 +00:00
|
|
|
|
|
|
|
libs=( symbols templates footprints packages3d )
|
|
|
|
|
2021-12-25 15:52:54 +00:00
|
|
|
get_rev() {
|
|
|
|
git ls-remote --heads --tags "$@"
|
|
|
|
}
|
2020-01-04 10:34:52 +00:00
|
|
|
|
|
|
|
gitlab="https://gitlab.com/kicad"
|
|
|
|
# append commit hash or tag
|
2021-12-25 15:52:54 +00:00
|
|
|
src_pre="https://gitlab.com/api/v4/projects/kicad%2Fcode%2Fkicad/repository/archive.tar.gz?sha="
|
|
|
|
lib_pre="https://gitlab.com/api/v4/projects/kicad%2Flibraries%2Fkicad-"
|
|
|
|
lib_mid="/repository/archive.tar.gz?sha="
|
2020-01-04 10:34:52 +00:00
|
|
|
|
|
|
|
count=0
|
|
|
|
|
|
|
|
printf "Latest tag is\t%s\n" "${latest_tag}" >&2
|
|
|
|
|
|
|
|
if [[ ! -f ${file} ]]; then
|
|
|
|
echo "No existing file, generating from scratch" >&2
|
|
|
|
check_stable=1; check_unstable=1; clean=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "Writing %s\n" "${tmp}" >&2
|
|
|
|
|
|
|
|
# not a dangling brace, grouping the output to redirect to file
|
|
|
|
{
|
|
|
|
|
|
|
|
printf "# This file was generated by update.sh\n\n"
|
|
|
|
printf "{\n"
|
|
|
|
|
|
|
|
for version in "${all_versions[@]}"; do
|
|
|
|
|
|
|
|
if [[ ${version} == "master" ]]; then
|
|
|
|
pname="kicad-unstable"
|
|
|
|
today="${now}"
|
|
|
|
else
|
|
|
|
pname="kicad"
|
|
|
|
today="${version}"
|
|
|
|
fi
|
|
|
|
# skip a version if we don't want to check it
|
|
|
|
if [[ (${version} != "master" && -n ${check_stable}) \
|
|
|
|
|| (${version} == "master" && -n ${check_unstable}) ]]; then
|
|
|
|
|
|
|
|
printf "\nChecking %s\n" "${pname}" >&2
|
|
|
|
|
|
|
|
printf "%2s\"%s\" = {\n" "" "${pname}"
|
|
|
|
printf "%4skicadVersion = {\n" ""
|
|
|
|
printf "%6sversion =\t\t\t\"%s\";\n" "" "${today}"
|
|
|
|
printf "%6ssrc = {\n" ""
|
|
|
|
|
|
|
|
echo "Checking src" >&2
|
2021-12-25 15:52:54 +00:00
|
|
|
scratch="$(get_rev "${gitlab}"/code/kicad.git "${version}")"
|
|
|
|
src_rev="$(cut -f1 <<< "${scratch}")"
|
2020-03-17 07:45:20 +00:00
|
|
|
has_rev="$(grep -sm 1 "\"${pname}\"" -A 4 "${file}" | grep -sm 1 "${src_rev}" || true)"
|
2020-11-06 05:53:42 +00:00
|
|
|
has_hash="$(grep -sm 1 "\"${pname}\"" -A 5 "${file}" | grep -sm 1 "sha256" || true)"
|
2021-12-25 15:52:54 +00:00
|
|
|
|
2020-03-17 07:45:20 +00:00
|
|
|
if [[ -n ${has_rev} && -n ${has_hash} && -z ${clean} ]]; then
|
2020-01-04 10:34:52 +00:00
|
|
|
echo "Reusing old ${pname}.src.sha256, already latest .rev" >&2
|
2021-12-25 15:52:54 +00:00
|
|
|
scratch=$(grep -sm 1 "\"${pname}\"" -A 5 "${file}")
|
|
|
|
grep -sm 1 "rev" -A 1 <<< "${scratch}"
|
2020-01-04 10:34:52 +00:00
|
|
|
else
|
2021-12-25 15:52:54 +00:00
|
|
|
prefetched="$(${prefetch} "${src_pre}${src_rev}")"
|
2020-01-04 10:34:52 +00:00
|
|
|
printf "%8srev =\t\t\t\"%s\";\n" "" "${src_rev}"
|
2021-12-25 15:52:54 +00:00
|
|
|
printf "%8ssha256 =\t\t\"%s\";\n" "" "${prefetched}"
|
2020-03-17 07:45:20 +00:00
|
|
|
count=$((count+1))
|
2020-01-04 10:34:52 +00:00
|
|
|
fi
|
|
|
|
printf "%6s};\n" ""
|
|
|
|
printf "%4s};\n" ""
|
|
|
|
|
|
|
|
printf "%4slibVersion = {\n" ""
|
|
|
|
printf "%6sversion =\t\t\t\"%s\";\n" "" "${today}"
|
|
|
|
printf "%6slibSources = {\n" ""
|
|
|
|
|
|
|
|
for lib in "${libs[@]}"; do
|
|
|
|
echo "Checking ${lib}" >&2
|
2020-10-09 02:46:57 +01:00
|
|
|
url="${gitlab}/libraries/kicad-${lib}.git"
|
2021-12-25 15:52:54 +00:00
|
|
|
scratch="$(get_rev "${url}" "${version}")"
|
|
|
|
scratch="$(cut -f1 <<< "${scratch}")"
|
|
|
|
lib_rev="$(tail -n1 <<< "${scratch}")"
|
2020-03-17 07:45:20 +00:00
|
|
|
has_rev="$(grep -sm 1 "\"${pname}\"" -A 19 "${file}" | grep -sm 1 "${lib_rev}" || true)"
|
2020-11-06 05:53:42 +00:00
|
|
|
has_hash="$(grep -sm 1 "\"${pname}\"" -A 20 "${file}" | grep -sm 1 "${lib}.sha256" || true)"
|
2020-03-17 07:45:20 +00:00
|
|
|
if [[ -n ${has_rev} && -n ${has_hash} && -z ${clean} ]]; then
|
2020-01-04 10:34:52 +00:00
|
|
|
echo "Reusing old kicad-${lib}-${today}.src.sha256, already latest .rev" >&2
|
2021-12-25 15:52:54 +00:00
|
|
|
scratch="$(grep -sm 1 "\"${pname}\"" -A 20 "${file}")"
|
|
|
|
grep -sm 1 "${lib}" -A 1 <<< "${scratch}"
|
2020-01-04 10:34:52 +00:00
|
|
|
else
|
2021-12-25 15:52:54 +00:00
|
|
|
prefetched="$(${prefetch} "${lib_pre}${lib}${lib_mid}${lib_rev}")"
|
2020-01-04 10:34:52 +00:00
|
|
|
printf "%8s%s.rev =\t" "" "${lib}"
|
|
|
|
case "${lib}" in
|
|
|
|
symbols|templates) printf "\t" ;; *) ;;
|
|
|
|
esac
|
|
|
|
printf "\"%s\";\n" "${lib_rev}"
|
2021-12-25 15:52:54 +00:00
|
|
|
printf "%8s%s.sha256 =\t\"%s\";\n" "" "${lib}" "${prefetched}"
|
2020-03-17 07:45:20 +00:00
|
|
|
count=$((count+1))
|
2020-01-04 10:34:52 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
printf "%6s};\n" ""
|
|
|
|
printf "%4s};\n" ""
|
|
|
|
printf "%2s};\n" ""
|
|
|
|
else
|
|
|
|
printf "\nReusing old %s\n" "${pname}" >&2
|
2021-12-23 13:25:32 +00:00
|
|
|
grep -sm 1 "\"${pname}\"" -A 21 "${file}"
|
2020-01-04 10:34:52 +00:00
|
|
|
fi
|
2020-10-09 02:46:57 +01:00
|
|
|
done
|
2020-01-04 10:34:52 +00:00
|
|
|
printf "}\n"
|
|
|
|
} > "${tmp}"
|
|
|
|
|
2020-03-17 07:45:20 +00:00
|
|
|
if grep '""' "${tmp}"; then
|
2020-12-23 11:44:46 +00:00
|
|
|
echo "empty value detected, out of space?" >&2
|
|
|
|
exit "1"
|
2020-03-17 07:45:20 +00:00
|
|
|
fi
|
|
|
|
|
2020-01-04 10:34:52 +00:00
|
|
|
mv "${tmp}" "${file}"
|
|
|
|
|
|
|
|
printf "\nFinished\nMoved output to %s\n\n" "${file}" >&2
|
|
|
|
|
|
|
|
if [[ ${count} -gt 0 ]]; then
|
|
|
|
if [[ ${count} -gt 1 ]]; then s="s"; else s=""; fi
|
|
|
|
echo "${count} revision${s} changed" >&2
|
|
|
|
if [[ -n ${commit} ]]; then
|
|
|
|
git commit -am "$(printf "kicad: automatic update of %s item%s\n" "${count}" "${s}")"
|
|
|
|
fi
|
|
|
|
echo "Please confirm the new versions.nix works before making a PR." >&2
|
|
|
|
else
|
|
|
|
echo "No changes, those checked are up to date" >&2
|
|
|
|
fi
|