From d17067d48ebc634d758dce1f2ae2fdf4ea2f44a1 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 13 Aug 2022 07:09:53 +0500 Subject: [PATCH 1/3] motds: move motds to separate directory --- Makefile.am | 11 ++------ configure.ac | 2 +- motds/Makefile.am | 38 ++++++++++++++++++++++++++ motd-playstore => motds/motd-playstore | 0 motd.sh => motds/motd.sh.in | 0 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 motds/Makefile.am rename motd-playstore => motds/motd-playstore (100%) rename motd.sh => motds/motd.sh.in (100%) 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/motds/Makefile.am b/motds/Makefile.am new file mode 100644 index 0000000..a27746f --- /dev/null +++ b/motds/Makefile.am @@ -0,0 +1,38 @@ +# 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-playstore + +CLEANFILES = motd.sh + + +define process-rule +$1: $1.in Makefile + @echo "Creating $1" + @cat $(srcdir)/$1.in > $1 +endef + +$(eval $(call process-rule,motd.sh)) diff --git a/motd-playstore b/motds/motd-playstore similarity index 100% rename from motd-playstore rename to motds/motd-playstore diff --git a/motd.sh b/motds/motd.sh.in similarity index 100% rename from motd.sh rename to motds/motd.sh.in From 5956876a989f1e198c6dcf4f724ed24637e8328f Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 13 Aug 2022 07:18:08 +0500 Subject: [PATCH 2/3] motds: fix and update dynamic motd.sh - The logo added in new dynamic motd would break due to word wrap if terminal columns were less than max line length. This fixes the issue by not drawing a logo if terminal columns are too few at draw time. Note that logo will still break if terminal size is changed after drawing. - Use TERMUX_APP_PACKAGE_MANAGER instead of TERMUX_MAIN_PACKAGE_FORMAT - Add donate link instead of gitter which should already exist in community link, including matrix rooms link. Related pull requests termux/termux-packages#11250 and termux/termux-packages#11294 --- motds/Makefile.am | 4 ++- motds/motd.sh.in | 84 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/motds/Makefile.am b/motds/Makefile.am index a27746f..a82feb4 100644 --- a/motds/Makefile.am +++ b/motds/Makefile.am @@ -29,10 +29,12 @@ sysconf_DATA = motd.sh motd-playstore CLEANFILES = motd.sh +do_subst = sed -e "s%[@]TERMUX_PREFIX[@]%$(termux_prefix)%g" + define process-rule $1: $1.in Makefile @echo "Creating $1" - @cat $(srcdir)/$1.in > $1 + @$$(do_subst) < $(srcdir)/$1.in > $1 endef $(eval $(call process-rule,motd.sh)) diff --git a/motds/motd.sh.in b/motds/motd.sh.in index dfe0ad2..1a76844 100644 --- a/motds/motd.sh.in +++ b/motds/motd.sh.in @@ -1,25 +1,61 @@ -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 "" +#!@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 -echo -e " Report issues at \e[4mtermux.dev/issues\e[0m" -echo "" + +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" From 6a0f5cc138c2c87fef91807fe0244e3531821d4c Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 13 Aug 2022 07:23:06 +0500 Subject: [PATCH 3/3] motds: add static motd back and use it as default instead of dynamic motd and add support for custom motd The dynamic motd has issues with logo word wrap as discussed in 5956876a and so can't be used as default. Users who want to use it or a custom one can create a motd file/symlink at `~/.termux/motd.sh` to load a custom motd. To use the dynamic motd provided by termux-tools package, run `ln -sf $PREFIX/etc/motd.sh ~/.termux/motd.sh` Also directly execute motd.sd and rely on interpreter instead of executing with bash in case its not available or user does not want a bash script as motd.sh --- motds/Makefile.am | 35 +++++++++++++++++++++++++++++++++-- scripts/login.in | 8 +++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/motds/Makefile.am b/motds/Makefile.am index a82feb4..5e34b42 100644 --- a/motds/Makefile.am +++ b/motds/Makefile.am @@ -24,9 +24,9 @@ # 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-playstore +sysconf_DATA = motd.sh motd motd-playstore -CLEANFILES = motd.sh +CLEANFILES = motd.sh motd do_subst = sed -e "s%[@]TERMUX_PREFIX[@]%$(termux_prefix)%g" @@ -38,3 +38,34 @@ $1: $1.in Makefile 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/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