bash: add to TWRP

Change-Id: Ie1826df01ad5fe2480e96d56b2c4fd1c91449cc2
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