From 65db0329a0683d494ff37a295562c19eae7df84c Mon Sep 17 00:00:00 2001
From: Robert Nelson <robertcnelson@gmail.com>
Date: Mon, 14 May 2018 10:51:30 -0500
Subject: [PATCH] ros: wirein

Signed-off-by: Robert Nelson <robertcnelson@gmail.com>
---
 .../bb.org-ubuntu-bionic-ros-iot-v4.14.conf   |   2 +-
 scripts/chroot.sh                             |  17 +
 target/chroot/beagleboard.org-bionic.sh       | 358 ++++++++++++++++++
 target/keyring/ros-archive-keyring.asc        |  29 ++
 4 files changed, 405 insertions(+), 1 deletion(-)
 create mode 100755 target/chroot/beagleboard.org-bionic.sh
 create mode 100644 target/keyring/ros-archive-keyring.asc

diff --git a/configs/bb.org-ubuntu-bionic-ros-iot-v4.14.conf b/configs/bb.org-ubuntu-bionic-ros-iot-v4.14.conf
index 6752c7920..4a1838ba3 100644
--- a/configs/bb.org-ubuntu-bionic-ros-iot-v4.14.conf
+++ b/configs/bb.org-ubuntu-bionic-ros-iot-v4.14.conf
@@ -163,6 +163,6 @@ include_firmware="enable"
 chroot_COPY_SETUP_SDCARD="enable"
 chroot_before_hook=""
 chroot_after_hook=""
-chroot_script="beagleboard.org-buster.sh"
+chroot_script="beagleboard.org-bionic.sh"
 chroot_post_uenv_txt=""
 chroot_tarball="enable"
diff --git a/scripts/chroot.sh b/scripts/chroot.sh
index 0f12bd7bc..f277b79cd 100755
--- a/scripts/chroot.sh
+++ b/scripts/chroot.sh
@@ -423,6 +423,14 @@ if [ "x${repo_rcnee}" = "xenable" ] ; then
 	sudo cp -v "${OIB_DIR}/target/keyring/repos.rcn-ee.net-archive-keyring.asc" "${tempdir}/tmp/repos.rcn-ee.net-archive-keyring.asc"
 fi
 
+if [ "x${repo_ros}" = "xenable" ] ; then
+	echo "" >> ${wfile}
+	echo "deb [arch=armhf] http://packages.ros.org/ros/${deb_distribution} ${deb_codename} main" >> ${wfile}
+	echo "#deb-src [arch=armhf] http://packages.ros.org/ros/${deb_distribution} ${deb_codename} main" >> ${wfile}
+
+	sudo cp -v "${OIB_DIR}/target/keyring/ros-archive-keyring.asc" "${tempdir}/tmp/ros-archive-keyring.asc"
+fi
+
 if [ -f /tmp/sources.list ] ; then
 	sudo mv /tmp/sources.list "${tempdir}/etc/apt/sources.list"
 fi
@@ -606,6 +614,10 @@ cat > "${DIR}/chroot_script.sh" <<-__EOF__
 			apt-key add /tmp/repos.rcn-ee.net-archive-keyring.asc
 			rm -f /tmp/repos.rcn-ee.net-archive-keyring.asc || true
 		fi
+		if [ "x${repo_ros}" = "xenable" ] ; then
+			apt-key add /tmp/ros-archive-keyring.asc
+			rm -f /tmp/ros-archive-keyring.asc || true
+		fi
 		if [ "x${repo_external}" = "xenable" ] ; then
 			apt-key add /tmp/${repo_external_key}
 			rm -f /tmp/${repo_external_key} || true
@@ -688,6 +700,11 @@ cat > "${DIR}/chroot_script.sh" <<-__EOF__
 			echo "Log: (chroot) Installing (from external repo): ${repo_external_pkg_list}"
 			apt-get -y \${apt_options} install ${repo_external_pkg_list}
 		fi
+
+		if [ ! "x${repo_ros_pkg_list}" = "x" ] ; then
+			echo "Log: (chroot) Installing (from external repo): ${repo_ros_pkg_list}"
+			apt-get -y \${apt_options} install ${repo_ros_pkg_list}
+		fi
 	}
 
 	system_tweaks () {
diff --git a/target/chroot/beagleboard.org-bionic.sh b/target/chroot/beagleboard.org-bionic.sh
new file mode 100755
index 000000000..bb51fca30
--- /dev/null
+++ b/target/chroot/beagleboard.org-bionic.sh
@@ -0,0 +1,358 @@
+#!/bin/sh -e
+#
+# Copyright (c) 2014-2018 Robert Nelson <robertcnelson@gmail.com>
+#
+# 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.
+
+export LC_ALL=C
+
+u_boot_release="v2018.03"
+u_boot_release_x15="ti-2017.01"
+
+#contains: rfs_username, release_date
+if [ -f /etc/rcn-ee.conf ] ; then
+	. /etc/rcn-ee.conf
+fi
+
+if [ -f /etc/oib.project ] ; then
+	. /etc/oib.project
+fi
+
+export HOME=/home/${rfs_username}
+export USER=${rfs_username}
+export USERNAME=${rfs_username}
+
+echo "env: [`env`]"
+
+is_this_qemu () {
+	unset warn_qemu_will_fail
+	if [ -f /usr/bin/qemu-arm-static ] ; then
+		warn_qemu_will_fail=1
+	fi
+}
+
+qemu_warning () {
+	if [ "${warn_qemu_will_fail}" ] ; then
+		echo "Log: (chroot) Warning, qemu can fail here... (run on real armv7l hardware for production images)"
+		echo "Log: (chroot): [${qemu_command}]"
+	fi
+}
+
+git_clone () {
+	mkdir -p ${git_target_dir} || true
+	qemu_command="git clone ${git_repo} ${git_target_dir} --depth 1 || true"
+	qemu_warning
+	git clone ${git_repo} ${git_target_dir} --depth 1 || true
+	sync
+	echo "${git_target_dir} : ${git_repo}" >> /opt/source/list.txt
+}
+
+git_clone_branch () {
+	mkdir -p ${git_target_dir} || true
+	qemu_command="git clone -b ${git_branch} ${git_repo} ${git_target_dir} --depth 1 || true"
+	qemu_warning
+	git clone -b ${git_branch} ${git_repo} ${git_target_dir} --depth 1 || true
+	sync
+	echo "${git_target_dir} : ${git_repo}" >> /opt/source/list.txt
+}
+
+git_clone_full () {
+	mkdir -p ${git_target_dir} || true
+	qemu_command="git clone ${git_repo} ${git_target_dir} || true"
+	qemu_warning
+	git clone ${git_repo} ${git_target_dir} || true
+	sync
+	echo "${git_target_dir} : ${git_repo}" >> /opt/source/list.txt
+}
+
+setup_system () {
+	#For when sed/grep/etc just gets way to complex...
+	cd /
+#	if [ -f /opt/scripts/mods/debian-add-sbin-usr-sbin-to-default-path.diff ] ; then
+#		if [ -f /usr/bin/patch ] ; then
+#			echo "Patching: /etc/profile"
+#			patch -p1 < /opt/scripts/mods/debian-add-sbin-usr-sbin-to-default-path.diff
+#		fi
+#	fi
+
+	echo "" >> /etc/securetty
+	echo "#USB Gadget Serial Port" >> /etc/securetty
+	echo "ttyGS0" >> /etc/securetty
+}
+
+setup_desktop () {
+	if [ -d /etc/X11/ ] ; then
+		wfile="/etc/X11/xorg.conf"
+		echo "Patching: ${wfile}"
+		echo "Section \"Monitor\"" > ${wfile}
+		echo "        Identifier      \"Builtin Default Monitor\"" >> ${wfile}
+		echo "EndSection" >> ${wfile}
+		echo "" >> ${wfile}
+		echo "Section \"Device\"" >> ${wfile}
+		echo "        Identifier      \"Builtin Default fbdev Device 0\"" >> ${wfile}
+		echo "        Driver          \"fbdev\"" >> ${wfile}
+		echo "#HWcursor_false        Option          \"HWcursor\"          \"false\"" >> ${wfile}
+		echo "EndSection" >> ${wfile}
+		echo "" >> ${wfile}
+		echo "Section \"Screen\"" >> ${wfile}
+		echo "        Identifier      \"Builtin Default fbdev Screen 0\"" >> ${wfile}
+		echo "        Device          \"Builtin Default fbdev Device 0\"" >> ${wfile}
+		echo "        Monitor         \"Builtin Default Monitor\"" >> ${wfile}
+		echo "#DefaultDepth        DefaultDepth    16" >> ${wfile}
+		echo "EndSection" >> ${wfile}
+		echo "" >> ${wfile}
+		echo "Section \"ServerLayout\"" >> ${wfile}
+		echo "        Identifier      \"Builtin Default Layout\"" >> ${wfile}
+		echo "        Screen          \"Builtin Default fbdev Screen 0\"" >> ${wfile}
+		echo "EndSection" >> ${wfile}
+	fi
+
+	wfile="/etc/lightdm/lightdm.conf"
+	if [ -f ${wfile} ] ; then
+		echo "Patching: ${wfile}"
+		sed -i -e 's:#autologin-user=:autologin-user='$rfs_username':g' ${wfile}
+		sed -i -e 's:#autologin-session=:autologin-session='$rfs_default_desktop':g' ${wfile}
+		if [ -f /opt/scripts/3rdparty/xinput_calibrator_pointercal.sh ] ; then
+			sed -i -e 's:#display-setup-script=:display-setup-script=/opt/scripts/3rdparty/xinput_calibrator_pointercal.sh:g' ${wfile}
+		fi
+	fi
+
+	if [ ! "x${rfs_desktop_background}" = "x" ] ; then
+		mkdir -p /home/${rfs_username}/.config/ || true
+		if [ -d /opt/scripts/desktop-defaults/stretch/lxqt/ ] ; then
+			cp -rv /opt/scripts/desktop-defaults/stretch/lxqt/* /home/${rfs_username}/.config
+		fi
+		chown -R ${rfs_username}:${rfs_username} /home/${rfs_username}/.config/
+	fi
+
+	#Disable dpms mode and screen blanking
+	#Better fix for missing cursor
+	wfile="/home/${rfs_username}/.xsessionrc"
+	echo "#!/bin/sh" > ${wfile}
+	echo "" >> ${wfile}
+	echo "xset -dpms" >> ${wfile}
+	echo "xset s off" >> ${wfile}
+	echo "xsetroot -cursor_name left_ptr" >> ${wfile}
+	chown -R ${rfs_username}:${rfs_username} ${wfile}
+}
+
+install_pip_pkgs () {
+	if [ -f /usr/bin/python ] ; then
+		wget https://bootstrap.pypa.io/get-pip.py || true
+		if [ -f get-pip.py ] ; then
+			python get-pip.py
+			rm -f get-pip.py || true
+
+			if [ -f /usr/local/bin/pip ] ; then
+				if [ -f /usr/bin/make ] ; then
+					echo "Installing pip packages"
+					git_repo="https://github.com/adafruit/adafruit-beaglebone-io-python.git"
+					git_target_dir="/opt/source/adafruit-beaglebone-io-python"
+					git_clone
+					if [ -f ${git_target_dir}/.git/config ] ; then
+						cd ${git_target_dir}/
+						sed -i -e 's:4.1.0:3.4.0:g' setup.py
+						python setup.py install
+					fi
+					pip install iw_parse
+				fi
+			fi
+		fi
+	fi
+}
+
+install_git_repos () {
+	if [ -d /usr/local/lib/node_modules/bonescript ] ; then
+		if [ -d /etc/apache2/ ] ; then
+			#bone101 takes over port 80, so shove apache/etc to 8080:
+			if [ -f /etc/apache2/ports.conf ] ; then
+				sed -i -e 's:80:8080:g' /etc/apache2/ports.conf
+			fi
+			if [ -f /etc/apache2/sites-enabled/000-default ] ; then
+				sed -i -e 's:80:8080:g' /etc/apache2/sites-enabled/000-default
+			fi
+			if [ -f /etc/apache2/sites-enabled/000-default.conf ] ; then
+				sed -i -e 's:80:8080:g' /etc/apache2/sites-enabled/000-default.conf
+			fi
+			if [ -f /var/www/html/index.html ] ; then
+				rm -rf /var/www/html/index.html || true
+			fi
+		fi
+	fi
+
+	if [ -f /var/www/html/index.nginx-debian.html ] ; then
+		rm -rf /var/www/html/index.nginx-debian.html || true
+
+		if [ -d /opt/scripts/distro/buster/nginx/ ] ; then
+			cp -v /opt/scripts/distro/buster/nginx/default /etc/nginx/sites-available/default
+		fi
+	fi
+
+	git_repo="https://github.com/prpplague/Userspace-Arduino"
+	git_target_dir="/opt/source/Userspace-Arduino"
+	git_clone
+
+	git_repo="https://github.com/strahlex/BBIOConfig.git"
+	git_target_dir="/opt/source/BBIOConfig"
+	git_clone
+
+	git_repo="https://github.com/prpplague/fb-test-app.git"
+	git_target_dir="/opt/source/fb-test-app"
+	git_clone
+	if [ -f ${git_target_dir}/.git/config ] ; then
+		cd ${git_target_dir}/
+		if [ -f /usr/bin/make ] ; then
+			make
+		fi
+		cd /
+	fi
+
+	#am335x-pru-package
+	if [ -f /usr/include/prussdrv.h ] ; then
+		git_repo="https://github.com/biocode3D/prufh.git"
+		git_target_dir="/opt/source/prufh"
+		git_clone
+		if [ -f ${git_target_dir}/.git/config ] ; then
+			cd ${git_target_dir}/
+			if [ -f /usr/bin/make ] ; then
+				make LIBDIR_APP_LOADER=/usr/lib/ INCDIR_APP_LOADER=/usr/include
+			fi
+			cd /
+		fi
+	fi
+
+	git_repo="https://github.com/RobertCNelson/dtb-rebuilder.git"
+	git_target_dir="/opt/source/dtb-4.9-ti"
+	git_branch="4.9-ti"
+	git_clone_branch
+
+	git_repo="https://github.com/RobertCNelson/dtb-rebuilder.git"
+	git_target_dir="/opt/source/dtb-4.14-ti"
+	git_branch="4.14-ti"
+	git_clone_branch
+
+	git_repo="https://github.com/beagleboard/bb.org-overlays"
+	git_target_dir="/opt/source/bb.org-overlays"
+	git_clone
+	if [ -f ${git_target_dir}/.git/config ] ; then
+		cd ${git_target_dir}/
+		if [ ! "x${repo_rcnee_pkg_version}" = "x" ] ; then
+			is_kernel=$(echo ${repo_rcnee_pkg_version} | grep 3.8.13 || true)
+			if [ "x${is_kernel}" = "x" ] ; then
+				if [ -f /usr/bin/make ] ; then
+					if [ ! -f /lib/firmware/BB-ADC-00A0.dtbo ] ; then
+						make
+						make install
+						make clean
+					fi
+					update-initramfs -u -k ${repo_rcnee_pkg_version}
+				fi
+			fi
+		fi
+	fi
+
+	git_repo="https://github.com/ungureanuvladvictor/BBBlfs"
+	git_target_dir="/opt/source/BBBlfs"
+	git_clone
+	if [ -f ${git_target_dir}/.git/config ] ; then
+		cd ${git_target_dir}/
+		if [ -f /usr/bin/make ] ; then
+			./autogen.sh
+			./configure
+			make
+		fi
+	fi
+
+	git_repo="https://github.com/StrawsonDesign/Robotics_Cape_Installer"
+	git_target_dir="/opt/source/Robotics_Cape_Installer"
+	git_clone
+
+	git_repo="https://github.com/mcdeoliveira/rcpy"
+	git_target_dir="/opt/source/rcpy"
+	git_clone
+	if [ -f ${git_target_dir}/.git/config ] ; then
+		cd ${git_target_dir}/
+		if [ -f /usr/bin/python3 ] && [ -f /usr/bin/easy_install ] ; then
+			/usr/bin/python3 setup.py install
+		fi
+	fi
+
+	git_repo="https://github.com/mcdeoliveira/pyctrl"
+	git_target_dir="/opt/source/pyctrl"
+	git_clone
+	if [ -f ${git_target_dir}/.git/config ] ; then
+		cd ${git_target_dir}/
+		if [ -f /usr/bin/python3 ] && [ -f /usr/bin/easy_install ] ; then
+			/usr/bin/python3 setup.py install
+		fi
+	fi
+
+	git_repo="https://github.com/mvduin/py-uio"
+	git_target_dir="/opt/source/py-uio"
+	git_clone
+
+	#beagle-tester
+	git_repo="https://github.com/jadonk/beagle-tester"
+	git_target_dir="/opt/source/beagle-tester"
+	git_clone
+#	if [ -f ${git_target_dir}/.git/config ] ; then
+#		if [ -f /usr/lib/libroboticscape.so ] ; then
+#			cd ${git_target_dir}/
+#			if [ -f /usr/bin/make ] ; then
+#				make
+#				make install || true
+##				if [ ! "x${image_type}" = "xtester-2gb" ] ; then
+##					systemctl disable beagle-tester.service || true
+##				fi
+#			fi
+#		fi
+#	fi
+}
+
+other_source_links () {
+	rcn_https="https://rcn-ee.com/repos/git/u-boot-patches"
+
+	mkdir -p /opt/source/u-boot_${u_boot_release}/
+	wget --directory-prefix="/opt/source/u-boot_${u_boot_release}/" ${rcn_https}/${u_boot_release}/0001-omap3_beagle-uEnv.txt-bootz-n-fixes.patch
+	wget --directory-prefix="/opt/source/u-boot_${u_boot_release}/" ${rcn_https}/${u_boot_release}/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
+	wget --directory-prefix="/opt/source/u-boot_${u_boot_release}/" ${rcn_https}/${u_boot_release}/0002-U-Boot-BeagleBone-Cape-Manager.patch
+	mkdir -p /opt/source/u-boot_${u_boot_release_x15}/
+	wget --directory-prefix="/opt/source/u-boot_${u_boot_release_x15}/" ${rcn_https}/${u_boot_release_x15}/0001-beagle_x15-uEnv.txt-bootz-n-fixes.patch
+
+	echo "u-boot_${u_boot_release} : /opt/source/u-boot_${u_boot_release}" >> /opt/source/list.txt
+	echo "u-boot_${u_boot_release_x15} : /opt/source/u-boot_${u_boot_release_x15}" >> /opt/source/list.txt
+
+	chown -R ${rfs_username}:${rfs_username} /opt/source/
+}
+
+is_this_qemu
+
+setup_system
+setup_desktop
+
+install_pip_pkgs
+if [ -f /usr/bin/git ] ; then
+	git config --global user.email "${rfs_username}@example.com"
+	git config --global user.name "${rfs_username}"
+	install_git_repos
+	git config --global --unset-all user.email
+	git config --global --unset-all user.name
+fi
+other_source_links
+#
diff --git a/target/keyring/ros-archive-keyring.asc b/target/keyring/ros-archive-keyring.asc
new file mode 100644
index 000000000..216b64e5d
--- /dev/null
+++ b/target/keyring/ros-archive-keyring.asc
@@ -0,0 +1,29 @@
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Version: SKS 1.1.6
+Comment: Hostname: pgp.mit.edu
+
+mQGiBEsy5KkRBADJbDSISoamRM5AA20bfAeBuhhaI+VaiCVcxw90sq9AI5lIc42FWzM2acm8
+yplqWiehAqOLKd+iIrqNGZ+VavZEPTx7o06UZUMRoPBiTFaCwrQ5avKzlt7ij8PRMVWNrJ7A
+2lDYXfFQVV1o3Xo06qVnv0KLLUmiur0LBu4H/oTH3wCgt+/ID3LUKaMJsc77KwFBTjHB0EsD
+/26Z2Ud12f3urSNyN6VMWnP3rz6xsmtY4QsmkbnrJuduxCQBZv6bX1Cr2ulXkv0fFOr+s5Oy
+Uv7zyCPbxiJFh3Br7fJGb0b5/M208KPegiITY9hMh/aUbKjXCPoOXPxSL6SWOWV8taR6903E
+FyLBN0qno/kXIBKnVqBZobgnjIEPA/0fTnxtZtE7EpirGQMF2caJfv7/LCgXmRs9xAhgbE0/
+caoa1tnc79uaHmLZFtbGFoAO31YNYM/IUHtmabbGdvZ4oYUwDhjBevVvC7aI+XhuNGK5mU8q
+CLLSEUOlCUr6BJq/0iFmjwjmwk9idZEYhqSNy2OoYJbq45rbHfbdKLEVrbQeUk9TIEJ1aWxk
+ZXIgPHJvc2J1aWxkQHJvcy5vcmc+iGAEExECACAFAksy5KkCGwMGCwkIBwMCBBUCCAMEFgID
+AQIeAQIXgAAKCRBVI7rusB+hFmk7AJ0XsLp05KA8l3YzAumZfjSN04MZjQCfQHfp4aQUXdOC
+UtetVo0QZUX3IuO5Ag0ESzLkrhAIAOCuSC83VXYWf8gOMSzdxwpsH/uLV9Wze2LGnajsJLjE
+Ohcsz2BHfxqNXhYaE9aQaodPCpbUAkPq8tLbpXy0SWRCx0F5RcplXx5vIWbP6TlfPbRpK70w
+7IWd6vsNrjwEHjlhOLcNcj42sp5pgx4bdceK06k5Ml2hYovPnD9o2TYgjOqg5FHZ2g1J0103
+n/66bN/hZnpLaZJYQiPWCyq6K0565i1k2Y7hgWB/OXqwaqCehqmLTvpyQGzE1UJvKLuYU+T+
+4hBnSPbT3KIi5fCzlIwvxijOMcfbkLhzYQXcU0Rd1VItcd5nmPL4z97jBxzuhkgxXpGR4WGK
+hvsA2Z9YUtsAAwYH/3Bf44bTpD9bVADUdab3e7zm8iHfh9K/a83mIgDB7mHV6WuemQVTf/1d
+eu4mI5WtpbOCoucybGfjGIIAcSxwIx6VfC7HSp4J51bOpHhbdDffUEk6QVsZjwoFyn3W9W3Z
+VeTI+ch/Qoo5a98SnmdjN8eXI/qCuiXOHc6rXDXc2R0iox/1EAS8xGVdcYZe7IWBO2CjCkny
+hLrWxZHoy+i1GCZ9KvPF/Ef2dmLhCydT73ZlumsY8N5vm76Qul1G7f8LNbnMgXQafRkPffrA
+XSVhGY3Z2IiBwFNgxcKTq479l7yedYRGeU1A+SYIYmRFWHXt3rTkMlQSpxCsB0fAYfrwEqqI
+SQQYEQIACQUCSzLkrgIbDAAKCRBVI7rusB+hFpryAJ4puo6cMZxa6wITHFAM/k84+aRijwCe
+ItuWpUngP25xDuDGMsKarcNiqYGISQQYEQIACQUCSzLkrgIbDAAKCRBVI7rusB+hFpryAJ9q
+Nz3h3ijt9TkAV0CHufsPT6Cl4gCglfg7tJn2lsSF3HTpoDDO1Fggx9o=
+=Ggee
+-----END PGP PUBLIC KEY BLOCK-----
-- 
GitLab