Include nano in TWRP by default

Use 'TW_EXCLUDE_NANO := true' to exclude from build

Will be excluded by default if 'TW_OEM_BUILD := true' is set

Change-Id: I812399ef9f3f5d3c7d4baf981924d49255c16e5a
diff --git a/Android.mk b/Android.mk
index 920b08a..699a601 100755
--- a/Android.mk
+++ b/Android.mk
@@ -138,6 +138,7 @@
     TW_USE_TOOLBOX := true
     TW_EXCLUDE_MTP := true
     TW_EXCLUDE_TZDATA := true
+    TW_EXCLUDE_NANO := true
 endif
 
 ifeq ($(AB_OTA_UPDATER),true)
@@ -413,6 +414,13 @@
     tzdata_twrp
 endif
 
+ifneq ($(TW_EXCLUDE_NANO), true)
+TWRP_REQUIRED_MODULES += \
+    nano_twrp \
+    nano.rc
+endif
+
+
 ifneq ($(TW_INCLUDE_CRYPTO),)
 TWRP_REQUIRED_MODULES += \
     hwservicemanager \
diff --git a/etc/Android.mk b/etc/Android.mk
index 58b45ad..e73bfed 100755
--- a/etc/Android.mk
+++ b/etc/Android.mk
@@ -58,6 +58,15 @@
 LOCAL_SRC_FILES := init.recovery.ldconfig.rc
 include $(BUILD_PREBUILT)
 
+include $(CLEAR_VARS)
+LOCAL_MODULE := nano.rc
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/etc/init
+
+LOCAL_SRC_FILES := init/$(LOCAL_MODULE)
+include $(BUILD_PREBUILT)
+
 ifeq ($(AB_OTA_UPDATER),true)
 	include $(CLEAR_VARS)
 	LOCAL_MODULE := android.hardware.boot@1.0-service.rc
diff --git a/etc/init/nano.rc b/etc/init/nano.rc
new file mode 100644
index 0000000..f57f656
--- /dev/null
+++ b/etc/init/nano.rc
@@ -0,0 +1,3 @@
+on fs
+    export TERMINFO /system/etc/terminfo
+    export TERM pcansi
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index 9885f3e..81acfac 100755
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -317,6 +317,13 @@
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/liblogwrap.so
 RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext2_misc.so
 
+ifneq ($(TW_EXCLUDE_NANO), true)
+    RECOVERY_BINARY_SOURCE_FILES += $(TARGET_OUT_OPTIONAL_EXECUTABLES)/nano
+    RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libncurses.so
+    RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libssh.so
+    RECOVERY_LIBRARY_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libssl.so
+endif
+
 include $(CLEAR_VARS)
 LOCAL_MODULE := relink_libraries
 LOCAL_MODULE_TAGS := optional
@@ -520,3 +527,15 @@
         cp -f $(TARGET_OUT)/usr/share/zoneinfo/tzdata $(TARGET_RECOVERY_ROOT_OUT)/system/usr/share/zoneinfo/;
     include $(BUILD_PHONY_PACKAGE)
 endif
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := nano_twrp
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/system/bin
+LOCAL_REQUIRED_MODULES := nano libncurses
+LOCAL_POST_INSTALL_CMD += \
+    cp -rf $(TARGET_OUT_ETC)/nano $(TARGET_RECOVERY_ROOT_OUT)/system/etc/; \
+    cp -rf external/libncurses/lib/terminfo $(TARGET_RECOVERY_ROOT_OUT)/system/etc/;
+include $(BUILD_PHONY_PACKAGE)
+