Official Debian support!
#84
Code:
#!/bin/sh

# This script installs RockPro64 devicetree files into /boot when new kernels
# are installed, removes them when kernels are removed, and updates the
# "dtbs" and "dtbs.old" symlinks accordingly.
# It should be copied into /etc/kernel/postinst.d/ and /etc/kernel/postrm.d/
# and given execute permission.
# https://www.debian.org/doc/manuals/debian-kernel-handbook/ch-update-hooks.html

set -e
exec </dev/null >&2  # Don't use stdin or stdout

version="$1"
pkgname=${DPKG_MAINTSCRIPT_PACKAGE:-kernel package}
if [ -z "$version" ]; then
    echo "W: $pkgname did not pass a version number; exiting."
    exit 0
fi

eval set -- "$DEB_MAINT_PARAMS"
action="$1"


# return 0 if $1 matches any of the remaining args
among() {
    val="$1"
    shift
    for a in "$@"; do
        if [ "$val" = "$a" ]; then return 0; fi
    done
    return 1;
}

# update /boot/dtbs and /boot/dtbs.old
# expects $1 to be "configure" or "remove"
# expects $version to be set
# see also: linux-update-symlinks
update_symlinks() {
    # build a list of dtbs-<ver> symlink targets, highest priority first...

    # ...first priority is a newly installed kernel
    if [ "$action" = configure ]; then
        set -- "dtbs-$version"
    else
        set --
    fi

    if [ "$action" = remove ]; then
        rmtarget=dtbs-$version
    fi

    # ...next priority is the existing primary symlink (if not being removed)
    link1=/boot/dtbs
    target1="$(readlink "$link1" || true)"
    if [ -e "$link1" ] && ! among "$target1" "$@"; then
        if [ "$target1" != "$rmtarget" ]; then
            set -- "$@" "$target1"
        fi
    fi

    # ...next priority is the existing secondary symlink (if not being removed)
    link2=/boot/dtbs.old
    target2="$(readlink "$link2" || true)"
    if [ -e "$link2" ] && ! among "$target2" "$@"; then
        if [ "$target2" != "$rmtarget" ]; then
            set -- "$@" "$target2"
        fi
    fi

    # ...finally, any other installed kernels, newest first
    for v in $(linux-version list | linux-version sort --reverse); do
        if [ "$action" = remove ] && [ "$v" = "$version" ]; then
            continue;
        fi
        if ! among "dtbs-$v" "$@"; then
            set -- "$@" "dtbs-$v"
        fi
    done

    # create/replace/remove the primary and secondary symlinks

    if [ $# -ge 1 ]; then
        echo "I: creating symlink $link1 -> $1"
        ln -sfn "$1" "$link1"
    elif [ -L "$link1" ]; then
        echo "I: removing $link1"
        rm -f "$link1"
    fi

    if [ $# -ge 2 ]; then shift; fi
    if [ $# -ge 1 ]; then
        echo "I: creating symlink $link2 -> $1"
        ln -sfn "$1" "$link2"
    elif [ -L "$link2" ]; then
        echo "I: removing $link2"
        rm -f "$link2"
    fi

    if [ ! -e "$link1" ]; then
        echo "W: $link1 symlink is missing; unable to find a target for it"
    fi
}


srcdir=/usr/lib/linux-image-${version}/rockchip
destbase=dtbs-${version}
destdir=/boot/$destbase/rockchip
fname=rk3399-rockpro64-v2.dtb

if [ "$action" = configure ]; then

    if [ -f "$srcdir/$fname" ]; then
        echo "I: installing $destdir/$fname"
        mkdir -p "$destdir"
        cp "$srcdir/$fname" "$destdir/$fname"
    else
        echo "W: $pkgname doesn't contain $srcdir/$fname; making symlink anyway"
    fi

    update_symlinks "$action"

fi

if [ "$action" = remove ]; then

    update_symlinks "$action"

    if [ -f "$destdir/$fname" ]; then
        echo "I: removing $destdir/$fname"
        rm "$destdir/$fname"
        rmdir "$destdir" || true
        rmdir "/boot/$destbase" || true
    fi
fi
  Reply


Messages In This Thread
Official Debian support! - by Luke - 04-26-2020, 03:02 PM
RE: Official Debian support! - by kuleszdl - 04-27-2020, 09:52 AM
RE: Official Debian support! - by linuxha - 04-27-2020, 10:43 PM
RE: Official Debian support! - by jazzmans - 04-28-2020, 05:35 PM
RE: Official Debian support! - by MIchael - 04-28-2020, 06:42 PM
RE: Official Debian support! - by jazzmans - 04-30-2020, 09:05 AM
RE: Official Debian support! - by pfeerick - 04-28-2020, 10:53 PM
RE: Official Debian support! - by fire219 - 04-30-2020, 12:28 PM
RE: Official Debian support! - by kuleszdl - 04-30-2020, 02:51 PM
RE: Official Debian support! - by amp - 05-01-2020, 01:28 AM
RE: Official Debian support! - by dukla2000 - 06-06-2020, 05:46 AM
RE: Official Debian support! - by pfeerick - 05-01-2020, 02:45 AM
RE: Official Debian support! - by kuleszdl - 05-01-2020, 10:31 AM
RE: Official Debian support! - by kuleszdl - 05-01-2020, 11:12 AM
RE: Official Debian support! - by foresto - 05-03-2020, 09:56 PM
RE: Official Debian support! - by tllim - 05-09-2020, 03:57 PM
RE: Official Debian support! - by xmixahlx - 06-06-2020, 03:06 PM
RE: Official Debian support! - by pinepersoon - 06-13-2020, 12:22 PM
RE: Official Debian support! - by foresto - 06-18-2020, 12:20 PM
RE: Official Debian support! - by pinepersoon - 06-25-2020, 03:53 PM
RE: Official Debian support! - by kuleszdl - 06-21-2020, 04:38 PM
RE: Official Debian support! - by xmixahlx - 06-21-2020, 09:18 PM
RE: Official Debian support! - by therrmann - 06-25-2020, 01:15 AM
RE: Official Debian support! - by therrmann - 06-25-2020, 02:03 AM
RE: Official Debian support! - by wasgurd - 07-03-2020, 01:01 PM
RE: Official Debian support! - by bcnaz - 07-03-2020, 06:31 PM
RE: Official Debian support! - by Nikolay_Po - 08-16-2020, 10:50 PM
RE: Official Debian support! - by Nikolay_Po - 08-17-2020, 04:31 PM
RE: Official Debian support! - by foresto - 08-16-2020, 11:21 PM
RE: Official Debian support! - by lrb - 09-12-2020, 09:53 PM
RE: Official Debian support! - by u974615 - 08-17-2020, 04:12 PM
RE: Official Debian support! - by xmixahlx - 08-19-2020, 11:54 AM
RE: Official Debian support! - by u974615 - 08-20-2020, 04:53 PM
RE: Official Debian support! - by moonwalkers - 08-21-2020, 10:49 PM
RE: Official Debian support! - by u974615 - 08-27-2020, 03:04 PM
RE: Official Debian support! - by moonwalkers - 08-27-2020, 04:30 PM
RE: Official Debian support! - by 5chn4pp - 08-26-2020, 01:28 PM
RE: Official Debian support! - by dkaparis - 10-11-2020, 08:10 AM
RE: Official Debian support! - by MSteam - 10-25-2020, 09:05 AM
RE: Official Debian support! - by snoopy_ca - 11-01-2020, 02:58 PM
RE: Official Debian support! - by eduapof - 11-17-2020, 06:42 PM
RE: Official Debian support! - by James Good - 12-21-2020, 11:39 AM
RE: Official Debian support! - by toons - 12-22-2020, 05:46 AM
RE: Official Debian support! - by kuleszdl - 12-24-2020, 12:00 PM
RE: Official Debian support! - by toons - 12-25-2020, 07:11 AM
RE: Official Debian support! - by kuleszdl - 12-25-2020, 08:46 AM
RE: Official Debian support! - by igorp - 01-05-2021, 07:17 AM
RE: Official Debian support! - by kuleszdl - 01-03-2021, 12:05 AM
RE: Official Debian support! - by kuleszdl - 01-05-2021, 09:44 AM
RE: Official Debian support! - by ryo - 01-06-2021, 04:08 AM
RE: Official Debian support! - by kwinz - 01-06-2021, 06:18 PM
RE: Official Debian support! - by igorp - 01-27-2021, 05:56 PM
RE: Official Debian support! - by ab1jx - 01-07-2021, 12:03 AM
RE: Official Debian support! - by kuleszdl - 01-07-2021, 09:12 AM
RE: Official Debian support! - by as365n4 - 01-19-2021, 12:35 PM
RE: Official Debian support! - by foobar - 01-30-2021, 07:52 PM
RE: Official Debian support! - by igorp - 01-31-2021, 06:34 PM
RE: Official Debian support! - by nyankat - 02-28-2021, 09:57 PM
RE: Official Debian support! - by ab1jx - 03-02-2021, 09:01 AM
RE: Official Debian support! - by alkisg - 04-26-2021, 03:01 AM
RE: Official Debian support! - by Enig123 - 04-28-2021, 01:22 PM
RE: Official Debian support! - by ab1jx - 04-28-2021, 03:38 PM
RE: Official Debian support! - by moonwalkers - 05-21-2021, 11:26 PM
RE: Official Debian support! - by jbrock - 05-30-2021, 03:43 PM
RE: Official Debian support! - by moonwalkers - 05-31-2021, 12:48 AM
RE: Official Debian support! - by jbrock - 06-01-2021, 01:09 AM
RE: Official Debian support! - by moonwalkers - 06-01-2021, 11:20 AM
missing firmware - by wchouser3 - 01-25-2022, 03:58 AM
RE: missing firmware - by foresto - 01-25-2022, 04:44 AM
RE: missing firmware - by wchouser3 - 01-25-2022, 11:49 AM
RE: Official Debian support! - by Barugon - 03-22-2022, 01:16 PM
RE: Official Debian support! - by as365n4 - 03-23-2022, 12:27 PM
RE: Official Debian support! - by Barugon - 03-24-2022, 11:43 PM
RE: Official Debian support! - by andersh - 05-19-2022, 10:11 AM
RE: Official Debian support! - by ljones - 10-29-2022, 11:44 AM
RE: Official Debian support! - by foresto - 10-29-2022, 01:35 PM
RE: Official Debian support! - by varac - 08-16-2023, 01:32 AM
RE: Official Debian support! - by foresto - 08-16-2023, 04:35 PM
debian kernel postinst/postrm script - by foresto - 12-16-2023, 03:00 PM
RE: Official Debian support! - by grobbs - 03-15-2024, 02:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  official support for aarch64 in OpenArena Opvolger 0 1,926 03-24-2022, 02:23 PM
Last Post: Opvolger
  Fedora 32 Release, improved support for Rock(Pro)64 Tharadash 2 6,441 05-05-2020, 08:37 AM
Last Post: zer0sig
  Kickstarter: Allwinner VPU support in the official Linux kernel xalius 8 16,271 10-03-2019, 03:03 AM
Last Post: bunkerWHz
Exclamation First images with DRM and Mali support for A64 Luke 74 130,743 04-27-2018, 10:22 PM
Last Post: Max11

Forum Jump:


Users browsing this thread: 3 Guest(s)