-
Notifications
You must be signed in to change notification settings - Fork 5
/
profile_to_configmap.sh
executable file
·131 lines (118 loc) · 3.21 KB
/
profile_to_configmap.sh
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
#!/bin/bash
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: (c) Copyright 2023 Advanced Micro Devices, Inc.
me=$(basename "$0")
bin=$(cd "$(dirname "$0")" && /bin/pwd)
err() { echo >&2 "$*"; }
log() { err "$me: $*"; }
vlog() { $verbose && log "$*"; }
fail() { log "$*"; exit 1; }
rawecho() { echo -E "x$*" | sed 's/^x//'; }
prefix() { sed "s/^/$me: /"; }
sfc_usage() {
err
err "usage:"
err " $me [options]"
err
err "options:"
err " -p,--profile=<profile> -- comma sep list of config profile(s)"
err " -h --help -- this help message"
err
exit 1
}
onload_set() {
if [ -z "$2" ]; then
# it's not in onload_set x y form - try onload_set x=y
VAR=$(echo "$1" | cut -f1 -d=)
VAL=$(echo "$1" | cut -f2 -d=)
else
VAR="$1"
VAL="$2"
fi
echo " $VAR: \"$VAL\""
}
onload_import() {
# Called below to import a profile. May also be called by config scripts
# and profile scripts to import another profile.
local profile="$1"
local pf1="$HOME/.openonload/profiles/$profile.opf"
local pf3="$profile"
# *.opf-fragment files are searched only for secondary imports, i.e. use of
# onload_import within another profile. This is to prevent fragments being
# accidentally used as full-fledged profiles by themselves
local pf_frag1="$HOME/.openonload/profiles/$profile.opf-fragment"
local pf="$pf1"
$toplevelimport || [ -f "$pf" ] || pf="$pf_frag1"
for dir in $profile_d; do
local pf2="$dir/$profile.opf"
[ -f "$pf" ] || pf="$pf2"
local pf_frag2="$dir/$profile.opf-fragment"
$toplevelimport || [ -f "$pf" ] || pf="$pf_frag2"
done
[ -f "$pf" ] || pf="$pf3"
if ! [ -f "$pf" ]; then
log "ERROR: Cannot find profile '$profile'"
log "I looked in these places:"
log " $pf1"
$toplevelimport || log " $pf_frag1"
for dir in $profile_d; do
local pf2="$dir/$profile.opf"
log " $pf2"
local pf_frag2="$dir/$profile.opf-fragment"
$toplevelimport || log " $pf_frag2"
done
log " $pf3"
exit 3
fi
toplevelimport=false
vlog "onload_import: $profile ($pf)"
# Source profile, with $@ representing the application and its options
shift
# shellcheck disable=SC1090
. "$pf"
vlog "onload_import-done: $profile"
}
######################################################################
# main()
if [ -x "$bin/mmaketool" ]; then
profile_d="$bin/onload_profiles"
else
profile_d=/usr/libexec/onload/profiles
fi
profiles=
verbose=false
while [ $# -gt 0 ]; do
case "$1" in
--profile=*)
onload_args="$onload_args $1"
profile="${1#--profile=}"
[ -n "$profile" ] || sfc_usage
profiles="$profiles ${profile//,/ }"
;;
--profile|-p)
onload_args="$onload_args $1 $2"
shift
profile="$1"
[ -n "$profile" ] || sfc_usage
profiles="$profiles ${profile//,/ }"
;;
-*) sfc_usage
;;
esac
shift
done
[ $# = 0 ] && [ -z "$profiles" ] && sfc_usage
for profile in $profiles; do
profile_d="$profile_d $(dirname "$profile")"
done
for profile in $profiles; do
echo "apiVersion: v1"
echo "kind: ConfigMap"
echo "metadata:"
echo " name: onload-$(basename "$profile" .opf)-profile"
echo " labels:"
echo " app.kubernetes.io/part-of: onload"
echo "data:"
onload_import "$profile" "$@"
echo "---"
done