Automate Elasticsearch-reset-password in bash script

I am automating the installation and configuration of elasticsearch and kibana. Following the post from 2018 - How to set passwords for built-in users in batch mode? - I should be able to automate elasticsearch-reset-password by running the following commands:

cd /usr/share/elasticsearch/bin
 printf "elk-demo" | elasticsearch-keystore add -x
sudo curl -uelastic -XPUT -H 'Content-Type: application/json' 'http://localhost:9200/_xpack/security/user/kibana/_password' -d '{ "password":new-kibana-password" }'

but when I did this, I got the message:
elasticsearch-keystore: command not found

I also tried:
sudo printf "elk-demo" | bin/elasticsearch-reset-password -i -b
but I got the error:

Enter password for [elastic]: Re-enter password for [elastic]: 
ERROR: unable to read from standard input; is standard input open and a tty attached?

What i am trying to achieve is reset the password through a script without any user interaction or request to type in password or re-enter password. There are no helpful elasticsearch logs. Just long list of warnings saying:

received plaintext http traffic on an https channel, closing connection Netty4HttpChannel{localAddress=