Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/scripts/makeboarddeb.sh
Views: 3960
#!/bin/bash1#2# Copyright (c) 2021 Igor Pecovnik, igor.pecovnik@gma**.com3#4# This file is licensed under the terms of the GNU General Public5# License version 2. This program is licensed "as is" without any6# warranty of any kind, whether express or implied.789#10# Functions:11# create_board_package1213141516create_board_package()17{18display_alert "Creating board support package for CLI" "$CHOSEN_ROOTFS" "info"1920bsptempdir=$(mktemp -d)21chmod 700 ${bsptempdir}22trap "rm -rf \"${bsptempdir}\" ; exit 0" 0 1 2 3 1523local destination=${bsptempdir}/${RELEASE}/${BSP_CLI_PACKAGE_FULLNAME}24mkdir -p "${destination}"/DEBIAN25cd $destination2627# copy general overlay from packages/bsp-cli28copy_all_packages_files_for "bsp-cli"2930# install copy of boot script & environment file31if [[ "${BOOTCONFIG}" != "none" ]]; then32# @TODO: add extension method bsp_prepare_bootloader(), refactor into u-boot extension33local bootscript_src=${BOOTSCRIPT%%:*}34local bootscript_dst=${BOOTSCRIPT##*:}35mkdir -p "${destination}"/usr/share/orangepi/3637# create extlinux config file38if [[ $SRC_EXTLINUX != yes ]]; then39if [ -f "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" ]; then40cp "${USERPATCHES_PATH}/bootscripts/${bootscript_src}" "${destination}/usr/share/orangepi/${bootscript_dst}"41else42cp "${EXTER}/config/bootscripts/${bootscript_src}" "${destination}/usr/share/orangepi/${bootscript_dst}"43fi44[[ -n $BOOTENV_FILE && -f $SRC/config/bootenv/$BOOTENV_FILE ]] && \45cp "${EXTER}/config/bootenv/${BOOTENV_FILE}" "${destination}"/usr/share/orangepi/orangepiEnv.txt46fi4748# add configuration for setting uboot environment from userspace with: fw_setenv fw_printenv49if [[ -n $UBOOT_FW_ENV ]]; then50UBOOT_FW_ENV=($(tr ',' ' ' <<< "$UBOOT_FW_ENV"))51mkdir -p "${destination}"/etc52echo "# Device to access offset env size" > "${destination}"/etc/fw_env.config53echo "/dev/mmcblk0 ${UBOOT_FW_ENV[0]} ${UBOOT_FW_ENV[1]}" >> "${destination}"/etc/fw_env.config54fi55fi5657# Replaces: base-files is needed to replace /etc/update-motd.d/ files on Xenial58# Replaces: unattended-upgrades may be needed to replace /etc/apt/apt.conf.d/50unattended-upgrades59# (distributions provide good defaults, so this is not needed currently)60# Depends: linux-base is needed for "linux-version" command in initrd cleanup script61# Depends: fping is needed for orangepimonitor to upload orangepi-hardware-monitor.log62cat <<-EOF > "${destination}"/DEBIAN/control63Package: ${BSP_CLI_PACKAGE_NAME}64Version: $REVISION65Architecture: $ARCH66Maintainer: $MAINTAINER <$MAINTAINERMAIL>67Installed-Size: 168Section: kernel69Priority: optional70Depends: bash, linux-base, u-boot-tools, initramfs-tools, lsb-release, fping71Provides: linux-${RELEASE}-root-legacy-$BOARD, linux-${RELEASE}-root-current-$BOARD, linux-${RELEASE}-root-next-$BOARD72Suggests: orangepi-config73Replaces: zram-config, base-files, orangepi-tools-$RELEASE, linux-${RELEASE}-root-legacy-$BOARD (<< $REVISION~), linux-${RELEASE}-root-current-$BOARD (<< $REVISION~), linux-${RELEASE}-root-next-$BOARD (<< $REVISION~)74Breaks: linux-${RELEASE}-root-legacy-$BOARD (<< $REVISION~), linux-${RELEASE}-root-current-$BOARD (<< $REVISION~), linux-${RELEASE}-root-next-$BOARD (<< $REVISION~)75Recommends: bsdutils, parted, util-linux, toilet76Description: OrangePi board support files for $BOARD77EOF7879# set up pre install script80cat <<-EOF > "${destination}"/DEBIAN/preinst81#!/bin/sh8283# tell people to reboot at next login84[ "\$1" = "upgrade" ] && touch /var/run/.reboot_required8586# convert link to file87if [ -L "/etc/network/interfaces" ]; then8889cp /etc/network/interfaces /etc/network/interfaces.tmp90rm /etc/network/interfaces91mv /etc/network/interfaces.tmp /etc/network/interfaces9293fi9495# fixing ramdisk corruption when using lz4 compression method96sed -i "s/^COMPRESS=.*/COMPRESS=gzip/" /etc/initramfs-tools/initramfs.conf9798# swap99grep -q vm.swappiness /etc/sysctl.conf100case \$? in1010)102sed -i 's/vm\.swappiness.*/vm.swappiness=100/' /etc/sysctl.conf103;;104*)105echo vm.swappiness=100 >>/etc/sysctl.conf106;;107esac108sysctl -p >/dev/null 2>&1109110# disable deprecated services111[ -f "/etc/profile.d/activate_psd_user.sh" ] && rm /etc/profile.d/activate_psd_user.sh112[ -f "/etc/profile.d/check_first_login.sh" ] && rm /etc/profile.d/check_first_login.sh113[ -f "/etc/profile.d/check_first_login_reboot.sh" ] && rm /etc/profile.d/check_first_login_reboot.sh114[ -f "/etc/profile.d/ssh-title.sh" ] && rm /etc/profile.d/ssh-title.sh115[ -f "/etc/update-motd.d/10-header" ] && rm /etc/update-motd.d/10-header116[ -f "/etc/update-motd.d/30-sysinfo" ] && rm /etc/update-motd.d/30-sysinfo117[ -f "/etc/update-motd.d/35-tips" ] && rm /etc/update-motd.d/35-tips118[ -f "/etc/update-motd.d/40-updates" ] && rm /etc/update-motd.d/40-updates119[ -f "/etc/update-motd.d/98-autoreboot-warn" ] && rm /etc/update-motd.d/98-autoreboot-warn120[ -f "/etc/update-motd.d/99-point-to-faq" ] && rm /etc/update-motd.d/99-point-to-faq121[ -f "/etc/update-motd.d/80-esm" ] && rm /etc/update-motd.d/80-esm122[ -f "/etc/update-motd.d/80-livepatch" ] && rm /etc/update-motd.d/80-livepatch123[ -f "/etc/apt/apt.conf.d/02compress-indexes" ] && rm /etc/apt/apt.conf.d/02compress-indexes124[ -f "/etc/apt/apt.conf.d/02periodic" ] && rm /etc/apt/apt.conf.d/02periodic125[ -f "/etc/apt/apt.conf.d/no-languages" ] && rm /etc/apt/apt.conf.d/no-languages126[ -f "/etc/init.d/armhwinfo" ] && rm /etc/init.d/armhwinfo127[ -f "/etc/logrotate.d/armhwinfo" ] && rm /etc/logrotate.d/armhwinfo128[ -f "/etc/init.d/firstrun" ] && rm /etc/init.d/firstrun129[ -f "/etc/init.d/resize2fs" ] && rm /etc/init.d/resize2fs130[ -f "/lib/systemd/system/firstrun-config.service" ] && rm /lib/systemd/system/firstrun-config.service131[ -f "/lib/systemd/system/firstrun.service" ] && rm /lib/systemd/system/firstrun.service132[ -f "/lib/systemd/system/resize2fs.service" ] && rm /lib/systemd/system/resize2fs.service133[ -f "/usr/lib/orangepi/apt-updates" ] && rm /usr/lib/orangepi/apt-updates134[ -f "/usr/lib/orangepi/firstrun-config.sh" ] && rm /usr/lib/orangepi/firstrun-config.sh135# fix for https://bugs.launchpad.net/ubuntu/+source/lightdm-gtk-greeter/+bug/1897491136[ -d "/var/lib/lightdm" ] && (chown -R lightdm:lightdm /var/lib/lightdm ; chmod 0750 /var/lib/lightdm)137exit 0138EOF139140chmod 755 "${destination}"/DEBIAN/preinst141142# postrm script143cat <<-EOF > "${destination}"/DEBIAN/postrm144#!/bin/sh145if [ remove = "\$1" ] || [ abort-install = "\$1" ]; then146147systemctl disable orangepi-hardware-monitor.service orangepi-hardware-optimize.service >/dev/null 2>&1148systemctl disable orangepi-zram-config.service orangepi-ramlog.service >/dev/null 2>&1149150fi151exit 0152EOF153154chmod 755 "${destination}"/DEBIAN/postrm155156# set up post install script157cat <<-EOF > "${destination}"/DEBIAN/postinst158#!/bin/sh159#160# ${BOARD} BSP post installation script161#162163[ -f /etc/lib/systemd/system/orangepi-ramlog.service ] && systemctl --no-reload enable orangepi-ramlog.service164165# check if it was disabled in config and disable in new service166if [ -n "\$(grep -w '^ENABLED=false' /etc/default/log2ram 2> /dev/null)" ]; then167168sed -i "s/^ENABLED=.*/ENABLED=false/" /etc/default/orangepi-ramlog169170fi171172# fix boot delay "waiting for suspend/resume device"173if [ -f "/etc/initramfs-tools/initramfs.conf" ]; then174175if ! grep --quiet "RESUME=none" /etc/initramfs-tools/initramfs.conf; then176echo "RESUME=none" >> /etc/initramfs-tools/initramfs.conf177fi178179fi180181EOF182# install bootscripts if they are not present. Fix upgrades from old images183if [[ $FORCE_BOOTSCRIPT_UPDATE == yes ]]; then184cat <<-EOF >> "${destination}"/DEBIAN/postinst185if [ true ]; then186187# this package recreate boot scripts188EOF189else190cat <<-EOF >> "${destination}"/DEBIAN/postinst191if [ ! -f /boot/$bootscript_dst ]; then192193# if boot script does not exits its recreated194EOF195fi196cat <<-EOF >> "${destination}"/DEBIAN/postinst197# move bootscript to /usr/share/orangepi198# create a backup199[ -f /etc/orangepi-release ] && . /etc/orangepi-release200[ -z \${VERSION} ] && VERSION=$(echo \`date +%s\`)201if [ -f /boot/$bootscript_dst ]; then202cp /boot/$bootscript_dst /usr/share/orangepi/${bootscript_dst}-\${VERSION} >/dev/null 2>&1203echo "NOTE: You can find previous bootscript versions in /usr/share/orangepi !"204fi205206# cleanup old bootscript backup207ls /usr/share/orangepi/boot.cmd-* >/dev/null 2>&1 | head -n -5 | xargs rm -f --208ls /usr/share/orangepi/boot.ini-* >/dev/null 2>&1 | head -n -5 | xargs rm -f --209210echo "Recreating boot script"211cp /usr/share/orangepi/$bootscript_dst /boot >/dev/null 2>&1212rootdev=\$(sed -e 's/^.*root=//' -e 's/ .*\$//' < /proc/cmdline)213rootfstype=\$(sed -e 's/^.*rootfstype=//' -e 's/ .*$//' < /proc/cmdline)214215# recreate orangepiEnv.txt if it and extlinux does not exists216if [ ! -f /boot/orangepiEnv.txt ] && [ ! -f /boot/extlinux/extlinux.conf ]; then217cp /usr/share/orangepi/orangepiEnv.txt /boot >/dev/null 2>&1218echo "rootdev="\$rootdev >> /boot/orangepiEnv.txt219echo "rootfstype="\$rootfstype >> /boot/orangepiEnv.txt220fi221222[ -f /boot/boot.ini ] && sed -i "s/setenv rootdev.*/setenv rootdev \\"\$rootdev\\"/" /boot/boot.ini223[ -f /boot/boot.ini ] && sed -i "s/setenv rootfstype.*/setenv rootfstype \\"\$rootfstype\\"/" /boot/boot.ini224[ -f /boot/boot.cmd ] && mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1225226fi227228[ ! -f "/etc/network/interfaces" ] && [ -f "/etc/network/interfaces.default" ] && cp /etc/network/interfaces.default /etc/network/interfaces229ln -sf /var/run/motd /etc/motd230rm -f /etc/update-motd.d/00-header /etc/update-motd.d/10-help-text231if [ -f "/boot/bin/$BOARD.bin" ] && [ ! -f "/boot/script.bin" ]; then ln -sf bin/$BOARD.bin /boot/script.bin >/dev/null 2>&1 || cp /boot/bin/$BOARD.bin /boot/script.bin; fi232if [ ! -f "/etc/default/orangepi-motd" ]; then233mv /etc/default/orangepi-motd.dpkg-dist /etc/default/orangepi-motd234fi235if [ ! -f "/etc/default/orangepi-ramlog" ] && [ -f /etc/default/orangepi-ramlog.dpkg-dist ]; then236mv /etc/default/orangepi-ramlog.dpkg-dist /etc/default/orangepi-ramlog237fi238if [ ! -f "/etc/default/orangepi-zram-config" ] && [ -f /etc/default/orangepi-zram-config.dpkg-dist ]; then239mv /etc/default/orangepi-zram-config.dpkg-dist /etc/default/orangepi-zram-config240fi241242if [ -L "/usr/lib/chromium-browser/master_preferences.dpkg-dist" ]; then243mv /usr/lib/chromium-browser/master_preferences.dpkg-dist /usr/lib/chromium-browser/master_preferences244fi245246# Read release value247if [ -f /etc/lsb-release ]; then248RELEASE=\$(cat /etc/lsb-release | grep CODENAME | cut -d"=" -f2 | sed 's/.*/\u&/')249sed -i "s/^PRETTY_NAME=.*/PRETTY_NAME=\"${VENDOR} $REVISION "\${RELEASE}"\"/" /etc/os-release250echo "${VENDOR} ${REVISION} \${RELEASE} \\l \n" > /etc/issue251echo "${VENDOR} ${REVISION} \${RELEASE}" > /etc/issue.net252fi253254# Reload services255systemctl --no-reload enable orangepi-hardware-monitor.service orangepi-hardware-optimize.service orangepi-zram-config.service >/dev/null 2>&1256exit 0257EOF258259chmod 755 "${destination}"/DEBIAN/postinst260261# won't recreate files if they were removed by user262# TODO: Add proper handling for updated conffiles263#cat <<-EOF > "${destination}"/DEBIAN/conffiles264#EOF265266# copy common files from a premade directory structure267rsync -a "${EXTER}"/packages/bsp/common/* ${destination}268269# trigger uInitrd creation after installation, to apply270# /etc/initramfs/post-update.d/99-uboot271cat <<-EOF > "${destination}"/DEBIAN/triggers272activate update-initramfs273EOF274275# copy distribution support status276local releases=($(find ${EXTER}/config/distributions -mindepth 1 -maxdepth 1 -type d))277for i in ${releases[@]}278do279echo "$(echo $i | sed 's/.*\///')=$(cat $i/support)" >> "${destination}"/etc/orangepi-distribution-status280done281282# armhwinfo, firstrun, orangepimonitor, etc. config file283cat <<-EOF > "${destination}"/etc/orangepi-release284# PLEASE DO NOT EDIT THIS FILE285BOARD=${BOARD}286BOARD_NAME="$BOARD_NAME"287BOARDFAMILY=${BOARDFAMILY}288BUILD_REPOSITORY_URL=${BUILD_REPOSITORY_URL}289BUILD_REPOSITORY_COMMIT=${BUILD_REPOSITORY_COMMIT}290DISTRIBUTION_CODENAME=${RELEASE}291DISTRIBUTION_STATUS=${DISTRIBUTION_STATUS}292VERSION=${REVISION}293LINUXFAMILY=${LINUXFAMILY}294ARCH=${ARCHITECTURE}295IMAGE_TYPE=$IMAGE_TYPE296BOARD_TYPE=$BOARD_TYPE297INITRD_ARCH=${INITRD_ARCH}298KERNEL_IMAGE_TYPE=${KERNEL_IMAGE_TYPE}299BRANCH=${BRANCH}300EOF301302# this is required for NFS boot to prevent deconfiguring the network on shutdown303sed -i 's/#no-auto-down/no-auto-down/g' "${destination}"/etc/network/interfaces.default304305if [[ ( $LINUXFAMILY == sun8i ) && $BRANCH == legacy ]]; then306# add mpv config for vdpau_sunxi307mkdir -p "${destination}"/etc/mpv/308cp "${EXTER}"/packages/bsp/mpv/mpv_sunxi.conf "${destination}"/etc/mpv/mpv.conf309echo "export VDPAU_OSD=1" > "${destination}"/etc/profile.d/90-vdpau.sh310chmod 755 "${destination}"/etc/profile.d/90-vdpau.sh311fi312if [[ $LINUXFAMILY == sunxi* ]]; then313# add mpv config for x11 output - slow, but it works compared to no config at all314# TODO: Test which output driver is better with DRM315mkdir -p "${destination}"/etc/mpv/316cp "${EXTER}"/packages/bsp/mpv/mpv_mainline.conf "${destination}"/etc/mpv/mpv.conf317fi318319case $RELEASE in320xenial)321if [[ $BRANCH == legacy && $LINUXFAMILY == sun8i ]]; then322# this is required only for old kernels323# not needed for Stretch since there will be no Stretch images with kernels < 4.4324mkdir -p "${destination}"/lib/systemd/system/haveged.service.d/325cp "${EXTER}"/packages/bsp/10-no-new-privileges.conf "${destination}"/lib/systemd/system/haveged.service.d/326fi327;;328esac329# execute $LINUXFAMILY-specific tweaks330[[ $(type -t family_tweaks_bsp) == function ]] && family_tweaks_bsp331332call_extension_method "post_family_tweaks_bsp" << 'POST_FAMILY_TWEAKS_BSP'333*family_tweaks_bsp overrrides what is in the config, so give it a chance to override the family tweaks*334This should be implemented by the config to tweak the BSP, after the board or family has had the chance to.335POST_FAMILY_TWEAKS_BSP336337# add some summary to the image338fingerprint_image "${destination}/etc/orangepi.txt"339340# fixing permissions (basic), reference: dh_fixperms341find "${destination}" -print0 2>/dev/null | xargs -0r chown --no-dereference 0:0342find "${destination}" ! -type l -print0 2>/dev/null | xargs -0r chmod 'go=rX,u+rw,a-s'343344# create board DEB file345fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${destination}.deb" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1346mkdir -p "${DEB_STORAGE}/${RELEASE}/"347rsync --remove-source-files -rq "${destination}.deb" "${DEB_STORAGE}/${RELEASE}/"348349# cleanup350rm -rf ${bsptempdir}351}352353354