-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake-spec
More file actions
executable file
·83 lines (80 loc) · 3.17 KB
/
make-spec
File metadata and controls
executable file
·83 lines (80 loc) · 3.17 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
#!/bin/bash
PKG=openbao
if [ ! -f $PKG.spec.in ]; then
echo "$PKG.spec.in doesn't exist!" >&2
exit 1
fi
ORG="$(grep ^Source0: $PKG.spec.in|cut -d/ -f4)"
# Check if someone accidentally modified $PKG.spec. This is tricky
# because git does not keep track of whether not a file is readonly.
# This script generates it read-only, so if it isn't writable then it
# is OK. Otherwise if it is more than 2 seconds newer than the .in
# most likely it was edited after git checkout.
if [ -w $PKG.spec ]; then
INTIME="$(stat -c '%Y' $PKG.spec.in)"
OUTTIME="$(stat -c '%Y' $PKG.spec)"
if (( $OUTTIME >= $INTIME + 2 )); then
echo "$PKG.spec is newer than $PKG.spec.in -- was it accidentally edited?" >&2
exit 2
fi
fi
VERSION="$(sed -n 's/%global package_version[ \t]*//p' $PKG.spec.in)"
DISTURL="$(sed -n "s/^Source0: //p" $PKG.spec.in|sed -e "s/%{name}/$PKG/g" -e "s/%{package_version}/$VERSION/g")"
DISTBALL="$(basename $DISTURL)"
DIST="$(echo $DISTBALL|sed 's/\.tar.*//')"
if [ ! -f "$DISTBALL" ]; then
curl -sLO "$DISTURL"
if [ ! -f "$DISTBALL" ]; then
echo "Couldn't download $DISTURL!" >&2
exit 4
fi
fi
GOMOD=go.mod
NVERS=VERSION_NODE_MODULES.txt
LDEP=LICENSE_DEPENDENCIES.md
NDEP=SPDX_NODE_MODULES.txt
DISTFILES="$GOMOD $NVERS $LDEP $NDEP"
trap "rm -f $DISTFILES" 0
TARPATHS=""
for F in $DISTFILES; do
TARPATHS="$TARPATHS $DIST/$F"
done
tar --xform "s/^$DIST/./" -xf $DISTBALL $TARPATHS
for F in $DISTFILES; do
if [ ! -f $F ]; then
echo "$F not found in $DISTBALL!" >&2
exit 4
fi
done
rm -f $PKG.spec
while IFS='' read -r LINE; do
if [[ "$LINE" = *"bundled provides" ]]; then
awk '{if (index($1, "/") != 0 && ($1 != "//")) {print "Provides: bundled(golang("$1")) = "$2}}' $GOMOD | sed -e 's/-/_/g' | sort | uniq
awk '{print "Provides: bundled(nodejs-"$1") = "$2}' $NVERS
elif [[ "$LINE" = "License:"* ]]; then
MAINLICENSE="$(echo $LINE|sed 's/^License: //')"
# These get detected by go_vendor_license but not by the tool
# used upstream, github.com/google/go-licenses.
# The first is from github.com/apparentlymart/go-textseg/v13/LICENSE
# and the second from github.com/Nvveen/Gotty/LICENSE
EXTRALICENSES="Unicode-DFS-2016 BSD-2-Clause-Views"
LICENSES="$((sed -n "s/^\*\*.*License:\*\* //p" $LDEP|grep -v Unknown;echo $EXTRALICENSES|tr ' ' '\n';sed 's/^BSD$/BSD-3-Clause/;/^Public Domain/d;s/^(\([^ ]*\) AND \([^)]*\))/\1\n\2/' $NDEP)|sort -u|grep -v "^$MAINLICENSE$"|tr '\n' ':'|sed 's/:$//;s/:/ AND /g')"
if [ -z "$LICENSES" ]; then
echo "Didn't find any licenses in $LDEP!" >&2
exit 4
fi
rm -f $LDEP
echo "License: $MAINLICENSE AND $LICENSES"
elif [[ "$LINE" = *"@GOVERSION@"* ]]; then
if [ -f goversion.patch ]; then
GOVERSION="$(sed -n 's/^\+go //p' goversion.patch)"
else
URL="https://raw.githubusercontent.com/$ORG/$PKG/refs/tags/v$VERSION/.go-version"
GOVERSION="$(curl -sSL -f -m 15 $URL)"
fi
echo "$LINE" | sed "s/@GOVERSION@/$GOVERSION/"
else
echo "$LINE"
fi
done <$PKG.spec.in >$PKG.spec
chmod 444 $PKG.spec