Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hush motd on login when using -c command #58

Closed
MolotovCherry opened this issue Mar 10, 2018 · 3 comments
Closed

Hush motd on login when using -c command #58

MolotovCherry opened this issue Mar 10, 2018 · 3 comments

Comments

@MolotovCherry
Copy link

MolotovCherry commented Mar 10, 2018

It would be best to ignore the displaying of motd when (and only when) using the -c command.

I believe this can be best accomplished by modifying the .bashrc . /etc/motd to the following. This disables motd if we have a .hushlogin (this one is for the user to make if they want to permanently disable it) or .chushlogin file. The .chushlogin is only temporarily used to hush the motd when we run commands from startarch (it's removed after)

if [ ! -e ~/.hushlogin ] && [ ! -e ~/.chushlogin ]; then
    . /etc/motd
fi
if [ -e ~/.chushlogin ]; then
    rm ~/.chushlogin
fi

And in the startarch script, when using -c, simply create the temporary file first

touch $HOME/arch/root/.chushlogin
exec proot ...

This is the best solution I found to this question. Hopefully it's elegant enough haha

@SDRausty
Copy link
Owner

@cherryleafroad the feature you requested is implemented. Test and see if it is to your liking. Thanks for sharing and improving this project. Do not hesitate if you still see room for improvement 🥁 🔊

@MolotovCherry
Copy link
Author

MolotovCherry commented Mar 15, 2018

Works perfect, just one thing.

Regarding this code in startarch (also including the relevant part under user login too)

if [[ $1 = [Cc]* ]] || [[ $1 = -[Cc]* ]] || [[ $1 = --[Cc]* ]];then
touch /data/data/com.termux/files/home/arch/root/.chushlogin
exec proot --kill-on-exit --link2symlink -0 -r /data/data/com.termux/files/home/arch -b /dev/ -b $ANDROID_DATA -b $EXTERNAL_STORAGE -b /proc/ -w "$PWD" /bin/env -i HOME=/root TERM=$TERM /bin/bash -lc "${@:2}"
rm /data/data/com.termux/files/home/arch/root/.chushlogin

The rm command shouldn't be there after the exec proot. Because exec replaces the current shell process, no commands will be run after it, so the rm commands will never get run (and will give us false security in the future too).
rm /data/data/com.termux/files/home/arch/root/.chushlogin

That's why we had to implement the removal of .chushlogin inside .bashrc

[20:59 ~ ]$ cat .bashrc
if [ ! -e $HOME/.hushlogin ] && [ ! -e $HOME/.chushlogin ];then
. /etc/motd
fi
if [ -e $HOME/.chushlogin ];then
rm $HOME/.chushlogin
fi

In short, your startarch should look like this


...
# [command args] Execute a command in BASH as root.
if [[ $1 = [Cc]* ]] || [[ $1 = -[Cc]* ]] || [[ $1 = --[Cc]* ]];then
touch /data/data/com.termux/files/home/arch/root/.chushlogin
exec proot --kill-on-exit --link2symlink -0 -r /data/data/com.termux/files/home/arch -b /dev/ -b $ANDROID_DATA -b $EXTERNAL_STORAGE -b /proc/ -w "$PWD" /bin/env -i HOME=/root TERM=$TERM /bin/bash -lc "${@:2}"
# [login user command] Login as user and execute command.  Use `addauser user` first to create this user and the user home directory.
elif [[ $1 = [Ll]* ]] || [[ $1 = -[Ll]* ]] || [[ $1 = --[Ll]* ]] ;then
touch /data/data/com.termux/files/home/arch/home/$2/.chushlogin
exec proot --kill-on-exit --link2symlink -0 -r /data/data/com.termux/files/home/arch -b /dev/ -b $ANDROID_DATA -b $EXTERNAL_STORAGE -b /proc/ -w "$PWD" /bin/env -i HOME=/root TERM=$TERM /bin/su - $2 -c "${@:3}"
...

@MolotovCherry
Copy link
Author

MolotovCherry commented Mar 15, 2018

And one more important note, in the user login section, you left it touching the root users home directory instead of the user the person is trying to login to, which means that . /etc/motd will still get run. You'll need to touch it inside the users home directory instead

elif [[ $1 = [Ll]* ]] || [[ $1 = -[Ll]* ]] || [[ $1 = --[Ll]* ]] ;then
touch /data/data/com.termux/files/home/arch/home/$2/.chushlogin
exec proot ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants