diff --git a/geth-install.sh b/geth-install.sh new file mode 100644 index 0000000..baef2c6 --- /dev/null +++ b/geth-install.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +defaultVERSION=1.10.26 + +if [ $1 ] +then + VERSION=$1 +else + echo "=== Enter geth or for default $defaultVERSION" + read -p ">>> " VERSION + if [ ! "$VERSION" ] + then + VERSION=$defaultVERSION + echo Use default version $defaultVERSION + fi +fi + + +echo "=== Install geth:[b] for 二进制, [s] for 源代码,[anything else or leave blank] for no change" +read -p ">>> " BINARY_OR_SOURCE +if [ "$BINARY_OR_SOURCE" == 'b' ] +then + echo "--- 下载二进制 geth (https://geth.ethereum.org/downloads)" + # mkdir -p ./geth-temp/ + # cd ./geth-temp + if [ "$VERSION" == '1.10.26' ] + then + wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.26-e5eb32ac.tar.gz -O geth-linux-amd64-$VERSION.tgz + elif [ "$VERSION" == '1.10.25' ] + then + wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.25-69568c55.tar.gz -O geth-linux-amd64-$VERSION.tgz + else + echo "=== please find the download link in https://geth.ethereum.org/downloads" + read -p ">>> " DOWNLINK + wget $DOWNLINK -O geth-linux-amd64-$VERSION.tgz + fi + tar xzf ./geth-linux-amd64-$VERSION.tgz # --strip-components 1 ## 去掉tar包中顶级目录,因为顶级目录含有checksum,不方便在下一步进入 + echo "--- 安装到 /usr/local/bin/geth" + mv ./geth-linux-amd64-*/geth /usr/local/bin/ + # echo "--- 删除原始文件" + # cd .. + # rm -fr ./geth-temp +elif [ "$BINARY_OR_SOURCE" == 's' ] +then + echo "--- 克隆并编译 geth" + git clone -b v$VERSION https://github.com/ethereum/go-ethereum ./geth-temp/go-ethereum + mkdir -p ./geth-temp/ + pushd ./geth-temp/go-ethereum && make geth && popd # 或者 make all + mv ./geth-temp/go-ethereum/build/bin/geth /usr/local/bin/ + rm -fr ./geth-temp/ +else + echo "--- Nothing changed." +fi +echo "" diff --git a/geth-prepare.sh b/geth-prepare.sh new file mode 100644 index 0000000..8b1bedc --- /dev/null +++ b/geth-prepare.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +echo "=== Set [datadir] name, leave [blank] for default 'pex-data-poa'(可以尚未存在):" +read -p ">>> " DATADIR +if [ ! "$DATADIR" ] +then + DATADIR=chain-poa +fi +echo "*** DATADIR === $DATADIR " +echo "" + +echo "=== Init accounts: [y] for yes, [anything else] for no change" +read -p ">>> " INIT_ACCOUNTS +if [ $INIT_ACCOUNTS ] && [ $INIT_ACCOUNTS == 'y' ] +then + echo "--- 生成新账户,自动存放在 ./$DATADIR/keystore/" + geth --datadir ./$DATADIR/ account list # 检查现有账户。如果 ./pex-data/ 已经有数据,就不用生成新账户 + # 生成 [datadir]/keystore/ 下的钱包文件。密码都设为 123 + geth --datadir ./$DATADIR/ account new # 0x3831e121b349aebaea8ed0c44d4c7cb7b15ad8ad 导入 MetaMask 可得私钥 0xd2ed4496be1251a7f55772bba6ef1106ec330e27002898a5e1c69cd4e39de965 用在 hardhat.config.js 的 network 定义里 + geth --datadir ./$DATADIR/ account new # 0x921b248a470f7d0bba40077c7aee3ab3440caa77 导入 MetaMask 可得私钥 0x155d0d6fb836244be84e12fb7d79c1ae8d4b398f045f9e1a4cfdfef6f21b8a8e + echo "--- 请编写创世区块 genesis-$DATADIR.json ,设置新账户的初始金额 (PoW 的私有链挖矿比较容易,所以实际上不需要预置有币的账号,需要的时候自己挖矿获币也可以)" +else + echo "--- Nothing changed." +fi +echo "" + +echo "=== Init chain from genesis-$DATADIR.json: [y] for yes, [anything else] for no change" +read -p ">>> " INIT_CHAIN +if [ $INIT_CHAIN ] && [ $INIT_CHAIN == 'y' ] +then + echo "--- 初始化链上数据,存放在 ./$DATADIR/geth/" + geth --datadir ./$DATADIR/ init ./genesis-$DATADIR.json +else + echo "--- Nothing changed." +fi +echo "" diff --git a/geth-run.sh b/geth-run.sh new file mode 100644 index 0000000..bfffb94 --- /dev/null +++ b/geth-run.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +DATADIR=$1 + +while [ ! "$DATADIR" ] || [ ! -d "./$DATADIR" ] +do + echo "=== Set [datadir] name, leave [blank] for default 'pex-data-poa'" + read -p ">>> " DATADIR + if [ ! "$DATADIR" ] + then + DATADIR=chain-poa + fi +done +echo "" + + +echo "Run geth in pm2? [y] for yes, [anything else] for raw geth:" +read -p ">>> " RUNPM2 +echo "--- Creating ./$DATADIR/geth.ipc ..." +# http.addr 默认为 127.0.0.1 => 无法从远处连接。要用 0.0.0.0 才能从远处用 IP 连接。 +# shh 是 whisper 协议,好像要先启动 websocket 接口才能启用。 +# 我的 PEX 链的默认端口: +# - pex=739 +# - chainid 6739 +# - networkid 6739 +# - rpc 端口/http.port 6739 +# - 网络端口/port 60739 + +while [ ! "$KEYCODE" ] +do + echo "=== Define chain keycode, for instance '739' for pexchain:" + read -p ">>> " KEYCODE +done + +if [ "$RUNPM2" == 'y' ] +then + pm2 start -x 'geth' --name $DATADIR -- --datadir ./$DATADIR/ --http --http.addr 0.0.0.0 --http.port 6$KEYCODE --http.api eth,net,web3,personal,admin,miner,debug,txpool,shh --http.corsdomain "*" --nodiscover --networkid 6$KEYCODE --port 60$KEYCODE --allow-insecure-unlock -unlock '0xbC0ab80eef0A86eF248993D3f59B73F142278fbc' --password ./keystore-password.txt --mine --miner.threads 1 +else + # 如果不是用 pm2 而是直接用 geth,那么可以在最后加 console。不提供password也可以,那就会在命令行提示输入。 + geth --datadir ./$DATADIR/ --http --http.addr 0.0.0.0 --http.port 6$KEYCODE --http.api eth,net,web3,personal,admin,miner,debug,txpool --http.corsdomain "*" --nodiscover --networkid 6$KEYCODE --port 60$KEYCODE --allow-insecure-unlock -unlock '0xbC0ab80eef0A86eF248993D3f59B73F142278fbc' --password ./keystore-password.txt --mine --miner.threads 1 console +fi diff --git a/ipfs-install.sh b/ipfs-install.sh index 5b7ace3..7668093 100755 --- a/ipfs-install.sh +++ b/ipfs-install.sh @@ -1,4 +1,4 @@ -defaultVERSION=0.17.0 +defaultVERSION=0.18.1 if [ $1 ] then diff --git a/nixhome/.bashrc b/nixhome/.bashrc index 12c0713..dc5377e 100644 --- a/nixhome/.bashrc +++ b/nixhome/.bashrc @@ -58,6 +58,7 @@ then alias ll='ls -lGA' # show .xxx alias dir='ls -lGA' alias lll='ls -lGa' # show .xxx and . and .. + alias sedi='sed -i ""' export HOMEBREW_NO_AUTO_UPDATE=true export BASH_SILENCE_DEPRECATION_WARNING=1 else @@ -65,6 +66,7 @@ else alias ll='ls -lA --color=auto' alias dir='ls -lA --color=auto' alias lll='ls -la --color=auto' + alias sedi='sed -i' export TIME_STYLE='+%Y-%m-%d--%H:%M:%S' fi #export LS_OPTIONS='--color=auto' # 如果没有指定,则自动选择颜色