Skip to content

Instantly share code, notes, and snippets.

@majal
Last active September 22, 2020 23:09
Show Gist options
  • Save majal/61fef77abea8923e08b2d94297347f74 to your computer and use it in GitHub Desktop.
Save majal/61fef77abea8923e08b2d94297347f74 to your computer and use it in GitHub Desktop.
Bash script for certikd upgrade
#!/bin/bash
# https://www.majlovesreg.one/tag/code/
height=224300
cdir='/home/majlovesreg/certik' # change to match your user directory
newv="${cdir}/v0.13.4-shentu-rts-broken" # the binaries should have been downloaded in advance to this directory
confdir='/home/majlovesreg/.certikd/config' # change to match your user directory
clidir='/home/majlovesreg/.certikcli/config' # change to match your user directory
oldchain='shentu-rts'
newchain='shentu-rts-2'
[ "${height}" ] || { echo "Please set block height! Exiting..."; exit 1; }
[ -d ${cdir} ] || { echo "${cdir} not found! Exiting..."; exit 2; }
[ -x ${cdir}/certikd ] || { echo "${cdir}/certikd not found executable! Exiting..."; exit 3; }
[ -x ${cdir}/certikcli ] || { echo "${cdir}/certikcli not found executable! Exiting..."; exit 4; }
[ -d ${newv} ] || { echo "${newv} not found! Exiting..."; exit 5; }
[ -x ${newv}/certikd ] || { echo "${newv}/certikd not found executable! Exiting..."; exit 6; }
[ -x ${newv}/certikcli ] || { echo "${newv}/certikcli not found executable! Exiting..."; exit 7; }
[ -d ${confdir} ] || { echo "${confdir} not found! Exiting..."; exit 8; }
[ -f ${confdir}/genesis.json ] || { echo "${confdir}/genesis.json not found! Exiting..."; exit 9; }
[ -d ${clidir} ] || { echo "${clidir} not found! Exiting..."; exit 10; }
[ -f ${clidir}/config.toml ] || { echo "${clidir}/config.toml not found! Exiting..."; exit 11; }
export PATH="${cdir}:$PATH"
while true; do
# echo $(certikcli status | jq -r '.sync_info.latest_block_height')
(( $(certikcli status | jq -r '.sync_info.latest_block_height') >= ${height} )) && break
sleep 1
done
time=$(certikcli query block ${height} | jq -r '.block["header"]["time"]')
gentime=$(TZ=UTC date -d "${time} +60 min" +"%Y-%m-%dT%H:%M:%SZ")
[ -f genesis.json.transition ] && rm genesis.json.transition
certikd export --for-zero-height --height ${height} > genesis.json.transition
sudo systemctl stop certikd
killall certikd
cd ${cdir}
mv certikd certikd.old
mv certikcli certikcli.old
cd ${newv}
cp certikd ${cdir}/
cp certikcli ${cdir}/
cd ${confdir}
mv genesis.json genesis.json.old
certikd migrate genesis.json.transition --chain-id=${newchain} --genesis-time="${gentime}" > genesis.json
certikd unsafe-reset-all
sudo systemctl start certikd
# Use if you have set configurations in your certikcli config
# cd ${clidir}
# cp config.toml config.toml.bk
# sed -i "s/${oldchain}/${newchain}/" config.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment