forked from kmods-via-containers/kmods-via-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kmods-via-containers
executable file
·105 lines (94 loc) · 3.45 KB
/
kmods-via-containers
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
#!/bin/bash
# The MIT License
# Copyright (c) 2019 Dusty Mabe
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
set -eu
# Helper functions for running containers
# Use set -x to print out the runtime CLI to log
# Run in a subshell so we don't also see `set +x`
kvc_c_run() { (set -x; $KVC_CONTAINER_RUNTIME run -i --rm $@ ); }
kvc_c_build() { (set -x; $KVC_CONTAINER_RUNTIME build $@ ); }
kvc_c_images(){ (set -x; $KVC_CONTAINER_RUNTIME images $@ ); }
kvc_c_rmi() { (set -x; $KVC_CONTAINER_RUNTIME rmi $@ ); }
# Define these functions in your library file
build_kmods() {
echo "build_kmods is unimplemented for ${KVC_SOFTWARE_NAME}!" 2>&1
return 1
}
load_kmods() {
echo "load_kmods is unimplemented for ${KVC_SOFTWARE_NAME}!" 2>&1
return 1
}
unload_kmods() {
echo "unload_kmods is unimplemented for ${KVC_SOFTWARE_NAME}!" 2>&1
return 1
}
wrapper() {
echo "wrapper is unimplemented for ${KVC_SOFTWARE_NAME}!" 2>&1
return 1
}
KVC_ACTION=$1; shift
KVC_SOFTWARE_NAME=$1; shift
KVC_KVER=$1; shift
echo "KVC: ${KVC_ACTION} ${KVC_SOFTWARE_NAME} for ${KVC_KVER}"
# Source in configuration for the KVC framework
source "/etc/kvc/kmods-via-containers.conf"
# Source in the library that defines {build,load,unload}_kmods,wrapper
# must be in one of /usr/{,local/}lib/kvc/${KVC_SOFTWARE_NAME}-lib.sh
for instance_library in /usr/{local/,}lib/kvc/${KVC_SOFTWARE_NAME}-lib.sh; do
if [ -f "${instance_library}" ]; then
source "${instance_library}"
found=1
fi
done
if [ "${found-}" != 1 ]; then
echo "KVC requires an instance library" \
"to define significant functionality" 2>&1
echo "No instance library found in one of required locations" \
/usr/{local/,}lib/kvc/${KVC_SOFTWARE_NAME}-lib.sh 2>&1
exit 1
fi
case "${KVC_ACTION}" in
build)
build_kmods
;;
load)
load_kmods
;;
unload)
unload_kmods
;;
reload)
build_kmods
unload_kmods
load_kmods
;;
wrapper)
# wraps/runs executables from within the kernel module container
wrapper $@
;;
*)
echo "Unknown command. Exiting."
echo "Usage:"
echo ""
echo "build Build kernel module(s) via container"
echo "load Load kernel module(s)"
echo "unload Unload kernel module(s)"
echo "reload Build and reload kernel module(s)"
echo "wrapper Run userspace tools from within the container"
exit 1
esac