| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | #!/usr/local/bin/zsh | 
					
						
							| 
									
										
										
										
											2020-05-25 18:42:00 +09:00
										 |  |  | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | HOSTNAME=$(hostname) | 
					
						
							| 
									
										
										
										
											2022-03-19 15:44:00 +00:00
										 |  |  | LOCATION=$(hostname|cut -d . -f2) | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  | LOCKFILE="${HOME}/lock" | 
					
						
							|  |  |  | REF=$(echo "${1:=origin/master}"|sed -e 's!:!/!') | 
					
						
							| 
									
										
										
										
											2020-05-25 18:42:00 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-12 11:11:12 +00:00
										 |  |  | # get rpc credentials | 
					
						
							|  |  |  | BITCOIN_RPC_USER=$(grep '^rpcuser' /bitcoin/bitcoin.conf | cut -d '=' -f2) | 
					
						
							|  |  |  | BITCOIN_RPC_PASS=$(grep '^rpcpassword' /bitcoin/bitcoin.conf | cut -d '=' -f2) | 
					
						
							|  |  |  | ELEMENTS_RPC_USER=$(grep '^rpcuser' /elements/elements.conf | cut -d '=' -f2) | 
					
						
							|  |  |  | ELEMENTS_RPC_PASS=$(grep '^rpcpassword' /elements/elements.conf | cut -d '=' -f2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | if [ -f "${LOCKFILE}" ];then | 
					
						
							|  |  |  |     echo "upgrade already running? check lockfile ${LOCKFILE}" | 
					
						
							| 
									
										
										
										
											2020-09-18 21:53:58 +09:00
										 |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 03:06:54 +09:00
										 |  |  | trap "rv=\$?; rm -rf "${LOCKFILE}"; exit \$rv" INT TERM EXIT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | touch "${LOCKFILE}" | 
					
						
							| 
									
										
										
										
											2020-10-19 19:43:30 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  | echo "Upgrading mempool to ${REF}" | wall | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | update_repo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     local site="$1" | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  |     echo "[*] Upgrading ${site} to ${REF}" | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  |     cd "$HOME/${site}" || exit 1 | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 21:56:42 +09:00
										 |  |  |     git fetch origin || exit 1 | 
					
						
							| 
									
										
										
										
											2021-12-31 06:55:16 +09:00
										 |  |  |     for remote in origin knorrium emzy nymkappa hunicus;do | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  |         git remote add "${remote}" "https://github.com/${remote}/mempool" >/dev/null 2>&1 | 
					
						
							|  |  |  |         git fetch "${remote}" || exit 1 | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if [ $(git tag -l "${REF}") ];then | 
					
						
							|  |  |  |         git reset --hard "tags/${REF}" || exit 1 | 
					
						
							| 
									
										
										
										
											2021-12-09 18:12:06 +09:00
										 |  |  |     elif [ $(git branch -r -l "origin/${REF}") ];then | 
					
						
							|  |  |  |         git reset --hard "origin/${REF}" || exit 1 | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  |         git reset --hard "${REF}" || exit 1 | 
					
						
							| 
									
										
										
										
											2020-05-26 21:33:50 +09:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  |     export HASH=$(git rev-parse HEAD) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | build_frontend() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     local site="$1" | 
					
						
							|  |  |  |     echo "[*] Building frontend for ${site}" | 
					
						
							|  |  |  |     [ -z "${HASH}" ] && exit 1 | 
					
						
							|  |  |  |     cd "$HOME/${site}/frontend" || exit 1 | 
					
						
							| 
									
										
										
										
											2022-03-12 11:11:12 +00:00
										 |  |  |     if [ ! -e "mempool-frontend-config.json" ];then | 
					
						
							|  |  |  |         cp "${HOME}/mempool/production/mempool-frontend-config.${site}.json" "mempool-frontend-config.json" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  |     npm install --no-optional || exit 1 | 
					
						
							|  |  |  |     npm run build || exit 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | build_backend() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     local site="$1" | 
					
						
							|  |  |  |     echo "[*] Building backend for ${site}" | 
					
						
							|  |  |  |     [ -z "${HASH}" ] && exit 1 | 
					
						
							|  |  |  |     cd "$HOME/${site}/backend" || exit 1 | 
					
						
							| 
									
										
										
										
											2022-03-12 11:11:12 +00:00
										 |  |  |     if [ ! -e "mempool-config.json" ];then | 
					
						
							|  |  |  |         cp "${HOME}/mempool/production/mempool-config.${site}.json" "mempool-config.json" | 
					
						
							|  |  |  | 	sed -i .orig \ | 
					
						
							|  |  |  | 	-e "s!__BITCOIN_RPC_USER__!${BITCOIN_RPC_USER}!" \ | 
					
						
							|  |  |  | 	-e "s!__BITCOIN_RPC_PASS__!${BITCOIN_RPC_PASS}!" \ | 
					
						
							|  |  |  | 	-e "s!__ELEMENTS_RPC_USER__!${ELEMENTS_RPC_USER}!" \ | 
					
						
							|  |  |  | 	-e "s!__ELEMENTS_RPC_PASS__!${ELEMENTS_RPC_PASS}!" \ | 
					
						
							|  |  |  | 	"mempool-config.json" | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  |     npm install --no-optional || exit 1 | 
					
						
							|  |  |  |     npm run build || exit 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ship_frontend() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     local site="$1" | 
					
						
							|  |  |  |     cd "$HOME/${site}/frontend" || exit 1 | 
					
						
							| 
									
										
										
										
											2022-03-12 11:11:12 +00:00
										 |  |  |     mkdir -p "${HOME}/public_html/${site}/" | 
					
						
							|  |  |  |     rsync -av "./dist/mempool/browser/" "${HOME}/public_html/${site}/" || exit 1 | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export NVM_DIR="${HOME}/.nvm" | 
					
						
							|  |  |  | source "${NVM_DIR}/nvm.sh" | 
					
						
							| 
									
										
										
										
											2020-05-26 21:33:50 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-12 11:11:12 +00:00
										 |  |  | for target in mainnet testnet signet liquid liquidtestnet bisq;do | 
					
						
							|  |  |  |     update_repo "${target}" | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for target in mainnet testnet signet liquid liquidtestnet bisq;do | 
					
						
							|  |  |  |     build_backend "${target}" | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for target in mainnet liquid bisq;do | 
					
						
							|  |  |  |     build_frontend "${target}" | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for target in mainnet liquid bisq;do | 
					
						
							|  |  |  |     ship_frontend "${target}" | 
					
						
							|  |  |  | done | 
					
						
							| 
									
										
										
										
											2020-05-25 18:42:00 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 14:49:15 +09:00
										 |  |  | echo "${HOSTNAME} updated to \`${REF}\` @ \`${HASH}\`" | /usr/local/bin/keybase chat send --nonblock --channel general mempool.dev | 
					
						
							| 
									
										
										
										
											2022-03-19 15:44:00 +00:00
										 |  |  | echo "${HOSTNAME} updated to \`${REF}\` @ \`${HASH}\`" | /usr/local/bin/keybase chat send --nonblock --channel general "mempool.ops.${LOCATION}" | 
					
						
							| 
									
										
										
										
											2020-05-25 18:42:00 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-14 06:03:30 +09:00
										 |  |  | exit 0 |