Skip to content

Instantly share code, notes, and snippets.

@whonion
Last active November 1, 2023 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whonion/804298f11dc60c6e04b9024b815301d5 to your computer and use it in GitHub Desktop.
Save whonion/804298f11dc60c6e04b9024b815301d5 to your computer and use it in GitHub Desktop.
quai.sh
#!/bin/bash
#0xf2b78c12f524b021fa5ebd95262ab23aa8223a54
#CPU Miner
#git clone https://github.com/dominant-strategies/quai-cpu-miner
#GPU Miner
#git clone https://github.com/dominant-strategies/quai-gpu-miner
#Stratum Proxy
#git clone
#Explorers
#https://cyprus1.colosseum.quaiscan.io/
exists()
{
command -v "$1" >/dev/null 2>&1
}
if exists curl; then
echo ''
else
sudo apt install curl -y < "/dev/null"
fi
bash_profile=$HOME/.bash_profile
if [ -f "$bash_profile" ]; then
. $HOME/.bash_profile
fi
sleep 1 && curl -s https://api.nodes.guru/logo.sh | bash && sleep 1
function setupVars {
read -p "Enter your wallet address: " WALLET
echo ""
#read -p "Write the chain in which the node will work(Available options: cyprus1, cyprus2, cyprus3, paxos1, paxos2, paxos3, hydra1, hydra2, hydra3.): " CHAIN
echo "Select the chain in which the node will work (input your option number and press enter):"
echo "1 - Cyprus-1"
echo "2 - Cyprus-2"
echo "3 - Cyprus-3"
echo "4 - Paxos-1"
echo "5 - Paxos-2"
echo "6 - Paxos-3"
echo "7 - Hydra-1"
echo "8 - Hydra-2"
echo "9 - Hydra-3"
read CHAIN;
case $CHAIN in
1) CHAIN=cyprus1;;
2) CHAIN=cyprus2;;
3) CHAIN=cyprus3;;
4) CHAIN=paxos1;;
5) CHAIN=paxos2;;
6) CHAIN=paxos3;;
7) CHAIN=hydra1;;
8) CHAIN=hydra2;;
9) CHAIN=hydra3;;
*) echo "Incorrect value. Please choose a different one."
exit;;
esac
}
function selectRegion {
case $CHAIN in
cyprus1 )
stratum="quai-stratum --region=8579 --zone=8611";;
# sed -i.back 's/SLICES=.*/SLICES="[0 0]"/' $HOME/go-quai/network.env;;
cyprus2 )
stratum="quai-stratum --region=8579 --zone=8643";;
# sed -i.back 's/SLICES=.*/SLICES="[0 1]"/' $HOME/go-quai/network.env;;
cyprus3 )
stratum="quai-stratum --region=8579 --zone=8675";;
# sed -i.back 's/SLICES=.*/SLICES="[0 2]"/' $HOME/go-quai/network.env;;
paxos1 )
stratum="quai-stratum --region=8581 --zone=8613";;
# sed -i.back 's/SLICES=.*/SLICES="[1 0]"/' $HOME/go-quai/network.env;;
paxos2 )
stratum="quai-stratum --region=8581 --zone=8645";;
# sed -i.back 's/SLICES=.*/SLICES="[1 1]"/' $HOME/go-quai/network.env;;
paxos3 )
stratum="quai-stratum --region=8581 --zone=8677";;
# sed -i.back 's/SLICES=.*/SLICES="[1 2]"/' $HOME/go-quai/network.env;;
hydra1 )
stratum="quai-stratum --region=8583 --zone=8615";;
# sed -i.back 's/SLICES=.*/SLICES="[2 0]"/' $HOME/go-quai/network.env;;
hydra2 )
stratum="quai-stratum --region=8583 --zone=8647";;
# sed -i.back 's/SLICES=.*/SLICES="[2 1]"/' $HOME/go-quai/network.env;;
hydra3 )
stratum="quai-stratum --region=8583 --zone=8679";;
# sed -i.back 's/SLICES=.*/SLICES="[2 2]"/' $HOME/go-quai/network.env;;
*)
echo "$CHAIN incorrect chain. Available options: cyprus1, cyprus2, cyprus3, paxos1, paxos2, paxos3, hydra1, hydra2, hydra3."
exit
esac
cd $HOME/go-quai
make go-quai
wget https://archive.quai.network/quai_colosseum_backup.tar.gz
tar -xzvf quai_colosseum_backup.tar.gz
cp -r quai_backup_2023_10_31 ~/.quai
sleep 1
make run
}
function setupMinerVars {
read -p "Enter your quai stratum ip address (default 127.0.0.1): " IP
# Set default value if input is empty
IP=${IP:-127.0.0.1}
if [[ $IP =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]];
then :
else
echo "Incorrect ip address"
exit
fi
}
function installSoftware {
sudo apt update
sudo apt install make curl clang pkg-config libssl-dev jq build-essential git ncdu expect -y < "/dev/null"
echo -e '\n\e[42mInstall Go\e[0m\n' && sleep 1
cd $HOME
VERSION=1.21.1
wget -O go.tar.gz https://go.dev/dl/go$VERSION.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
echo 'export GOROOT=/usr/local/go' >> $HOME/.bash_profile
echo 'export GOPATH=$HOME/go' >> $HOME/.bash_profile
echo 'export GO111MODULE=on' >> $HOME/.bash_profile
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile && . $HOME/.bash_profile
go version
sleep 2
}
function installGpuDep {
sudo apt install git cmake build-essential mesa-common-dev nvidia-driver-535 radeontop -y
}
function installNode {
NODE_LATEST_TAG=$(curl -s "https://api.github.com/repos/dominant-strategies/go-quai/tags" | jq -r '.[0].name')
cd $HOME
rm -rf go-quai
git clone https://github.com/dominant-strategies/go-quai
cd go-quai
git checkout $NODE_LATEST_TAG
cp network.env.dist network.env
sed -i.bak "s/COINBASE=.*/COINBASE=$WALLET/g" network.env
sed -i.bak "s/ENABLE_NAT=.*/ENABLE_NAT=true/" $HOME/go-quai/network.env
echo "EXT_IP=$(curl ipinfo.io/ip)" >> $HOME/go-quai/network.env
#make go-quai
#sleep 1
#make run
}
function installProxy {
PROXY_LATEST_TAG=$(curl -s "https://api.github.com/repos/dominant-strategies/go-quai-stratum/tags" | jq -r '.[0].name')
cd $HOME
rm -rf go-quai-stratum
git clone https://github.com/dominant-strategies/go-quai-stratum
cd go-quai-stratum
git checkout $PROXY_LATEST_TAG
cp config/config.example.json config/config.json
make quai-stratum
sudo mv ./build/bin/quai-stratum /usr/local/bin/
}
function installService {
echo "[Unit]
Description=Quai stratum
After=network.target
[Service]
User=$USER
Type=simple
WorkingDirectory=$HOME/go-quai-stratum
ExecStart=/usr/local/bin/$stratum
Restart=on-failure
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target" > $HOME/proxy.service
sudo mv $HOME/proxy.service /etc/systemd/system
sudo tee <<EOF >/dev/null /etc/systemd/journald.conf
Storage=persistent
EOF
echo -e '\n\e[42mRunning a service\e[0m\n' && sleep 1
sudo systemctl restart systemd-journald
sudo systemctl daemon-reload
sudo systemctl enable proxy
sudo systemctl restart proxy
echo -e '\n\e[42mCheck node status\e[0m\n' && sleep 1
if [[ `service proxy status | grep active` =~ "running" ]]; then
echo -e "Your Quai stratum \e[32minstalled and works\e[39m!"
echo -e "You can check node status by the command \e[7mservice proxy status\e[0m"
echo -e "Press \e[7mQ\e[0m for exit from status menu"
else
echo -e "Your Quai stratum node \e[31mwas not installed correctly\e[39m, please reinstall."
fi
}
function installMiner {
cd $HOME
rm -rf quai-gpu-miner
git clone https://github.com/dominant-strategies/quai-gpu-miner && cd quai-gpu-miner
git submodule update --init --recursive
mkdir build && cd build
cmake .. && cmake --build .
sudo mv ./ethcoreminer/ethcoreminer /usr/local/bin/
}
function installMinerService {
echo "[Unit]
Description=Quai miner
After=network.target
[Service]
User=$USER
Type=simple
WorkingDirectory=$HOME/quai-gpu-miner
ExecStart=/usr/local/bin/ethcoreminer -G -P stratum://$IP:3333
Restart=on-failure
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target" > $HOME/miner.service
sudo mv $HOME/miner.service /etc/systemd/system
sudo tee <<EOF >/dev/null /etc/systemd/journald.conf
Storage=persistent
EOF
echo -e '\n\e[42mRunning a service\e[0m\n' && sleep 1
sudo systemctl restart systemd-journald
sudo systemctl daemon-reload
sudo systemctl enable miner
sudo systemctl restart miner
echo -e '\n\e[42mCheck node status\e[0m\n' && sleep 1
if [[ `service miner status | grep active` =~ "running" ]]; then
echo -e "Your Quai miner \e[32minstalled and works\e[39m!"
echo -e "You can check node status by the command \e[7mservice miner status\e[0m"
echo -e "Press \e[7mQ\e[0m for exit from status menu"
else
echo -e "Your Quai miner \e[31mwas not installed correctly\e[39m, please reinstall."
fi
}
PS3='Please enter your choice (input your option number and press enter): '
options=("Install node and stratum proxy" "Install GPU miner" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Install node and stratum proxy")
echo -e '\n\e[42mYou choose Install node and stratum proxy...\e[0m\n' && sleep 1
setupVars
installSoftware
installNode
installProxy
selectRegion
installService
break
;;
"Install GPU miner")
echo -e '\n\e[33mYou choose Install GPU miner...\e[0m\n' && sleep 1
setupMinerVars
installSoftware
installGpuDep
installMiner
installMinerService
break
;;
"Quit")
break
;;
*) echo -e "\e[91minvalid option $REPLY\e[0m";;
esac
done
echo -e '\n\e[42mInstallation completed\e[0m\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment