Skip to content

Commit

Permalink
Update librealsense build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed Jun 3, 2020
1 parent c421b87 commit 9882dcd
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ RUN apt-get update && apt-get install -y \
# https://github.com/IntelRealSense/librealsense/issues/4781

# Installation of librealsense fix
COPY docker/build-librealsense.sh /tmp/build-librealsense.sh
RUN mkdir -p /tmp/librealsense && cd /tmp/librealsense && /tmp/build-librealsense.sh \
RUN mkdir -p /tmp/librealsense
COPY docker/build-librealsense.sh /tmp/librealsense/build-librealsense.sh
COPY docker/postinst.fix /tmp/librealsense/postinst
RUN cd /tmp/librealsense && sh /tmp/librealsense/build-librealsense.sh \
&& rm -rf /tmp/librealsense \
&& rm -rf /var/lib/apt/lists/*

Expand Down
3 changes: 2 additions & 1 deletion docker/build-librealsense.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ apt-get install -y libssl-dev libssl-doc libusb-1.0-0 libusb-1.0-0-dev libusb-1.
apt-get download ros-kinetic-librealsense
dpkg-deb -R ros-kinetic-librealsense*.deb ros-rslib/

wget https://gist.githubusercontent.com/dizz/404ef259a15e1410d692792da0c27a47/raw/3769e80a051b5f2ce2a08d4ee6f79c766724f495/postinst
# File is already provided by Docker; skipping download.
# wget https://gist.githubusercontent.com/sunsided/c5dbc2d293de8e5851a404876f0df33c/raw/3769e80a051b5f2ce2a08d4ee6f79c766724f495/postinst
chmod +x postinst
cp postinst ros-rslib/DEBIAN

Expand Down
165 changes: 165 additions & 0 deletions docker/postinst.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/bin/sh
# postinst script for ros librealsense package
#
# see: dh_installdeb(1)
# see: https://gist.github.com/sunsided/c5dbc2d293de8e5851a404876f0df33c
# see: https://gist.github.com/dizz/404ef259a15e1410d692792da0c27a47

set -e

# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

# source debconf library
. /usr/share/debconf/confmodule

OLDLIB="/usr/local/lib/librealsense.so"
OLDHEADER="/usr/local/include/librealsense"
OLDUDEV="/etc/udev/rules.d/99-realsense-libusb.rules"

# Are we running in a Docker Environment?
# docker_cnt=$(awk '$2 == "(1,"' /proc/1/sched | wc -l)
docker_cnt=$(awk -F/ '$2 == "docker"' /proc/1/cgroup | wc -l)
# docker_cnt == 0 we are in a docker environment

case "$1" in

configure)
# Set FORCE_UDEV_IN_DOCKER to non-empty to override
# fix: if docker_cnt > 0 was -eq
if [ ${docker_cnt} -gt 0 -a -z "${FORCE_UDEV_IN_DOCKER}" ]
then
echo "INFO: Docker environment not supported for udevadm; skipping."
else
# Enforce the newly installed udev rules
(udevadm control --reload-rules && udevadm trigger) || true
fi

# Warn user about /usr/local installation
if [ -f ${OLDLIB} -o -d ${OLDHEADER} -o -f ${OLDUDEV} ]
then
echo "WARNING: Locally installed librealsense components should removed:"
if [ -f ${OLDLIB} ]
then
echo " sudo rm -f ${OLDLIB}"
fi
if [ -d ${OLDHEADER} ]
then
echo " sudo rm -rf ${OLDHEADER}"
fi
if [ -f ${OLDUDEV} ]
then
echo " sudo rm -f ${OLDUDEV}"
fi
fi

# Set FORCE_DKMS_IN_DOCKER to non-empty to override
# fix: if docker_cnt > 0 was -eq
if [ ${docker_cnt} -gt 0 -a -z "${FORCE_DKMS_IN_DOCKER}" ]
then
echo "INFO: Docker environment not supported for DKMS; skipping."
else
# Check for uvcvideo loadable kernel module patches in the running kernel
UVC_MODULE=$(modinfo -F filename uvcvideo)
PATCHED_FORMATS=$(/usr/bin/strings ${UVC_MODULE} | \
/bin/egrep '\((Y8I|Y12I|Z16|SRGGB10P|RAW8|RW16|INVZ|INZI|INVR|INRI|INVI|RELI|L8|L16|D16)\)' | \
/usr/bin/wc -l)

if [ ${PATCHED_FORMATS} -eq 15 ]
then
echo "INFO: Intel RealSense(TM) F200, SR300, R200, LR200, and ZR300 cameras are already supported."
echo " DKMS will not be enabled for this system."
else
IS_DKMS_INSTALLED=$(dkms status uvcvideo/1.1.1-3-realsense)
case "${IS_DKMS_INSTALLED}" in
*Installed*|*installed*)
echo "INFO: DKMS module already installed"
;;
*Added*|*added*)
dkms build -m uvcvideo -v "1.1.1-3-realsense" && dkms install -m uvcvideo -v "1.1.1-3-realsense" || true
;;
*)
dkms add -m uvcvideo -v "1.1.1-3-realsense" && \
dkms build -m uvcvideo -v "1.1.1-3-realsense" && dkms install -m uvcvideo -v "1.1.1-3-realsense" || true
;;
esac

IS_DKMS_INSTALLED=$(dkms status uvcvideo/1.1.1-3-realsense)
case "${IS_DKMS_INSTALLED}" in
*Installed*|*installed*)
echo "INFO: DKMS module installed successfully."
;;
*Added*|*added*)
echo "WARNING: DKMS module failed to installed; removing..."
dkms remove -m uvcvideo -v "1.1.1-3-realsense" --all || true
;;
esac

# Check for uvcvideo loadable kernel module patches in the running kernel
UVC_MODULE=$(modinfo -F filename uvcvideo)
PATCHED_FORMATS=$(/usr/bin/strings ${UVC_MODULE} | \
/bin/egrep '\((Y8I|Y12I|Z16|SRGGB10P|RAW8|RW16|INVZ|INZI|INVR|INRI|INVI|RELI|L8|L16|D16)\)' | \
/usr/bin/wc -l)
case "${PATCHED_FORMATS}" in
15)
echo "INFO: Intel RealSense(TM) F200, SR300, R200, LR200, and ZR300 cameras are supported."
;;
4)
echo "WARNING: Only Intel RealSense(TM) R200 camera is supported!"
echo " To resolve, please follow the installation directions at:"
echo " http://wiki.ros.org/librealsense#Installation"
;;
0)
echo "WARNING: No Intel RealSense(TM) cameras are supported!"
echo " To resolve, please follow the installation directions at:"
echo " http://wiki.ros.org/librealsense#Installation"
;;
*)
echo "WARNING: Unknown configuration for Intel RealSense(TM) cameras!"
echo " To resolve, please follow the installation directions at:"
echo " http://wiki.ros.org/librealsense#Installation"
;;
esac
fi
fi
;;

abort-upgrade|abort-remove|abort-deconfigure)
exit 0
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;

esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

# Automatically added by dh_installudev
if [ "$1" = configure ]; then
if [ -e "/etc/udev/rules.d/z60_ros-kinetic-librealsense.rules" ]; then
echo "Preserving user changes to /etc/udev/rules.d/60-ros-kinetic-librealsense.rules ..."
if [ -e "/etc/udev/rules.d/60-ros-kinetic-librealsense.rules" ]; then
mv -f "/etc/udev/rules.d/60-ros-kinetic-librealsense.rules" "/etc/udev/rules.d/60-ros-kinetic-librealsense.rules.dpkg-new"
fi
mv -f "/etc/udev/rules.d/z60_ros-kinetic-librealsense.rules" "/etc/udev/rules.d/60-ros-kinetic-librealsense.rules"
fi
fi
# End automatically added section


db_stop

exit 0

0 comments on commit 9882dcd

Please sign in to comment.