diff options
| author | Alexandre Flament <alex@al-f.net> | 2021-07-30 18:57:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-30 18:57:00 +0200 |
| commit | 38ee88b3905148460e30982715277e7b30857629 (patch) | |
| tree | 61cf8004cc09fefeffaafb082b8ce86a1c959da4 /utils | |
| parent | 3b97657f3bbe9bd84a99d46ad1e26391d62ba496 (diff) | |
| parent | 5b3eeb6e54d4b88adccdf847c32d8102ff6202a5 (diff) | |
Merge pull request #229 from dalf/version-from-git
version based on git
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/brand.env | 4 | ||||
| -rw-r--r-- | utils/build_env.py | 18 | ||||
| -rwxr-xr-x | utils/searx.sh | 75 |
3 files changed, 66 insertions, 31 deletions
diff --git a/utils/brand.env b/utils/brand.env index 2075a2bf4..bd1629175 100644 --- a/utils/brand.env +++ b/utils/brand.env @@ -1,5 +1,5 @@ -export GIT_URL='https://github.com/searxng/searxng' -export GIT_BRANCH='master' export SEARX_URL='' export SEARX_PORT='8888' export SEARX_BIND_ADDRESS='127.0.0.1' +export GIT_URL='https://github.com/searxng/searxng' +export GIT_BRANCH='master' diff --git a/utils/build_env.py b/utils/build_env.py index dc55bd0a8..0ff99e99f 100644 --- a/utils/build_env.py +++ b/utils/build_env.py @@ -10,10 +10,9 @@ from os.path import realpath, dirname, join, sep, abspath repo_root = realpath(dirname(realpath(__file__)) + sep + '..') sys.path.insert(0, repo_root) -# Under the assumption that a brand is always a fork assure that the settings -# file from reposetorie's working tree is used to generate the build_env, not -# from /etc/searx/settings.yml. -os.environ['SEARX_SETTINGS_PATH'] = abspath(dirname(__file__) + sep + 'settings.yml') +# Assure that the settings file from reposetorie's working tree is used to +# generate the build_env, not from /etc/searx/settings.yml. +os.environ['SEARX_SETTINGS_PATH'] = join(repo_root, 'etc', 'settings.yml') def _env(*arg, **kwargs): val = get_setting(*arg, **kwargs) @@ -30,9 +29,6 @@ def _env(*arg, **kwargs): name_val = [ - ('GIT_URL' , 'brand.git_url'), - ('GIT_BRANCH' , 'brand.git_branch'), - ('SEARX_URL' , 'server.base_url'), ('SEARX_PORT' , 'server.port'), ('SEARX_BIND_ADDRESS' , 'server.bind_address'), @@ -50,15 +46,17 @@ for name, option in name_val: if not os.environ.get(name, _unset) is _unset: del os.environ[name] -# After the variables are unset in the environ, we can import settings -# (get_setting) from searx module. +# After the variables are unset in the environ, we can import from the searx +# package (what will read the values from the settings.yml). +from searx.version import GIT_URL, GIT_BRANCH from searx import get_setting print('build %s (settings from: %s)' % (brand_env, os.environ['SEARX_SETTINGS_PATH'])) sys.path.insert(0, repo_root) -from searx import settings with open(repo_root + sep + brand_env, 'w', encoding='utf-8') as f: for name, option in name_val: print("export %s='%s'" % (name, _env(option)), file=f) + print(f"export GIT_URL='{GIT_URL}'", file=f) + print(f"export GIT_BRANCH='{GIT_BRANCH}'", file=f) diff --git a/utils/searx.sh b/utils/searx.sh index f02611059..3ebe5df11 100755 --- a/utils/searx.sh +++ b/utils/searx.sh @@ -213,20 +213,26 @@ main() { *) usage "$_usage"; exit 42;; esac ;; install) - rst_title "SearXNG (install)" part sudo_or_exit case $2 in - all) install_all ;; + all) + rst_title "SearXNG (install)" part + install_all + ;; user) + rst_title "SearXNG (install user)" verify_continue_install assert_user ;; pyenv) + rst_title "SearXNG (install pyenv)" verify_continue_install create_pyenv ;; searx-src) + rst_title "SearXNG (install searx-src)" verify_continue_install + assert_user clone_searx install_DOT_CONFIG init_SEARX_SRC @@ -241,6 +247,7 @@ main() { install_settings ;; uwsgi) + rst_title "SearXNG (install uwsgi)" verify_continue_install install_searx_uwsgi if ! service_is_available "http://${SEARX_INTERNAL_HTTP}"; then @@ -248,9 +255,11 @@ main() { fi ;; packages) + rst_title "SearXNG (install packages)" pkg_install "$SEARX_PACKAGES" ;; buildhost) + rst_title "SearXNG (install buildhost)" pkg_install "$SEARX_PACKAGES" pkg_install "$BUILD_PACKAGES" ;; @@ -377,6 +386,11 @@ installations that were installed with this script." assert_user() { rst_title "user $SERVICE_USER" section echo + if getent passwd "$SERVICE_USER" > /dev/null; then + echo "user exists" + return 0 + fi + tee_stderr 1 <<EOF | bash | prefix_stdout useradd --shell /bin/bash --system \ --home-dir "$SERVICE_HOME" \ @@ -431,31 +445,36 @@ EOF prompt_installation_status(){ - local state branch remote remote_url instance_setting + # shellcheck disable=SC2034 + local GIT_URL GIT_BRANCH VERSION_STRING VERSION_TAG + local ret_val state branch remote remote_url state="$(install_searx_get_state)" - branch="$(git name-rev --name-only HEAD)" - remote="$(git config branch."${branch}".remote)" - remote_url="$(git config remote."${remote}".url)" case $state in - missing-searx-clone) + missing-searx-clone|missing-searx-pyenv) info_msg "${_BBlue}(status: $(install_searx_get_state))${_creset}" return 0 ;; *) - warn_msg "SearXNG instance already installed at: $SEARX_SRC" - warn_msg "status: ${_BBlue}$(install_searx_get_state)${_creset} " - instance_setting="$(prompt_installation_setting brand.git_url)" - if ! [ "$instance_setting" = "$remote_url" ]; then - warn_msg "instance's brand.git_url: '${instance_setting}'" \ + info_msg "SearXNG instance already installed at: $SEARX_SRC" + info_msg "status: ${_BBlue}$(install_searx_get_state)${_creset} " + branch="$(git name-rev --name-only HEAD)" + remote="$(git config branch."${branch}".remote)" + remote_url="$(git config remote."${remote}".url)" + eval "$(get_installed_version_variables)" + + ret_val=0 + if ! [ "$GIT_URL" = "$remote_url" ]; then + warn_msg "instance's git URL: '${GIT_URL}'" \ "differs from local clone's remote URL: ${remote_url}" + ret_val=42 fi - instance_setting="$(prompt_installation_setting brand.git_branch)" - if ! [ "$instance_setting" = "$branch" ]; then - warn_msg "instance brand.git_branch: ${instance_setting}" \ + if ! [ "$GIT_BRANCH" = "$branch" ]; then + warn_msg "instance git branch: ${GIT_BRANCH}" \ "differs from local clone's branch: ${branch}" + ret_val=42 fi - return 42 + return $ret_val ;; esac } @@ -469,7 +488,7 @@ verify_continue_install(){ prompt_installation_setting(){ - # usage: prompt_installation_setting brand.git_url + # usage: prompt_installation_setting brand.docs_url # # Prompts the value of the (YAML) setting in the SearXNG instance. @@ -496,6 +515,23 @@ EOF esac } +get_installed_version_variables() { + + # usage: eval "$(get_installed_version_variables)" + # + # Set variables VERSION_STRING, VERSION_TAG, GIT_URL, GIT_BRANCH + + local _state + _state="$(install_searx_get_state)" + case $_state in + python-installed|installer-modified) + sudo -H -u "${SERVICE_USER}" "${SEARX_PYENV}/bin/python" -m searx.version;; + *) + return 42 + ;; + esac +} + init_SEARX_SRC(){ rst_title "Update instance: ${SEARX_SRC}/" section @@ -512,20 +548,21 @@ init_SEARX_SRC(){ fi echo - echo "Manipulating files like settings.yml can break existing installation!" echo "Update instance with file(s) from: ${REPO_ROOT}" echo for i in "${SEARX_SRC_INIT_FILES[@]}"; do echo "- $i" done + echo + echo "Be careful when modifying an existing installation." if ! ask_yn "Do you really want to update these files in the instance?" Yn; then return 42 fi for fname in "${SEARX_SRC_INIT_FILES[@]}"; do while true; do choose_one _reply "choose next step with file ${fname}" \ - "leave file unchanged" \ "replace file" \ + "leave file unchanged" \ "diff files" \ "interactive shell" |