forked from mempool/mempool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mempool-build-all
executable file
·179 lines (155 loc) · 5.86 KB
/
mempool-build-all
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env zsh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin
HOSTNAME=$(hostname)
LOCATION=$(hostname|cut -d . -f2)
LOCKFILE="${HOME}/lock"
REF=$(echo "${1:=origin/master}"|sed -e 's!:!/!')
# 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)
# get mysql credentials
MYSQL_CRED_FILE=${HOME}/.mysql_credentials
if [ -f "${MYSQL_CRED_FILE}" ];then
. ${MYSQL_CRED_FILE}
fi
if [ -f "${LOCKFILE}" ];then
echo "upgrade already running? check lockfile ${LOCKFILE}"
exit 1
fi
# on exit, remove lockfile but preserve exit code
trap "rv=\$?; rm -f "${LOCKFILE}"; exit \$rv" INT TERM EXIT
# create lockfile
touch "${LOCKFILE}"
# notify logged in users
echo "Upgrading mempool to ${REF}" | wall
update_repo()
{
local site="$1"
echo "[*] Upgrading ${site} to ${REF}"
cd "$HOME/${site}" || exit 1
git fetch origin || exit 1
for remote in origin;do
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
elif [ $(git branch -r -l "origin/${REF}") ];then
git reset --hard "origin/${REF}" || exit 1
else
git reset --hard "${REF}" || exit 1
fi
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
if [ ! -e "mempool-frontend-config.json" ];then
cp "${HOME}/mempool/production/mempool-frontend-config.${site}.json" "mempool-frontend-config.json"
fi
npm install --omit=dev --omit=optional || exit 1
npm run build || exit 1
}
build_unfurler()
{
local site="$1"
echo "[*] Building unfurler for ${site}"
[ -z "${HASH}" ] && exit 1
cd "$HOME/${site}/unfurler" || exit 1
if [ ! -e "config.json" ];then
cp "${HOME}/mempool/production/unfurler-config.${site}.json" "config.json"
fi
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install || 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
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}!" \
-e "s!__MEMPOOL_MAINNET_USER__!${MEMPOOL_MAINNET_USER}!" \
-e "s!__MEMPOOL_MAINNET_PASS__!${MEMPOOL_MAINNET_PASS}!" \
-e "s!__MEMPOOL_TESTNET_USER__!${MEMPOOL_TESTNET_USER}!" \
-e "s!__MEMPOOL_TESTNET_PASS__!${MEMPOOL_TESTNET_PASS}!" \
-e "s!__MEMPOOL_TESTNET4_USER__!${MEMPOOL_TESTNET4_USER}!" \
-e "s!__MEMPOOL_TESTNET4_PASS__!${MEMPOOL_TESTNET4_PASS}!" \
-e "s!__MEMPOOL_SIGNET_USER__!${MEMPOOL_SIGNET_USER}!" \
-e "s!__MEMPOOL_SIGNET_PASS__!${MEMPOOL_SIGNET_PASS}!" \
-e "s!__MEMPOOL_MAINNET_LIGHTNING_USER__!${MEMPOOL_MAINNET_LIGHTNING_USER}!" \
-e "s!__MEMPOOL_MAINNET_LIGHTNING_PASS__!${MEMPOOL_MAINNET_LIGHTNING_PASS}!" \
-e "s!__MEMPOOL_TESTNET_LIGHTNING_USER__!${MEMPOOL_TESTNET_LIGHTNING_USER}!" \
-e "s!__MEMPOOL_TESTNET_LIGHTNING_PASS__!${MEMPOOL_TESTNET_LIGHTNING_PASS}!" \
-e "s!__MEMPOOL_SIGNET_LIGHTNING_USER__!${MEMPOOL_SIGNET_LIGHTNING_USER}!" \
-e "s!__MEMPOOL_SIGNET_LIGHTNING_PASS__!${MEMPOOL_SIGNET_LIGHTNING_PASS}!" \
-e "s!__MEMPOOL_LIQUID_USER__!${MEMPOOL_LIQUID_USER}!" \
-e "s!__MEMPOOL_LIQUID_PASS__!${MEMPOOL_LIQUID_PASS}!" \
-e "s!__MEMPOOL_LIQUIDTESTNET_USER__!${MEMPOOL_LIQUIDTESTNET_USER}!" \
-e "s!__MEMPOOL_LIQUIDTESTNET_PASS__!${MEMPOOL_LIQUIDTESTNET_PASS}!" \
-e "s!__MEMPOOL_BISQ_USER__!${MEMPOOL_BISQ_USER}!" \
-e "s!__MEMPOOL_BISQ_PASS__!${MEMPOOL_BISQ_PASS}!" \
"mempool-config.json"
fi
npm install --omit=dev --omit=optional || exit 1
npm run build || exit 1
}
ship_frontend()
{
local site="$1"
cd "$HOME/${site}/frontend" || exit 1
mkdir -p "${HOME}/public_html/${site}/"
rsync -av "./dist/mempool/browser/" "${HOME}/public_html/${site}/" || exit 1
}
# load nvm if necessary
export NVM_DIR="${HOME}/.nvm"
source "${NVM_DIR}/nvm.sh"
# what to look for
frontends=(mainnet liquid onbtc)
backends=(mainnet testnet testnet4 signet liquid liquidtestnet onbtc)
frontend_repos=()
backend_repos=()
# find which frontend repos we have
for repo in $frontends;do
[ -d "${repo}" ] && frontend_repos+="${repo}"
done
# find which backend repos we have
for repo in $backends;do
[ -d "${repo}" ] && backend_repos+="${repo}"
[ -d "${repo}-lightning" ] && backend_repos+="${repo}-lightning"
done
# update all repos
for repo in $backend_repos;do
update_repo "${repo}"
done
# build backends
for repo in $backend_repos;do
build_backend "${repo}"
done
# build frontends
for repo in $frontend_repos;do
build_frontend "${repo}"
done
# ship frontend dist folders to public_html
for target in $frontend_repos;do
ship_frontend "${target}"
done
# build unfurlers
for repo in $frontend_repos;do
build_unfurler "${repo}"
done
# notify everyone
echo "${HOSTNAME} updated to \`${REF}\` @ \`${HASH}\`" | /usr/local/bin/keybase chat send --nonblock --channel general mempool.dev
echo "${HOSTNAME} updated to \`${REF}\` @ \`${HASH}\`" | /usr/local/bin/keybase chat send --nonblock --channel general "mempool.ops.${LOCATION}"
exit 0