mempool update to v2.5.0 (#4353)

* formatting
* mempool update to v2.5.0
* fix shellcheck warns
* check for command outcomes directly
* use npm ci, exit on failed install
* use npm ci in update

Co-authored-by: Christoph Stenglein <9399034+cstenglein@users.noreply.github.com>
This commit is contained in:
openoms
2024-01-15 19:43:33 +01:00
committed by GitHub
parent ce89ac53fa
commit af65af5e14

View File

@@ -2,7 +2,7 @@
# https://github.com/mempool/mempool # https://github.com/mempool/mempool
pinnedVersion="v2.4.0" pinnedVersion="v2.5.0"
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
@@ -135,40 +135,36 @@ if [ "$1" = "install" ]; then
sudo adduser --system --group --home /home/mempool mempool sudo adduser --system --group --home /home/mempool mempool
# install mempool # install mempool
cd /home/mempool cd /home/mempool || exit 1
sudo -u mempool git clone https://github.com/mempool/mempool.git sudo -u mempool git clone https://github.com/mempool/mempool.git
cd mempool cd mempool || exit 1
sudo -u mempool git reset --hard $pinnedVersion sudo -u mempool git reset --hard $pinnedVersion
sudo -u mempool /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1 sudo -u mempool /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1
echo "# npm install for mempool explorer (frontend)" echo "# npm install for mempool explorer (frontend)"
cd frontend cd frontend || exit 1
sudo -u mempool NG_CLI_ANALYTICS=false npm install --no-optional if ! sudo -u mempool NG_CLI_ANALYTICS=false npm ci; then
if ! [ $? -eq 0 ]; then echo "FAIL - npm install did not run correctly, aborting"
echo "FAIL - npm install did not run correctly, aborting" exit 1
exit 1
fi fi
sudo -u mempool NG_CLI_ANALYTICS=false npm run build if ! sudo -u mempool NG_CLI_ANALYTICS=false npm run build; then
if ! [ $? -eq 0 ]; then echo "FAIL - npm run build did not run correctly, aborting (1)"
echo "FAIL - npm run build did not run correctly, aborting (1)" exit 1
exit 1
fi fi
echo "# npm install for mempool explorer (backend)" echo "# npm install for mempool explorer (backend)"
cd ../backend/ cd ../backend/ || exit 1
sudo -u mempool NG_CLI_ANALYTICS=false npm install --no-optional if ! sudo -u mempool NG_CLI_ANALYTICS=false npm ci; then
if ! [ $? -eq 0 ]; then echo "# FAIL - npm install did not run correctly, aborting"
echo "# FAIL - npm install did not run correctly, aborting" echo "result='failed npm install'"
echo "result='failed npm install'" exit 1
exit 1
fi fi
sudo -u mempool NG_CLI_ANALYTICS=false npm run build if ! sudo -u mempool NG_CLI_ANALYTICS=false npm run build; then
if ! [ $? -eq 0 ]; then echo "# FAIL - npm run build did not run correctly, aborting (2)"
echo "# FAIL - npm run build did not run correctly, aborting (2)" echo "result='failed npm run build'"
echo "result='failed npm run build'" exit 1
exit 1
fi fi
exit 0 exit 0
@@ -198,7 +194,10 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
isInstalled=$(compgen -u | grep -c mempool) isInstalled=$(compgen -u | grep -c mempool)
if [ "${isInstalled}" == "0" ]; then if [ "${isInstalled}" == "0" ]; then
echo "# Install code base first ...." echo "# Install code base first ...."
/home/admin/config.scripts/bonus.mempool.sh install if ! /home/admin/config.scripts/bonus.mempool.sh install; then
echo "FAIL - install did not run correctly, aborting"
exit 1
fi
fi fi
echo "# *** Activate MEMPOOL ***" echo "# *** Activate MEMPOOL ***"
@@ -214,7 +213,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
sudo mariadb -e "GRANT ALL PRIVILEGES ON mempool.* TO 'mempool' IDENTIFIED BY 'mempool';" sudo mariadb -e "GRANT ALL PRIVILEGES ON mempool.* TO 'mempool' IDENTIFIED BY 'mempool';"
sudo mariadb -e "FLUSH PRIVILEGES;" sudo mariadb -e "FLUSH PRIVILEGES;"
if [ -f "mariadb-structure.sql" ]; then if [ -f "mariadb-structure.sql" ]; then
mariadb -umempool -pmempool mempool < mariadb-structure.sql mariadb -umempool -pmempool mempool <mariadb-structure.sql
fi fi
# prepare .env file # prepare .env file
@@ -225,7 +224,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
touch /var/cache/raspiblitz/mempool-config.json touch /var/cache/raspiblitz/mempool-config.json
chmod 600 /var/cache/raspiblitz/mempool-config.json || exit 1 chmod 600 /var/cache/raspiblitz/mempool-config.json || exit 1
cat > /var/cache/raspiblitz/mempool-config.json <<EOF cat >/var/cache/raspiblitz/mempool-config.json <<EOF
{ {
"MEMPOOL": { "MEMPOOL": {
"NETWORK": "mainnet", "NETWORK": "mainnet",
@@ -262,7 +261,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
EOF EOF
sudo mv /var/cache/raspiblitz/mempool-config.json /home/mempool/mempool/backend/mempool-config.json sudo mv /var/cache/raspiblitz/mempool-config.json /home/mempool/mempool/backend/mempool-config.json
sudo chown mempool:mempool /home/mempool/mempool/backend/mempool-config.json sudo chown mempool:mempool /home/mempool/mempool/backend/mempool-config.json
cd /home/mempool/mempool/frontend cd /home/mempool/mempool/frontend || exit 1
sudo mkdir -p /mnt/hdd/app-storage/mempool/cache sudo mkdir -p /mnt/hdd/app-storage/mempool/cache
sudo chown mempool:mempool /mnt/hdd/app-storage/mempool/cache sudo chown mempool:mempool /mnt/hdd/app-storage/mempool/cache
@@ -297,7 +296,7 @@ EOF
# install service # install service
echo "*** Install mempool systemd ***" echo "*** Install mempool systemd ***"
cat > /var/cache/raspiblitz/mempool.service <<EOF cat >/var/cache/raspiblitz/mempool.service <<EOF
# systemd unit for Mempool # systemd unit for Mempool
[Unit] [Unit]
@@ -341,8 +340,8 @@ EOF
sleep 10 sleep 10
# check install success by testing backend # check install success by testing backend
isWorking=$(sudo systemctl status mempool | grep -c "Active: active") isWorking=$(sudo systemctl status mempool | grep -c "Active: active")
if [ ${isWorking} -lt 1 ]; then if [ ${isWorking} -lt 1 ]; then
# signal an error to WebUI # signal an error to WebUI
echo "result='mempool service not active'" echo "result='mempool service not active'"
exit 1 exit 1
@@ -368,7 +367,6 @@ EOF
echo "result='OK'" echo "result='OK'"
exit 0 exit 0
fi fi
# switch off # switch off
@@ -422,73 +420,66 @@ fi
if [ "$1" = "update" ]; then if [ "$1" = "update" ]; then
echo "*** Checking Mempool Explorer Version ***" echo "*** Checking Mempool Explorer Version ***"
cd /home/mempool/mempool cd /home/mempool/mempool || exit 1
localVersion=$(git describe --tag) localVersion=$(git describe --tag)
updateVersion=$(curl --header "X-GitHub-Api-Version:2022-11-28" -s https://api.github.com/repos/mempool/mempool/releases/latest|grep tag_name|head -1|cut -d '"' -f4) updateVersion=$(curl --header "X-GitHub-Api-Version:2022-11-28" -s https://api.github.com/repos/mempool/mempool/releases/latest | grep tag_name | head -1 | cut -d '"' -f4)
if [ $localVersion = $updateVersion ]; then if [ $localVersion = $updateVersion ]; then
echo "*** You are up-to-date on version $localVersion ***" echo "*** You are up-to-date on version $localVersion ***"
sudo systemctl restart mempool 2>/dev/null sudo systemctl restart mempool 2>/dev/null
echo "*** Restarting Mempool ***" echo "*** Restarting Mempool ***"
else else
# Preserve Config # Preserve Config
sudo cp backend/mempool-config.json /home/admin sudo cp backend/mempool-config.json /home/admin
sudo -u mempool git fetch sudo -u mempool git fetch
sudo -u mempool git checkout $updateVersion sudo -u mempool git checkout $updateVersion
echo "# npm install for mempool explorer (backend)" echo "# npm install for mempool explorer (backend)"
cd /home/mempool/mempool/backend/ cd /home/mempool/mempool/backend/ || exit 1
if ! sudo -u mempool NG_CLI_ANALYTICS=false npm ci; then
echo "FAIL - npm install did not run correctly, aborting"
exit 1
fi
if ! sudo -u mempool NG_CLI_ANALYTICS=false npm run build; then
echo "FAIL - npm run build did not run correctly, aborting (3)"
exit 1
fi
sudo -u mempool NG_CLI_ANALYTICS=false npm install echo "# npm install for mempool explorer (frontend)"
if ! [ $? -eq 0 ]; then
echo "FAIL - npm install did not run correctly, aborting"
exit 1
fi
sudo -u mempool NG_CLI_ANALYTICS=false npm run build
if ! [ $? -eq 0 ]; then
echo "FAIL - npm run build did not run correctly, aborting (3)"
exit 1
fi
echo "# npm install for mempool explorer (frontend)" cd ../frontend || exit 1
if ! sudo -u mempool NG_CLI_ANALYTICS=false npm ci; then
echo "FAIL - npm install did not run correctly, aborting"
exit 1
fi
if ! sudo -u mempool NG_CLI_ANALYTICS=false npm run build; then
echo "FAIL - npm run build did not run correctly, aborting (4)"
exit 1
fi
cd ../frontend sudo mv /home/admin/mempool-config.json /home/mempool/mempool/backend/mempool-config.json
sudo -u mempool NG_CLI_ANALYTICS=false npm install sudo chown mempool:mempool /home/mempool/mempool/backend/mempool-config.json
if ! [ $? -eq 0 ]; then
echo "FAIL - npm install did not run correctly, aborting"
exit 1
fi
sudo -u mempool NG_CLI_ANALYTICS=false npm run build
if ! [ $? -eq 0 ]; then
echo "FAIL - npm run build did not run correctly, aborting (4)"
exit 1
fi
sudo mv /home/admin/mempool-config.json /home/mempool/mempool/backend/mempool-config.json # Restore frontend files
sudo chown mempool:mempool /home/mempool/mempool/backend/mempool-config.json cd /home/mempool/mempool/frontend || exit 1
sudo rsync -I -av --delete dist/mempool/ /var/www/mempool/
sudo chown -R www-data:www-data /var/www/mempool
cd /home/mempool/mempool || exit 1
# Restore frontend files # Reinstall the mempool configuration for nginx
cd /home/mempool/mempool/frontend cp nginx.conf nginx-mempool.conf /etc/nginx/nginx.conf
sudo rsync -I -av --delete dist/mempool/ /var/www/mempool/ sudo systemctl restart nginx
sudo chown -R www-data:www-data /var/www/mempool
cd /home/mempool/mempool # Remove useless deps
echo "Removing unnecessary modules..."
npm prune --production
# Reinstall the mempool configuration for nginx echo "*** Restarting Mempool ***"
cp nginx.conf nginx-mempool.conf /etc/nginx/nginx.conf sudo systemctl start mempool
sudo systemctl restart nginx
# Remove useless deps
echo "Removing unnecessary modules..."
npm prune --production
echo "*** Restarting Mempool ***"
sudo systemctl start mempool
fi fi