forked from JohanSjoblom/picochess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-library-updates.sh
More file actions
executable file
·94 lines (78 loc) · 2.29 KB
/
check-library-updates.sh
File metadata and controls
executable file
·94 lines (78 loc) · 2.29 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
# check-library-updates
#
# Check updates via pip-review ONLY for libraries pinned with "==" in
# requirements.txt. Runs one library at a time, filters dependency noise,
# normalizes '_' vs '-', and always stops on Ctrl-C.
#
# Usage:
# ./check-library-updates [requirements.txt]
#
# Optional:
# TIMEOUT_SECS=20 ./check-library-updates
# NOTE:
# pip-review outputs may differ:
# - "pkg old -> new"
# - "pkg==new is available (you have old)"
# This script intentionally supports both.
REQ_FILE=${1:-requirements.txt}
TIMEOUT_SECS=${TIMEOUT_SECS:-10}
if [ ! -f "$REQ_FILE" ]; then
echo "Error: requirements file not found: $REQ_FILE" >&2
exit 2
fi
if ! command -v pip-review >/dev/null 2>&1; then
echo "Error: pip-review not found. Install with: pip install pip-review" >&2
exit 2
fi
if ! command -v timeout >/dev/null 2>&1; then
echo "Error: 'timeout' not found (coreutils required)." >&2
exit 2
fi
tmp_pkgs=$(mktemp "${TMPDIR:-/tmp}/check-libs.XXXXXX") || exit 2
tmp_out=$(mktemp "${TMPDIR:-/tmp}/check-libs-out.XXXXXX") || exit 2
cleanup() {
echo "" >&2
echo "Interrupted. Stopping." >&2
rm -f "$tmp_pkgs" "$tmp_out"
exit 130
}
trap cleanup INT TERM HUP
# Extract pinned package names (left side of '==')
sed -n '
s/\r$//
s/#.*$//
s/^[[:space:]]*//
s/[[:space:]]*$//
/^[[:space:]]*$/d
s/^\([^=[:space:]]*\)==.*/\1/p
' "$REQ_FILE" > "$tmp_pkgs"
export PIP_NO_INPUT=1
export PIP_DISABLE_PIP_VERSION_CHECK=1
while IFS= read -r pkg; do
[ -n "$pkg" ] || continue
echo "Checking $pkg..." >&2
: > "$tmp_out"
timeout --foreground -k 2s "${TIMEOUT_SECS}s" \
pip-review "$pkg" </dev/null >"$tmp_out" 2>/dev/null || true
# Print only lines for THIS package, supporting both pip-review output formats:
# 1) "pkg 1.0 -> 1.1"
# 2) "pkg==1.1 is available (you have 1.0)"
awk -v p="$pkg" '
function norm(s) { s=tolower(s); gsub(/_/, "-", s); return s }
BEGIN { pl = norm(p) }
{
line = $0
low = norm($0)
# allow "pkg " OR "pkg==" at start
if (index(low, pl " ") == 1 || index(low, pl "==") == 1) {
# keep only lines that look like an update
if (index(low, "->") > 0 || index(low, " is available") > 0) {
print line
}
}
}
' "$tmp_out"
done < "$tmp_pkgs"
rm -f "$tmp_pkgs" "$tmp_out"
exit 0