From eed8eb7bbfb5f806aa31ff5d64d054fdb61c5d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 8 Mar 2024 19:40:29 +0100 Subject: [PATCH] Manifest v2 --- .github/workflows/updater.sh | 103 -------- .github/workflows/updater.yml | 49 ---- check_process | 26 -- conf/.env | 2 +- conf/app.src | 6 - conf/libheif.src | 7 - conf/systemd.service | 6 +- doc/DISCLAIMER.md | 0 doc/DISCLAIMER_fr.md | 0 manifest.json | 58 ----- manifest.toml | 104 ++++++++ scripts/_common.sh | 445 ++++++++++++++++------------------ scripts/backup | 42 +--- scripts/change_url | 97 +------- scripts/install | 179 +++----------- scripts/remove | 98 +------- scripts/restore | 128 +++------- scripts/upgrade | 164 +++---------- tests.toml | 5 + 19 files changed, 451 insertions(+), 1068 deletions(-) delete mode 100644 .github/workflows/updater.sh delete mode 100644 .github/workflows/updater.yml delete mode 100644 check_process delete mode 100644 conf/app.src delete mode 100644 conf/libheif.src delete mode 100644 doc/DISCLAIMER.md delete mode 100644 doc/DISCLAIMER_fr.md delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh deleted file mode 100644 index 2a6f88e..0000000 --- a/.github/workflows/updater.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/bash - -#================================================= -# PACKAGE UPDATING HELPER -#================================================= - -# This script is meant to be run by GitHub Actions -# The YunoHost-Apps organisation offers a template Action to run this script periodically -# Since each app is different, maintainers can adapt its contents so as to perform -# automatic actions when a new upstream release is detected. - -#================================================= -# FETCHING LATEST RELEASE AND ITS ASSETS -#================================================= - -# Fetching information -current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') -repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') -# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) -version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) -assets="https://github.com/$repo/archive/refs/tags/$version.tar.gz" - -# Later down the script, we assume the version has only digits and dots -# Sometimes the release name starts with a "v", so let's filter it out. -# You may need more tweaks here if the upstream repository has different naming conventions. -if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then - version=${version:1} -fi - -# Setting up the environment variables -echo "Current version: $current_version" -echo "Latest release from upstream: $version" -echo "VERSION=$version" >> $GITHUB_ENV -# For the time being, let's assume the script will fail -echo "PROCEED=false" >> $GITHUB_ENV - -# Proceed only if the retrieved version is greater than the current one -if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then - echo "::warning ::No new version available" - exit 0 -# Proceed only if a PR for this new version does not already exist -elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then - echo "::warning ::A branch already exists for this update" - exit 0 -fi - -#================================================= -# UPDATE SOURCE FILES -#================================================= - -# Let's download source tarball -asset_url=$assets -echo "Handling asset at $asset_url" -src="app" - -# Create the temporary directory -tempdir="$(mktemp -d)" - -# Download sources and calculate checksum -filename=${asset_url##*/} -curl --silent -4 -L $asset_url -o "$tempdir/$filename" -checksum=$(sha256sum "$tempdir/$filename" | head -c 64) - -# Delete temporary directory -rm -rf $tempdir - -# Get extension -if [[ $filename == *.tar.gz ]]; then - extension=tar.gz -else - extension=${filename##*.} -fi - -# Rewrite source file -cat < conf/$src.src -SOURCE_URL=$asset_url -SOURCE_SUM=$checksum -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=$extension -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -EOT -echo "... conf/$src.src updated" - -#================================================= -# SPECIFIC UPDATE STEPS -#================================================= - -# Any action on the app's source code can be done. -# The GitHub Action workflow takes care of committing all changes after this script ends. - -#================================================= -# GENERIC FINALIZATION -#================================================= - -# Replace new version in manifest -echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json - -# No need to update the README, yunohost-bot takes care of it - -# The Action will proceed only if the PROCEED environment variable is set to true -echo "PROCEED=true" >> $GITHUB_ENV -exit 0 diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml deleted file mode 100644 index a56d7cb..0000000 --- a/.github/workflows/updater.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected. -# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization. -# This file should be enough by itself, but feel free to tune it to your needs. -# It calls updater.sh, which is where you should put the app-specific update steps. -name: Check for new upstream releases -on: - # Allow to manually trigger the workflow - workflow_dispatch: - # Run it every day at 6:00 UTC - schedule: - - cron: '0 6 * * *' -jobs: - updater: - runs-on: ubuntu-latest - steps: - - name: Fetch the source code - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Run the updater script - id: run_updater - run: | - # Setting up Git user - git config --global user.name 'yunohost-bot' - git config --global user.email 'yunohost-bot@users.noreply.github.com' - # Run the updater script - /bin/bash .github/workflows/updater.sh - - name: Commit changes - id: commit - if: ${{ env.PROCEED == 'true' }} - run: | - git commit -am "Upgrade to v$VERSION" - - name: Create Pull Request - id: cpr - if: ${{ env.PROCEED == 'true' }} - uses: peter-evans/create-pull-request@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Update to version ${{ env.VERSION }} - committer: 'yunohost-bot ' - author: 'yunohost-bot ' - signoff: false - base: testing - branch: ci-auto-update-v${{ env.VERSION }} - delete-branch: true - title: 'Upgrade to version ${{ env.VERSION }}' - body: | - Upgrade to v${{ env.VERSION }} - draft: false diff --git a/check_process b/check_process deleted file mode 100644 index 9047380..0000000 --- a/check_process +++ /dev/null @@ -1,26 +0,0 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - -;; Test complet - ; Manifest - domain="domain.tld" (DOMAIN) - is_public=1 (PUBLIC|public=1|private=0) - mapbox_token= - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none -;;; Upgrade options diff --git a/conf/.env b/conf/.env index 5b591d4..286662d 100644 --- a/conf/.env +++ b/conf/.env @@ -8,7 +8,7 @@ PHOTOVIEW_LISTEN_PORT=__PORT__ PHOTOVIEW_API_ENDPOINT=https://__DOMAIN__/ PHOTOVIEW_UI_ENDPOINT=https://__DOMAIN__/ # Path where media should be cached -PHOTOVIEW_MEDIA_CACHE=__DATA_PATH__/media_cache +PHOTOVIEW_MEDIA_CACHE=__DATA_DIR__/media_cache # Set to 1 for the server to also serve the built static ui files PHOTOVIEW_SERVE_UI=1 diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index f88f803..0000000 --- a/conf/app.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://github.com/photoview/photoview/archive/refs/tags/v2.3.12.tar.gz -SOURCE_SUM=f9de00fb2d854217655a71264c06f8451b06b67170d3a5bbd9160fc94f1dda0f -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/libheif.src b/conf/libheif.src deleted file mode 100644 index 24a3d49..0000000 --- a/conf/libheif.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz -SOURCE_SUM=e1ac2abb354fdc8ccdca71363ebad7503ad731c84022cf460837f0839e171718 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=libheif-1.12.0.tar.gz -SOURCE_EXTRACT=true diff --git a/conf/systemd.service b/conf/systemd.service index ff1b5fc..d773d7d 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,9 +6,9 @@ After=network.target mysql.service Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__/output -EnvironmentFile=__FINALPATH__/output/.env -ExecStart=/usr/bin/env bash -c "LD_LIBRARY_PATH=__FINALPATH__/local/lib:$LD_LIBRARY_PATH __FINALPATH__/output/photoview" +WorkingDirectory=__INSTALL_DIR__/output +EnvironmentFile=__INSTALL_DIR__/output/.env +ExecStart=/usr/bin/env bash -c "LD_LIBRARY_PATH=__INSTALL_DIR__/local/lib:$LD_LIBRARY_PATH __INSTALL_DIR__/output/photoview" StandardOutput=append:/var/log/__APP__/__APP__.log StandardError=inherit diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e69de29..0000000 diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md deleted file mode 100644 index e69de29..0000000 diff --git a/manifest.json b/manifest.json deleted file mode 100644 index d75bb6a..0000000 --- a/manifest.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "name": "Photoview", - "id": "photoview", - "packaging_format": 1, - "description": { - "en": "Simple and user-friendly photo gallery that's made for photographers ", - "fr": "Galerie photos simple et facile à utiliser, faite pour les photographes" - }, - "version": "2.3.12~ynh1", - "url": "https://photoview.github.io/", - "upstream": { - "license": "AGPL-3.0-only", - "website": "https://photoview.github.io/", - "demo": "https://photos.qpqp.dk/", - "admindoc": "https://photoview.github.io/docs/", - "code": "https://github.com/photoview/photoview" - }, - "license": "AGPL-3.0-only", - "maintainer": { - "name": "Jules Bertholet", - "email": "jules.bertholet@gmail.com" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": true, - "services": [ - "nginx", - "mysql" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "default": true - }, - { - "name": "mapbox_token", - "type": "string", - "default": "", - "optional": true, - "ask": { - "en": "Mapbox API token", - "fr": "Clé API Mapbox" - }, - "help": { - "en": "Required for mapping features. You can get one for free at https://www.mapbox.com/", - "fr": "Nécessaire pour les fonctionnalités cartographiques. Vous pouvez en obtenir une gratuitement à https://www.mapbox.com/" - } - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..a3fe07d --- /dev/null +++ b/manifest.toml @@ -0,0 +1,104 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "photoview" +name = "Photoview" +description.en = "Simple and user-friendly photo gallery that's made for photographers " +description.fr = "Galerie photos simple et facile à utiliser, faite pour les photographes" + +version = "2.3.12~ynh1" + +maintainers = ["Jules Bertholet"] + +[upstream] +license = "AGPL-3.0-only" +website = "https://photoview.github.io/" +demo = "https://photos.qpqp.dk/" +admindoc = "https://photoview.github.io/docs/" +code = "https://github.com/photoview/photoview" +fund = "https://github.com/sponsors/viktorstrate" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true +ldap = false +sso = false +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + type = "domain" + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.mapbox_token] + ask.en = "Mapbox API token" + ask.fr = "Clé API Mapbox" + help.en = "Required for mapping features. You can get one for free at https://www.mapbox.com/" + help.fr = "Nécessaire pour les fonctionnalités cartographiques. Vous pouvez en obtenir une gratuitement à https://www.mapbox.com/" + type = "string" + default = "" + optional = true + +[resources] + [resources.sources] + [resources.sources.main] + url = "https://github.com/photoview/photoview/archive/refs/tags/v2.3.12.tar.gz" + sha256 = "f9de00fb2d854217655a71264c06f8451b06b67170d3a5bbd9160fc94f1dda0f" + + autoupdate.strategy = "latest_github_release" + + [resources.sources.libheif] + url = "https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz" + sha256 = "e1ac2abb354fdc8ccdca71363ebad7503ad731c84022cf460837f0839e171718" + + autoupdate.strategy = "latest_github_release" + + [resources.system_user] + + [resources.install_dir] + + [resources.data_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 4001 + + [resources.apt] + packages = [ + "curl", + "gpg", + "libdlib19", + "ffmpeg", + "exiftool", + "libheif1", + "ca-certificates", + "golang", + "libdlib-dev", + "libblas-dev", + "libatlas-base-dev", + "liblapack-dev", + "libjpeg-dev", + "libheif-dev", + "build-essential", + "pkg-config", + "autoconf", + "automake", + "libx265-dev", + "libde265-dev", + "libaom-dev", + # "darktable", + + "mariadb-server", + ] + + [resources.database] + type = "mysql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 9b271f0..8430406 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,128 +4,107 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="curl gpg libdlib19 ffmpeg exiftool libheif1 ca-certificates golang libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg-dev libheif-dev build-essential pkg-config autoconf automake libx265-dev libde265-dev libaom-dev" - -if ! (apt-cache -q=0 show darktable |& grep ': No packages found' &>/dev/null); then - pkg_dependencies="$pkg_dependencies darktable" -fi +go_version=1.16 +node_version=16 #================================================= # PERSONAL HELPERS #================================================= -function install_dependencies { - ynh_install_app_dependencies $pkg_dependencies - ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -} - -function setup_sources { - ynh_secure_remove "$final_path" - ynh_setup_source --dest_dir="$final_path" - ynh_setup_source --source_id=libheif --dest_dir="$final_path/libheif" - - set_permissions -} - -function build_libheif { - export GOPATH="$final_path/build/go" - export GOCACHE="$final_path/build/.cache" - - pushd "$final_path/libheif" || ynh_die - chown -R $app:$app "$final_path/libheif" - mkdir -p "$final_path/local" - chown -R $app:$app "$final_path/libheif" - chown -R $app:$app "$final_path/local" - sudo -u $app "$final_path/libheif/autogen.sh" 2>&1 - sudo -u $app "$final_path/libheif/configure" --prefix="$final_path/local" --disable-gdk-pixbuf 2>&1 - make clean 2>&1 - make 2>&1 - make install 2>&1 - make clean 2>&1 - popd || ynh_die - - set_permissions -} - function set_go_vars { - ynh_install_go --go_version=1.16 - ynh_use_go + ynh_use_go - export GOPATH="$final_path/build/go" - export GOCACHE="$final_path/build/.cache" + export GOPATH="$install_dir/build/go" + export GOCACHE="$install_dir/build/.cache" - go_shims_path=$goenv_install_dir/shims - go_path_full="$go_shims_path":"$(sudo -u $app bash -c 'echo $PATH')" - heif_lib_path="$final_path/local/lib":"$(sudo -u $app bash -c 'echo $LIBRARY_PATH')" - heif_ld_lib_path="$final_path/local/lib":"$(sudo -u $app bash -c 'echo $LD_LIBRARY_PATH')" - heif_cgo_cflags="-I$final_path/local/include" -} - -function build_api { - set_go_vars - - pushd "$final_path/api" || ynh_die - chown -R $app:$app "$final_path" - set +e - for i in {1..5}; do - sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go mod download 2>&1 && break - sleep 5 - done - set -e - sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go install github.com/mattn/go-sqlite3 github.com/Kagami/go-face 2>&1 - sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version go build -o photoview "$final_path/api" 2>&1 - popd || ynh_die - - cp -T "$final_path/api/photoview" "$final_path/output/photoview" - cp -rT "$final_path/api/data" "$final_path/output/data" - set_permissions -} - -function build_ui { - set_node_vars - - ui_path="$final_path/ui" - - ynh_replace_string -m "npm" -r "yarn" -f "$ui_path/package.json" - ynh_replace_string -m "npx" -r "yarn run" -f "$ui_path/package.json" - ynh_replace_string -m "cd .. && " -r "" -f "$ui_path/package.json" - - pushd "$ui_path" || ynh_die - chown -R $app:$app $final_path - sudo -u $app touch $ui_path/.yarnrc - sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" import 2>&1 - sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add husky 2>&1 - sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" install 2>&1 - sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add graphql --ignore-engines 2>&1 - sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" run build --public-url "$path_url" 2>&1 - popd || ynh_die - - cp -rT "$final_path/ui/build" "$final_path/output/ui" - - set_permissions + go_shims_path=$goenv_install_dir/shims + go_path_full="$go_shims_path":"$(sudo -u $app bash -c 'echo $PATH')" + heif_lib_path="$install_dir/local/lib":"$(sudo -u $app bash -c 'echo $LIBRARY_PATH')" + heif_ld_lib_path="$install_dir/local/lib":"$(sudo -u $app bash -c 'echo $LD_LIBRARY_PATH')" + heif_cgo_cflags="-I$install_dir/local/include" } function set_node_vars { - nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version) - if [ $nodejs_version -ne 16 ]; then - ynh_exec_warn_less ynh_remove_nodejs - fi - ynh_exec_warn_less ynh_install_nodejs --nodejs_version=16 - ynh_use_nodejs - node_path=$nodejs_path:$(sudo -u $app sh -c 'echo $PATH') + ynh_use_nodejs + node_path=$nodejs_path:$(sudo -u $app sh -c 'echo $PATH') } function set_permissions { - mkdir -p "$final_path/output/"{data,ui} - chown -R root:$app $final_path - chmod -R g=u,g-w,o-rwx "$final_path" + mkdir -p "$install_dir/output/"{data,ui} + chown -R "root:$app" "$install_dir" + chmod -R g=u,g-w,o-rwx "$install_dir" - mkdir -p "$data_path/media_cache" - chown -R $app:$app "$data_path" + mkdir -p "$data_dir/media_cache" + chown -R "$app:$app" "$data_dir" - mkdir -p /var/log/$app - chmod -R o-rwx /var/log/$app + mkdir -p "/var/log/$app" + chmod -R o-rwx "/var/log/$app" +} + +function build_libheif { + export GOPATH="$install_dir/build/go" + export GOCACHE="$install_dir/build/.cache" + + pushd "$install_dir/libheif" || ynh_die + # mkdir -p "$install_dir/local" + # chown -R $app:$app "$install_dir/local" + ynh_exec_as "$app" ./autogen.sh 2>&1 + ynh_exec_as "$app" ./configure --prefix="$install_dir/local" --disable-gdk-pixbuf 2>&1 + ynh_exec_as "$app" make clean 2>&1 + ynh_exec_as "$app" make 2>&1 + ynh_exec_as "$app" make install 2>&1 + ynh_exec_as "$app" make clean 2>&1 + popd || ynh_die +} + +function build_api { + set_go_vars + + gobuild_env=( + "PATH=$go_path_full" + "LIBRARY_PATH=$heif_lib_path" + "LD_LIBRARY_PATH=$heif_ld_lib_path" + "CGO_CFLAGS=$heif_cgo_cflags" + "GOENV_VERSION=$go_version" + CGO_ENABLED=1 + ) + + pushd "$install_dir/sources/api" || ynh_die + set +e + for i in {1..5}; do + ynh_exec_as "$app" env "${gobuild_env[@]}" go mod download 2>&1 && break + sleep 5 + done + set -e + ynh_exec_as "$app" env "${gobuild_env[@]}" go install github.com/mattn/go-sqlite3 github.com/Kagami/go-face 2>&1 + ynh_exec_as "$app" env "${gobuild_env[@]}" go build -o photoview . 2>&1 + popd || ynh_die + + cp -T "$install_dir/sources/api/photoview" "$install_dir/output/photoview" + cp -rT "$install_dir/sources/api/data" "$install_dir/output/data" + set_permissions +} + +function build_ui { + set_node_vars + + ui_path="$install_dir/sources/ui" + + ynh_replace_string -m "npm" -r "yarn" -f "$ui_path/package.json" + ynh_replace_string -m "npx" -r "yarn run" -f "$ui_path/package.json" + ynh_replace_string -m "cd .. && " -r "" -f "$ui_path/package.json" + + pushd "$ui_path" || ynh_die + # chown -R "$app:$app" $install_dir + ynh_exec_as "$app" touch "$ui_path/.yarnrc" + ynh_exec_as "$app" env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" import 2>&1 + ynh_exec_as "$app" env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add husky 2>&1 + ynh_exec_as "$app" env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" install 2>&1 + ynh_exec_as "$app" env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add graphql --ignore-engines 2>&1 + ynh_exec_as "$app" env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" run build --public-url "$path" 2>&1 + popd || ynh_die + + cp -rT "$ui_path/build" "$install_dir/output/ui" } #================================================= @@ -135,11 +114,11 @@ function set_permissions { #!/bin/bash ynh_go_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." - } - fi + 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." + } + fi } goenv_install_dir="/opt/goenv" @@ -164,14 +143,14 @@ export GOENV_ROOT="$goenv_install_dir" # However, $PATH is duplicated into $go_path to outlast any manipulation of $PATH # You can use the variable `$ynh_go_load_path` to quickly load your Go version # in $PATH for an usage into a separate script. -# Exemple: $ynh_go_load_path $final_path/script_that_use_gem.sh` +# Exemple: $ynh_go_load_path $install_dir/script_that_use_gem.sh` # # # Finally, to start a Go service with the correct version, 2 solutions # Either the app is dependent of Go or gem, but does not called it directly. # In such situation, you need to load PATH # `Environment="__YNH_GO_LOAD_ENV_PATH__"` -# `ExecStart=__FINALPATH__/my_app` +# `ExecStart=__INSTALL_DIR__/my_app` # You will replace __YNH_GO_LOAD_ENV_PATH__ with $ynh_go_load_path # # Or Go start the app directly, then you don't need to load the PATH variable @@ -186,29 +165,29 @@ export GOENV_ROOT="$goenv_install_dir" # # Requires YunoHost version 3.2.2 or higher. ynh_use_go() { - go_version=$(ynh_app_setting_get --app=$app --key=go_version) + go_version=$(ynh_app_setting_get --app=$app --key=go_version) - # Get the absolute path of this version of Go - go_path="$go_version_path/$go_version/bin" + # Get the absolute path of this version of Go + go_path="$go_version_path/$go_version/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 Go and a variable as fallback - ynh_go="$go_path/go" - alias ynh_go="$ynh_go" + # Create an alias for the specific version of Go and a variable as fallback + ynh_go="$go_path/go" + alias ynh_go="$ynh_go" - # Load the path of this version of Go in $PATH - if [[ :$PATH: != *":$go_path"* ]]; then - PATH="$go_path:$PATH" - fi - # Create an alias to easily load the PATH - ynh_go_load_path="PATH=$PATH" + # Load the path of this version of Go in $PATH + if [[ :$PATH: != *":$go_path"* ]]; then + PATH="$go_path:$PATH" + fi + # Create an alias to easily load the PATH + ynh_go_load_path="PATH=$PATH" - # Sets the local application-specific Go version - pushd $final_path - $goenv_install_dir/bin/goenv local $go_version - popd + # Sets the local application-specific Go version + pushd $install_dir + $goenv_install_dir/bin/goenv local $go_version + popd } # Install a specific version of Go @@ -228,93 +207,93 @@ ynh_use_go() { # # Requires YunoHost version 3.2.2 or higher. ynh_install_go() { - # Declare an array to define the options of this helper. - local legacy_args=v - local -A args_array=([v]=go_version=) - local go_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]=go_version=) + local go_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" - # Load goenv path in PATH - local CLEAR_PATH="$goenv_install_dir/bin:$PATH" + # Load goenv path in PATH + local CLEAR_PATH="$goenv_install_dir/bin:$PATH" - # Remove /usr/local/bin in PATH in case of Go prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + # Remove /usr/local/bin in PATH in case of Go prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - # Move an existing Go binary, to avoid to block goenv - test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv + # Move an existing Go binary, to avoid to block goenv + test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv - # Install or update goenv - goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)" - if [ -n "$goenv" ]; then - ynh_print_info --message="goenv already seems installed in \`$goenv'." - pushd "${goenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then - echo "Trying to update with git..." - git pull -q --tags origin master - cd .. - ynh_go_try_bash_extension - fi - popd - else - ynh_print_info --message="Installing goenv with git..." - mkdir -p $goenv_install_dir - pushd $goenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/syndbg/goenv.git >/dev/null 2>&1 - git checkout -q -b master origin/master - ynh_go_try_bash_extension - goenv=$goenv_install_dir/bin/goenv - popd - fi + # Install or update goenv + goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)" + if [ -n "$goenv" ]; then + ynh_print_info --message="goenv already seems installed in \`$goenv'." + pushd "${goenv%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then + echo "Trying to update with git..." + git pull -q --tags origin master + cd .. + ynh_go_try_bash_extension + fi + popd + else + ynh_print_info --message="Installing goenv with git..." + mkdir -p $goenv_install_dir + pushd $goenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/syndbg/goenv.git >/dev/null 2>&1 + git checkout -q -b master origin/master + ynh_go_try_bash_extension + goenv=$goenv_install_dir/bin/goenv + popd + fi - goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)" - if [ -n "$goenv_latest" ]; then - ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'." - pushd "${goenv_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 "${goenv_install_dir}/plugins" - git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest" - fi + goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)" + if [ -n "$goenv_latest" ]; then + ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'." + pushd "${goenv_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 "${goenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest" + fi - # Enable caching - mkdir -p "${goenv_install_dir}/cache" + # Enable caching + mkdir -p "${goenv_install_dir}/cache" - # Create shims directory if needed - mkdir -p "${goenv_install_dir}/shims" + # Create shims directory if needed + mkdir -p "${goenv_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 Go binary - test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go + # And replace the old Go binary + test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go - # Install the requested version of Go - local final_go_version=$(goenv latest --print $go_version) - ynh_print_info --message="Installation of Go-$final_go_version" - goenv install --skip-existing $final_go_version + # Install the requested version of Go + local final_go_version=$(goenv latest --print $go_version) + ynh_print_info --message="Installation of Go-$final_go_version" + goenv install --skip-existing $final_go_version - # Store go_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version + # Store go_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version - # Cleanup Go versions - ynh_cleanup_go + # Cleanup Go versions + ynh_cleanup_go - # Set environment for Go users - echo "#goenv + # Set environment for Go users + echo "#goenv export GOENV_ROOT=$goenv_install_dir export PATH=\"$goenv_install_dir/bin:$PATH\" eval \"\$(goenv init -)\" #goenv" >/etc/profile.d/goenv.sh - # Load the environment - eval "$(goenv init -)" + # Load the environment + eval "$(goenv init -)" } # Remove the version of Go used by the app. @@ -323,19 +302,19 @@ eval \"\$(goenv init -)\" # # usage: ynh_remove_go ynh_remove_go() { - local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version) + local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version) - # Load goenv path in PATH - local CLEAR_PATH="$goenv_install_dir/bin:$PATH" + # Load goenv path in PATH + local CLEAR_PATH="$goenv_install_dir/bin:$PATH" - # Remove /usr/local/bin in PATH in case of Go prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + # Remove /usr/local/bin in PATH in case of Go prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - # Remove the line for this app - ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version - # Cleanup Go versions - ynh_cleanup_go + # Cleanup Go versions + ynh_cleanup_go } # Remove no more needed versions of Go used by the app. @@ -347,32 +326,32 @@ ynh_remove_go() { # usage: ynh_cleanup_go ynh_cleanup_go() { - # List required Go versions - local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') - local required_go_versions="" - for installed_app in $installed_apps; do - local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") - if [[ $installed_app_go_version ]]; then - required_go_versions="${installed_app_go_version}\n${required_go_versions}" - fi - done + # List required Go versions + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_go_versions="" + for installed_app in $installed_apps; do + local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") + if [[ $installed_app_go_version ]]; then + required_go_versions="${installed_app_go_version}\n${required_go_versions}" + fi + done - # Remove no more needed Go versions - local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/') - for installed_go_version in $installed_go_versions; do - if ! $(echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1); then - ynh_print_info --message="Removing of Go-$installed_go_version" - $goenv_install_dir/bin/goenv uninstall --force $installed_go_version - fi - done + # Remove no more needed Go versions + local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/') + for installed_go_version in $installed_go_versions; do + if ! $(echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1); then + ynh_print_info --message="Removing of Go-$installed_go_version" + $goenv_install_dir/bin/goenv uninstall --force $installed_go_version + fi + done - # If none Go version is required - if [[ ! $required_go_versions ]]; then - # Remove goenv environment configuration - ynh_print_info --message="Removing of goenv" - ynh_secure_remove --file="$goenv_install_dir" - ynh_secure_remove --file="/etc/profile.d/goenv.sh" - fi + # If none Go version is required + if [[ ! $required_go_versions ]]; then + # Remove goenv environment configuration + ynh_print_info --message="Removing of goenv" + ynh_secure_remove --file="$goenv_install_dir" + ynh_secure_remove --file="/etc/profile.d/goenv.sh" + fi } #================================================= diff --git a/scripts/backup b/scripts/backup index 8a1d93f..89c91f6 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,28 +8,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -41,33 +17,29 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE APP DATA DIR #================================================= -ynh_backup --src_path="$data_path" --is_big +ynh_backup --src_path="$data_dir" --is_big #================================================= -# BACKUP THE NGINX CONFIGURATION +# BACKUP THE SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= -# BACKUP SYSTEMD +# BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup --src_path="/var/log/$app/" #================================================= # BACKUP THE MYSQL DATABASE diff --git a/scripts/change_url b/scripts/change_url index 773a160..131f5d3 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,116 +7,33 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path="/" - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -# Add settings here as needed by your application -domain=$new_domain -path_url=$new_path -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -port=$(ynh_app_setting_get --app=$app --key=port) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -mapbox_token=$(ynh_app_setting_get --app=$app --key=mapbox_token) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=35 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 - -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +ynh_change_url_nginx_config -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - -#================================================= -# SPECIFIC MODIFICATIONS #================================================= # ADD A CONFIGURATION #================================================= -ynh_add_config --template=".env" --destination="$final_path/output/.env" +ynh_add_config --template=".env" --destination="$install_dir/output/.env" -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 5d82380..c9a91cb 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,186 +8,73 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INSTALL GO #================================================= +ynh_script_progression --message="Installing Go..." --weight=10 -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +ynh_install_go --go_version="$go_version" #================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST +# INSTALL NODEJS #================================================= +ynh_script_progression --message="Installing NodeJS..." --weight=10 -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -is_public=$YNH_APP_ARG_IS_PUBLIC -mapbox_token=$YNH_APP_ARG_MAPBOX_TOKEN - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -final_path=/opt/yunohost/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -data_path=/home/yunohost.app/$app - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=mapbox_token --value=$mapbox_token - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -port=$(ynh_find_port --port=4001) -ynh_app_setting_set --app=$app --key=port --value=$port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=60 - -install_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" - -#================================================= -# CREATE A MYSQL DATABASE -#================================================= -ynh_script_progression --message="Creating a MySQL database..." --weight=1 - -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name +ynh_install_nodejs --nodejs_version="$node_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=10 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path -ynh_app_setting_set --app=$app --key=data_path --value=$data_path -# Download, check integrity, uncompress and patch the source from app.src -setup_sources +ynh_setup_source --dest_dir="$install_dir/sources" +ynh_setup_source --source_id=libheif --dest_dir="$install_dir/libheif" + +chown -R "$app:$app" "$install_dir" #================================================= -# NGINX CONFIGURATION +# BUILD APP #================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC SETUP -#================================================= -# BUILD LIBHEIF -#================================================= -ynh_script_progression --message="Compiling libheif..." --weight=70 - +ynh_script_progression --message="Compiling libheif..." --weight=10 build_libheif -#================================================= -# BUILD API -#================================================= -ynh_script_progression --message="Compiling Go API..." --weight=165 - +ynh_script_progression --message="Compiling Go API..." --weight=10 build_api -#================================================= -# BUILD UI -#================================================= -ynh_script_progression --message="Building static UI files..." --weight=45 - +ynh_script_progression --message="Building static UI files..." --weight=10 build_ui -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# ADD A CONFIGURATION -#================================================= -ynh_script_progression --message="Adding a configuration file..." - -ynh_add_config --template=".env" --destination="$final_path/output/.env" - set_permissions #================================================= -# GENERIC FINALIZATION +# ADD A CONFIGURATION #================================================= -# SETUP LOGROTATE +ynh_script_progression --message="Adding $app's configuration file..." + +ynh_add_config --template=".env" --destination="$install_dir/output/.env" +chown "$app:$app" "$install_dir/output/.env" + #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config +yunohost service add "$app" --description="Photoview photo manager API" --log="/var/log/$app/$app.log" # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Photoview photo manager API" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" -fi - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index c040eff..f34c36a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,111 +8,35 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Removing the MySQL database..." --weight=1 - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE DATA DIR -#================================================= - -# Remove the data directory if --purge option is used -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then - ynh_script_progression --message="Removing app data directory..." --time --weight=1 - ynh_secure_remove --file="$data_path" -fi - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 - # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=5 - -# Remove metapackage and its dependencies -ynh_remove_go -ynh_remove_nodejs -ynh_remove_app_dependencies - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= - -# Remove the log files +# Remove other various files specific to the app... such as : ynh_secure_remove --file="/var/log/$app" #================================================= -# GENERIC FINALIZATION +# REMOVE DEPENDENCIES #================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 +ynh_script_progression --message="Removing Go..." --weight=5 +ynh_remove_go -# Delete a system user -ynh_system_user_delete --username=$app +ynh_script_progression --message="Removing NodeJS..." --weight=5 +ynh_remove_nodejs #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 5c0042c..e245f49 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -11,133 +9,71 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INSTALL GO #================================================= +ynh_script_progression --message="Reinstalling Go..." --weight=10 -ynh_clean_setup() { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +ynh_install_go --go_version="$go_version" #================================================= -# LOAD SETTINGS +# INSTALL NODEJS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression --message="Reinstalling NodeJS..." --weight=10 -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -port=$(ynh_app_setting_get --app=$app --key=port) -mapbox_token=$(ynh_app_setting_get --app=$app --key=mapbox_token) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_install_nodejs --nodejs_version="$node_version" #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" - -set_permissions +ynh_restore_file --origin_path="$install_dir" #================================================= # RESTORE THE APP DATA DIR #================================================= ynh_script_progression --message="Restoring the app data directory..." --weight=1 -ynh_restore_file --origin_path="$data_path" --not_mandatory - -set_permissions - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=30 - -# Define and install dependencies -install_dependencies -set_go_vars -set_node_vars +ynh_restore_file --origin_path="$data_dir" --not_mandatory #================================================= # RESTORE THE MYSQL DATABASE #================================================= ynh_script_progression --message="Restoring the MySQL database..." --weight=1 -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql #================================================= -# RESTORE SYSTEMD +# SPECIFIC RESTORATION + +set_go_vars +set_node_vars + #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +# RESTORE VARIOUS FILES +#================================================= + +ynh_restore_file --origin_path="/var/log/$app/" + +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description="Photoview photo manager API" --log="/var/log/$app/$app.log" ynh_restore_file --origin_path="/etc/logrotate.d/$app" -set_permissions +#================================================= +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE +#================================================= +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Photoview photo manager API" --log="/var/log/$app/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 0c5ecb2..acf1fdd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,145 +7,68 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -port=$(ynh_app_setting_get --app=$app --key=port) -mapbox_token=$(ynh_app_setting_get --app=$app --key=mapbox_token) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=30 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public +if [ ! -d "$install_dir/sources" ]; then + # Final cleanup... + ynh_secure_remove --file="$install_dir" + mkdir -p "$install_dir" + chmod 750 "$install_dir" fi #================================================= -# CREATE DEDICATED USER +# INSTALL GO #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_script_progression --message="Upgrading Go..." --weight=10 -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_install_go --go_version="$go_version" + +#================================================= +# INSTALL NODEJS +#================================================= +ynh_script_progression --message="Upgrading NodeJS..." --weight=10 + +ynh_install_nodejs --nodejs_version="$node_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=5 -if [ "$upgrade_type" == "UPGRADE_APP" ]; then - ynh_script_progression --message="Upgrading source files..." --weight=5 +ynh_setup_source --dest_dir="$install_dir/sources" --full_replace=1 +ynh_setup_source --source_id=libheif --dest_dir="$install_dir/libheif" --full_replace=1 - setup_sources -fi +chown -R "$app:$app" "$install_dir" -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -install_dependencies - -#================================================= -# SPECIFIC UPGRADE #================================================= # BUILD APP #================================================= +ynh_script_progression --message="Compiling libheif..." --weight=70 +build_libheif -if [ "$upgrade_type" == "UPGRADE_APP" ]; then - #================================================= - # BUILD LIBHEIF - #================================================= - ynh_script_progression --message="Compiling libheif..." --weight=70 +ynh_script_progression --message="Compiling Go API..." --weight=165 +build_api - build_libheif - - #================================================= - # BUILD API - #================================================= - ynh_script_progression --message="Compiling Go API..." --weight=165 - - build_api - - #================================================= - # BUILD UI - #================================================= - ynh_script_progression --message="Building static UI files..." --weight=45 - - build_ui -fi - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 - -# Create a dedicated systemd config -ynh_add_systemd_config +ynh_script_progression --message="Building static UI files..." --weight=45 +build_ui #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." -ynh_add_config --template=".env" --destination="$final_path/output/.env" +ynh_add_config --template=".env" --destination="$install_dir/output/.env" -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= @@ -156,33 +77,26 @@ ynh_add_config --template=".env" --destination="$final_path/output/.env" set_permissions #================================================= -# SETUP LOGROTATE +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config +yunohost service add "$app" --description="Photoview photo manager API" --log="/var/log/$app/$app.log" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Photoview photo manager API" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..94abb79 --- /dev/null +++ b/tests.toml @@ -0,0 +1,5 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default]