1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/syncserver-rs_ynh.git synced 2024-09-03 20:26:32 +02:00

Aligned with Artemis doc.

This commit is contained in:
orhtej2 2023-10-09 15:03:06 +02:00
parent d59decc543
commit 907fe67d3d
15 changed files with 86 additions and 424 deletions

View file

@ -1,85 +1,43 @@
# Packaging an app, starting from this example
* Copy this app before working on it, using the ['Use this template'](https://github.com/YunoHost/example_ynh/generate) button on the Github repo.
* Edit the `manifest.toml` with app specific info.
* Edit the `install`, `upgrade`, `remove`, `backup` and `restore` scripts, and any relevant conf files in `conf/`.
* Using the [script helpers documentation.](https://yunohost.org/packaging_apps_helpers)
* Edit the `change_url` and `config` scripts too, or remove them if you have no use of them
* Add a `LICENSE` file for the package. NB: this LICENSE file is not meant to necessarily be the LICENSE of the upstream app - it is only the LICENSE you want this package's code to published with ;). We recommend to use [the AGPL-3](https://www.gnu.org/licenses/agpl-3.0.txt).
* Edit `doc/DISCLAIMER*.md`
* The `README.md` files are to be automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
---
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
# Example app for YunoHost
# Firefox Sync Storage-rs for YunoHost
[![Integration level](https://dash.yunohost.org/integration/example.svg)](https://dash.yunohost.org/appci/app/example) ![Working status](https://ci-apps.yunohost.org/ci/badges/example.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/example.maintain.svg)
[![Install Example app with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=example)
[![Integration level](https://dash.yunohost.org/integration/syncstorage-rs.svg)](https://dash.yunohost.org/appci/app/syncstorage-rs) ![Working status](https://ci-apps.yunohost.org/ci/badges/syncstorage-rs.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/syncstorage-rs.maintain.svg)
*[Lire ce readme en français.](./README_fr.md)*
[![Install Firefox Sync Storage-rs with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=syncstorage-rs)
> *This package allows you to install Example app quickly and simply on a YunoHost server.
*[Lire ce readme en fran<61>ais.](./README_fr.md)*
> *This package allows you to install Firefox Sync Storage-rs quickly and simply on a YunoHost server.
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
## Overview
Some long and extensive description of what the app is and does, lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
### Features
- Ut enim ad minim veniam, quis nostrud exercitation ullamco ;
- Laboris nisi ut aliquip ex ea commodo consequat ;
- Duis aute irure dolor in reprehenderit in voluptate ;
- Velit esse cillum dolore eu fugiat nulla pariatur ;
- Excepteur sint occaecat cupidatat non proident, sunt in culpa."
Second-generation server for Firefox Sync written in Rust.
**Shipped version:** 1.0~ynh1
**Demo:** https://demo.example.com
## Screenshots
![Screenshot of Example app](./doc/screenshots/example.jpg)
## Disclaimers / important information
* Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?
* not-working single-sign on or LDAP integration ?
* the app requires an important amount of RAM / disk / .. to install or to work properly
* etc...
* Other infos that people should be aware of, such as:
* any specific step to perform after installing (such as manually finishing the install, specific admin credentials, ...)
* how to configure / administrate the application if it ain't obvious
* upgrade process / specificities / things to be aware of ?
* security considerations ?
**Shipped version:**
## Documentation and resources
* Official app website: <https://example.com>
* Official user documentation: <https://yunohost.org/apps>
* Official admin documentation: <https://yunohost.org/packaging_apps>
* Upstream app code repository: <https://some.forge.com/example/example>
* YunoHost documentation for this app: <https://yunohost.org/app_example>
* Report a bug: <https://github.com/YunoHost-Apps/example_ynh/issues>
* Official app website: <https://www.mozilla.org/en-GB/firefox/features/sync/>
* Official admin documentation: <https://github.com/mozilla-services/syncstorage-rs/blob/master/docs/config.md>
* Upstream app code repository: <https://github.com/mozilla-services/syncstorage-rs>
* YunoHost documentation for this app: <https://yunohost.org/app_syncstorage-rs>
* Report a bug: <https://github.com/YunoHost-Apps/syncstorage-rs_ynh/issues>
## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/example_ynh/tree/testing).
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/syncstorage-rs_ynh/tree/testing).
To try the testing branch, please proceed like that.
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/example_ynh/tree/testing --debug
sudo yunohost app install https://github.com/YunoHost-Apps/syncstorage-rs_ynh/tree/testing --debug
or
sudo yunohost app upgrade example -u https://github.com/YunoHost-Apps/example_ynh/tree/testing --debug
sudo yunohost app upgrade syncstorage-rs -u https://github.com/YunoHost-Apps/syncstorage-rs_ynh/tree/testing --debug
```
**More info regarding app packaging:** <https://yunohost.org/packaging_apps>

View file

@ -3,71 +3,41 @@ N.B.: This README was automatically generated by https://github.com/YunoHost/app
It shall NOT be edited by hand.
-->
# Exemple d'app pour YunoHost
# Firefox Sync Storage-rs pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/example.svg)](https://dash.yunohost.org/appci/app/example) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/example.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/example.maintain.svg)
[![Installer Example app avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=example)
[![Niveau dintégration](https://dash.yunohost.org/integration/syncstorage-rs.svg)](https://dash.yunohost.org/appci/app/syncstorage-rs) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/syncstorage-rs.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/syncstorage-rs.maintain.svg)
[![Installer Firefox Sync Storage-rs avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=syncstorage-rs)
*[Read this readme in english.](./README.md)*
> *Ce package vous permet d'installer Example app rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
> *Ce package vous permet dinstaller Firefox Sync Storage-rs rapidement et simplement sur un serveur YunoHost.
Si vous navez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment linstaller et en profiter.*
## Vue d'ensemble
## Vue densemble
Some long and extensive description of what the app is and does, lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
### Features
- Ut enim ad minim veniam, quis nostrud exercitation ullamco ;
- Laboris nisi ut aliquip ex ea commodo consequat ;
- Duis aute irure dolor in reprehenderit in voluptate ;
- Velit esse cillum dolore eu fugiat nulla pariatur ;
- Excepteur sint occaecat cupidatat non proident, sunt in culpa."
Ceci est une fausse description des fonctionalités de l'app
**Version incluse :** 1.0~ynh1
**Démo :** https://demo.example.com
## Captures d'écran
![Capture d'écran de Example app](./doc/screenshots/example.jpg)
## Avertissements / informations importantes
* Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?
* not-working single-sign on or LDAP integration ?
* the app requires an important amount of RAM / disk / .. to install or to work properly
* etc...
* Other infos that people should be aware of, such as:
* any specific step to perform after installing (such as manually finishing the install, specific admin credentials, ...)
* how to configure / administrate the application if it ain't obvious
* upgrade process / specificities / things to be aware of ?
* security considerations ?
**Version incluse :**
## Documentations et ressources
* Site officiel de l'app : <https://example.com>
* Documentation officielle utilisateur : <https://yunohost.org/apps>
* Documentation officielle de l'admin : <https://yunohost.org/packaging_apps>
* Dépôt de code officiel de l'app : <https://some.forge.com/example/example>
* Documentation YunoHost pour cette app : <https://yunohost.org/app_example>
* Signaler un bug : <https://github.com/YunoHost-Apps/example_ynh/issues>
* Site officiel de lapp : <https://www.mozilla.org/en-GB/firefox/features/sync/>
* Documentation officielle de ladmin : <https://github.com/mozilla-services/syncstorage-rs/blob/master/docs/config.md>
* Dépôt de code officiel de lapp : <https://github.com/mozilla-services/syncstorage-rs>
* Documentation YunoHost pour cette app : <https://yunohost.org/app_syncstorage-rs>
* Signaler un bug : <https://github.com/YunoHost-Apps/syncstorage-rs_ynh/issues>
## Informations pour les développeurs
## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/example_ynh/tree/testing).
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/syncstorage-rs_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit.
Pour essayer la branche testing, procédez comme suit.
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/example_ynh/tree/testing --debug
sudo yunohost app install https://github.com/YunoHost-Apps/syncstorage-rs_ynh/tree/testing --debug
ou
sudo yunohost app upgrade example -u https://github.com/YunoHost-Apps/example_ynh/tree/testing --debug
sudo yunohost app upgrade syncstorage-rs -u https://github.com/YunoHost-Apps/syncstorage-rs_ynh/tree/testing --debug
```
**Plus d'infos sur le packaging d'applications :** <https://yunohost.org/packaging_apps>
**Plus dinfos sur le packaging dapplications :** <https://yunohost.org/packaging_apps>

View file

@ -1,4 +1,4 @@
master_secret = "__SECRET__"
master_secret = "__MASTER_SECRET__"
# removing this line will default to moz_json formatted logs (which is preferred for production envs)
human_logs = 1
@ -18,7 +18,7 @@ syncstorage.enabled = true
syncstorage.limits.max_total_records = 1666 # See issues #298/#333
# Example Tokenserver settings:
tokenserver.database_url = "mysql://__DB_USER__:__DB_PWD__@localhost/__DB_NAME__"
tokenserver.database_url = "mysql://__DB_USER__:__DB_PWD__@localhost/__DB_NAME_TOKENSERVER__"
tokenserver.enabled = true
tokenserver.node_type = "mysql"
tokenserver.fxa_email_domain = "api-accounts.stage.mozaws.net"

View file

@ -13,7 +13,7 @@ StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit
Environment=PATH="__INSTALL_DIR__/venv/bin:$(PATH)"
Environment=PYTHONPATH=$(PYTHON_SITE_PACKGES)
Environment=RUST_LOG=debug
Environment=RUST_LOG=error
Environment=RUST_BACKTRACE=full
# Sandboxing options to harden security

View file

View file

@ -1,3 +0,0 @@
This is a dummy admin doc for this app
The app install dir is `__INSTALL_DIR__`

View file

@ -1,3 +0,0 @@
Ceci est une fausse doc d'admin pour cette app
Le dossier d'install de l'app est `__INSTALL_DIR__`

View file

@ -1 +1 @@
This is a dummy description of this app features
Second-generation server for Firefox Sync written in Rust.

View file

@ -1,7 +1 @@
This is a dummy disclaimer to display after the install
The app url is `__DOMAIN____PATH__`
The app install dir is `__INSTALL_DIR__`
The app id is `__ID__`
Please open `about:config` in your Firefox and point `identity.sync.tokenserver.uri` to `__DOMAIN____PATH__`.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

View file

@ -7,7 +7,7 @@ name = "Firefox Sync Storage-rs"
en = "New Firefox Sync Storage implemented in Rust. Allows syncing tabs, passwords, history etc. between Firefox instances."
fr = "New Firefox Sync Storage implemented in Rust."
version = "0.13.6~ynh1"
version = "0.13.7-20230926~ynh1"
maintainers = [""]

View file

@ -13,18 +13,17 @@ source ynh_install_go
source /usr/share/yunohost/helpers
secret=$(ynh_string_random --length=40)
master_secret=$(ynh_string_random --length=40)
db_name_tokenserver = "${db_name}_tokenserver"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=10
ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION
#trap "ynh_remove_go" EXIT
export GOPATH="$install_dir/build/go"
export GOCACHE="$install_dir/build/.cache"
ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$install_dir"/.rustup CARGO_HOME="$install_dir"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y'
export PATH="$install_dir/.cargo/bin:$PATH"
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH cargo install diesel_cli --no-default-features --features 'mysql'
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
@ -44,12 +43,18 @@ ynh_setup_source --dest_dir="$install_dir/build"
# ownership to all files such as after the ynh_setup_source step
chown -R $app:www-data "$install_dir"
#=================================================
# PROVISION SECOND DB
#=================================================
ynh_script_progression --message="Configuring second MySQL database..."
ynh_mysql_create_db "$db_name_tokenserver" "$db_user" "$db_pwd"
#=================================================
# BUILD
#=================================================
ynh_script_progression --message="Building the sources (it will take some time)..." --weight=10
ynh_use_go
ynh_script_progression --message="Building the sources (it will take some time)..." --weight=10
ynh_exec_as $app python -m venv "${install_dir}/venv"
(
@ -60,16 +65,28 @@ ynh_exec_as $app python -m venv "${install_dir}/venv"
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install --upgrade pip
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install --upgrade setuptools
pushd $install_dir/build
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH GOPATH=$GOPATH GOCACHE=$GOCACHE CGO_ENABLED=1 $install_dir/venv/bin/pip install -r requirements.txt
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH GOPATH=$GOPATH GOCACHE=$GOCACHE CGO_ENABLED=1 cargo install --path ./syncserver --locked --root $install_dir --no-default-features --features=syncstorage-db/mysql
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install -r requirements.txt
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH $install_dir/venv/bin/pip install -r tools/tokenserver/requirements.txt
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH cargo install --path ./syncserver --locked --root $install_dir --no-default-features --features=syncstorage-db/mysql
ynh_script_progression --message="Seeding the databases..."
# syncstorage db
diesel --database-url "mysql://$db_user:${db_pwd}@localhost/$db_name" migration --migration-dir syncstorage-mysql/migrations run
# tokenserver db
diesel --database-url "mysql://db_user:${db_pwd}@localhost/$db_name_tokenserver" migration --migration-dir tokenserver-db/migrations run
ynh_mysql_run_as_root --sql="INSERT INTO services (id, service, pattern) VALUES (1, 'sync-1.5', '{node}/1.5/{uid}')" --database="$db_name_tokenserver";
ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH SYNC_TOKENSERVER__DATABASE_URL="mysql://syncstorage:${SYNCSTORAGE_PW}@localhost/tokenserver_rs" $install_dir/venv/bin/python tools/tokenserver/add_node.py "https://$domain$path_url" 10
popd
)
#ynh_secure_remove --file="$install_dir/.cargo"
#ynh_secure_remove --file="$install_dir/.rustup"
#ynh_secure_remove --file="$install_dir/.cache"
#ynh_secure_remove --file="$install_dir/.local"
#ynh_secure_remove --file="$install_dir/build"
ynh_secure_remove --file="$install_dir/.cargo"
ynh_secure_remove --file="$install_dir/.rustup"
ynh_secure_remove --file="$install_dir/.cache"
ynh_secure_remove --file="$install_dir/.local"
ynh_secure_remove --file="$install_dir/build"
#=================================================
# SYSTEM CONFIGURATION
@ -81,8 +98,13 @@ ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
mkdir /var/log/$app
touch /var/log/$app/$app.log
chown -R $user: /var/log/$app
yunohost service add $app --description="Firefox Sync Server (Rust)" --log="/var/log/$app/$app.log"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
@ -103,22 +125,6 @@ ynh_add_config --template="config.toml" --destination="$install_dir/config.toml"
chmod 400 "$install_dir/config.toml"
chown $app:$app "$install_dir/config.toml"
### For more complex cases where you want to replace stuff using regexes,
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
### When doing so, you also need to manually call ynh_store_file_checksum
###
### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file"
### ynh_store_file_checksum --file="$install_dir/some_config_file"
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
#### TODO in Yunohost App Generator
# Installation with curl
#ynh_script_progression --message="Finalizing installation..." --weight=1
#ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -1,8 +1,5 @@
#!/bin/bash
#### App file generated with YoloGen, the Yunohost app generator, version 0.6.5.
# This is the tutorial version of the app.
# It contains extra commands to explain what should be done in case you want to adjust some part of the script.
# Once you are done, you may remove them.
#=================================================
# GENERIC START
#=================================================
@ -11,18 +8,6 @@
source _common.sh
source /usr/share/yunohost/helpers
# Settings are automatically loaded as bash variables
# in every app script context, therefore typically these will exist:
# - $domain
# - $path
# - $language
# - $install_dir
# - $port
# ...
# For remove operations :
# - the core will deprovision every resource defined in the manifest **after** this script is ran
# this includes removing the install directory, and data directory (if --purge was used)
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
@ -42,15 +27,17 @@ ynh_remove_systemd_config
ynh_remove_nginx_config
ynh_remove_logrotate
ynh_remove_fail2ban_config
# Remove other various files specific to the app... such as :
ynh_secure_remove --file="/etc/cron.d/$app"
ynh_secure_remove --file="/etc/$app"
ynh_secure_remove --file="/var/log/$app"
#=================================================
# DROP TOKENSERVER DB
#=================================================
ynh_script_progression --message="Deprovisioning TokenServer DB..."
db_name_tokenserver=$(ynh_app_setting_get --app=$app --key=db_name_tokenserver)
ynh_mysql_drop_db "$db_name_tokenserver"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -1,247 +0,0 @@
#!/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
}
goenv_install_dir="/opt/goenv"
go_version_path="$goenv_install_dir/versions"
# goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable.
export GOENV_ROOT="$goenv_install_dir"
# Load the version of Go for an app, and set variables.
#
# ynh_use_go has to be used in any app scripts before using Go for the first time.
# This helper will provide alias and variables to use in your scripts.
#
# To use gem or Go, use the alias `ynh_gem` and `ynh_go`
# Those alias will use the correct version installed for the app
# For example: use `ynh_gem install` instead of `gem install`
#
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_go`
# And propagate $PATH to sudo with $ynh_go_load_path
# Exemple: `ynh_exec_as $app $ynh_go_load_path $ynh_gem install`
#
# $PATH contains the path of the requested version of Go.
# 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 $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_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_GO_LOAD_PATH__ with $ynh_go_load_path
#
# Or Go start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_GO__ my_app run`
# You will replace __YNH_GO__ with $ynh_go
#
#
# one other variable is also available
# - $go_path: The absolute path to Go binaries for the chosen version.
#
# usage: ynh_use_go
#
# Requires YunoHost version 3.2.2 or higher.
ynh_use_go () {
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"
# 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"
# 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 $install_dir
$goenv_install_dir/bin/goenv local $go_version
popd
}
# Install a specific version of Go
#
# ynh_install_go will install the version of Go provided as argument by using goenv.
#
# This helper creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
#
# Don't forget to execute go-dependent command in a login environment
# (e.g. sudo --login option)
# When not possible (e.g. in systemd service definition), please use direct path
# to goenv shims (e.g. $goenv_ROOT/shims/bundle)
#
# usage: ynh_install_go --go_version=go_version
# | arg: -v, --go_version= - Version of go to install.
#
# 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 "$@"
# 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:@@')
# 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
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"
# Create shims directory if needed
mkdir -p "${goenv_install_dir}/shims"
# 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
# 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
# Cleanup Go versions
ynh_cleanup_go
# 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 -)"
}
# Remove the version of Go used by the app.
#
# This helper will also cleanup Go versions
#
# usage: ynh_remove_go
ynh_remove_go () {
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"
# 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
# Cleanup Go versions
ynh_cleanup_go
}
# Remove no more needed versions of Go used by the app.
#
# This helper will check what Go version are no more required,
# and uninstall them
# If no app uses Go, goenv will be also removed.
#
# usage: ynh_cleanup_go
ynh_cleanup_go () {
# List required Go versions
local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)
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
# 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
}