Skip to content

Instantly share code, notes, and snippets.

@nobiit
Created November 15, 2024 04:47
Show Gist options
  • Select an option

  • Save nobiit/2dee5605e130c81008ac1d6918e9c8ad to your computer and use it in GitHub Desktop.

Select an option

Save nobiit/2dee5605e130c81008ac1d6918e9c8ad to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
data="$(cat values.yaml | yq -r 'tojson')"
origin_state="$(echo "${data}" | jq -r '.partner | { stage1: (.lotteryConfigStage1 | fromjson), stage2: (.lotteryConfigStage2 | fromjson) }')"
state="${origin_state}"
changes=0
while true; do
printf 'Nhap stage muon thay doi (Go n de exit): '
read answer_stage
if [ "${answer_stage}" == n ] || [ "${done}" == 1 ]; then
if [ ${changes} -gt 0 ]; then
a_tmp=$(mktemp)
b_tmp=$(mktemp)
echo "${origin_state}" | tee ${a_tmp} >>/dev/null
echo "${state}" | tee ${b_tmp} >>/dev/null
diff --color -U 1000000 ${a_tmp} ${b_tmp} || true
rm ${a_tmp} ${b_tmp}
printf "Xac nhan thay doi (y/n): "
read confirm
if [ "${confirm}" == y ]; then
for i in $(seq 1 2); do
yq -i "$(printf ".partner.lotteryConfigStage${i} = (\"%s\" | @base64d)" "$(echo "${state}" | jq -r ".stage${i} | tojson | @base64")")" values.yaml
done
fi
exit 0
else
echo "Khong co thay doi nao !"
fi
exit
fi
if [ $(echo "${state}" | jq -r "to_entries | map(select(.key == \"stage${answer_stage}\")) | length") == 0 ]; then
echo "Stage khong hop le !"
else
printf '\033[0;31m=== Stage %s ===\033[0m\n' "${answer_stage}"
current_state="$(echo "${state}" | jq -r ".stage${answer_stage}")"
for item in $(echo "${current_state}" | jq -r 'to_entries[].key'); do
printf '%s: \033[0;32m%s\033[0m\n' "${item}" "$(echo "${current_state}" | jq -r ".${item}")"
while true; do
printf 'Nhap gia tri moi (Go n de bo qua): '
read answer
if [ "${answer}" == n ]; then
break
elif ! [ -z "${answer}" ]; then
current_state="$(echo "${current_state}" | jq -r "$(printf '.%s = "%s"' "${item}" "${answer}")")"
break
fi
done
done
state="$(echo "${state}" | jq -r "$(printf ".stage${answer_stage} = %s" "${current_state}")")"
((changes++)) || true
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment