From 8b5f01a22c2da374f550afa4b53b5d938a15a64c Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 22 Dec 2021 20:02:11 +0100 Subject: [PATCH] Fix(adduser): better changing of shell --- plugins/adduser/adduser.plugin.zsh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/adduser/adduser.plugin.zsh b/plugins/adduser/adduser.plugin.zsh index 35a8af16f..f6b2f35b7 100644 --- a/plugins/adduser/adduser.plugin.zsh +++ b/plugins/adduser/adduser.plugin.zsh @@ -18,19 +18,28 @@ adduser() { #copy install.sh to a new file in temp that we can give the right owner to execute #and also make sure that after the install script we are no longer the new user temp_installscript=$(mktemp) - cat $path_installscript | \ - sed 's/read -r opt/opt=y; echo "\n--- This time I am answering \\"yes\\" for you, but you will still have to type in the password of that user ---"/' \ - > $temp_installscript + cp $path_installscript $temp_installscript chown ${@[$#]} $temp_installscript && chmod +x $temp_installscript #try installing with sudo or su when not available if [[ -x "$commands[sudo]" ]] ; then - sudo -u ${@[$#]} RUNZSH=no $temp_installscript + sudo -u ${@[$#]} sh -c "$temp_installscript --unattended" + returncode=$? + if [[ -x "$commands[chsh]" ]] ; then + sudo chsh -s $commands[zsh] ${@[$#]} + else + echo "'chsh' is not available, change the shell manually." > /dev/stderr + fi returncode=$? else if [[ -x "$commands[su]" ]] ; then su -l ${@[$#]} -c "$temp_installscript --unattended" returncode=$? + if [[ -x "$commands[chsh]" ]] ; then + su -c "chsh -s $commands[zsh] ${@[$#]}" + else + echo "'chsh' is not available, change the shell manually." > /dev/stderr + fi else echo "You can't become ${@[$#]} (no 'sudo' or 'su' available)" > /dev/stderr; returncode=1