forked from PhotoboothProject/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-gphoto-python.sh
More file actions
111 lines (101 loc) · 3.4 KB
/
install-gphoto-python.sh
File metadata and controls
111 lines (101 loc) · 3.4 KB
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/bash
COMMON_PACKAGES=(
'gphoto2'
'ffmpeg'
'v4l2loopback-dkms'
'v4l-utils'
'python3'
'python3-gphoto2'
'python3-psutil'
'python3-zmq'
)
function info {
echo -e "\033[0;36m${1}\033[0m"
}
function error {
echo -e "\033[0;31m${1}\033[0m"
}
if [ "$UID" != 0 ]; then
error "ERROR: Only root is allowed to execute the installer. Forgot sudo?"
exit 1
fi
#Param 1: Question / Param 2: Default / silent answer
function ask_yes_no {
read -p "${1}: " -n 1 -r
}
function gphoto_preview() {
# make configs persistent
[[ ! -d /etc/modules-load.d ]] && mkdir /etc/modules-load.d
echo v4l2loopback >/etc/modules-load.d/v4l2loopback.conf
[[ ! -d /etc/modprobe.d ]] && mkdir /etc/modprobe.d
cat >/etc/modprobe.d/v4l2loopback.conf <<EOF
options v4l2loopback exclusive_caps=1 card_label="GPhoto2 Webcam"
blacklist bcm2835-isp
EOF
# adjust current runtime
modprobe v4l2loopback exclusive_caps=1 card_label="GPhoto2 Webcam"
rmmod bcm2835-isp || true
}
info "This script installs some dependencies and simplifies the setup for using gphoto2 as webcam."
info "It installs required dependencies and sets up a virtual webcam that gphoto2 can stream video to."
info "It can remove the gphoto2 webcam setup, as well."
info ""
echo "Your options are:"
echo "1 Install gphoto2 webcam"
echo "2 Remove gphoto2 webcam"
echo "3 Migrate from systemd service to modprobe config"
echo "4 Nothing"
info ""
ask_yes_no "Please enter your choice" "3"
info ""
if [[ $REPLY =~ ^[1]$ ]]; then
info "### Installing required software..."
for package in "${COMMON_PACKAGES[@]}"; do
if [ "$(dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then
info "[Package] ${package} installed already"
else
info "[Package] Installing missing package: ${package}"
apt install -y "$package"
fi
done
info "All required software was installed."
info ""
info "Note: Installing gphoto2 as webcam disables other webcams."
info ""
ask_yes_no "Do you want to setup gphoto2 as a webcam? (y/n)" "n"
info ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
info "### Installing gphoto2 webcam"
# make it persistent
[[ ! -d /etc/modprobe.d ]] && mkdir /etc/modprobe.d
cat >/etc/modprobe.d/v4l2loopback.conf <<EOF
options v4l2loopback exclusive_caps=1 card_label="GPhoto2 Webcam"
blacklist bcm2835-isp
EOF
# adjust runtime
modprobe v4l2loopback exclusive_caps=1 card_label="GPhoto2 Webcam"
rmmod bcm2835-isp || true
fi
elif [[ $REPLY =~ ^[2]$ ]]; then
info "### Stopping and removing gphoto2 webcam service."
[[ -f /etc/modprobe.d/v4l2loopback.conf ]] && rm /etc/modprobe.d/v4l2loopback.conf
rmmod v4l2loopback || true
info "gphoto2 webcam removed..."
elif [[ $REPLY =~ ^[3]$ ]]; then
info "### Migrating to modprobe config"
gphoto_preview
if [[ -f /etc/systemd/system/ffmpeg-webcam.service ]]; then
info "### Old ffmpeg-webcam.service detected. Uninstalling..."
systemctl disable --now ffmpeg-webcam.service
rm /etc/systemd/system/ffmpeg-webcam.service
systemctl daemon-reload
if [[ -f /usr/ffmpeg-webcam.sh ]]; then
info "### Also removing the /usr/ffmpeg-webcam.sh file"
rm /usr/ffmpeg-webcam.sh
fi
fi
else
info "Okay... doing nothing!"
fi
info "Done!"
exit 0