blob: 6ed63f72457cd9c5c730796bf0236e0a3aab83a4 (
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
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
|
#!/bin/bash
# post-commit hook: create SBo submission archive for added/updated packages
set -u
REPO_ROOT=$(git rev-parse --show-toplevel)
SBO_DIR="$REPO_ROOT/SBo"
# Find packages whose .SlackBuild was added (A) or modified (M) in this commit.
# git diff-tree output format: <status>\t<file>
# We only want files exactly one directory deep, e.g. hugo/hugo.SlackBuild.
PACKAGES=()
while IFS=$'\t' read -r status file; do
[[ "$status" != "A" && "$status" != "M" ]] && continue
dir=$(dirname "$file")
base=$(basename "$file")
[[ "$dir" == "." ]] && continue # skip root-level files
[[ "$dir" == *"/"* ]] && continue # skip files deeper than one level
[[ "$base" == *.SlackBuild ]] || continue
PACKAGES+=("$dir")
done < <(git diff-tree --no-commit-id -r --name-status HEAD)
[[ ${#PACKAGES[@]} -eq 0 ]] && exit 0
for pkg in "${PACKAGES[@]}"; do
echo ""
echo "==> Package: $pkg"
echo ""
echo "Files to be archived:"
echo "---------------------"
while IFS= read -r f; do
printf '%s\n' "${f#"$REPO_ROOT/"}"
done < <(find "$REPO_ROOT/$pkg" -type f | sort)
echo ""
# Non-interactive override: set SBO_ARCHIVE=yes|no to skip the prompt.
# Lets agents and scripts answer without a terminal.
case "${SBO_ARCHIVE:-}" in
[yY]|[yY][eE][sS]) answer=yes ;;
[nN]|[nN][oO]) echo " -> Skipped (SBO_ARCHIVE=no)."; continue ;;
"")
# No override: need an interactive terminal to prompt.
if [ ! -r /dev/tty ]; then
echo " -> No terminal, skipped (set SBO_ARCHIVE=yes to archive)."
continue
fi
printf "Create SBo archive for '%s'? [y/N] " "$pkg"
answer=""
read -r answer </dev/tty || answer=""
;;
*) echo " -> Skipped (SBO_ARCHIVE='$SBO_ARCHIVE' unrecognized)."; continue ;;
esac
case "$answer" in
[yY]|[yY][eE][sS])
mkdir -p "$SBO_DIR"
if tar -czf "$SBO_DIR/$pkg.tar.gz" -C "$REPO_ROOT" "$pkg"; then
echo " -> Archive created: SBo/$pkg.tar.gz"
else
echo " -> Archive FAILED." >&2
fi
;;
*)
echo " -> Skipped."
;;
esac
done
exit 0
|