Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
chroot.sh 43.1 KiB
Newer Older
	if [ -f "${DIR}/git/linux-firmware/htc_9271.fw" ] ; then
		sudo cp -v "${DIR}/git/linux-firmware/LICENCE.atheros_firmware" "${tempdir}/lib/firmware/"
		sudo cp -v "${DIR}/git/linux-firmware/htc_9271.fw" "${tempdir}/lib/firmware/"
	if [ -d "${DIR}/git/linux-firmware/rtlwifi/" ] ; then
		sudo mkdir -p "${tempdir}/lib/firmware/rtlwifi"
		sudo cp -v "${DIR}/git/linux-firmware/LICENCE.rtlwifi_firmware.txt" "${tempdir}/lib/firmware/"
Robert Nelson's avatar
Robert Nelson committed
		sudo cp -v "${DIR}"/git/linux-firmware/rtlwifi/* "${tempdir}/lib/firmware/rtlwifi"
	if [ -d "${DIR}/git/linux-firmware/ti-connectivity/" ] ; then
		sudo mkdir -p "${tempdir}/lib/firmware/ti-connectivity"
		sudo cp -v "${DIR}/git/linux-firmware/LICENCE.ti-connectivity" "${tempdir}/lib/firmware/"
Robert Nelson's avatar
Robert Nelson committed
		sudo cp -v "${DIR}"/git/linux-firmware/ti-connectivity/* "${tempdir}/lib/firmware/ti-connectivity"
	if [ -f "${DIR}/git/linux-firmware/mt7601u.bin" ] ; then
		sudo cp -v "${DIR}/git/linux-firmware/mt7601u.bin" "${tempdir}/lib/firmware/mt7601u.bin"
if [ -n "${early_chroot_script}" -a -r "${DIR}/target/chroot/${early_chroot_script}" ] ; then
	report_size
	echo "Calling early_chroot_script script: ${early_chroot_script}"
	sudo cp -v "${DIR}/.project" "${tempdir}/etc/oib.project"
	sudo /bin/bash -e "${DIR}/target/chroot/${early_chroot_script}" "${tempdir}"
	early_chroot_script=""
	sudo rm -f "${tempdir}/etc/oib.project" || true
sudo chroot "${tempdir}" /bin/bash -e chroot_script.sh
echo "Log: Complete: [sudo chroot ${tempdir} /bin/bash -e chroot_script.sh]"
#Do /etc/issue & /etc/issue.net after chroot_script:
#
#Unpacking base-files (7.2ubuntu5.1) over (7.2ubuntu5) ...
#Setting up base-files (7.2ubuntu5.1) ...
#
#Configuration file '/etc/issue'
# ==> Modified (by you or by a script) since installation.
# ==> Package distributor has shipped an updated version.
#   What would you like to do about it ?  Your options are:
#    Y or I  : install the package maintainer's version
#    N or O  : keep your currently-installed version
#      D     : show the differences between the versions
#      Z     : start a shell to examine the situation
# The default action is to keep your current version.
#*** issue (Y/I/N/O/D/Z) [default=N] ? n

Robert Nelson's avatar
Robert Nelson committed
if [ ! "x${rfs_console_banner}" = "x" ] || [ ! "x${rfs_console_user_pass}" = "x" ] ; then
	echo "Log: setting up: /etc/issue"
Robert Nelson's avatar
Robert Nelson committed
	if [ ! "x${rfs_etc_dogtag}" = "x" ] ; then
		sudo sh -c "cat '${tempdir}/etc/dogtag' >> ${wfile}"
		sudo sh -c "echo '' >> ${wfile}"
Robert Nelson's avatar
Robert Nelson committed
	if [ ! "x${rfs_console_banner}" = "x" ] ; then
		sudo sh -c "echo '${rfs_console_banner}' >> ${wfile}"
		sudo sh -c "echo '' >> ${wfile}"
Robert Nelson's avatar
Robert Nelson committed
	if [ ! "x${rfs_console_user_pass}" = "x" ] ; then
		sudo sh -c "echo 'default username:password is [${rfs_username}:${rfs_password}]' >> ${wfile}"
		sudo sh -c "echo '' >> ${wfile}"
Robert Nelson's avatar
Robert Nelson committed
if [ ! "x${rfs_ssh_banner}" = "x" ] || [ ! "x${rfs_ssh_user_pass}" = "x" ] ; then
	echo "Log: setting up: /etc/issue.net"
	wfile="${tempdir}/etc/issue.net"
	sudo sh -c "echo '' >> ${wfile}"
Robert Nelson's avatar
Robert Nelson committed
	if [ ! "x${rfs_etc_dogtag}" = "x" ] ; then
		sudo sh -c "cat '${tempdir}/etc/dogtag' >> ${wfile}"
		sudo sh -c "echo '' >> ${wfile}"
Robert Nelson's avatar
Robert Nelson committed
	if [ ! "x${rfs_ssh_banner}" = "x" ] ; then
		sudo sh -c "echo '${rfs_ssh_banner}' >> ${wfile}"
		sudo sh -c "echo '' >> ${wfile}"
Robert Nelson's avatar
Robert Nelson committed
	if [ ! "x${rfs_ssh_user_pass}" = "x" ] ; then
		sudo sh -c "echo 'default username:password is [${rfs_username}:${rfs_password}]' >> ${wfile}"
		sudo sh -c "echo '' >> ${wfile}"
if [ ! "x${rfs_opt_scripts}" = "x" ] ; then
	#we might not have read permissions:
	if [ -r "${tempdir}/opt/scripts/" ] ; then
		if [ ! -f "${tempdir}/opt/scripts/.git/config" ] ; then
			echo "Log: ERROR: git clone of ${rfs_opt_scripts} failed.."
			exit 1
		fi
	else
		echo "Log: unable to test /opt/scripts/.git/config no read permissions, assuming git clone success"
if [ -n "${chroot_before_hook}" -a -r "${DIR}/${chroot_before_hook}" ] ; then
	report_size
	echo "Calling chroot_before_hook script: ${chroot_before_hook}"
	. "${DIR}/${chroot_before_hook}"
	chroot_before_hook=""
fi

if [ -n "${chroot_script}" -a -r "${DIR}/target/chroot/${chroot_script}" ] ; then
Robert Nelson's avatar
Robert Nelson committed
	report_size
	echo "Calling chroot_script script: ${chroot_script}"
Robert Nelson's avatar
Robert Nelson committed
	sudo cp -v "${DIR}/.project" "${tempdir}/etc/oib.project"
	sudo cp -v "${DIR}/target/chroot/${chroot_script}" "${tempdir}/final.sh"
	sudo chroot "${tempdir}" /bin/bash -e final.sh
	sudo rm -f "${tempdir}/final.sh" || true
	sudo rm -f "${tempdir}/etc/oib.project" || true
Robert Nelson's avatar
Robert Nelson committed
	chroot_script=""
	if [ -f "${tempdir}/npm-debug.log" ] ; then
		echo "Log: ERROR: npm error in script, review log [cat ${tempdir}/npm-debug.log]..."
		exit 1
	fi
Robert Nelson's avatar
Robert Nelson committed
fi

##Building final tar file...

if [ -d "${DIR}/deploy/${export_filename}/" ] ; then
	rm -rf "${DIR}/deploy/${export_filename}/" || true
mkdir -p "${DIR}/deploy/${export_filename}/" || true
cp -v "${DIR}/.project" "${DIR}/deploy/${export_filename}/image-builder.project"
if [ -n "${chroot_after_hook}" -a -r "${DIR}/${chroot_after_hook}" ] ; then
	echo "Calling chroot_after_hook script: ${DIR}/${chroot_after_hook}"
	. "${DIR}/${chroot_after_hook}"
	chroot_after_hook=""
cat > "${DIR}/cleanup_script.sh" <<-__EOF__
	#!/bin/sh -e
	export LC_ALL=C
	export DEBIAN_FRONTEND=noninteractive

	#set distro:
	. /etc/rcn-ee.conf

	cleanup () {
		echo "Log: (chroot): cleanup"
		mkdir -p /boot/uboot/

		if [ -f /etc/apt/apt.conf ] ; then
			rm -rf /etc/apt/apt.conf || true
		fi
		apt-get clean
		rm -rf /var/lib/apt/lists/*

		if [ -d /var/cache/bb-node-red-installer ] ; then
			rm -rf /var/cache/bb-node-red-installer|| true
		fi
		if [ -d /var/cache/c9-core-installer/ ] ; then
			rm -rf /var/cache/c9-core-installer/ || true
		fi
		if [ -d /var/cache/ipumm-dra7xx-installer/ ] ; then
			rm -rf /var/cache/ipumm-dra7xx-installer/ || true
		fi
		if [ -d /var/cache/ti-c6000-cgt-v8.0.x-installer/ ] ; then
			rm -rf /var/cache/ti-c6000-cgt-v8.0.x-installer/ || true
		fi
		if [ -d /var/cache/ti-c6000-cgt-v8.1.x-installer/ ] ; then
			rm -rf /var/cache/ti-c6000-cgt-v8.1.x-installer/ || true
		fi
		if [ -d /var/cache/ti-pru-cgt-installer/ ] ; then
			rm -rf /var/cache/ti-pru-cgt-installer/ || true
		fi
		if [ -d /var/cache/vpdma-dra7xx-installer/ ] ; then
			rm -rf /var/cache/vpdma-dra7xx-installer/ || true
		fi
		rm -f /usr/sbin/policy-rc.d

		if [ "x\${distro}" = "xUbuntu" ] ; then
			rm -f /sbin/initctl || true
			dpkg-divert --local --rename --remove /sbin/initctl
		fi
#		#This is tmpfs, clear out any left overs...
#		if [ -d /run/ ] ; then
#			rm -rf /run/* || true
#		fi
	}

	cleanup
	rm -f /cleanup_script.sh || true
__EOF__

###MUST BE LAST...
sudo mv "${DIR}/cleanup_script.sh" "${tempdir}/cleanup_script.sh"
sudo chroot "${tempdir}" /bin/bash -e cleanup_script.sh
echo "Log: Complete: [sudo chroot ${tempdir} /bin/bash -e cleanup_script.sh]"
#add /boot/uEnv.txt update script
if [ -d "${tempdir}/etc/kernel/postinst.d/" ] ; then
	if [ ! -f "${tempdir}/etc/kernel/postinst.d/zz-uenv_txt" ] ; then
		sudo cp -v "${OIB_DIR}/target/other/zz-uenv_txt" "${tempdir}/etc/kernel/postinst.d/"
		sudo chmod +x "${tempdir}/etc/kernel/postinst.d/zz-uenv_txt"
		sudo chown root:root "${tempdir}/etc/kernel/postinst.d/zz-uenv_txt"
	fi
fi

if [ -f "${tempdir}/usr/bin/qemu-arm-static" ] ; then
	sudo rm -f "${tempdir}/usr/bin/qemu-arm-static" || true
fi

if [ -f "${tempdir}/usr/bin/qemu-aarch64-static" ] ; then
	sudo rm -f "${tempdir}/usr/bin/qemu-aarch64-static" || true
fi

echo "${rfs_username}:${rfs_password}" > /tmp/user_password.list
sudo mv /tmp/user_password.list "${DIR}/deploy/${export_filename}/user_password.list"

#Fixes:
if [ -d "${tempdir}/etc/ssh/" -a "x${keep_ssh_keys}" = "x" ] ; then
	#Remove pre-generated ssh keys, these will be regenerated on first bootup...
	sudo rm -rf "${tempdir}"/etc/ssh/ssh_host_* || true
	sudo touch "${tempdir}/etc/ssh/ssh.regenerate" || true
fi

#ID.txt:
if [ -f "${tempdir}/etc/dogtag" ] ; then
	sudo cp "${tempdir}/etc/dogtag" "${DIR}/deploy/${export_filename}/ID.txt"
	sudo chown root:root "${DIR}/deploy/${export_filename}/ID.txt"
report_size
chroot_umount

Robert Nelson's avatar
Robert Nelson committed
if [ "x${chroot_COPY_SETUP_SDCARD}" = "xenable" ] ; then
	echo "Log: copying setup_sdcard.sh related files"
	sudo cp "${DIR}/tools/setup_sdcard.sh" "${DIR}/deploy/${export_filename}/"
	sudo mkdir -p "${DIR}/deploy/${export_filename}/hwpack/"
Robert Nelson's avatar
Robert Nelson committed
	sudo cp "${DIR}"/tools/hwpack/*.conf "${DIR}/deploy/${export_filename}/hwpack/"
	if [ -n "${chroot_uenv_txt}" -a -r "${OIB_DIR}/target/boot/${chroot_uenv_txt}" ] ; then
		sudo cp "${OIB_DIR}/target/boot/${chroot_uenv_txt}" "${DIR}/deploy/${export_filename}/uEnv.txt"
	if [ -n "${chroot_flasher_uenv_txt}" -a -r "${OIB_DIR}/target/boot/${chroot_flasher_uenv_txt}" ] ; then
		sudo cp "${OIB_DIR}/target/boot/${chroot_flasher_uenv_txt}" "${DIR}/deploy/${export_filename}/eMMC-flasher.txt"
	if [ -n "${chroot_post_uenv_txt}" -a -r "${OIB_DIR}/target/boot/${chroot_post_uenv_txt}" ] ; then
		sudo cp "${OIB_DIR}/target/boot/${chroot_post_uenv_txt}" "${DIR}/deploy/${export_filename}/post-uEnv.txt"
if [ "x${chroot_directory}" = "xenable" ]; then
	echo "Log: moving rootfs to directory: [${deb_arch}-rootfs-${deb_distribution}-${deb_codename}]"
	sudo mv -v "${tempdir}" "${DIR}/deploy/${export_filename}/${deb_arch}-rootfs-${deb_distribution}-${deb_codename}"
	du -h --max-depth=0 "${DIR}/deploy/${export_filename}/${deb_arch}-rootfs-${deb_distribution}-${deb_codename}"
	echo "Log: packaging rootfs: [${deb_arch}-rootfs-${deb_distribution}-${deb_codename}.tar]"
	sudo LANG=C tar --numeric-owner -cf "${DIR}/deploy/${export_filename}/${deb_arch}-rootfs-${deb_distribution}-${deb_codename}.tar" .
	cd "${DIR}/" || true
	ls -lh "${DIR}/deploy/${export_filename}/${deb_arch}-rootfs-${deb_distribution}-${deb_codename}.tar"
	sudo chown -R ${USER}:${USER} "${DIR}/deploy/${export_filename}/"
echo "Log: USER:${USER}"

if [ "x${chroot_tarball}" = "xenable" ] ; then
	echo "Creating: ${export_filename}.tar"
	sudo tar cvf ${export_filename}.tar ./${export_filename}
	sudo chown -R ${USER}:${USER} "${export_filename}.tar"