-
Notifications
You must be signed in to change notification settings - Fork 11
/
silverblue-v4l2loopback-module
executable file
·152 lines (122 loc) · 5.15 KB
/
silverblue-v4l2loopback-module
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# The MIT License
# Copyright (c) 2020 Robert Bohne
# 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 -e
if [ -f /etc/sysconfig/silverblue-v4l2loopback ]; then
source /etc/sysconfig/silverblue-v4l2loopback
else
source ./silverblue-v4l2loopback
fi
if [ $(id -u) -ne 0 ]; then
echo "Please run as root"
exit 1;
fi;
V4L2LOOPBACK_KERNEL_VERSION=$(uname -r)
V4L2LOOPBACK_IMAGETAG=${V4L2LOOPBACK_VERSION}-${V4L2LOOPBACK_KERNEL_VERSION}
build_v4l2loopback()
{
set +e
podman pull ${V4L2LOOPBACK_IMAGE}:${V4L2LOOPBACK_IMAGETAG}
RC=$?
# 125 failed to pull
set -e
if [[ $RC -eq 125 ]]; then
echo "The v4l2loopback ${V4L2LOOPBACK_VERSION} kernel module container is not built."
echo "Building ${V4L2LOOPBACK_VERSION} kernel module for ${V4L2LOOPBACK_KERNEL_VERSION} ..."
podman pull registry.fedoraproject.org/fedora:latest
podman build --network=host --build-arg V4L2LOOPBACK_VERSION=${V4L2LOOPBACK_VERSION} \
--build-arg V4L2LOOPBACK_SHA256=${V4L2LOOPBACK_SHA256} \
--build-arg V4L2LOOPBACK_KERNEL_VERSION=${V4L2LOOPBACK_KERNEL_VERSION} \
-t ${V4L2LOOPBACK_IMAGE}:${V4L2LOOPBACK_IMAGETAG} ${BUILD_SOURCE}
else
echo "The v4l2loopback ${V4L2LOOPBACK_VERSION} kernel module container is already built."
fi
# No version information in V4L2LOOPBACK
# if [ "${V4L2LOOPBACK_VERSION}" != "$(podman run --name v4l2loopback -e "V4L2LOOPBACK_VERSION=${V4L2LOOPBACK_VERSION}" \
# -e "V4L2LOOPBACK_KERNEL_VERSION=${V4L2LOOPBACK_KERNEL_VERSION}" --rm --privileged \
# ${V4L2LOOPBACK_IMAGE}:${V4L2LOOPBACK_IMAGETAG} modinfo /usr/lib/modules/${V4L2LOOPBACK_KERNEL_VERSION}/extra/v4l2loopback.ko \
# |grep '^version'|awk '{print $2}')" ]; then
#
# echo "The v4l2loopback kernel module for ${V4L2LOOPBACK_KERNEL_VERSION} is not the correct version."
# echo "Building ${V4L2LOOPBACK_VERSION} kernel module for ${V4L2LOOPBACK_KERNEL_VERSION} ..."
#
# podman build --build-arg V4L2LOOPBACK_VERSION=${V4L2LOOPBACK_VERSION} \
# --build-arg V4L2LOOPBACK_SHA256=${V4L2LOOPBACK_SHA256} \
# --build-arg V4L2LOOPBACK_KERNEL_VERSION=${V4L2LOOPBACK_KERNEL_VERSION} \
# -t ${V4L2LOOPBACK_IMAGE}:${V4L2LOOPBACK_IMAGETAG} ${BUILD_SOURCE}
# fi
echo "Cleaning up old v4l2loopback kernel module container builds..."
podman rmi $(podman images -f "dangling=true" -q) &> /dev/null || :
if [ "$V4L2LOOPBACK_PRUNE_OLD_VERSIONS" = true ] ; then
for OLD_IMAGES in $(podman images -n|grep v4l2loopback|grep -v ${V4L2LOOPBACK_VERSION}|awk '{print $3}'); do
podman rmi ${OLD_IMAGES} &> /dev/null || :
done
fi
}
unload_v4l2loopback()
{
echo "Unloading v4l2loopback..."
if lsmod |grep "v4l2loopback" &> /dev/null; then
rmmod v4l2loopback
fi
}
load_v4l2loopback()
{
echo "Loading v4l2loopback..."
if ! lsmod |grep "v4l2loopback" &> /dev/null; then
podman run --name v4l2loopback -e "V4L2LOOPBACK_VERSION=${V4L2LOOPBACK_VERSION}" \
-e "V4L2LOOPBACK_KERNEL_VERSION=${V4L2LOOPBACK_KERNEL_VERSION}" --rm --privileged \
${V4L2LOOPBACK_IMAGE}:${V4L2LOOPBACK_IMAGETAG} \
insmod /usr/lib/modules/${V4L2LOOPBACK_KERNEL_VERSION}/extra/v4l2loopback.ko exclusive_caps=1
fi
}
check(){
podman run --name v4l2loopback -e "V4L2LOOPBACK_VERSION=${V4L2LOOPBACK_VERSION}" \
-e "V4L2LOOPBACK_KERNEL_VERSION=${V4L2LOOPBACK_KERNEL_VERSION}" --rm --privileged \
${V4L2LOOPBACK_IMAGE}:${V4L2LOOPBACK_IMAGETAG} \
/usr/bin/v4l2-ctl --list-devices
}
case "$1" in
build)
build_v4l2loopback
;;
load)
load_v4l2loopback
;;
unload)
unload_v4l2loopback
;;
reload)
build_v4l2loopback
unload_v4l2loopback
load_v4l2loopback
;;
check)
check
;;
*)
echo $"Unknown command. Exiting."
echo "Usage:"
echo ""
echo "build Build v4l2loopback kernel module container"
echo "load Load v4l2loopback kernel module"
echo "unload Unload v4l2loopback kernel module"
echo "reload Build and reload v4l2loopback kernel module"
echo "check Check module (runs v4l2-ctl --list-devices)"
exit 1
esac