-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalmanac
executable file
·108 lines (90 loc) · 3.72 KB
/
almanac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
while getopts "d:" OPTION; do
case $OPTION in
d)
DIFFTOOL=${OPTARG}
;;
*)
echo "Unknow comandline switch: $OPTION"
exit 1
esac
done
if ! command -v yq &> /dev/null; then
echo "Could not find 'yq'."
echo "Please visit https://github.com/mikefarah/yq/#install"
exit 1
fi
CH_CFG_PATH=~/.chia/mainnet/config/config.yaml
if [[ ! -f $CH_CFG_PATH ]]; then
echo "Could not find $CH_CFG_PATH"
exit 1
fi
if [[ "$(git rev-parse --show-toplevel 2>/dev/null)" != $(pwd -P) ]]; then
echo "Not in chia-blockchain project root."
exit 1
fi
python -m pip freeze | grep 'pyaml' > /dev/null 2>&1
RESULT=$?
if [[ $RESULT -eq 1 ]]; then
echo "This requires the python module 'pyaml'."
echo "Install this with 'pip install pyaml' and try again."
exit 1
fi
GIT_REMOTE=$(git remote -v 2>/dev/null | head -n1 | awk '{print $2}')
REPO=$(echo "${GIT_REMOTE}" | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//')
if [[ $REPO != chia-blockchain ]]; then
echo "You must run this command from the chia-blockchain project root."
exit 1
fi
TMPCUR=$(mktemp /tmp/curconfXXXXXXXXXX)
TMPNEW=$(mktemp /tmp/newconfXXXXXXXXXX)
TMPNOPOOL=$(mktemp /tmp/nopoolXXXXXXXXXX)
CH_CFG_INIT=$PWD/chia/util/initial-config.yaml
CUR_TS=$(date "+%d%b%Y_%H-%M-%S")
CH_CFG_BAK=$CH_CFG_PATH-$CUR_TS
TOOL=${DIFFTOOL:-vimdiff}
yq --front-matter=process '.pool.pool_list=[]' "$CH_CFG_PATH" > "$TMPNOPOOL"
yq '.pool.pool_list' "$CH_CFG_PATH" -s '"/tmp/tmppool"'
python -m pyaml "$TMPNOPOOL" > "$TMPCUR"
python -m pyaml "$CH_CFG_INIT" > "$TMPNEW"
VIMDIFF_CONTROLS=$(bat -Ppl cmd-help <<- EOF
^[[38;5;186mVIMDIFF CONTROLS ~^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m ]c | advance to the next block with differences |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m [c | reverse search for the previous block with differences |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m do | bring changes from the other file to the current file |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m dp | send changes from the current file to the other file |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m zo | unfold/unhide text |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m zc | refold/rehide text |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m zr | unfold both files completely |^[[0m
^[[38;5;203m|^[[0m^[[38;5;231m zm | fold both files completely |^[[0m
^[[38;5;203mNOTE ABOUT DIFF OBTAIN/PUT CONTROL^[[0m^[[38;5;231m:^[[0m
^[[38;5;231m-^[[0m^[[38;5;231m ^[[0m^[[38;5;203mNormal Mode^[[0m^[[38;5;231m:^[[0m^[[38;5;231m ^[[0m^[[38;5;186mUse "do" and "dp" controls when your cursor is on, or just one line under a block.^[[0m
^[[38;5;231m-^[[0m^[[38;5;231m ^[[0m^[[38;5;203mVisual Mode^[[0m^[[38;5;231m:^[[0m^[[38;5;231m ^[[0m^[[38;5;186mUse ":'<,'>diffget" and ":'<,'>diffput" when selecting lines of text.^[[0m
^[[38;5;231m ^[[0m^[[38;5;186mSee also ":h copy-diffs".^[[0m
^[[38;5;186m"^[[0m^[[38;5;186m:diffupdate^[[0m^[[38;5;186m"^[[0m^[[38;5;231m ^[[0m^[[38;5;186mwill re-scan the files for changes.^[[0
^[[38;5;186mWhen you are finished editing, press "escape", and enter ":wqa" and press "enter".^[[0m
EOF
)
echo "You will now see a diff view of:"
echo "$CH_CFG_PATH"
echo "and"
echo "$CH_CFG_INIT"
echo "This will open in $TOOL."
if [[ $TOOL == "vimdiff" ]]; then
echo -e "$VIMDIFF_CONTROLS"
echo ""
fi
read -rp "Press enter to continue."
$TOOL "$TMPCUR" "$TMPNEW"
read -r -p "Do you want to replace your current Chia config file with your saved changes? [y/N] " CFG_CONFIRM
case "$CFG_CONFIRM" in
[yY][eE][sS]|[yY])
mv "$CH_CFG_PATH" "$CH_CFG_BAK"
#cp "$TMPCUR" "$CH_CFG_PATH"
yq '.pool.pool_list |=load("/tmp/tmppool.yml")' "$TMPCUR" > "$CH_CFG_PATH"
;;
*)
exit 0
;;
esac
rm "$TMPCUR" "$TMPNEW" /tmp/tmppool.yml