2021-12-21 18:40:46 +00:00
|
|
|
# Copyright (c) 2021 Nikolas Garofil
|
|
|
|
|
|
|
|
adduser() {
|
|
|
|
local returncode
|
|
|
|
local result_string="Installation of 'Oh My Zsh' "
|
|
|
|
local temp_installscript
|
|
|
|
local path_installscript="$ZSH/tools/install.sh"
|
|
|
|
|
|
|
|
|
|
|
|
#Create user, errors will be reported by the 'real' adduser
|
|
|
|
#Use which/tail combination to call the binary instead of this function
|
2021-12-22 18:15:09 +00:00
|
|
|
command adduser $@ || return 1
|
2021-12-21 18:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
echo "\nUser '${@[$#]}' has been created. I will now try to install 'Oh My Zsh'"
|
|
|
|
if [[ -f $path_installscript ]] ; then
|
|
|
|
|
|
|
|
#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
|
|
|
|
chown ${@[$#]} $temp_installscript && chmod +x $temp_installscript
|
|
|
|
|
|
|
|
#try installing with sudo or su when not available
|
2021-12-22 18:16:50 +00:00
|
|
|
if [[ -x "$commands[sudo]" ]] ; then
|
2021-12-22 18:18:04 +00:00
|
|
|
sudo -u ${@[$#]} RUNZSH=no $temp_installscript
|
2021-12-21 18:40:46 +00:00
|
|
|
returncode=$?
|
|
|
|
else
|
2021-12-22 18:16:50 +00:00
|
|
|
if [[ -x "$commands[su]" ]] ; then
|
2021-12-22 18:18:04 +00:00
|
|
|
su -l ${@[$#]} -c "$temp_installscript --unattended"
|
2021-12-21 18:40:46 +00:00
|
|
|
returncode=$?
|
|
|
|
else
|
|
|
|
echo "You can't become ${@[$#]} (no 'sudo' or 'su' available)" > /dev/stderr;
|
|
|
|
returncode=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
#cleanup
|
|
|
|
rm $temp_installscript
|
|
|
|
else
|
2021-12-22 18:15:49 +00:00
|
|
|
echo "Installationscript '$path_installscript' not available" > /dev/stderr;
|
2021-12-21 18:40:46 +00:00
|
|
|
returncode=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#mention the result
|
|
|
|
if [[ $returncode -eq 0 ]]; then
|
|
|
|
echo "$result_string succeeded."
|
|
|
|
else
|
2021-12-22 18:15:49 +00:00
|
|
|
echo "$result_string failed." > /dev/stderr
|
2021-12-21 18:40:46 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
return $returncode
|
|
|
|
}
|