-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·111 lines (94 loc) · 3.33 KB
/
install.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
#!/bin/sh
set -eu
use_venv=""
device=""
usage() {
cat <<EOF
$0 [-v] [-d device]
-v use python virtualenv for package installation
-d device use specified v4l2loopback device as output
EOF
exit ${1:-0}
}
while getopts 'vd:h' OPT; do
case "$OPT" in
v) use_venv="y";;
d) device="$OPTARG";;
h) usage;;
*) usage 2;;
esac
done
if ! lsmod | grep -q '^v4l2loopback\s'; then
modinfo v4l2loopback >/dev/null 2>&1 &&
echo 'v4l2loopback needs to be loaded. Please do something like this:' ||
cat <<'EOF'
The v4l2loopback module was not found.
Please install it (the package is probably named v4l2loopback-dkms).
After the installation, please do something like this:
EOF
cat <<'EOF'
echo 'options v4l2loopback devices=1 exclusive_caps=1 video_nr=100 card_label="bgcam"' | sudo tee /etc/modprobe.d/v4l2loopback.conf
echo v4l2loopback | sudo tee /etc/modules-load.d/v4l2loopback.conf
sudo modprobe v4l2loopback
EOF
exit 1
fi
test -n "$device" ||
device="$(
{ command -v v4l2-ctl >/dev/null 2>/dev/null &&
v4l2-ctl --list-devices |
awk 'BEGIN{RS="\n\n"} /platform:v4l2loopback-/{print $NF}' ||
ls /dev/video[0-9]* | grep -vFx "$(readlink -e /dev/v4l/by-path/*)"
} | sed -rn 's|^/dev/video([0-9]+)|\1\t\0|p' |
sort -n | head -1 | cut -f2)" 2>/dev/null
if [ -z "$device" ]; then
echo "Could auto-detect v4l2loopback device."
echo "Try to specify it manually with -d."
exit 1
fi
if [ ! -c "$device" ]; then
echo "'$device' is not a character device."
exit 1
fi
if [ ! -w "$device" ]; then
echo "'$device' is not writeable."
echo "Try adding yourself to the '$(stat -c%G "$device")' group."
exit 1
fi
dir="$(dirname "$(readlink -f "$0")")"
cd "$dir"
if [ -n "$use_venv" ]; then
test -d venv || python3 -m virtualenv venv
source venv/bin/activate
else
opencv="$(pip3 list --user | grep -o \
-e '^opencv-contrib-python-headless\s' \
-e '^opencv-python(-headless)?\s')" &&
pip3 uninstall --yes $opencv opencv-contrib-python || :
fi
opencv_path() {
python3 -c 'import os,cv2;print(os.path.dirname(cv2.__file__))' \
2>/dev/null || :
}
old_opencv_path="$(opencv_path)"
pip3 install -r requirements.txt
test -z "$old_opencv_path" -o "$old_opencv_path" = "$(opencv_path)" ||
pip3 uninstall -y opencv-contrib-python
mkdir -p ~/.config/systemd/user ~/.config/bgcam ~/.local/bin
ln -srf "$dir/bgcam" ~/.local/bin/bgcam
ln -srf "$dir/bgcam-set-background" ~/.local/bin/bgcam-set-background
ln -srf "$dir/bgcam.service" ~/.config/systemd/user/bgcam.service
wget -NP ~/.config/bgcam \
https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite \
https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter_landscape/float16/latest/selfie_segmenter_landscape.tflite
touch ~/.config/bgcam/config
sed -i -e '/^\s*BGCAM_LOOPBACK_DEVICE\s*=/d' ~/.config/bgcam/config
echo "BGCAM_LOOPBACK_DEVICE=\"$device\"" >> ~/.config/bgcam/config
grep -q '^\s*BGCAM_CAMERA\s*=' ~/.config/bgcam/config ||
echo "BGCAM_CAMERA=\"$(ls /dev/v4l/by-id/*-index0)\"" >> \
~/.config/bgcam/config
systemctl --user daemon-reload
systemctl --user enable bgcam.service
systemctl --user restart bgcam.service
sleep 1
systemctl --user status bgcam.service