https://gitlab.com/tezos/tezos
Raw File
Tip revision: 21f6f3d87dec681fd711036387cf7b4b3da7be47 authored by Gauthier SEBILLE on 25 August 2023, 13:52:51 UTC
DAC: fix deamon of DAC
Tip revision: 21f6f3d
update_links.sh
#!/bin/sh

# Scan the log of `make linkcheck` and try to fix any redirected links.
# BEWARE: Sometimes the fixes must be more intelligent than simply replacing
# a link with its redirection (e.g. missing file redirected to a whole website).
# ALWAYS CHECK THE CHANGES BEFORE COMMITTING THEM!

set -eu

trace_file="_build/output.txt"

if ! [ -f $trace_file ]; then
  echo "Should be run within docs/ under the Tezos root directory"
  echo "The log of \`make linkcheck\`, which is assumed to be executed before,"
  echo "must be in _build/output.txt (under docs/)"
  exit 1
fi

regesc_pattern() {
    printf "%s\n" "$1" | sed -e 's/\([][\/.*|]\)/\\&/g'
}

# developer/snoop_example.rst:12: [redirected permanently] https://github.com/project-everest/hacl-star to https://github.com/hacl-star/hacl-star
# user/snapshots.rst:198: [redirected with Found] https://mainnet.xtz-shots.io/ to https://xtz-shots.io/mainnet/
grep -o '^[^/].*:[0-9][0-9]*: .*redirected.*' "$trace_file" | while read -r redirect; do
    pattern="^\([^:]*\):\([0-9][0-9]*\): .*redirected.*\(http[^ ]*\).*\(http[^ ]*\).*";

    file=$(echo "$redirect" | sed "s@${pattern}@\1@");
    line=$(echo "$redirect" | sed "s@${pattern}@\2@");
    prev=$(echo "$redirect" | sed "s@${pattern}@\3@");
    next=$(echo "$redirect" | sed "s@${pattern}@\4@");

    echo "Replacing '$prev' with '$next' on line '$line' of '$file'"
    sed "s/$(regesc_pattern "$prev")/$(regesc_pattern "$next")/" "$file" > "$file.fixed";

    if diff -q "$file" "$file.fixed" > /dev/null ; then
        echo "No replacement was made"
        rm -f "$file.fixed"
    else
        mv "$file.fixed" "$file"
    fi
done
back to top