Last active
November 1, 2022 12:18
-
-
Save plowsof/b2bf7b425d3389006e8cad945a3ba7eb to your computer and use it in GitHub Desktop.
verify p2pool hashes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pprint as pp | |
import os | |
import subprocess | |
import sys | |
from urllib.request import urlretrieve | |
#for git --reset hard origin/master | |
hard_reset_remote = "origin" | |
#for pushing | |
your_remote = "lol" | |
local_branch = "p2poolupdateNEW" | |
def pop_index_line(fname): | |
with open(fname, "r") as f: | |
lines = f.readlines() | |
with open(fname, "w") as f: | |
for line in lines: | |
if "index" not in line: | |
f.write(line) | |
def get_hash(fname): | |
fhash = subprocess.check_output(["sha256sum", fname]).decode("utf-8") | |
print(fhash.strip()) | |
return fhash.split()[0] | |
def check_current_tag(): | |
global local_branch, hard_reset_remote | |
os.chdir("monero-gui") | |
os.system("git stash") | |
os.system(f"git checkout -b {local_branch}") | |
os.system(f"git fetch {hard_reset_remote}") | |
os.system(f"git reset --hard {hard_reset_remote}/master") | |
current_tag = [1,1] | |
with open("src/p2pool/P2PoolManager.cpp","r") as f: | |
lines = f.readlines() | |
for line in lines: | |
if "fileName =" in line: | |
print(line) | |
pp.pprint(line.split("-")[1]) | |
current_tag[0] =line.split("-")[1] | |
current_tag[1] = lines | |
break | |
os.chdir("../") | |
return current_tag | |
def main(PR=None): | |
global your_remote, local_branch, hard_reset_remote | |
data = requests.get("https://api.github.com/repos/SChernykh/p2pool/releases/latest").json() | |
# if tag is not == some stored value somewhere continue.. | |
tag = data["tag_name"] | |
data = check_current_tag() | |
current_tag = data[0] | |
p2pool_lines = data[1] | |
if current_tag == tag: | |
print(f"No update required: current tag {tag}") | |
return | |
else: | |
print(f"Update required: {current_tag} -> {tag}") | |
head = f"p2pool-{tag}-" | |
url = f"https://github.com/SChernykh/p2pool/releases/download/{tag}/" | |
files = [f"{head}macos-x64.tar.gz",f"{head}linux-x64.tar.gz",f"{head}windows-x64.zip","sha256sums.txt.asc"] | |
#get pubkey of sech1 | |
urlretrieve("https://p2pool.io/SChernykh.asc","SChernykh.asc") | |
for f in files: | |
dl = f"{url}{f}" | |
print(dl) | |
urlretrieve(dl, f) | |
subprocess.check_call(["gpg", "--import", "SChernykh.asc"]) | |
subprocess.check_call(["gpg", "--verify", "sha256sums.txt.asc"]) | |
with open("sha256sums.txt.asc","r") as f: | |
lines = f.readlines() | |
verified_hashes = {} | |
for line in lines: | |
if "Name:" in line: | |
fname = line.split()[1] | |
if fname not in files: | |
continue | |
if "SHA256:" in line: | |
verified_hashes[fname] = line.split()[1].lower() | |
mac_hash = get_hash(files[0]) | |
lin_hash = get_hash(files[1]) | |
win_hash = get_hash(files[2]) | |
assert mac_hash == verified_hashes[files[0]] | |
assert lin_hash == verified_hashes[files[1]] | |
assert win_hash == verified_hashes[files[2]] | |
with open("monero-gui/src/p2pool/P2PoolManager.cpp","w") as f: | |
ignore = 0 | |
for line in p2pool_lines: | |
if "QString validHash;" in line: | |
f.write(line) | |
template=f""" #ifdef Q_OS_WIN | |
url = "https://github.com/SChernykh/p2pool/releases/download/{tag}/p2pool-{tag}-windows-x64.zip"; | |
fileName = m_p2poolPath + "/{head}windows-x64.zip"; | |
validHash = "{win_hash}"; | |
#elif defined(Q_OS_LINUX) | |
url = "https://github.com/SChernykh/p2pool/releases/download/{tag}/p2pool-{tag}-linux-x64.tar.gz"; | |
fileName = m_p2poolPath + "/{head}linux-x64.tar.gz"; | |
validHash = "{lin_hash}"; | |
#elif defined(Q_OS_MACOS) | |
url = "https://github.com/SChernykh/p2pool/releases/download/{tag}/p2pool-{tag}-macos-x64.tar.gz"; | |
fileName = m_p2poolPath + "/{head}macos-x64.tar.gz"; | |
validHash = "{mac_hash}";\n""" | |
f.write(template) | |
ignore = 1 | |
if "#endif" in line and ignore == 1: | |
ignore = 0 | |
if ignore == 0: | |
f.write(line) | |
if PR: | |
diff_url = requests.get("https://api.github.com/repos/monero-project/monero-gui/pulls/4060").json()["diff_url"] | |
urlretrieve(diff_url,"verify_me.patch") | |
os.chdir("monero-gui") | |
os.system("git diff > ../local_diff.patch") | |
#pop index line from diff file because it will never match | |
pop_index_line("../local_diff.patch") | |
pop_index_line("../verify_me.patch") | |
#check_call acts like assert | |
subprocess.check_call(["diff", "../local_diff.patch", "../verify_me.patch"]) | |
print("LGTM") | |
else: | |
os.chdir("monero-gui") | |
subprocess.check_call(["git", "add", "src/p2pool/P2PoolManager.cpp"]) | |
subprocess.check_call(["git", "commit", "-m", f"p2pool: update to {tag}"]) | |
subprocess.check_call(["git", "push", "--set-upstream", your_remote, local_branch, "--force"]) | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
main(sys.argv[1]) | |
else: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
place file outside of your
monero-gui
git folderedit
local_branch
,hard_reset_remote
,your_remote
accordinglyCheck/PR p2pool update to your remote branch:
Verify someone elses PR: "outputs LGTM if its ok"