#!/bin/sh
# 

# new header not using prereqs
if [ "$1" = "prereqs" ]; then
  echo ""
  exit 0
fi


quiet=n

. /scripts/functions
# if break=download_secret STOP here
maybe_break download_secret

. /conf/tcos.conf
. /conf/tcos-run-functions



log_begin_msg "Download Tcos secret"
  download_file /tcos/netconfig/etc/tcospasswd /mnt/tmp/tcospasswd

  if [ "$(if_is_zero /mnt/tmp/tcospasswd)" = "0" ]; then
     echo -e "Error downloading Tcos secret"
     rm -f /mnt/tmp/tcospasswd 2>/dev/null
     log_end_msg 1
  else
     new_passwd=$(cat /mnt/tmp/tcospasswd | awk -F":" '{print $2}')
     sed -i -e "/^root:/s/:[^:]*:/:$new_passwd:/" /etc/shadow
     mv /mnt/tmp/tcospasswd /etc/tcospasswd
     log_end_msg 0
  fi

update_progress 2


exit 0
