Skip to content

Commit 549f7d4

Browse files
authored
chore: refactor camera-streamer build conditions (#201)
1 parent 2bdc30b commit 549f7d4

File tree

5 files changed

+101
-15
lines changed

5 files changed

+101
-15
lines changed

tools/install.sh

+27-12
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,11 @@ main() {
4949

5050
[[ -n "${BASE_USER}" ]] || BASE_USER="${SUDO_USER}"
5151

52-
5352
if [[ "$(is_buster)" = "1" ]]; then
5453
not_supported_msg
5554
exit 1
5655
fi
5756

58-
if [[ "$(is_raspbian)" = "1" ]]; then
59-
link_pkglist_rpi
60-
fi
61-
62-
if [[ "$(is_raspbian)" = "0" ]]; then
63-
link_pkglist_generic
64-
fi
65-
6657
welcome_msg
6758

6859
msg "Running apt-get update first ...\n"
@@ -72,6 +63,30 @@ main() {
7263
status_msg "Running apt-get update first ..." "1"
7364
fi
7465

66+
if [[ "${CROWSNEST_UNATTENDED}" != "1" ]]; then
67+
msg "Doing some tests ...\n"
68+
if shallow_cs_dependencies_check; then
69+
CN_INSTALL_CS="1"
70+
else
71+
CN_INSTALL_CS="0"
72+
fi
73+
status_msg "Doing some tests ..." "0"
74+
else
75+
if [[ "$(is_raspbian)" = "1" ]]; then
76+
CN_INSTALL_CS="1"
77+
else
78+
CN_INSTALL_CS="0"
79+
fi
80+
fi
81+
82+
if [[ "${CN_INSTALL_CS}" = "1" ]]; then
83+
msg "Installing with camera-streamer ...\n"
84+
link_pkglist_rpi
85+
else
86+
msg "Installing without camera-streamer ...\n"
87+
link_pkglist_generic
88+
fi
89+
7590
source_pkglist_file
7691
msg "Installing dependencies ...\n"
7792
if install_dependencies ;then
@@ -128,9 +143,9 @@ main() {
128143

129144
add_group_video
130145

131-
if [[ "$(is_bookworm)" = "1" ]]; then
132-
msg "Bookworm detected!"
133-
msg "Using main branch of camera-streamer for Bookworm..."
146+
if [[ "$(is_bookworm)" = "1" ]] && [[ "${CN_INSTALL_CS}" = "1" ]]; then
147+
msg "\nBookworm detected!"
148+
msg "Using main branch of camera-streamer for Bookworm ...\n"
134149
CROWSNEST_CAMERA_STREAMER_REPO_BRANCH="main"
135150
fi
136151

tools/libs/build_apps.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ build_apps() {
4444
msg "Cloning ustreamer repository ..."
4545
clone_ustreamer
4646
## Detect Image build for Raspberrys
47-
if [[ "$(is_raspbian)" = "1" ]]; then
47+
if [[ "${CN_INSTALL_CS}" = "1" ]]; then
4848
msg "Cloning camera-streamer repository ..."
4949
clone_cstreamer
50-
fi
51-
if [[ "$(is_raspbian)" = "0" ]]; then
50+
else
5251
msg "Install of camera-streamer skipped, only supported on Raspberry SBC's! ... "
5352
fi
5453
sudo -u "${BASE_USER}" "${PWD}"/bin/build.sh --build

tools/libs/core.sh

+68
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,74 @@ is_raspbian() {
4848
fi
4949
}
5050

51+
is_raspberry_pi() {
52+
if [[ -f /proc/device-tree/model ]] &&
53+
grep -q "Raspberry" /proc/device-tree/model; then
54+
echo "1"
55+
else
56+
echo "0"
57+
fi
58+
}
59+
60+
is_ubuntu_arm() {
61+
if [[ "$(is_raspberry_pi)" = "1" ]] &&
62+
grep -q "ubuntu" /etc/os-release; then
63+
echo "1"
64+
else
65+
echo "0"
66+
fi
67+
}
68+
69+
test_load_module() {
70+
if modprobe -n "${1}" &> /dev/null; then
71+
echo 1
72+
else
73+
echo 0
74+
fi
75+
}
76+
77+
shallow_cs_dependencies_check() {
78+
msg "Checking for camera-streamer dependencies ...\n"
79+
80+
msg "Checking if device is a Raspberry Pi ...\n"
81+
if [[ "$(is_raspberry_pi)" = "0" ]]; then
82+
status_msg "Checking if device is a Raspberry Pi ..." "3"
83+
msg "This device is not a Raspberry Pi therefore camera-streeamer cannot be installed ..."
84+
return 1
85+
fi
86+
status_msg "Checking if device is a Raspberry Pi ..." "0"
87+
88+
msg "Checking if device is not running Ubuntu ...\n"
89+
if [[ "$(is_ubuntu_arm)" = "1" ]]; then
90+
status_msg "Checking if device is not running Ubuntu ..." "3"
91+
msg "This device is running Ubuntu therefore camera-streeamer cannot be installed ..."
92+
return 1
93+
fi
94+
status_msg "Checking if device is not running Ubuntu ..." "0"
95+
96+
msg "Checking for required kernel module ...\n"
97+
SHALLOW_CHECK_MODULESLIST="bcm2835_codec"
98+
if [[ "$(test_load_module ${SHALLOW_CHECK_MODULESLIST})" = "0" ]]; then
99+
status_msg "Checking for required kernel module ..." "3"
100+
msg "Not all required kernel modules for camera-streamer can be loaded ..."
101+
return 1
102+
fi
103+
status_msg "Checking for required kernel module ..." "0"
104+
105+
msg "Checking for required packages ...\n"
106+
# Update the number below if you update SHALLOW_CHECK_PKGLIST
107+
SHALLOW_CHECK_PKGLIST="^(libavformat-dev|libavutil-dev|libavcodec-dev|liblivemedia-dev|libcamera-dev|libcamera-apps-lite)$"
108+
if [[ $(apt-cache search --names-only "${SHALLOW_CHECK_PKGLIST}" | wc -l) -lt 6 ]]; then
109+
status_msg "Checking for required packages ..." "3"
110+
msg "Not all required packages for camera-streamer can be installed ..."
111+
return 1
112+
fi
113+
status_msg "Checking for required packages ..." "0"
114+
115+
status_msg "Checking for camera-streamer dependencies ..." "0"
116+
return 0
117+
}
118+
51119
link_pkglist_rpi() {
52120
sudo -u "${BASE_USER}" ln -sf "${SRC_DIR}/libs/pkglist-rpi.sh" "${SRC_DIR}/pkglist.sh" &> /dev/null || return 1
53121
}

tools/libs/messages.sh

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ status_msg() {
4444
if [[ "${status}" == "2" ]]; then
4545
echo -e "${msg} [\e[33mSKIPPED\e[0m]"
4646
fi
47+
if [[ "${status}" == "3" ]]; then
48+
echo -e "${msg} [\e[33mFAILED\e[0m]"
49+
fi
4750
}
4851

4952
not_as_root_msg() {

tools/libs/pkglist-rpi.sh

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ PKGLIST="git crudini bsdutils findutils v4l-utils curl"
2222
### Ustreamer Dependencies
2323
PKGLIST="${PKGLIST} build-essential libevent-dev libjpeg-dev libbsd-dev"
2424
### Camera-Streamer Dependencies
25+
### If you change something below, also have a look at tools/libs/core.sh->shallow_cs_dependencies_check
2526
PKGLIST="${PKGLIST} cmake libavformat-dev libavutil-dev libavcodec-dev libcamera-dev libcamera-apps-lite"
2627
PKGLIST="${PKGLIST} liblivemedia-dev pkg-config xxd build-essential cmake libssl-dev"

0 commit comments

Comments
 (0)