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 f5821cc..1cc73eb 100755
--- a/Android.mk
+++ b/Android.mk
@@ -177,6 +177,7 @@
     TW_USE_TOOLBOX := true
     TW_EXCLUDE_MTP := true
     TW_EXCLUDE_TZDATA := true
+    TW_EXCLUDE_NANO := true
 endif
 
 ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
@@ -529,6 +530,11 @@
 ifneq ($(TW_EXCLUDE_TZDATA), true)
     TWRP_REQUIRED_MODULES += tzdata_twrp
 endif
+ifneq ($(TW_EXCLUDE_NANO), true)
+    TWRP_REQUIRED_MODULES += \
+        nano_twrp \
+        init.recovery.nano.rc
+endif
 # Allow devices to specify device-specific recovery dependencies
 ifneq ($(TARGET_RECOVERY_DEVICE_MODULES),)
     TWRP_REQUIRED_MODULES += $(TARGET_RECOVERY_DEVICE_MODULES)
diff --git a/etc/Android.mk b/etc/Android.mk
index ece8bd6..ff9d8b1 100644
--- a/etc/Android.mk
+++ b/etc/Android.mk
@@ -14,6 +14,15 @@
 
 LOCAL_PATH := $(call my-dir)
 
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.recovery.nano.rc
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
+
+LOCAL_SRC_FILES := $(LOCAL_MODULE)
+include $(BUILD_PREBUILT)
+
 ifneq ($(TW_EXCLUDE_DEFAULT_USB_INIT), true)
 
 include $(CLEAR_VARS)
diff --git a/etc/init.rc b/etc/init.rc
index fc32bb8..a2bef2b 100644
--- a/etc/init.rc
+++ b/etc/init.rc
@@ -1,6 +1,7 @@
 import /init.recovery.logd.rc
 import /init.recovery.ldconfig.rc
 import /init.recovery.mksh.rc
+import /init.recovery.nano.rc
 import /init.recovery.usb.rc
 import /init.recovery.service.rc
 import /init.recovery.vold_decrypt.rc
diff --git a/etc/init.recovery.nano.rc b/etc/init.recovery.nano.rc
new file mode 100644
index 0000000..c835be4
--- /dev/null
+++ b/etc/init.recovery.nano.rc
@@ -0,0 +1,3 @@
+on fs
+    export TERMINFO /etc/terminfo
+    export TERM pcansi
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index 0cdf5c2..44bf7ed 100644
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -405,6 +405,12 @@
     RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/liblogwrap.so
     RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libext2_misc.so
 endif
+ifneq ($(TW_EXCLUDE_NANO), true)
+    RELINK_SOURCE_FILES += $(TARGET_OUT_OPTIONAL_EXECUTABLES)/nano
+    RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libncurses.so
+    RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libssh.so
+    RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libssl.so
+endif
 
 TW_BB_SYMLINKS :=
 ifneq ($(TW_USE_TOOLBOX), true)
@@ -622,3 +628,15 @@
     endif
     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)/sbin
+LOCAL_REQUIRED_MODULES := nano libncurses
+LOCAL_POST_INSTALL_CMD += \
+    cp -rf $(TARGET_OUT_ETC)/nano $(TARGET_RECOVERY_ROOT_OUT)/etc/; \
+    cp -rf external/libncurses/lib/terminfo $(TARGET_RECOVERY_ROOT_OUT)/etc/;
+include $(BUILD_PHONY_PACKAGE)
+