mirror of
https://pagure.io/fedora-docs/quick-docs.git
synced 2024-11-28 06:54:52 +00:00
chore(builder.sh): sync with upstream version
This commit is contained in:
parent
b5d01b36c9
commit
b8508f7b30
1 changed files with 80 additions and 6 deletions
86
builder.sh
86
builder.sh
|
@ -1,13 +1,35 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# script to watch source directory for changes, and re-run build and preview
|
||||||
|
#
|
||||||
|
# License: MIT
|
||||||
|
# https://fedoraproject.org/wiki/Licensing:MIT#Another_Minimal_variant_(found_in_libatomic_ops)
|
||||||
|
#
|
||||||
|
# Copyright (c) Fedora community contributors.
|
||||||
|
#
|
||||||
|
# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR
|
||||||
|
# IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted to use or copy this program for any purpose,
|
||||||
|
# provided the above notices are retained on all copies. Permission to modify
|
||||||
|
# the code and to distribute modified code is granted, provided the above
|
||||||
|
# notices are retained, and a notice that the code was modified is included
|
||||||
|
# with the above copyright notice.
|
||||||
|
|
||||||
# script to watch source directory for changes, and automatically call build.sh to rebuild as required.
|
|
||||||
|
|
||||||
|
script_name="docsbuilder.sh"
|
||||||
|
script_source="https://gitlab.com/fedora/docs/templates/fedora-docs-template/-/raw/main/${script_name}"
|
||||||
|
version="1.2.0"
|
||||||
image="docker.io/antora/antora"
|
image="docker.io/antora/antora"
|
||||||
cmd="--html-url-extension-style=indexify site.yml"
|
cmd="--html-url-extension-style=indexify site.yml"
|
||||||
srcdir="modules"
|
srcdir="modules"
|
||||||
buildir="public"
|
buildir="public"
|
||||||
previewpidfile="preview.pid"
|
previewpidfile="preview.pid"
|
||||||
inotifyignore=".git*"
|
|
||||||
|
# 4913: for vim users, vim creates a temporary file to test it can write to
|
||||||
|
# directory
|
||||||
|
# https://groups.google.com/g/vim_dev/c/sppdpElxY44
|
||||||
|
# .git: so we don't get rebuilds each time git metadata changes
|
||||||
|
inotifyignore="\.git.*|4913"
|
||||||
|
|
||||||
watch_and_build () {
|
watch_and_build () {
|
||||||
if ! command -v inotifywait > /dev/null
|
if ! command -v inotifywait > /dev/null
|
||||||
|
@ -29,12 +51,12 @@ watch_and_build () {
|
||||||
# temporary files that are updated regularly and so on, so better
|
# temporary files that are updated regularly and so on, so better
|
||||||
# to get the list from git. It'll also look at global gitingore
|
# to get the list from git. It'll also look at global gitingore
|
||||||
# settings and so on.
|
# settings and so on.
|
||||||
inotifyignore="$(git status -s --ignored | grep '^!!' | sed -e 's/^!! //' -e 's:/:\*:' | tr '\n' '|')${inotifyignore}"
|
inotifyignore="$(git status -s --ignored | grep '^!!' | sed -e 's/^!! //' | tr '\n' '|')${inotifyignore}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
echo "Watching current directory (excluding ${inotifyignore}) for changes and re-building as required. Use Ctrl C to stop."
|
echo "Watching current directory (excluding: ${inotifyignore}) for changes and re-building as required. Use Ctrl C to stop."
|
||||||
inotifywait -q --exclude "($inotifyignore)" -e modify,create,delete,move -r . && echo "Change detected, rebuilding.." && build
|
inotifywait -q --exclude "($inotifyignore)" -e modify,create,delete,move -r . && echo "Change detected, rebuilding.." && build
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -138,6 +160,47 @@ stop_preview_and_exit ()
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# https://apple.stackexchange.com/questions/83939/compare-multi-digit-version-numbers-in-bash/123408#123408
|
||||||
|
version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
|
||||||
|
|
||||||
|
|
||||||
|
check_update () {
|
||||||
|
if ! command -v curl > /dev/null
|
||||||
|
then
|
||||||
|
echo "curl command could not be found. Please install curl."
|
||||||
|
echo "On Fedora, run: sudo dnf install curl"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
script_version="$(grep "^version=" ${script_name} | cut -d '=' -f2 | tr --delete '"')"
|
||||||
|
tempdir="$(mktemp -d)"
|
||||||
|
echo "$tempdir"
|
||||||
|
pushd "$tempdir" > /dev/null 2>&1
|
||||||
|
curl "$script_source" --silent --output "${script_name}"
|
||||||
|
upstream_version="$(grep "^version=" ${script_name} | cut -d '=' -f2 | tr --delete '"')"
|
||||||
|
echo "${upstream_version}"
|
||||||
|
if [ $(version $upstream_version) -gt $(version $script_version) ]; then
|
||||||
|
echo "Update available"
|
||||||
|
echo "Script version $upstream_version is available at $script_source"
|
||||||
|
echo "This version is $script_version."
|
||||||
|
echo "Please use the '-U' option to update."
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
popd > /dev/null 2&>1
|
||||||
|
}
|
||||||
|
|
||||||
|
install_update () {
|
||||||
|
if ! command -v curl > /dev/null
|
||||||
|
then
|
||||||
|
echo "curl command could not be found. Please install curl."
|
||||||
|
echo "On Fedora, run: sudo dnf install curl"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
curl "$script_source" --silent --output "${script_name}.new"
|
||||||
|
mv "${script_name}.new" "${script_name}"
|
||||||
|
chmod +x "${script_name}"
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "$0: Build and preview Fedora antora based documentation"
|
echo "$0: Build and preview Fedora antora based documentation"
|
||||||
echo
|
echo
|
||||||
|
@ -149,6 +212,8 @@ usage() {
|
||||||
echo "-p: start_preview"
|
echo "-p: start_preview"
|
||||||
echo "-k: stop_preview"
|
echo "-k: stop_preview"
|
||||||
echo "-h: print this usage text and exit"
|
echo "-h: print this usage text and exit"
|
||||||
|
echo "-u: check builder script update"
|
||||||
|
echo "-U: install builder script from upstream"
|
||||||
echo
|
echo
|
||||||
echo "Maintained by the Fedora documentation team."
|
echo "Maintained by the Fedora documentation team."
|
||||||
echo "Please contact on our channels: https://docs.fedoraproject.org/en-US/fedora-docs/#find-docs"
|
echo "Please contact on our channels: https://docs.fedoraproject.org/en-US/fedora-docs/#find-docs"
|
||||||
|
@ -165,6 +230,7 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ $# -lt 1 ]
|
if [ $# -lt 1 ]
|
||||||
then
|
then
|
||||||
echo "No options provided, running preview with watch and build."
|
echo "No options provided, running preview with watch and build."
|
||||||
|
@ -178,7 +244,7 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while getopts "awbpkh" OPTION
|
while getopts "awbpkhuU" OPTION
|
||||||
do
|
do
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
a)
|
a)
|
||||||
|
@ -199,7 +265,7 @@ do
|
||||||
;;
|
;;
|
||||||
p)
|
p)
|
||||||
start_preview
|
start_preview
|
||||||
echo "Please run ./builder.sh -k to stop the preview server"
|
echo "Please run ./${script_name} -k to stop the preview server"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
k)
|
k)
|
||||||
|
@ -210,6 +276,14 @@ do
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
u)
|
||||||
|
check_update
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
U)
|
||||||
|
install_update
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
?)
|
?)
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in a new issue