forked from jedahan/kiss-find
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_database.sh
executable file
·73 lines (58 loc) · 1.82 KB
/
build_database.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh -e
# might not work for non-github repos, fix that
sanitize_folder_name() {
printf "%s\n" "${1%.git}" | cut -d"/" -f4- | sed 's@/@_@'
}
get_path_in_repo() {
echo "$1" | cut -d"/" -f2-
}
find_packages() {
find -L "$1" -name build -type f -exec dirname {} \;
}
fetch_repo() {
REPO="$1"
FOLDER="$2"
if [ -d "$FOLDER" ]; then
echo " -> Pulling" >&2
cd "$FOLDER"
git pull -f >&2 || true
cd ".."
else
echo " -> Cloning" >&2
git clone "$REPO" "$FOLDER" >&2 || return 1
cd "$FOLDER"
git config user.email "kissfind@mail.invalid" >&2
git config user.name "kiss-find database" >&2
cd ".."
fi
}
process_repo() {
REPO="$1"
FOLDER="$2"
find_packages "$FOLDER" | while read -r PACKAGE; do
PPATH="$(get_path_in_repo "$PACKAGE")"
BRANCH="$(git -C "$FOLDER" branch --show-current || echo unknown)"
echo " -> Found package $PACKAGE" >&2
if [ -L "$PACKAGE/version" ]; then
# not sure how to handle symlinks in a proper way yet
VERSION="symlink"
MAINTAINER="unknown"
elif [ -f "$PACKAGE/version" ]; then
VERSION="$(cat "$PACKAGE/version")"
MAINTAINER="$(git -C "$FOLDER" log --max-count 1 --format='%aN' -- "$PPATH/version" 2>/dev/null)"
else
VERSION="unknown"
MAINTAINER="unknown"
fi
NAME="$(basename "$PACKAGE")"
printf '%s,%s,%s,%s,%s,"%s"\n' \
"$NAME" "$VERSION" "$REPO" "$PPATH" "$BRANCH" "$MAINTAINER"
done
}
mkdir -p "build/repos" && cd build/repos
while read -r REPO; do
FOLDER="$(sanitize_folder_name "$REPO")"
echo ":: $REPO ($FOLDER)" >&2
fetch_repo "$REPO" "$FOLDER" || continue
process_repo "$REPO" "$FOLDER"
done <"${1:-/dev/stdin}"