From ed536471b22a644c364b9b582ec80d4c3fcc6934 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 3 Sep 2022 18:27:29 +0200 Subject: [PATCH] spacing --- conf/nginx.conf | 2 +- scripts/install | 6 +- scripts/restore | 6 +- scripts/upgrade | 40 ++--- scripts/ynh_install_python | 320 ++++++++++++++++++------------------- 5 files changed, 188 insertions(+), 186 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 4353cf5..6f929db 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,6 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - try_files $uri @__NAME__; + try_files $uri @__NAME__; } location __PATH__/protected/ { diff --git a/scripts/install b/scripts/install index 9fb5ff3..85c0117 100644 --- a/scripts/install +++ b/scripts/install @@ -120,9 +120,9 @@ ynh_script_progression --message="Installing more dependencies..." --weight=1 pushd "$final_path" ynh_use_python ynh_exec_warn_less $ynh_pip install --upgrade pip - ynh_exec_warn_less $ynh_pip install gunicorn - echo "django-auth-ldap<1.4" >> $final_path/requirements.txt - ynh_exec_warn_less $ynh_pip install -r $final_path/requirements.txt + ynh_exec_warn_less $ynh_pip install gunicorn + echo "django-auth-ldap<1.4" >> $final_path/requirements.txt + ynh_exec_warn_less $ynh_pip install -r $final_path/requirements.txt popd #================================================= diff --git a/scripts/restore b/scripts/restore index f2c426f..b16c175 100644 --- a/scripts/restore +++ b/scripts/restore @@ -105,9 +105,9 @@ ynh_script_progression --message="Installing more dependencies..." --weight=1 pushd "$final_path" ynh_use_python ynh_exec_warn_less $ynh_pip install --upgrade pip - ynh_exec_warn_less $ynh_pip install gunicorn - echo "django-auth-ldap<1.4" >> $final_path/requirements.txt - ynh_exec_warn_less $ynh_pip install -r $final_path/requirements.txt + ynh_exec_warn_less $ynh_pip install gunicorn + echo "django-auth-ldap<1.4" >> $final_path/requirements.txt + ynh_exec_warn_less $ynh_pip install -r $final_path/requirements.txt popd #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 8a395ba..9aeadb4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -138,28 +138,30 @@ ynh_store_file_checksum --file="$final_path/coin/settings_local.py" pushd "$final_path" ynh_use_python - - #================================================= - # PYTHON DEPENDENCIES - #================================================= - ynh_script_progression --message="Installing more dependencies..." --weight=1 + + #================================================= + # PYTHON DEPENDENCIES + #================================================= + ynh_script_progression --message="Installing more dependencies..." --weight=1 - echo "django-auth-ldap<1.4" >> $final_path/requirements.txt - ynh_exec_warn_less $ynh_pip install -r $final_path/requirements.txt - - #================================================= - # MIGRATE DB - #================================================= - ynh_script_progression --message="Migrating database..." --weight=1 + ynh_exec_warn_less $ynh_pip install --upgrade pip + ynh_exec_warn_less $ynh_pip install gunicorn + echo "django-auth-ldap<1.4" >> $final_path/requirements.txt + ynh_exec_warn_less $ynh_pip install -r $final_path/requirements.txt + + #================================================= + # MIGRATE DB + #================================================= + ynh_script_progression --message="Migrating database..." --weight=1 - ynh_exec_warn_less $ynh_python manage.py migrate --noinput - - #================================================= - # COLLECT FILES - #================================================= - ynh_script_progression --message="Collecting files..." --weight=1 + ynh_exec_warn_less $ynh_python manage.py migrate --noinput + + #================================================= + # COLLECT FILES + #================================================= + ynh_script_progression --message="Collecting files..." --weight=1 - ynh_exec_warn_less $ynh_python manage.py collectstatic --noinput + ynh_exec_warn_less $ynh_python manage.py collectstatic --noinput popd chmod 750 "$final_path" diff --git a/scripts/ynh_install_python b/scripts/ynh_install_python index 10648c4..4e03ff6 100644 --- a/scripts/ynh_install_python +++ b/scripts/ynh_install_python @@ -2,9 +2,9 @@ ynh_python_try_bash_extension() { if [ -x src/configure ]; then - src/configure && make -C src || { - ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." - } + src/configure && make -C src || { + ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." + } fi } @@ -40,13 +40,13 @@ pyenv_dependencies="make build-essential libssl-dev zlib1g-dev libbz2-dev librea # Finally, to start a Python service with the correct version, 2 solutions # Either the app is dependent of python or pip, but does not called it directly. # In such situation, you need to load PATH -# `Environment="__YNH_PYTHON_LOAD_PATH__"` -# `ExecStart=__FINALPATH__/my_app` -# You will replace __YNH_PYTHON_LOAD_PATH__ with $ynh_python_load_path +# `Environment="__YNH_PYTHON_LOAD_PATH__"` +# `ExecStart=__FINALPATH__/my_app` +# You will replace __YNH_PYTHON_LOAD_PATH__ with $ynh_python_load_path # # Or Python start the app directly, then you don't need to load the PATH variable -# `ExecStart=__YNH_PYTHON__ my_app run` -# You will replace __YNH_PYTHON__ with $ynh_python +# `ExecStart=__YNH_PYTHON__ my_app run` +# You will replace __YNH_PYTHON__ with $ynh_python # # # one other variable is also available @@ -56,32 +56,32 @@ pyenv_dependencies="make build-essential libssl-dev zlib1g-dev libbz2-dev librea # # Requires YunoHost version 3.2.2 or higher. ynh_use_python () { - python_version=$(ynh_app_setting_get --app=$app --key=python_version) + python_version=$(ynh_app_setting_get --app=$app --key=python_version) - # Get the absolute path of this version of Python - ynh_python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin" + # Get the absolute path of this version of Python + ynh_python_path="$python_version_path/$YNH_APP_INSTANCE_NAME/bin" - # Allow alias to be used into bash script - shopt -s expand_aliases + # Allow alias to be used into bash script + shopt -s expand_aliases - # Create an alias for the specific version of Python and a variable as fallback - ynh_python="$ynh_python_path/python" - alias ynh_python="$ynh_python" - # And pip - ynh_pip="$ynh_python_path/pip" - alias ynh_pip="$ynh_pip" + # Create an alias for the specific version of Python and a variable as fallback + ynh_python="$ynh_python_path/python" + alias ynh_python="$ynh_python" + # And pip + ynh_pip="$ynh_python_path/pip" + alias ynh_pip="$ynh_pip" - # Load the path of this version of Python in $PATH - if [[ :$PATH: != *":$ynh_python_path"* ]]; then - PATH="$ynh_python_path:$PATH" - fi - # Create an alias to easily load the PATH - ynh_python_load_path="PATH=$PATH" + # Load the path of this version of Python in $PATH + if [[ :$PATH: != *":$ynh_python_path"* ]]; then + PATH="$ynh_python_path:$PATH" + fi + # Create an alias to easily load the PATH + ynh_python_load_path="PATH=$PATH" - # Sets the local application-specific Python version - pushd $final_path - $pyenv_install_dir/bin/pyenv local $python_version - popd + # Sets the local application-specific Python version + pushd $final_path + $pyenv_install_dir/bin/pyenv local $python_version + popd } # Install a specific version of Python @@ -101,120 +101,120 @@ ynh_use_python () { # # Requires YunoHost version 3.2.2 or higher. ynh_install_python () { - # Declare an array to define the options of this helper. - local legacy_args=v - local -A args_array=( [v]=python_version= ) - local python_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" + # Declare an array to define the options of this helper. + local legacy_args=v + local -A args_array=( [v]=python_version= ) + local python_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Install required dependencies - ynh_add_app_dependencies --package="$pyenv_dependencies" + # Install required dependencies + ynh_add_app_dependencies --package="$pyenv_dependencies" - # Load pyenv path in PATH - local CLEAR_PATH="$pyenv_install_dir/bin:$PATH" + # Load pyenv path in PATH + local CLEAR_PATH="$pyenv_install_dir/bin:$PATH" - # Remove /usr/local/bin in PATH in case of Python prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + # Remove /usr/local/bin in PATH in case of Python prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - # Move an existing Python binary, to avoid to block pyenv - #test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv + # Move an existing Python binary, to avoid to block pyenv + #test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv - # Install or update pyenv - pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)" - if [ -n "$pyenv" ]; then - ynh_print_info --message="pyenv already seems installed in \`$pyenv'." - pushd "${pyenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then - ynh_print_info --message="Trying to update with git..." - git pull -q --tags origin master - cd .. - ynh_python_try_bash_extension - fi - popd - else - ynh_print_info --message="Installing pyenv with git..." - mkdir -p $pyenv_install_dir - pushd $pyenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_python_try_bash_extension - pyenv=$pyenv_install_dir/bin/pyenv - popd - fi + # Install or update pyenv + pyenv="$(command -v pyenv $pyenv_install_dir/bin/pyenv | head -1)" + if [ -n "$pyenv" ]; then + ynh_print_info --message="pyenv already seems installed in \`$pyenv'." + pushd "${pyenv%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv.git"; then + ynh_print_info --message="Trying to update with git..." + git pull -q --tags origin master + cd .. + ynh_python_try_bash_extension + fi + popd + else + ynh_print_info --message="Installing pyenv with git..." + mkdir -p $pyenv_install_dir + pushd $pyenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/pyenv/pyenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_python_try_bash_extension + pyenv=$pyenv_install_dir/bin/pyenv + popd + fi - pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)" - if [ -n "$pyenv_virtualenv" ]; then - ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'." - pushd "${pyenv_virtualenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv-virtualenv.git"; then - ynh_print_info --message="Trying to update pyenv-virtualenv with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing pyenv-virtualenv with git..." - mkdir -p "${pyenv_install_dir}/plugins" - git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv" - fi + pyenv_virtualenv="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-virtualenv pyenv-virtualenv | head -1)" + if [ -n "$pyenv_virtualenv" ]; then + ynh_print_info --message="\`pyenv virtualenv' command already available in \`$pyenv_virtualenv'." + pushd "${pyenv_virtualenv%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/pyenv/pyenv-virtualenv.git"; then + ynh_print_info --message="Trying to update pyenv-virtualenv with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing pyenv-virtualenv with git..." + mkdir -p "${pyenv_install_dir}/plugins" + git clone -q https://github.com/pyenv/pyenv-virtualenv.git "${pyenv_install_dir}/plugins/pyenv-virtualenv" + fi - pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)" - if [ -n "$pyenv_latest" ]; then - ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'." - pushd "${pyenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then - ynh_print_info --message="Trying to update xxenv-latest with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing xxenv-latest with git..." - mkdir -p "${pyenv_install_dir}/plugins" - git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest" - fi + pyenv_latest="$(command -v "$pyenv_install_dir"/plugins/*/bin/pyenv-latest pyenv-latest | head -1)" + if [ -n "$pyenv_latest" ]; then + ynh_print_info --message="\`pyenv latest' command already available in \`$pyenv_latest'." + pushd "${pyenv_latest%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then + ynh_print_info --message="Trying to update xxenv-latest with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing xxenv-latest with git..." + mkdir -p "${pyenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${pyenv_install_dir}/plugins/xxenv-latest" + fi - # Enable caching - mkdir -p "${pyenv_install_dir}/cache" + # Enable caching + mkdir -p "${pyenv_install_dir}/cache" - # Create shims directory if needed - mkdir -p "${pyenv_install_dir}/shims" + # Create shims directory if needed + mkdir -p "${pyenv_install_dir}/shims" - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH - # And replace the old Python binary - # test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python + # And replace the old Python binary + # test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python - # Install the requested version of Python - local final_python_version=$(pyenv latest --print $python_version) - ynh_print_info --message="Installation of Python-$python_version" - pyenv install --skip-existing $final_python_version > /dev/null 2>&1 + # Install the requested version of Python + local final_python_version=$(pyenv latest --print $python_version) + ynh_print_info --message="Installation of Python-$python_version" + pyenv install --skip-existing $final_python_version > /dev/null 2>&1 - # Store python_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version + # Store python_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=python_version --value=$python_version - # Remove app virtualenv - if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` - then - pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME - fi + # Remove app virtualenv + if `pyenv virtualenvs | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1` + then + pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME + fi - # Create app virtualenv - pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME + # Create app virtualenv + pyenv virtualenv --force $python_version $YNH_APP_INSTANCE_NAME - # Cleanup Python versions - ynh_cleanup_python + # Cleanup Python versions + ynh_cleanup_python - # Set environment for Python users - echo "#pyenv + # Set environment for Python users + echo "#pyenv export PYENV_ROOT=$pyenv_install_dir export PATH=\"$pyenv_install_dir/bin:$PATH\" eval \"\$(pyenv init -)\" #pyenv" > /etc/profile.d/pyenv.sh - # Load the environment - eval "$(pyenv init -)" + # Load the environment + eval "$(pyenv init -)" } # Remove the version of Python used by the app. @@ -223,21 +223,21 @@ eval \"\$(pyenv init -)\" # # usage: ynh_remove_python ynh_remove_python () { - local python_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=python_version) + local python_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=python_version) - # Load pyenv path in PATH - local CLEAR_PATH="$pyenv_install_dir/bin:$PATH" + # Load pyenv path in PATH + local CLEAR_PATH="$pyenv_install_dir/bin:$PATH" - # Remove /usr/local/bin in PATH in case of Python prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + # Remove /usr/local/bin in PATH in case of Python prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME + pyenv virtualenv-delete --force $YNH_APP_INSTANCE_NAME - # Remove the line for this app - ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=python_version - # Cleanup Python versions - ynh_cleanup_python + # Cleanup Python versions + ynh_cleanup_python } # Remove no more needed versions of Python used by the app. @@ -249,35 +249,35 @@ ynh_remove_python () { # usage: ynh_cleanup_python ynh_cleanup_python () { - # List required Python versions - local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') - local required_python_versions="" - for installed_app in $installed_apps - do - local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version") - if [[ $installed_app_python_version ]] - then - required_python_versions="${installed_app_python_version}\n${required_python_versions}" - fi - done + # List required Python versions + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_python_versions="" + for installed_app in $installed_apps + do + local installed_app_python_version=$(ynh_app_setting_get --app=$installed_app --key="python_version") + if [[ $installed_app_python_version ]] + then + required_python_versions="${installed_app_python_version}\n${required_python_versions}" + fi + done - # Remove no more needed Python versions - local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/') - for installed_python_version in $installed_python_versions - do - if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1` - then - ynh_print_info --message="Removing of Python-$installed_python_version" - $pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version - fi - done + # Remove no more needed Python versions + local installed_python_versions=$(pyenv versions --bare --skip-aliases | grep -Ev '/') + for installed_python_version in $installed_python_versions + do + if ! `echo ${required_python_versions} | grep "${installed_python_version}" 1>/dev/null 2>&1` + then + ynh_print_info --message="Removing of Python-$installed_python_version" + $pyenv_install_dir/bin/pyenv uninstall --force $installed_python_version + fi + done - # If none Python version is required - if [[ ! $required_python_versions ]] - then - # Remove pyenv environment configuration - ynh_print_info --message="Removing of pyenv-$pyenv_version" - ynh_secure_remove --file="$pyenv_install_dir" - ynh_secure_remove --file="/etc/profile.d/pyenv.sh" - fi + # If none Python version is required + if [[ ! $required_python_versions ]] + then + # Remove pyenv environment configuration + ynh_print_info --message="Removing of pyenv-$pyenv_version" + ynh_secure_remove --file="$pyenv_install_dir" + ynh_secure_remove --file="/etc/profile.d/pyenv.sh" + fi }