toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

upgrade fails due invalid mongo version parsing

Open qupfer opened this issue 1 year ago • 2 comments

Steps to Reproduce

  1. run ./bin/upgrade
  2. modify /config/overleaf.rc to new split mongo
MONGO_ENABLED=true
MONGO_DATA_PATH=data/mongo
MONGO_IMAGE=mongo
MONGO_VERSION=5.0
  1. run ./bin/upgrade

Expected Behaviour

  • should upgrade

Observed Behaviour

error message

---------------------  ERROR  -----------------------
  Invalid MONGO_VERSION: MONGO_VERSION=5.0

  MONGO_VERSION must start with the actual major version of mongo, followed by a dot.
  Example: MONGO_IMAGE=my.dockerhub.com/custom-mongo
           MONGO_VERSION=6.0-custom
---------------------  ERROR  -----------------------

Analysis

a set -x in lib/shared-functions.sh looks (for me) that some variable name/value splitting is not done correctly

overleaf:~/overleaf-toolkit# ./bin/upgrade 
Checking for code update...
No code update available for download
New docker image version available (5.1.1)
Current image version is '5.0.6' (from config/version)
Upgrade image? [y/n] y
Upgrading config/version from 5.0.6 to 5.1.1
++ read_configuration MONGO_IMAGE
++ local name=MONGO_IMAGE
++ grep -E '^MONGO_IMAGE=' /root/overleaf-toolkit/config/overleaf.rc
++ sed -r 's/^MONGO_IMAGE=(["'\'']?)(.+)\1$/\2/'
+ local mongo_image=MONGO_IMAGE=mongo
++ read_configuration MONGO_VERSION
++ local name=MONGO_VERSION
++ grep -E '^MONGO_VERSION=' /root/overleaf-toolkit/config/overleaf.rc
++ sed -r 's/^MONGO_VERSION=(["'\'']?)(.+)\1$/\2/'
+ local mongo_version=MONGO_VERSION=5.0
+ '[' -z MONGO_VERSION=5.0 ']'
+ [[ ! MONGO_VERSION=5.0 =~ ^([0-9]+)\.(.+)$ ]]
+ echo '---------------------  ERROR  -----------------------'
+ echo '  Invalid MONGO_VERSION: MONGO_VERSION=5.0'
+ echo ''
+ echo '  MONGO_VERSION must start with the actual major version of mongo, followed by a dot.'
+ echo '  Example: MONGO_IMAGE=my.dockerhub.com/custom-mongo'
+ echo '           MONGO_VERSION=6.0-custom'
+ echo '---------------------  ERROR  -----------------------'
+ exit 1

I think mongo_version should be 5.0 and not MONGO_VERSION=5.0

qupfer avatar Aug 21 '24 19:08 qupfer

This is indeed a bug that I can confirm. Changing the lib/shared-functions.sh sed regex syntax in the read_variable() and read_configuration() from "s/^$name=([\"']?)(.+)\1\$/\2/" to "s/^$name=['\"]?(.*)['\"]?$/\1/" resolves this issue.

dev-lukas avatar Oct 25 '24 10:10 dev-lukas

This is indeed a bug that I can confirm. Changing the lib/shared-functions.sh sed regex syntax in the read_variable() and read_configuration() from "s/^$name=([\"']?)(.+)\1\$/\2/" to "s/^$name=['\"]?(.*)['\"]?$/\1/" resolves this issue.

It's like a typo bug in this file, but this helped me! Thank you bro.

liuup avatar Dec 29 '24 11:12 liuup