-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsum-and-commit.sh
executable file
·69 lines (56 loc) · 1.35 KB
/
sum-and-commit.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
#!/usr/bin/bash
# SPDX-License-Identifier: GPL-3.0
set -Eeuo pipefail
trap 'errorHandler "$?" "${FUNCNAME[0]}" "$LINENO"' ERR
error() {
echo -e "\e[0;31m[ERROR] $*\e[0m" >&2
}
die() {
error "$*"
exit 1
}
log() {
echo -e "\e[0;32m$*\e[0m" >&2
}
errorHandler() {
echo -e "\e[0;31m[BUG] Line $3 ($2): $1\e[0m" >&2
exit "$1"
}
getPkgDir() {
local path
path="$(find . -mindepth 2 -maxdepth 2 -type d -name "$1" -print -quit)"
echo "${path#./}"
}
getPkgVer() {
(
# shellcheck source=/dev/null
source "$1"/spec
echo "$VER"
)
}
sumAndCommit() {
local pkg="$1"
local pkgDir pkgVer
pkgDir="$(getPkgDir "$pkg")"
pkgVer="$(getPkgVer "$pkgDir")"
log "[$pkg] Updated to $pkgVer"
log "[$pkg] Updating checksum ..."
if ! abbs-update-checksum "$pkg"; then
return 1
fi
log "[$pkg] Committing ..."
git add "$pkgDir"
git commit -m "$pkg: update to $pkgVer" -- "$pkgDir"
local commitLog
commitLog="$(git -c core.abbrev=16 \
log HEAD \
--oneline -1 --no-decorate --color=always)"
log "[$pkg] $commitLog"
log "[$pkg] SUCCESS!"
}
readarray -t pkgs < <(git status --porcelain | cut -d' ' -f 3 | (grep -E '/spec$' || true) | cut -d'/' -f2)
for pkg in "${pkgs[@]}"; do
if ! sumAndCommit "$pkg"; then
error "[$pkg] FAILED"
fi
done