Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/Tools/scripts/bump-revision.sh
18157 views
1
#!/bin/sh
2
3
#
4
# bump-revision.sh category/portname category/portname ...
5
# Bump PORTREVISION if it exists or create it with number 1 if it does not
6
#
7
# ----------------------------------------------------------------------------
8
# "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
9
# Bartek Rutkowski <[email protected]> wrote this file. As long as you retain
10
# this notice you can do whatever you want with this stuff. If we meet some
11
# day, and you think this stuff is worth it, you can buy me a beer in return.
12
#
13
# Bartek Rutkowski
14
# ----------------------------------------------------------------------------
15
#
16
# MAINTAINER= [email protected]
17
18
#
19
# functions
20
#
21
22
printc () {
23
# $1 - msg is obligatory, $2 - color (red/green)of the message, default if not passed
24
if [ -t 1 ]; then
25
if [ $# -eq 2 ]; then
26
if [ $2 = "red" ]; then
27
echo -e "\033[1;31m$1\033[m"
28
elif [ $2 = "green" ]; then
29
echo -e "\033[1;32m$1\033[m"
30
else
31
echo "$1"
32
fi
33
fi
34
else
35
echo $1
36
fi
37
}
38
39
#
40
# main loop
41
#
42
43
tempfile=$(mktemp)
44
trap "rm -f $tempfile" 0 1 2 3 15
45
46
while [ $# -gt 0 ]
47
do
48
if [ -f "$1/Makefile" ]; then
49
# See what the port thinks its PORTREVISION is and save that.
50
pre=$(make -C "$1" -V PORTREVISION)
51
52
# If the Makefile exists, continue and empty the tempfile, set up variables
53
echo -n > $tempfile
54
revision_str=`grep "^PORTREVISION?\?=" "$1/Makefile"`
55
56
case $? in
57
0)
58
# If the exit code is 0, then PORTREVISION line was found
59
if [ `echo "$revision_str" | wc -l` = 1 ]; then
60
# If the $revision_str variable has only 1 line, then proceed with processing it
61
case `echo "$revision_str" | awk -F "\t+" '{ print $2 }'` in
62
(*[^0-9]*|'')
63
# If the value of PORTREVISION is not an integer, we can't bump its value
64
printc "ERROR: $1 PORTREVISION value is not a number, unable to solve!" "red"
65
;;
66
(*)
67
# If the value of PORTREVISION is an integer, increase it by 1
68
printc "INFO: $1 $revision_str found, bumping it by 1." "green"
69
rm -f $tempfile && awk -F "\t+" '/^PORTREVISION\??=/{ gsub ($2, $2+1) }; { print }' "$1/Makefile" > $tempfile \
70
&& cat $tempfile > "$1/Makefile" \
71
|| printc "ERROR: $1 PORTREVISION found but failed to bump it!" "red"
72
;;
73
esac
74
else
75
# If the $revision_str variable had more than 1 line, we can't bump its value safely
76
printc "ERROR: $1 PORTREVISION found more than once, unable to bump it reliably!" "red"
77
fi
78
;;
79
1)
80
# If the exit code is 1 then PORTREVISION wasn't found, so we need to add one with value of 1
81
printc "INFO: $1 PORTREVISION not found, adding PORTREVISION= 1" "green"
82
rm -f $tempfile && awk '/^(PORT|DIST)VERSION\??=\t/{ print; print "PORTREVISION=\t1"; next } { print }' "$1/Makefile" > $tempfile \
83
&& cat $tempfile > "$1/Makefile"
84
# If there is not PORTREVISION line, maybe it is a slave port, try
85
# to add it before a CATEGORIES, PKGNAMESUFFIX or PKGNAMEPREFIX line:
86
for line in CATEGORIES PKGNAMEPREFIX PKGNAMESUFFIX; do
87
if ! grep -q "^PORTREVISION?\?=" $1/Makefile; then
88
rm -f $tempfile && awk '/^'${line}'\??=\t/{ print "PORTREVISION=\t1"; print; next } { print }' "$1/Makefile" > $tempfile \
89
&& cat $tempfile > "$1/Makefile"
90
fi
91
done
92
# If it still is not there, bail out
93
if ! grep -q "^PORTREVISION?\?=" $1/Makefile; then
94
printc "ERROR: $1 PORTREVISION not found and failed to add it!" "red"
95
fi
96
97
# See what the port now has for PORTREVISION.
98
post=$(make -C "$1" -V PORTREVISION)
99
100
if [ "$post" -le "$pre" ]; then
101
printc "ERROR: $1 PORTREVISION went backwards from $pre to $post!" "red"
102
fi
103
;;
104
*)
105
printc "ERROR: PORTREVISION grep for $1 exited with error!" "red"
106
;;
107
esac
108
else
109
# The directory specified had no Makefile, so it seems like a mistake
110
printc "ERROR: $1 might not be a port directory because $1/Makefile is missing!" "red"
111
fi
112
shift
113
done
114
115
116