From 0f1645e3899ce8bfc58da917c4c176e5c21c1acd Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Fri, 19 Jul 2024 00:49:51 +0200 Subject: [PATCH] Various small packaging fixes (#7686) * move repo setting for packager to yml * fix python detection * fix persistent setting writing (during onboarding) * clean up OS before uninstalling --- .pkgr.yml | 2 ++ contrib/packager.io/before.sh | 9 ++++----- contrib/packager.io/functions.sh | 14 +++++++------- contrib/packager.io/preinstall.sh | 2 +- src/backend/InvenTree/config_template.yaml | 2 ++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.pkgr.yml b/.pkgr.yml index 4ddf0a86f5..970723ef9d 100644 --- a/.pkgr.yml +++ b/.pkgr.yml @@ -14,8 +14,10 @@ env: - INVENTREE_BACKUP_DIR=/opt/inventree/backup - INVENTREE_PLUGIN_FILE=/opt/inventree/plugins.txt - INVENTREE_CONFIG_FILE=/opt/inventree/config.yaml + - APP_REPO=inventree/InvenTree before_install: contrib/packager.io/preinstall.sh after_install: contrib/packager.io/postinstall.sh +before_remove: contrib/packager.io/preinstall.sh before: - contrib/packager.io/before.sh dependencies: diff --git a/contrib/packager.io/before.sh b/contrib/packager.io/before.sh index 41ca3688b5..0da421fd38 100755 --- a/contrib/packager.io/before.sh +++ b/contrib/packager.io/before.sh @@ -6,7 +6,6 @@ set -eu # The sha is the second element in APP_PKG_ITERATION -REPO="inventree/InvenTree" VERSION="$APP_PKG_VERSION-$APP_PKG_ITERATION" SHA=$(echo $APP_PKG_ITERATION | cut -d'.' -f2) @@ -15,17 +14,17 @@ echo "INFO collection | Getting info from github for commit $SHA" curl -L -s -f \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$REPO/commits/$SHA > commit.json + https://api.github.com/repos/$APP_REPO/commits/$SHA > commit.json echo "INFO collection | Got commit.json with size $(wc -c commit.json)" curl -L -s -f \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$REPO/commits/$SHA/branches-where-head > branches.json + https://api.github.com/repos/$APP_REPO/commits/$SHA/branches-where-head > branches.json echo "INFO collection | Got branches.json with size $(wc -c branches.json)" curl -L -s -f \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$REPO/commits/$APP_PKG_VERSION > tag.json + https://api.github.com/repos/$APP_REPO/commits/$APP_PKG_VERSION > tag.json echo "INFO collection | Got tag.json with size $(wc -c tag.json)" # Extract info @@ -60,7 +59,7 @@ if [ "$TAG_SHA" != "$FULL_SHA" ]; then echo "INFO frontend | Tag sha '$TAG_SHA' is not the same as commit sha $FULL_SHA, can not download frontend" else echo "INFO frontend | Getting frontend from github via tag" - curl https://github.com/$REPO/releases/download/$APP_PKG_VERSION/frontend-build.zip -L -O -f + curl https://github.com/$APP_REPO/releases/download/$APP_PKG_VERSION/frontend-build.zip -L -O -f mkdir -p src/backend/InvenTree/web/static echo "INFO frontend | Unzipping frontend" unzip -qq frontend-build.zip -d src/backend/InvenTree/web/static/web diff --git a/contrib/packager.io/functions.sh b/contrib/packager.io/functions.sh index 9087e1e0aa..29c9d53ff4 100755 --- a/contrib/packager.io/functions.sh +++ b/contrib/packager.io/functions.sh @@ -60,7 +60,7 @@ function detect_python() { fi # Try to detect a python between 3.9 and 3.12 in reverse order - if [ -z "${SETUP_PYTHON}" ]; then + if [ -z "$(which ${SETUP_PYTHON})" ]; then echo "# Trying to detecting python3.${PYTHON_FROM} to python3.${PYTHON_TO} - using newest version" for i in $(seq $PYTHON_TO -1 $PYTHON_FROM); do echo "# Checking for python3.${i}" @@ -318,17 +318,17 @@ function set_env() { sed -i s=debug:\ True=debug:\ False=g ${INVENTREE_CONFIG_FILE} # Database engine - sed -i s=#ENGINE:\ sampleengine=ENGINE:\ ${INVENTREE_DB_ENGINE}=g ${INVENTREE_CONFIG_FILE} + sed -i s=#\ ENGINE:\ Database\ engine.\ Selection\ from:=ENGINE:\ ${INVENTREE_DB_ENGINE}=g ${INVENTREE_CONFIG_FILE} # Database name - sed -i s=#NAME:\ \'/path/to/database\'=NAME:\ \'${INVENTREE_DB_NAME}\'=g ${INVENTREE_CONFIG_FILE} + sed -i s=#\ NAME:\ Database\ name=NAME:\ \'${INVENTREE_DB_NAME}\'=g ${INVENTREE_CONFIG_FILE} # Database user - sed -i s=#USER:\ sampleuser=USER:\ ${INVENTREE_DB_USER}=g ${INVENTREE_CONFIG_FILE} + sed -i s=#\ USER:\ Database\ username\ \(if\ required\)=USER:\ ${INVENTREE_DB_USER}=g ${INVENTREE_CONFIG_FILE} # Database password - sed -i s=#PASSWORD:\ samplepassword=PASSWORD:\ ${INVENTREE_DB_PASSWORD}=g ${INVENTREE_CONFIG_FILE} + sed -i s=#\ PASSWORD:\ Database\ password\ \(if\ required\)=PASSWORD:\ ${INVENTREE_DB_PASSWORD}=g ${INVENTREE_CONFIG_FILE} # Database host - sed -i s=#HOST:\ samplehost=HOST:\ ${INVENTREE_DB_HOST}=g ${INVENTREE_CONFIG_FILE} + sed -i s=#\ HOST:\ Database\ host\ address\ \(if\ required\)=HOST:\ ${INVENTREE_DB_HOST}=g ${INVENTREE_CONFIG_FILE} # Database port - sed -i s=#PORT:\ 123456=PORT:\ ${INVENTREE_DB_PORT}=g ${INVENTREE_CONFIG_FILE} + sed -i s=#\ PORT:\ Database\ host\ port\ \(if\ required\)=PORT:\ ${INVENTREE_DB_PORT}=g ${INVENTREE_CONFIG_FILE} # Fixing the permissions chown ${APP_USER}:${APP_GROUP} ${DATA_DIR} ${INVENTREE_CONFIG_FILE} diff --git a/contrib/packager.io/preinstall.sh b/contrib/packager.io/preinstall.sh index ba9ebc0d5d..0e59daebb2 100755 --- a/contrib/packager.io/preinstall.sh +++ b/contrib/packager.io/preinstall.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# packager.io preinstall script +# packager.io preinstall/preremove script # PATH=${APP_HOME}/env/bin:${APP_HOME}/:/sbin:/bin:/usr/sbin:/usr/bin: diff --git a/src/backend/InvenTree/config_template.yaml b/src/backend/InvenTree/config_template.yaml index a5b8495187..4ef1bf42bf 100644 --- a/src/backend/InvenTree/config_template.yaml +++ b/src/backend/InvenTree/config_template.yaml @@ -11,6 +11,8 @@ # Note: Database configuration options can also be specified from environmental variables, # with the prefix INVENTREE_DB_ # e.g INVENTREE_DB_NAME / INVENTREE_DB_USER / INVENTREE_DB_PASSWORD +# Do not change this section if you are using the package - use `inventree config` instead +# TO MAINTAINERS: Do not change database strings database: # --- Available options: --- # ENGINE: Database engine. Selection from: