#!/bin/bash

TMOUT=0
read -s -p "please input root password:" root_pwd
echo -e "\n"

read -s -p "please input FI admin password:" admin_pwd
echo -e "\n"

root_pwd=$(perl -e 'print quotemeta shift(@ARGV)' "${root_pwd}")
admin_pwd=$(perl -e 'print quotemeta shift(@ARGV)' "${admin_pwd}")

expect <<END
        spawn sudo bash /opt/fiupdate/update_cluster_fi.sh
        set timeout 60
        expect {
            "*assword for root*" {send "$root_pwd\r"}
        }
        expect {
            "*assword*" {send "$root_pwd\r"}
        }
        expect {
            "*assword*" {send "$admin_pwd\r"}
        }
        set timeout -1
        expect eof

        catch wait ret
        set exit_status [lindex \$ret 3]
        exit \$exit_status
END