2023-12-07 04:15:27 +01:00
|
|
|
#!/usr/bin/env bash
|
2023-03-22 02:05:19 +01:00
|
|
|
# Copyright (C) 2022-2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
|
2022-11-22 20:30:28 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2023-03-22 02:05:19 +01:00
|
|
|
# For compatibility with sysexits.h (see man 3 sysexits.h for more details)
|
|
|
|
EX_USAGE=64
|
|
|
|
|
2023-08-17 01:25:02 +02:00
|
|
|
untitled_uri="https://notabug.org/untitled/untitled.git"
|
2023-04-03 02:47:23 +02:00
|
|
|
untitled_path=""
|
2024-01-13 19:19:31 +01:00
|
|
|
untitled_commit="ee3cf7e29d672e5e5fc1a9409e7327ea9abe9325"
|
|
|
|
|
2023-03-22 02:05:19 +01:00
|
|
|
help()
|
|
|
|
{
|
|
|
|
echo "Usage: $0 [options]"
|
|
|
|
echo ""
|
|
|
|
echo "Available options:"
|
|
|
|
echo -e "\t-h, --help"
|
|
|
|
echo -e "\t\tDisplay this help and exit."
|
2023-04-03 02:47:23 +02:00
|
|
|
echo -e "\t--with-untitled-path PATH"
|
|
|
|
echo -e "\t\tUse a local untitled directory from PATH\n" \
|
|
|
|
"\t\tinstead of downloading the latest version from\n" \
|
|
|
|
"\t\t${untitled_uri}"
|
2023-12-07 13:58:57 +01:00
|
|
|
echo -e "\t--download-only"
|
|
|
|
echo -e "\t\tOnly download and setup Untitled. Does not build the"
|
|
|
|
echo -e "\t\twebsite."
|
|
|
|
|
2023-04-01 12:38:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_repo()
|
|
|
|
{
|
|
|
|
dst_path="$1"
|
|
|
|
src_uri="$2"
|
|
|
|
src_path="$3"
|
2023-10-11 14:12:08 +02:00
|
|
|
src_revision="$4"
|
2023-12-06 20:41:16 +01:00
|
|
|
src_patches="$5"
|
2023-04-01 12:38:02 +02:00
|
|
|
|
|
|
|
if [ -z "${src_path}" ] && [ ! -d "${dst_path}" ] ; then
|
|
|
|
git clone "${src_uri}" "${dst_path}"
|
2023-10-11 14:12:08 +02:00
|
|
|
git -C "${dst_path}" checkout "${src_revision}"
|
2023-04-01 12:38:02 +02:00
|
|
|
elif [ ! -d "${dst_path}" ] ; then
|
2024-05-21 15:45:14 +02:00
|
|
|
mkdir -p "$(dirname "${dst_path}")"
|
2023-04-01 12:38:02 +02:00
|
|
|
cp -a "${src_path}" "${dst_path}"
|
2023-10-11 14:12:08 +02:00
|
|
|
if [ -n "${src_revision}" ] ; then
|
|
|
|
git -C "${dst_path}" checkout "${src_revision}"
|
|
|
|
fi
|
2023-04-01 12:38:02 +02:00
|
|
|
elif [ -z "${src_path}" ] ; then
|
2023-12-07 18:50:19 +01:00
|
|
|
localrev="$(git -C "${dst_path}" --no-pager \
|
|
|
|
log --oneline HEAD -1 --format='%H')"
|
2023-11-17 10:14:35 +01:00
|
|
|
|
2023-10-11 14:12:08 +02:00
|
|
|
git -C "${dst_path}" remote get-url origin || \
|
|
|
|
git -C "${dst_path}" remote add origin "${src_uri}"
|
2023-04-01 12:38:02 +02:00
|
|
|
git -C "${dst_path}" remote set-url origin "${src_uri}"
|
|
|
|
git -C "${dst_path}" clean -dfx
|
2023-11-17 10:14:35 +01:00
|
|
|
|
|
|
|
if [ "${localrev}" != "${src_revision}" ] ; then
|
|
|
|
git -C "${dst_path}" fetch origin
|
|
|
|
git -C "${dst_path}" checkout "${src_revision}"
|
|
|
|
fi
|
2023-08-17 01:25:02 +02:00
|
|
|
|
2023-12-06 20:41:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
if git -C "${dst_path}" status | \
|
|
|
|
grep '^rebase in progress;' > /dev/null ; then
|
|
|
|
git -C "${dst_path}" am --abort
|
|
|
|
fi
|
|
|
|
|
|
|
|
for patch in ${src_patches} ; do
|
|
|
|
GIT_COMMITTER_EMAIL="noreply@gnuboot.gnu.org" \
|
|
|
|
GIT_COMMITTER_NAME="website-build" \
|
2024-05-21 15:45:14 +02:00
|
|
|
git -C "${dst_path}" am "$(realpath "${patch}")"
|
2023-12-06 20:41:16 +01:00
|
|
|
done
|
2023-04-01 12:38:02 +02:00
|
|
|
else
|
|
|
|
rm -rf "${dst_path}"
|
|
|
|
cp -a "${src_path}" "${dst_path}"
|
2023-10-11 14:12:08 +02:00
|
|
|
if [ -n "${src_revision}" ] ; then
|
|
|
|
git -C "${dst_path}" checkout "${src_revision}"
|
|
|
|
fi
|
2023-04-01 12:38:02 +02:00
|
|
|
fi
|
2023-03-22 02:05:19 +01:00
|
|
|
}
|
|
|
|
|
2023-11-08 03:40:27 +01:00
|
|
|
copy_website()
|
|
|
|
{
|
|
|
|
dst_path="$1"
|
|
|
|
|
|
|
|
rm -rf "${dst_path}"
|
|
|
|
mkdir -p "${dst_path}"
|
|
|
|
cp "../site.cfg" "${dst_path}"
|
|
|
|
cp -a "../site/" "${dst_path}"
|
|
|
|
}
|
|
|
|
|
2023-04-03 02:33:26 +02:00
|
|
|
help_missing_arg()
|
|
|
|
{
|
|
|
|
printf "Error: Argument of %s is missing.\n\n" "$1"
|
2023-03-22 02:05:19 +01:00
|
|
|
help
|
2023-04-03 02:33:26 +02:00
|
|
|
}
|
|
|
|
|
2023-12-07 13:58:57 +01:00
|
|
|
download_only=0
|
2023-04-03 02:33:26 +02:00
|
|
|
i=1
|
2023-11-07 20:03:17 +01:00
|
|
|
while [ "$i" -le $# ] ; do
|
2023-04-03 02:33:26 +02:00
|
|
|
opt="$(eval echo \$$i)"
|
|
|
|
|
|
|
|
case "${opt}" in
|
|
|
|
-h|--help)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
;;
|
2023-12-07 13:58:57 +01:00
|
|
|
--download-only)
|
|
|
|
download_only=1
|
|
|
|
;;
|
2023-04-03 02:47:23 +02:00
|
|
|
--with-untitled-path)
|
2023-11-07 20:03:17 +01:00
|
|
|
if [ "$i" -ge $# ] ; then
|
2023-04-03 02:47:23 +02:00
|
|
|
help_missing_arg "--with-untitled-path"
|
|
|
|
exit ${EX_USAGE}
|
|
|
|
fi
|
2024-05-21 15:45:14 +02:00
|
|
|
untitled_path="$(eval echo \$$((i + 1)))"
|
|
|
|
i="$((i + 1))"
|
2023-04-03 02:47:23 +02:00
|
|
|
;;
|
2023-04-03 02:33:26 +02:00
|
|
|
*)
|
|
|
|
help
|
|
|
|
exit ${EX_USAGE}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2024-05-21 15:45:14 +02:00
|
|
|
i="$((i + 1))"
|
2023-04-03 02:33:26 +02:00
|
|
|
done
|
2023-03-22 02:05:19 +01:00
|
|
|
|
2022-11-22 20:30:28 +01:00
|
|
|
set -e
|
|
|
|
|
2023-08-17 01:25:02 +02:00
|
|
|
sync_repo "untitled" \
|
2023-12-06 20:41:16 +01:00
|
|
|
"${untitled_uri}" "${untitled_path}" \
|
2024-01-13 19:19:31 +01:00
|
|
|
"${untitled_commit}"
|
2022-11-22 20:30:28 +01:00
|
|
|
|
2023-12-07 13:58:57 +01:00
|
|
|
if [ "${download_only}" -eq 0 ] ; then
|
|
|
|
copy_website "untitled/www/lbwww/"
|
|
|
|
|
|
|
|
cd untitled
|
|
|
|
./build sites lbwww
|
|
|
|
fi
|