forked from freeipa/freeipa-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-spec.sh
More file actions
executable file
·132 lines (111 loc) · 3.04 KB
/
fix-spec.sh
File metadata and controls
executable file
·132 lines (111 loc) · 3.04 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<EOF
usage: $(basename "$0") [-h] [options] [specfile]
Automatically fill in bundled dependencies
Default action is to update the spec file
Options:
-h Show this message and exit
-r Replace the #NPM_PROVIDES with proper contents
-f Revert the changes, removes Provides bundled(npm(...)) with #NPM_PROVIDES
-u Simply updates the listed dependencies
-i In-place, does not create a new file
EOF
}
replace() {
# Patch given spec file to have the correct version and declare bundled NPM dependencies
PROVIDES=$(npm ls --omit dev --package-lock-only --depth=Infinity |
grep -Eo '[^[:space:]]+@[^[:space:]]+' |
sort -u |
# only replace the *last* occurrence of @, not e.g. the one in @patternfly/..
sed 's/^/Provides: bundled(npm(/; s/\(.*\)@/\1)) = /')
awk -v p="${PROVIDES}" 'gsub(/#NPM_PROVIDES/, p) 1' "${spec}" > "${spec}".new
if [ "${backup}" = false ]; then
mv -f "${spec}".new "${spec}"
fi
}
revert() {
# Delete all lines but the first one containing "Provides: bundled(npm(
sed '/^Provides: bundled(npm(/{x;/^$/!d;g;}' < "${spec}" > "${spec}".new
# Replace the first line containing "Provides: bundled(npm(" with "#NPM_PROVIDES"
sed -i 's/^Provides: bundled(npm(.*/#NPM_PROVIDES/' "${spec}".new
if [ "${backup}" = false ]; then
mv -f "${spec}".new "${spec}"
fi
}
update() {
revert
# We need to use the backup file for the next step if not in-place
if [ "${backup}" = true ]; then
spec="${spec}".new
fi
replace
# There is no need for two backups, we can just move the replace backup to the original revert backup
if [ "${backup}" = true ]; then
mv -f "${spec}".new "${spec}"
fi
}
action="update"
backup=true
action_set=false
while { [[ "$#" -ge 1 ]] && [[ "$1" == "-"* ]]; } || [[ "$#" -gt 1 ]];
do
case $1 in
"-h")
usage
exit 0
;;
"-r")
if [ "${action_set}" = true ]; then
usage
exit 1
fi
action_set=true
;;
"-f")
if [ "${action_set}" = true ]; then
usage
exit 1
fi
action_set=true
action="revert"
;;
"-u")
if [ "${action_set}" = true ]; then
usage
exit 1
fi
action_set=true
action="update"
;;
"-i")
backup=false
;;
*)
usage
exit 1
;;
esac
shift
done
spec="${1:-../../freeipa.spec.in}"
if [[ ! -f "${spec}" ]]; then
echo "Spec file ${spec} does not exist"
exit 1
fi
case "${action}" in
"replace")
replace
;;
"revert")
revert
;;
"update")
update
;;
*)
echo "Error: Unknown action '${action}'" >&2
exit 1
;;
esac