From 79ba7455adc121f2b6c0b167aea31d65d5c6a830 Mon Sep 17 00:00:00 2001
From: Merlin Mathesius <mmathesi@redhat.com>
Date: Thu, 27 Apr 2017 12:02:37 -0500
Subject: [PATCH] Squashed commit of the following:

commit 9b810f64a814e89469b1788cb755465c25011636
Author: Merlin Mathesius <mmathesi@redhat.com>
Date:   Tue Apr 25 11:46:47 2017 -0500

    Revert "BuildArch: noarch" since it causes Koji to be unable to build package.
    Correct copyright dates in script.

commit 984f7e5acd49c9865d3145d65b64b10116592c3a
Author: Merlin Mathesius <mmathesi@redhat.com>
Date:   Tue Apr 25 11:44:14 2017 -0500

    Add "BuildArch: noarch" since the package contents are now architecture independent.

commit f5a0acdcfb06ec04ed14f4023986b3049c5bb1d9
Author: Merlin Mathesius <mmathesi@redhat.com>
Date:   Mon Apr 24 14:58:42 2017 -0500

    SPEC file cleanup.

commit f99db2da8dc5c4cca05a58b89b8ae7bfd4038ae6
Author: Merlin Mathesius <mmathesi@redhat.com>
Date:   Mon Apr 24 08:53:37 2017 -0500

    Fix typo in appended line.

commit 7dda526caf893b910f63b5d31b3821e6d6ce0a4a
Author: Merlin Mathesius <mmathesi@redhat.com>
Date:   Fri Apr 21 12:19:39 2017 -0500

    Use bash version of extlinux for all build types.

commit 81bd08da5ca78c7433aff58a11dbe4bc76fa2b67
Author: Merlin Mathesius <mmathesi@redhat.com>
Date:   Mon Apr 3 12:16:29 2017 -0500

    Convert extlinux to bash script for Modularity to eliminate need for Python.
---
 extlinux-bootloader.spec | 11 +++++---
 extlinux.sh              | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 4 deletions(-)
 create mode 100755 extlinux.sh

diff --git a/extlinux-bootloader.spec b/extlinux-bootloader.spec
index dcd4aa7..10710f7 100644
--- a/extlinux-bootloader.spec
+++ b/extlinux-bootloader.spec
@@ -1,11 +1,11 @@
 Name:           extlinux-bootloader
-Version:        1.1
-Release:        7%{?dist}
+Version:        1.2
+Release:        0.6%{?dist}
 Summary:        The EXTLINUX bootloader framework, for booting the local system
 
 License:        GPLv2+
 URL:            http://fedoraproject.org/wiki/extlinux-bootloader
-Source1:        extlinux
+Source1:        extlinux.sh
 
 Provides:       syslinux-extlinux
 
@@ -27,7 +27,7 @@ mkdir -p %{buildroot}/boot/extlinux/
 
 mkdir -p %{buildroot}/etc
 ( cd %{buildroot}/etc && ln -s ../boot/extlinux/extlinux.conf . )
-install -p %{SOURCE1} %{buildroot}%{_sbindir}
+install -p %{SOURCE1} %{buildroot}%{_sbindir}/extlinux
 
 %files
 %doc
@@ -38,6 +38,9 @@ install -p %{SOURCE1} %{buildroot}%{_sbindir}
 
 
 %changelog
+* Mon Apr 03 2017 Merlin Mathesius <mmathesi@redhat.com> - 1.2-0
+- Convert extlinux to bash script to eliminate need for Python.
+
 * Fri Feb 10 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.1-7
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild
 
diff --git a/extlinux.sh b/extlinux.sh
new file mode 100755
index 0000000..600e45d
--- /dev/null
+++ b/extlinux.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# Copyright (C) 2015, 2017 Red Hat Inc.
+# Author(s): Dennis Gilmore <dennis@ausil.us>
+#            Merlin Mathesius <mmathesi@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
+# the full text of the license.
+
+# is the system a calxeda one
+is_calxeda() {
+    grep -Eq '^Hardware[^ ]* (Highbank|Midway)' /proc/cpuinfo
+}
+
+# update /etc/sysconfig/uboot to reflect if the platform provides its own dtb and
+# we do not need to pass anything.
+update_sysconfig() {
+    sed -i -e 's/#SHIPSDTB=no/SHIPSDTB=yes/g' /etc/sysconfig/uboot
+}
+
+# insert into /boot/extlinux/extlinux.conf a fdtdir line
+insert_fdtdir() {
+    sed -i \
+        -e '/	kernel/{h;s/kernel/fdtdir/g;s/vmlinuz/dtb/g;x}' \
+        -e '/	append/{p;x}' \
+        /boot/extlinux/extlinux.conf
+}
+
+# check if there is a rescue image and copy the dtb files if there is
+copy_rescue_dtbs() {
+    has_rescue=0
+    for target in /boot/vmlinuz-0-rescue* ; do
+        # if target exists, the glob matched a file
+        if [ -e "$target" ] ; then
+            has_rescue=1
+            dtbdest=$(echo "$target" | sed -e 's/vmlinuz/dtb/g')
+        fi
+	break
+    done
+    for target in /boot/dtb* ; do
+        # if target exists, the glob matched a file
+        if [ -e "$target" ] ; then
+            dtbsource="$target"
+        fi
+	break
+    done
+    if [ $has_rescue = 1 ] && [ ! -d "$dtbdest" ] ; then
+       mkdir "$dtbdest"
+       for dtb in $(ls "$dtbsource") ; do
+           ln "$dtbsource/$dtb" "$dtbdest/$dtb"
+       done
+    fi
+}
+
+# platform ships its own dtb
+if is_calxeda
+then
+    update_sysconfig
+else
+    # need to add fdtdir to extlinux.conf
+    insert_fdtdir
+    copy_rescue_dtbs
+fi
-- 
2.9.3

