Fix whitespace issues in td

This commit is contained in:
Jordan Bancino 2022-12-14 01:00:52 +00:00
parent b63eeffb0f
commit 5255c3f773
2 changed files with 126 additions and 124 deletions

View file

@ -45,6 +45,8 @@ Added support for environment variable substitution in all site
files. This makes it easier to release files. This makes it easier to release
.Nm .Nm
versions. versions.
.It
Fix whitespace issues in various shell scripts.
.El .El
.Sh v0.1.0 .Sh v0.1.0
.Pp .Pp

View file

@ -35,9 +35,9 @@
CFLAGS="${CFLAGS} ${DEFINES} ${INCLUDES}" CFLAGS="${CFLAGS} ${DEFINES} ${INCLUDES}"
if [ "$DEBUG" = "1" ]; then if [ "$DEBUG" = "1" ]; then
CFLAGS="$CFLAGS -O0 -g" CFLAGS="$CFLAGS -O0 -g"
LDFLAGS="-lm -pthread -v" LDFLAGS="-lm -pthread -v"
PROG="$PROG-debug" PROG="$PROG-debug"
fi fi
# Check the modificiation time of a file. This is used to do # Check the modificiation time of a file. This is used to do
@ -53,8 +53,8 @@ mod_time() {
stat -f %m "$1" stat -f %m "$1"
;; ;;
*) *)
# Platform unknown, force rebuilding the whole # Platform unknown, force rebuilding the whole
# project every time. # project every time.
echo "0" echo "0"
;; ;;
esac esac
@ -84,72 +84,72 @@ setsubst() {
# Build the source code, and generate the 'build/telodendria' # Build the source code, and generate the 'build/telodendria'
# binary. # binary.
recipe_build() { recipe_build() {
mkdir -p build mkdir -p build
do_rebuild=0 do_rebuild=0
objs="" objs=""
for src in $(find src -name '*.c'); do for src in $(find src -name '*.c'); do
obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/') obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/')
objs="$objs $obj" objs="$objs $obj"
if [ $(mod_time "$src") -ge $(mod_time "$obj") ]; then if [ $(mod_time "$src") -ge $(mod_time "$obj") ]; then
echo "CC $(basename $obj)" echo "CC $(basename $obj)"
obj_dir=$(dirname "$obj") obj_dir=$(dirname "$obj")
mkdir -p "$obj_dir" mkdir -p "$obj_dir"
if ! $CC $CFLAGS -c -o "$obj" "$src"; then if ! $CC $CFLAGS -c -o "$obj" "$src"; then
exit 1 exit 1
fi fi
do_rebuild=1 do_rebuild=1
fi fi
done done
if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then
echo "LD $PROG" echo "LD $PROG"
$CC $LDFLAGS -o "build/$PROG" $objs $CC $LDFLAGS -o "build/$PROG" $objs
else else
echo "Up to date." echo "Up to date."
fi fi
} }
recipe_run() { recipe_run() {
if [ -f "build/$PROG" ]; then if [ -f "build/$PROG" ]; then
"build/$PROG" -f contrib/development.conf "build/$PROG" -f contrib/development.conf
else else
echo "build/$PROG does not exist; build it first." echo "build/$PROG does not exist; build it first."
fi fi
} }
# Remove all build files, which can be regenerated by re-running the # Remove all build files, which can be regenerated by re-running the
# build recipe. # build recipe.
recipe_clean() { recipe_clean() {
rm -r build rm -r build
} }
# Format the source code by updating the copyright headers and # Format the source code by updating the copyright headers and
# then running indent(1) on each source code file. # then running indent(1) on each source code file.
recipe_format() { recipe_format() {
find src -name '*.c' -or -name '*.h' | while IFS= read -r src; do find src -name '*.c' -or -name '*.h' | while IFS= read -r src; do
# Update the headers # Update the headers
srcHeader=$(grep -n -m 1 '^ \*/' "$src" | cut -d ':' -f 1) srcHeader=$(grep -n -m 1 '^ \*/' "$src" | cut -d ':' -f 1)
head "-n$srcHeader" "$src" | head "-n$srcHeader" "$src" |
diff -u -p - LICENSE.txt | diff -u -p - LICENSE.txt |
patch "$src" | grep -v "^Hmm" patch "$src" | grep -v "^Hmm"
# Format the source code # Format the source code
if indent "$src"; then if indent "$src"; then
rm $(basename "$src").BAK rm $(basename "$src").BAK
fi fi
done done
} }
# Deploy the Telodendria website by copying the required files to # Deploy the Telodendria website by copying the required files to
# a web root defined by TELODENDRIA_PUB. # a web root defined by TELODENDRIA_PUB.
recipe_site() { recipe_site() {
if [ -z "$TELODENDRIA_PUB" ]; then if [ -z "$TELODENDRIA_PUB" ]; then
echo "No public root directory specified." echo "No public root directory specified."
echo "Set TELODENDRIA_PUB." echo "Set TELODENDRIA_PUB."
exit 1 exit 1
fi fi
DATE=$(date) DATE=$(date)
@ -165,53 +165,53 @@ recipe_site() {
done done
cd - > /dev/null cd - > /dev/null
find man/ -name '*.[1-9]' | while IFS= read -r man; do find man/ -name '*.[1-9]' | while IFS= read -r man; do
dir=$(dirname "$man") dir=$(dirname "$man")
html=$(basename "$man") html=$(basename "$man")
mkdir -p "$TELODENDRIA_PUB/$dir/" mkdir -p "$TELODENDRIA_PUB/$dir/"
mandoc -Thtml \ mandoc -Thtml \
-O style=/style.css,man=man/man%S/%N.%S.html "$man" \ -O style=/style.css,man=man/man%S/%N.%S.html "$man" \
> "$TELODENDRIA_PUB/$dir/$html.html" > "$TELODENDRIA_PUB/$dir/$html.html"
echo "$TELODENDRIA_PUB/$dir/$html.html" echo "$TELODENDRIA_PUB/$dir/$html.html"
done done
} }
# Generate a release tarball, checksum and sign it, and push it to # Generate a release tarball, checksum and sign it, and push it to
# the web root. # the web root.
recipe_release() { recipe_release() {
if [ -z "$TELODENDRIA_PUB" ]; then if [ -z "$TELODENDRIA_PUB" ]; then
echo "No public root directory specified." echo "No public root directory specified."
echo "Set TELODENDRIA_PUB." echo "Set TELODENDRIA_PUB."
exit 1 exit 1
fi fi
# Tag the release at this point in time. # Tag the release at this point in time.
cvs tag "$CVS_TAG" cvs tag "$CVS_TAG"
mkdir -p "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION" mkdir -p "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
cd "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION" cd "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
# Generate the release tarball. # Generate the release tarball.
cvs export "-r$CVS_TAG" "Telodendria" cvs export "-r$CVS_TAG" "Telodendria"
mv "Telodendria" "Telodendria-v$TELODENDRIA_VERSION" mv "Telodendria" "Telodendria-v$TELODENDRIA_VERSION"
tar -czf "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \ tar -czf "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
"Telodendria-v$TELODENDRIA_VERSION" "Telodendria-v$TELODENDRIA_VERSION"
rm -r "Telodendria-v$TELODENDRIA_VERSION" rm -r "Telodendria-v$TELODENDRIA_VERSION"
# Checksum the release tarball. # Checksum the release tarball.
sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \ sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
> "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256" > "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256"
# Sign the release tarball. # Sign the release tarball.
if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then
signify -S -s "$TELODENDRIA_SIGNIFY_SECRET" \ signify -S -s "$TELODENDRIA_SIGNIFY_SECRET" \
-m "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \ -m "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
-x "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sig" -x "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sig"
else else
echo "Warning: TELODENDRIA_SIGNIFY_SECRET not net." echo "Warning: TELODENDRIA_SIGNIFY_SECRET not net."
echo "The built tarball will not be signed." echo "The built tarball will not be signed."
fi fi
} }
# Generate a formatted patch file. The Telodendria project isn't # Generate a formatted patch file. The Telodendria project isn't
@ -219,63 +219,63 @@ recipe_release() {
# best. Makes them easy to read. # best. Makes them easy to read.
recipe_patch() { recipe_patch() {
# If the user has not set their MXID, try to deduce one from # If the user has not set their MXID, try to deduce one from
# their system. # their system.
if [ -z "$MXID" ]; then if [ -z "$MXID" ]; then
MXID="@${USER}:$(hostname)" MXID="@${USER}:$(hostname)"
fi fi
# If the user has not set their DISPLAY_NAME, try to deduce it # If the user has not set their DISPLAY_NAME, try to deduce it
# from their system. # from their system.
if [ -z "$DISPLAY_NAME" ]; then if [ -z "$DISPLAY_NAME" ]; then
DISPLAY_NAME=$(getent passwd "$USER" | cut -d ':' -f 5 | cut -d ',' -f 1) DISPLAY_NAME=$(getent passwd "$USER" | cut -d ':' -f 5 | cut -d ',' -f 1)
fi fi
# If the user has not set their EDITOR, use a safe default. # If the user has not set their EDITOR, use a safe default.
# (vi should be available on any POSIX system) # (vi should be available on any POSIX system)
if [ -z "$EDITOR" ]; then if [ -z "$EDITOR" ]; then
EDITOR=vi EDITOR=vi
fi fi
NORMALIZED_MXID=$(echo "$MXID" | sed -e 's/@//g' -e 's/:/-/g') NORMALIZED_MXID=$(echo "$MXID" | sed -e 's/@//g' -e 's/:/-/g')
PATCH_FILE="${NORMALIZED_MXID}_$(date +%s).patch" PATCH_FILE="${NORMALIZED_MXID}_$(date +%s).patch"
# Generate the actual patch file # Generate the actual patch file
# Here we write some nice headers, and then do a cvs diff. # Here we write some nice headers, and then do a cvs diff.
( (
printf 'From: "%s" <%s>\n' "$DISPLAY_NAME" "$MXID" printf 'From: "%s" <%s>\n' "$DISPLAY_NAME" "$MXID"
echo "Date: $(date)" echo "Date: $(date)"
echo "Subject: " echo "Subject: "
echo echo
echo "[ ] I have read the Telodendria Project developer certificate" echo "[ ] I have read the Telodendria Project developer certificate"
echo " of origin, and certify that I have permission to submit" echo " of origin, and certify that I have permission to submit"
echo " this patch under the conditions specified in it." echo " this patch under the conditions specified in it."
echo echo
cvs -q diff -uNp $PATCHSET | grep -v '^\? ' cvs -q diff -uNp $PATCHSET | grep -v '^\? '
) > "$PATCH_FILE" ) > "$PATCH_FILE"
"$EDITOR" "$PATCH_FILE" "$EDITOR" "$PATCH_FILE"
echo "$PATCH_FILE" echo "$PATCH_FILE"
} }
recipe_diff() { recipe_diff() {
tmp_patch="/tmp/telodendria-$(date +%s).patch" tmp_patch="/tmp/telodendria-$(date +%s).patch"
cvs -q diff -uNp $PATCHSET > "$tmp_patch" cvs -q diff -uNp $PATCHSET > "$tmp_patch"
if [ -z "$PAGER" ]; then if [ -z "$PAGER" ]; then
PAGER="less -F" PAGER="less -F"
fi fi
$PAGER "$tmp_patch" $PAGER "$tmp_patch"
rm "$tmp_patch" rm "$tmp_patch"
} }
# Execute the user-specified recipes. # Execute the user-specified recipes.
for recipe in $@; do for recipe in $@; do
recipe_$recipe recipe_$recipe
done done
# If no recipe was provided, run a build. # If no recipe was provided, run a build.
if [ -z "$1" ]; then if [ -z "$1" ]; then
recipe_build recipe_build
fi fi