From 25531e0f26ab6f55a06bb7bbecf61abb9fd0ff51 Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <olteanv@gmail.com>
Date: Fri, 22 Mar 2019 22:37:05 +0000
Subject: [PATCH] onclite: Sync extractors with templates

 * This introduces fixup scripts and kang mode and fixes
   passing of arguments longer than one word,
   such as --section "Hello world".

Change-Id: I42dde659e9bea4f7e1c9a7a3fa8da3243774ca4e
---
 extract-files.sh   | 44 ++++++++++++++++++++++++++------------------
 setup-makefiles.sh |  5 ++---
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/extract-files.sh b/extract-files.sh
index c13675a..7225c15 100755
--- a/extract-files.sh
+++ b/extract-files.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # Copyright (C) 2016 The CyanogenMod Project
-# Copyright (C) 2017 The LineageOS Project
+# Copyright (C) 2017-2019 The LineageOS Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -23,45 +23,53 @@ VENDOR=xiaomi
 
 # Load extract_utils and do some sanity checks
 MY_DIR="${BASH_SOURCE%/*}"
-if [[ ! -d "$MY_DIR" ]]; then MY_DIR="$PWD"; fi
+if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi
 
-LINEAGE_ROOT="$MY_DIR"/../../..
+LINEAGE_ROOT="${MY_DIR}/../../.."
 
-HELPER="$LINEAGE_ROOT"/vendor/lineage/build/tools/extract_utils.sh
-if [ ! -f "$HELPER" ]; then
-    echo "Unable to find helper script at $HELPER"
+HELPER="${LINEAGE_ROOT}/vendor/lineage/build/tools/extract_utils.sh"
+if [ ! -f "${HELPER}" ]; then
+    echo "Unable to find helper script at ${HELPER}"
     exit 1
 fi
-. "$HELPER"
+source "${HELPER}"
 
 # Default to sanitizing the vendor folder before extraction
 CLEAN_VENDOR=true
+SECTION=
+KANG=
 
 while [ "$1" != "" ]; do
-    case $1 in
+    case "$1" in
         -n | --no-cleanup )     CLEAN_VENDOR=false
                                 ;;
+        -k | --kang)            KANG="--kang"
+                                ;;
         -s | --section )        shift
-                                SECTION=$1
+                                SECTION="$1"
                                 CLEAN_VENDOR=false
                                 ;;
-        * )                     SRC=$1
+        * )                     SRC="$1"
                                 ;;
     esac
     shift
 done
 
-if [ -z "$SRC" ]; then
+if [ -z "${SRC}" ]; then
     SRC=adb
 fi
 
-# Initialize the helper
-setup_vendor "$DEVICE" "$VENDOR" "$LINEAGE_ROOT" false "$CLEAN_VENDOR"
+function blob_fixup() {
+    case "${1}" in
+    vendor/lib/hw/camera.msm8953.so)
+        patchelf --add-needed camera.msm8953_shim.so "${2}"
+        ;;
+    esac
+}
 
-extract "$MY_DIR"/proprietary-files.txt "$SRC" "$SECTION"
+# Initialize the helper
+setup_vendor "${DEVICE}" "${VENDOR}" "${LINEAGE_ROOT}" false "${CLEAN_VENDOR}"
 
-# Load camera.msm8953.so shim
-CAM_MSM8953="$LINEAGE_ROOT"/vendor/"$VENDOR"/"$DEVICE"/proprietary/vendor/lib/hw/camera.msm8953.so
-patchelf --add-needed camera.msm8953_shim.so "$CAM_MSM8953"
+extract "${MY_DIR}/proprietary-files.txt" "${SRC}" ${KANG} --section "${SECTION}"
 
-"$MY_DIR"/setup-makefiles.sh
+"${MY_DIR}/setup-makefiles.sh"
diff --git a/setup-makefiles.sh b/setup-makefiles.sh
index 5affab7..1b7ac8a 100755
--- a/setup-makefiles.sh
+++ b/setup-makefiles.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # Copyright (C) 2016 The CyanogenMod Project
-# Copyright (C) 2017 The LineageOS Project
+# Copyright (C) 2017-2019 The LineageOS Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -42,8 +42,7 @@ setup_vendor "$DEVICE" "$VENDOR" "$LINEAGE_ROOT"
 # Copyright headers and guards
 write_headers
 
-# Device blobs
 write_makefiles "$MY_DIR"/proprietary-files.txt true
 
-# We are done!
+# Finish
 write_footers
-- 
GitLab