diff --git a/Makefile.am b/Makefile.am
index 2944318..28b4b44 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,14 +16,7 @@
# along with termux-tools. If not, see
# .
-SUBDIRS = scripts doc mirrors
-
-# We have two variants of our motd message:
-# 1. motd.sh: is sourced and echo'es a motd message with something that looks
-# like termux's logo.
-# 3. motd-playstore: plain text that will only be displayed if the termux-app
-# version is very old (like the version found in playstore is)
-sysconf_DATA = motd.sh motd-playstore
+SUBDIRS = scripts doc mirrors motds
do_subst = sed -e "s%[@]TERMUX_PREFIX[@]%$(termux_prefix)%g" \
-e "s%[@]TERMUX_APP_PACKAGE[@]%${termux_app_package}%g" \
@@ -41,7 +34,7 @@ $1: $1.in Makefile
endef
# Login script
-sysconf_DATA += termux-login.sh
+sysconf_DATA = termux-login.sh
# profile.d script
pkgdata_PROFILE = init-termux-properties.sh
diff --git a/configure.ac b/configure.ac
index bc8f0ed..f16f99b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,6 @@ AC_SUBST(termux_package_manager)
AC_PROG_LN_S
AC_CONFIG_FILES([Makefile scripts/Makefile doc/Makefile
-mirrors/Makefile])
+mirrors/Makefile motds/Makefile])
AC_OUTPUT
diff --git a/motd.sh b/motd.sh
deleted file mode 100644
index dfe0ad2..0000000
--- a/motd.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-echo ""
-echo -e " \e[47m \e[0m \e[1mWelcome to Termux!\e[0m"
-echo -e " \e[47m \e[0m \e[0;37m\e[47m .\e[0m"
-echo -e " \e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mDocs:\e[0m \e[4mtermux.dev/docs\e[0m"
-echo -e " \e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mGitter:\e[0m \e[4mgitter.im/termux/termux\e[0m"
-echo -e " \e[47m \e[0m \e[47m \e[0m \e[1mCommunity:\e[0m \e[4mtermux.dev/community\e[0m"
-echo -e " \e[47m \e[0m \e[0;37m\e[47m .\e[0m"
-echo -e " \e[47m \e[0m \e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown}"
-echo ""
-echo -e " \e[1mWorking with packages:\e[0m"
-echo -e " \e[1mSearch:\e[0m pkg search "
-echo -e " \e[1mInstall:\e[0m pkg install "
-echo -e " \e[1mUpdate:\e[0m pkg update"
-echo ""
-if [ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" ]; then
-echo -e " \e[1mSubscribing to additional repos:\e[0m"
-echo -e " \e[1mRoot:\e[0m pkg install root-repo"
-echo -e " \e[1mX11: \e[0m pkg install x11-repo"
-echo ""
-echo " For fixing any repository issues,"
-echo " try 'termux-change-repo' command."
-echo ""
-fi
-echo -e " Report issues at \e[4mtermux.dev/issues\e[0m"
-echo ""
diff --git a/motds/Makefile.am b/motds/Makefile.am
new file mode 100644
index 0000000..5e34b42
--- /dev/null
+++ b/motds/Makefile.am
@@ -0,0 +1,71 @@
+# Copyright (C) 2022 Termux
+
+# This file is part of termux-tools.
+
+# termux-tools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# termux-tools is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with termux-tools. If not, see
+# .
+
+
+# We have two variants of our motd message loaded by login script:
+# 1. motd.sh: A dynamic motd that is executed with bash and echos a
+# motd message with escape sequences, optionally with a terminal logo.
+# 2. motd: A static motd that is just read as is with cat and displayed.
+
+# The motd-playstore is an additional motd that will only be displayed
+# if the termux-app version is very old (like the version found on playstore)
+sysconf_DATA = motd.sh motd motd-playstore
+
+CLEANFILES = motd.sh motd
+
+
+do_subst = sed -e "s%[@]TERMUX_PREFIX[@]%$(termux_prefix)%g"
+
+define process-rule
+$1: $1.in Makefile
+ @echo "Creating $1"
+ @$$(do_subst) < $(srcdir)/$1.in > $1
+endef
+
+$(eval $(call process-rule,motd.sh))
+
+
+motd:
+ @echo "Creating motd file"
+
+ @echo "Welcome to Termux!" > motd
+ @echo "" >> motd
+ @echo "Docs: https://termux.dev/docs" >> motd
+ @echo "Donate: https://termux.dev/donate" >> motd
+ @echo "Community: https://termux.dev/community" >> motd
+
+ @echo "" >> motd
+ @echo "Working with packages:" >> motd
+ @echo "" >> motd
+ @echo " - Search: pkg search " >> motd
+ @echo " - Install: pkg install " >> motd
+ @echo " - Upgrade: pkg upgrade" >> motd
+
+ ifeq ($(TERMUX_PACKAGE_MANAGER),apt)
+ @echo "" >> motd
+ @echo "Subscribing to additional repositories:" >> motd
+ @echo "" >> motd
+ @echo " - Root: pkg install root-repo" >> motd
+ @echo " - X11: pkg install x11-repo" >> motd
+ @echo "" >> motd
+ @echo "For fixing any repository issues," >> motd
+ @echo "try 'termux-change-repo' command." >> motd
+ endif
+
+ @echo "" >> motd
+ @echo "Report issues at https://termux.dev/issues" >> motd
diff --git a/motd-playstore b/motds/motd-playstore
similarity index 100%
rename from motd-playstore
rename to motds/motd-playstore
diff --git a/motds/motd.sh.in b/motds/motd.sh.in
new file mode 100644
index 0000000..1a76844
--- /dev/null
+++ b/motds/motd.sh.in
@@ -0,0 +1,61 @@
+#!@TERMUX_PREFIX@/bin/bash
+
+# Setup TERMUX_APP_PACKAGE_MANAGER
+source "@TERMUX_PREFIX@/bin/termux-setup-package-manager" || exit 1
+
+terminal_width="$(stty size | cut -d" " -f2)"
+if [[ "$terminal_width" =~ ^[0-9]+$ ]] && [ "$terminal_width" -gt 60 ]; then
+
+ motd="
+ \e[47m \e[0m \e[1mWelcome to Termux!\e[0m
+ \e[47m \e[0m \e[0;37m\e[47m .\e[0m
+ \e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mDocs:\e[0m \e[4mhttps://termux.dev/docs\e[0m
+ \e[47m \e[0m \e[47m \e[0m \e[47m \e[0m \e[1mDonate:\e[0m \e[4mhttps://termux.dev/donate\e[0m
+ \e[47m \e[0m \e[47m \e[0m \e[1mCommunity:\e[0m \e[4mhttps://termux.dev/community\e[0m
+ \e[47m \e[0m \e[0;37m\e[47m .\e[0m
+ \e[47m \e[0m \e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown}
+"
+
+ motd_indent=" "
+
+else
+
+ motd="
+\e[1mWelcome to Termux!\e[0m
+
+\e[1mDocs:\e[0m \e[4mhttps://termux.dev/docs\e[0m
+\e[1mDonate:\e[0m \e[4mhttps://termux.dev/donate\e[0m
+\e[1mCommunity:\e[0m \e[4mhttps://termux.dev/community\e[0m
+
+\e[1mTermux version:\e[0m ${TERMUX_VERSION-Unknown}
+"
+
+ motd_indent=""
+fi
+
+motd+="
+${motd_indent}\e[1mWorking with packages:\e[0m
+${motd_indent}\e[1mSearch:\e[0m pkg search
+${motd_indent}\e[1mInstall:\e[0m pkg install
+${motd_indent}\e[1mUpgrade:\e[0m pkg upgrade
+"
+
+
+if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
+
+ motd+="
+${motd_indent}\e[1mSubscribing to additional repos:\e[0m
+${motd_indent}\e[1mRoot:\e[0m pkg install root-repo
+${motd_indent}\e[1mX11:\e[0m pkg install x11-repo
+
+${motd_indent}For fixing any repository issues,
+${motd_indent}try 'termux-change-repo' command.
+"
+
+fi
+
+motd+="
+${motd_indent}Report issues at \e[4mhttps://termux.dev/issues\e[0m
+"
+
+echo -e "$motd"
diff --git a/scripts/login.in b/scripts/login.in
index fee5239..393322e 100644
--- a/scripts/login.in
+++ b/scripts/login.in
@@ -1,9 +1,11 @@
#!/bin/sh
if tty >/dev/null 2>&1 && [ $# = 0 ] && [ ! -f ~/.hushlogin ] && [ -z "$TERMUX_HUSHLOGIN" ]; then
- if [ -f @TERMUX_PREFIX@/etc/motd.sh ]; then
- # Dynamic motd is preferred over plain-text.
- bash @TERMUX_PREFIX@/etc/motd.sh
+ # Use user defined dynamic motd file if it exists
+ if [ -f ~/.termux/motd.sh ]; then
+ [ ! -x ~/.termux/motd.sh ] && chmod u+x ~/.termux/motd.sh
+ ~/.termux/motd.sh
+ # Default to termux-tools package provided static motd file if it exists
elif [ -f @TERMUX_PREFIX@/etc/motd ]; then
cat @TERMUX_PREFIX@/etc/motd
fi