bash: add to TWRP

Change-Id: Ie1826df01ad5fe2480e96d56b2c4fd1c91449cc2
diff --git a/Android.mk b/Android.mk
index 2292a83..a721885 100755
--- a/Android.mk
+++ b/Android.mk
@@ -178,6 +178,7 @@
     TW_EXCLUDE_MTP := true
     TW_EXCLUDE_TZDATA := true
     TW_EXCLUDE_NANO := true
+    TW_EXCLUDE_BASH := true
 endif
 
 ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
@@ -538,6 +539,12 @@
         nano_twrp \
         init.recovery.nano.rc
 endif
+ifneq ($(TW_EXCLUDE_BASH), true)
+    ifneq ($(wildcard external/bash/.),)
+        TWRP_REQUIRED_MODULES += \
+            bash_twrp
+    endif
+endif
 # Allow devices to specify device-specific recovery dependencies
 ifneq ($(TARGET_RECOVERY_DEVICE_MODULES),)
     TWRP_REQUIRED_MODULES += $(TARGET_RECOVERY_DEVICE_MODULES)
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index a28cde0..5b1d873 100644
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -411,6 +411,9 @@
     RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libssh.so
     RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libssl.so
 endif
+ifneq ($(TW_EXCLUDE_BASH), true)
+    RELINK_SOURCE_FILES += $(TARGET_OUT_OPTIONAL_EXECUTABLES)/bash
+endif
 
 TW_BB_SYMLINKS :=
 ifneq ($(TW_USE_TOOLBOX), true)
@@ -648,3 +651,30 @@
 endif
 include $(BUILD_PHONY_PACKAGE)
 
+ifneq ($(TW_EXCLUDE_BASH), true)
+	include $(CLEAR_VARS)
+	LOCAL_MODULE := bash_twrp
+	LOCAL_MODULE_TAGS := optional
+	LOCAL_MODULE_CLASS := ETC
+	LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin
+	LOCAL_REQUIRED_MODULES := bash
+
+    ifeq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
+        LOCAL_POST_INSTALL_CMD += \
+            mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/system_root/system/etc/bash; \
+            cp -rf external/bash/etc/* $(TARGET_RECOVERY_ROOT_OUT)/system_root/system/etc/bash/; \
+            sed -i 's/ro.cm.device/ro.product.device/' $(TARGET_RECOVERY_ROOT_OUT)/system_root/system/etc/bash/bashrc; \
+            sed -i 's/ro.lineage.device/ro.product.device/' $(TARGET_RECOVERY_ROOT_OUT)/system_root/system/etc/bash/bashrc; \
+            sed -i 's/ro.omni.device/ro.product.device/' $(TARGET_RECOVERY_ROOT_OUT)/system_root/system/etc/bash/bashrc; \
+            sed -i '/export TERM/d' $(TARGET_RECOVERY_ROOT_OUT)/system_root/system/etc/bash/bashrc;
+    else
+        LOCAL_POST_INSTALL_CMD += \
+            mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/system/etc/bash; \
+            cp -rf external/bash/etc/* $(TARGET_RECOVERY_ROOT_OUT)/system/etc/bash/; \
+            sed -i 's/ro.cm.device/ro.product.device/' $(TARGET_RECOVERY_ROOT_OUT)/system/etc/bash/bashrc; \
+            sed -i 's/ro.lineage.device/ro.product.device/' $(TARGET_RECOVERY_ROOT_OUT)/system/etc/bash/bashrc; \
+            sed -i 's/ro.omni.device/ro.product.device/' $(TARGET_RECOVERY_ROOT_OUT)/system/etc/bash/bashrc; \
+            sed -i '/export TERM/d' $(TARGET_RECOVERY_ROOT_OUT)/system/etc/bash/bashrc;
+    endif
+	include $(BUILD_PHONY_PACKAGE)
+endif