#!/bin/sh

echo "Please make sure that you want to remove all the files in /home/tiup-repo and init a new one."
read -r -p "Please type in 'I solemnly swear that I am up to no good.': " response
if [[ $response == "I solemnly swear that I am up to no good." ]]; then
	echo "start resetting"
else
	echo "do nothing"
	exit 1
fi

REPO=tiup-repo

cd /home/
echo "##### remove repo /home/${REPO} started #####"
rm -rf ${REPO}
echo "##### remove repo /home/${REPO} finished #####"
echo

echo "##### init repo /home/${REPO} started #####"
tiup mirror init ${REPO}
echo "##### init repo /home/${REPO} finished #####"
echo

echo "##### set mirror to repo /home/${REPO} started #####"
tiup mirror set ${REPO}
echo "##### set mirror to repo /home/${REPO} finished #####"
echo

echo "##### remove old private.json started #####"
rm -f /root/.tiup/keys/private.json
echo "##### remove old private.json finished #####"
echo

echo "##### set owner started #####"
cd /home/tiup-opts
sh set_owner.sh
echo "##### set owner finished #####"
echo

cd

echo "##### The em repo /home/${REPO} has been successfully reset, now you can use update_em_repo.sh to push and update the repo #####"
