2 # SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
3 # SPDX-License-Identifier: MPL-2.0
5 # This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
6 # If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
8 IGNORE_PATTERN='README\..*|LICENSES/.*|post-receive'
11 if grep -q " refs/heads/$LIVE_BRANCH"
13 # Live branch was updated; copy resulting files.
15 # This isn’t super robust; if there is a failure partway thru then
16 # some files will be old and some will be new.
17 hashfiles=$(git ls-tree -rz "$LIVE_BRANCH" | tr '\000\t' '\n;' | sed 's/^[^ ]* [^ ]* //')
18 files=$(printf '%s' "$hashfiles" | sed 's|.*;|/var/www/gitweb/|')
19 existings=$(find /var/www/gitweb -type f)
21 echo '`'"$LIVE_BRANCH"'´ was updated; updating files…'
23 while test -n "$hashfiles"
25 # Iterate over each file and extract it into the appropriate
27 hashfile=$(printf '%s' "$hashfiles" | head -n 1)
28 hash=$(printf '%s\n' "$hashfile" | sed 's/;.*//')
29 file=$(printf '%s\n' "$hashfile" | sed 's|.*;|/var/www/gitweb/|')
30 dir=$(printf '%s\n' "$file" | sed 's|[^/]*$||')
34 # The containing directory does not exist yet.
38 if printf '%s\n' "$file" | grep -E -q '^/var/www/gitweb/('"$IGNORE_PATTERN"')$'
40 # The current file matches the ignore pattern.
43 # The current file does not match the ignore pattern.
44 printf 'Updating <%s>…\n' "$file"
45 git cat-file blob "$hash" > "$file"
48 hashfiles=$(printf '%s' "$hashfiles" | tail -n +2)
51 while test -n "$existings"
53 # Iterate over existing files and remove ones which aren’t in the
55 existing=$(printf '%s' "$existings" | head -n 1)
56 if printf '%s' "$files" | grep -F -q -x "$existing"
58 # The file matches a file in the repo.
61 # The file does not match a file in the repo.
62 printf 'Removing <%s>…\n' "$file"
65 existings=$(printf '%s' "$existings" | tail -n +2)