aboutsummaryrefslogtreecommitdiff
path: root/scripts/get-repo-desc.bash
blob: baf5d4adddf19f09ed60f4e3f21d17167c352cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

# This script extracts the repository description from the .gitinfo file and writes it to the repository's description file.

LOCK_FILE=/var/lock/get-repo-desc.lock

exec 9>"$LOCK_FILE"
if ! flock --nonblock 9; then
  echo "Another instance is already running. Exiting."
  exit 1
fi

for repository in /repositories/*; do
  echo "Processing repository: $(basename "$repository")"

  cd /repositories/$(basename "$repository")

  gitinfoExists=$(git ls-tree HEAD -- .gitinfo 2>/dev/null)

  echo "gitinfoExists: $gitinfoExists"

  # does gitinfo exist?
  if [ -z "$gitinfoExists" ]; then
    echo "No .gitinfo found for $(basename "$repository"). Blanking description."
    echo "" > /repositories/$(basename "$repository")/description
    continue
  fi

  gitinfoContents=$(git cat-file -p @:.gitinfo)

  echo "gitinfoContents: $gitinfoContents"

  # extract description from gitinfo (json format)
  description=$(echo "$gitinfoContents" | grep -oP '"description":\s*"\K[^"]+')

  echo "Extracted description: $description"

  # write description to repository description file
  echo "$description" > /repositories/$(basename "$repository")/description
done