Skip to content

Commit d305b32

Browse files
committed
hack: update scripts to work on mac
update the Makefile and scripts to work on mac as well as on linux Signed-off-by: Rewant Soni <resoni@redhat.com>
1 parent 0eb9214 commit d305b32

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ set -e; \
354354
package=$(2)@$(3) ;\
355355
echo "Downloading $${package}" ;\
356356
GOBIN=$(LOCALBIN) go install $${package} ;\
357-
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
357+
tmp="$(1)" ;\
358+
mv "$${tmp%-$(3)}" $(1) ;\
358359
}
359360
endef

hack/patch-csi-operator-helm-chart.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,28 @@ if [ ! -f "$SA_FILE" ]; then
1313
exit 1
1414
fi
1515

16-
TEMPLATE_SNIPPET=$(
17-
cat <<'EOF'
18-
{{- with .Values.imagePullSecrets }}
19-
imagePullSecrets:
20-
{{ toYaml . | indent 2 }}
21-
{{- end }}
22-
EOF
23-
)
24-
2516
echo "Patching $SA_FILE for imagePullSecrets"
2617

27-
awk -v snippet="$TEMPLATE_SNIPPET" '
18+
# Use awk to insert the snippet before each '---' separator and at the end
19+
awk '
2820
# Before printing a separator, print the snippet
29-
/^---/ { print snippet }
21+
/^---/ {
22+
print "{{- with .Values.imagePullSecrets }}"
23+
print "imagePullSecrets:"
24+
print "{{ toYaml . | indent 2 }}"
25+
print "{{- end }}"
26+
}
3027
3128
# Print the current line
3229
{ print }
3330
3431
# At the end of the file, print the snippet for the last section
35-
END { print snippet }
32+
END {
33+
print "{{- with .Values.imagePullSecrets }}"
34+
print "imagePullSecrets:"
35+
print "{{ toYaml . | indent 2 }}"
36+
print "{{- end }}"
37+
}
3638
' "$SA_FILE" >"${SA_FILE}.tmp"
3739

3840
mv "${SA_FILE}.tmp" "$SA_FILE"
@@ -51,12 +53,12 @@ if [[ "$CHART_DIR" == *"ceph-csi-operator"* ]]; then
5153

5254
# Check if the file already has the $root variable definition
5355
if ! grep -q "{{- \$root := . -}}" "$file"; then
54-
# Add the $root variable definition at the top of the file
55-
sed -i "1i{{- \$root := . -}}" "$file"
56+
# Add the $root variable definition at the top of the file using a temp file
57+
echo "{{- \$root := . -}}" | cat - "$file" > "$file.tmp" && mv "$file.tmp" "$file"
5658
fi
5759

58-
# Replace the namespace string
59-
sed -i "s/namespace: ceph-csi-operator-system/namespace: {{ \$root.Release.Namespace }}/g" "$file"
60+
# Replace the namespace string using a temp file (portable across all platforms)
61+
sed "s/namespace: ceph-csi-operator-system/namespace: {{ \$root.Release.Namespace }}/g" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
6062
fi
6163
done
6264

0 commit comments

Comments
 (0)