mirror of
https://github.com/YunoHost-Apps/acropolis_ynh.git
synced 2024-09-03 18:06:22 +02:00
commit
07e71d864d
20 changed files with 590 additions and 1044 deletions
13
README.md
13
README.md
|
@ -19,18 +19,7 @@ It shall NOT be edited by hand.
|
||||||
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
||||||
|
|
||||||
|
|
||||||
**Shipped version:** 2022.01.29~ynh1
|
**Shipped version:** 2022.01.29~ynh2
|
||||||
## Disclaimers / important information
|
|
||||||
|
|
||||||
Acropolis is beta software, and under active development. Use at your own risk!
|
|
||||||
|
|
||||||
* This app require a dedicated domain or subdomain.
|
|
||||||
* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin.
|
|
||||||
* Configuration of the instance requires editing one or more config files which must also be done manually.
|
|
||||||
* Single sign-on doesn't work.
|
|
||||||
|
|
||||||
You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface.
|
|
||||||
|
|
||||||
## Documentation and resources
|
## Documentation and resources
|
||||||
|
|
||||||
- Official app website: <https://magicstone.dev>
|
- Official app website: <https://magicstone.dev>
|
||||||
|
|
13
README_fr.md
13
README_fr.md
|
@ -19,18 +19,7 @@ Il NE doit PAS être modifié à la main.
|
||||||
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
||||||
|
|
||||||
|
|
||||||
**Version incluse :** 2022.01.29~ynh1
|
**Version incluse :** 2022.01.29~ynh2
|
||||||
## Avertissements / informations importantes
|
|
||||||
|
|
||||||
Acropolis is beta software, and under active development. Use at your own risk!
|
|
||||||
|
|
||||||
* This app require a dedicated domain or subdomain.
|
|
||||||
* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin.
|
|
||||||
* Configuration of the instance requires editing one or more config files which must also be done manually.
|
|
||||||
* Single sign-on doesn't work.
|
|
||||||
|
|
||||||
You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface.
|
|
||||||
|
|
||||||
## Documentations et ressources
|
## Documentations et ressources
|
||||||
|
|
||||||
- Site officiel de l’app : <https://magicstone.dev>
|
- Site officiel de l’app : <https://magicstone.dev>
|
||||||
|
|
13
README_gl.md
13
README_gl.md
|
@ -19,18 +19,7 @@ NON debe editarse manualmente.
|
||||||
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
||||||
|
|
||||||
|
|
||||||
**Versión proporcionada:** 2022.01.29~ynh1
|
**Versión proporcionada:** 2022.01.29~ynh2
|
||||||
## Avisos / información importante
|
|
||||||
|
|
||||||
Acropolis is beta software, and under active development. Use at your own risk!
|
|
||||||
|
|
||||||
* This app require a dedicated domain or subdomain.
|
|
||||||
* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin.
|
|
||||||
* Configuration of the instance requires editing one or more config files which must also be done manually.
|
|
||||||
* Single sign-on doesn't work.
|
|
||||||
|
|
||||||
You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface.
|
|
||||||
|
|
||||||
## Documentación e recursos
|
## Documentación e recursos
|
||||||
|
|
||||||
- Web oficial da app: <https://magicstone.dev>
|
- Web oficial da app: <https://magicstone.dev>
|
||||||
|
|
13
README_it.md
13
README_it.md
|
@ -19,18 +19,7 @@ NON DEVE essere modificato manualmente.
|
||||||
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
Acropolis was forked from diaspora* in August 2021. The idea for the fork is to optimize toward community, that is making it as easy as possible to contribute. We're following a protocol that basically says if you are addressing a valid problem, your code gets merged. Everything else follows from that.
|
||||||
|
|
||||||
|
|
||||||
**Versione pubblicata:** 2022.01.29~ynh1
|
**Versione pubblicata:** 2022.01.29~ynh2
|
||||||
## Attenzione/informazioni importanti
|
|
||||||
|
|
||||||
Acropolis is beta software, and under active development. Use at your own risk!
|
|
||||||
|
|
||||||
* This app require a dedicated domain or subdomain.
|
|
||||||
* No admin user is created during installation so you will need to sign up and follow manual steps to promote your user to admin.
|
|
||||||
* Configuration of the instance requires editing one or more config files which must also be done manually.
|
|
||||||
* Single sign-on doesn't work.
|
|
||||||
|
|
||||||
You may wish to close or limit registration for your instance of Ecko, so that the instance stays small. We invite you to block remote malicious instances from the administration interface.
|
|
||||||
|
|
||||||
## Documentazione e risorse
|
## Documentazione e risorse
|
||||||
|
|
||||||
- Sito web ufficiale dell’app: <https://magicstone.dev>
|
- Sito web ufficiale dell’app: <https://magicstone.dev>
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
;; Test complet
|
|
||||||
; Manifest
|
|
||||||
domain="domain.tld"
|
|
||||||
is_public=1
|
|
||||||
admin="john"
|
|
||||||
password="1Strong-Password"
|
|
||||||
email="admin@domain.tld"
|
|
||||||
; Checks
|
|
||||||
pkg_linter=1
|
|
||||||
setup_sub_dir=0
|
|
||||||
setup_root=1
|
|
||||||
setup_nourl=0
|
|
||||||
setup_private=1
|
|
||||||
setup_public=1
|
|
||||||
upgrade=1
|
|
||||||
# 2022.01.29~ynh1
|
|
||||||
upgrade=1 from_commit=dc712d6bf6dd2f67b9863b03b8a6a3705713a81c
|
|
||||||
backup_restore=1
|
|
||||||
multi_instance=0
|
|
||||||
port_already_use=0
|
|
||||||
change_url=0
|
|
||||||
;;; Options
|
|
||||||
Email=
|
|
||||||
Notification=none
|
|
|
@ -5,7 +5,7 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=__APP__
|
User=__APP__
|
||||||
WorkingDirectory=__FINALPATH__
|
WorkingDirectory=__INSTALL_DIR__
|
||||||
Environment="RAILS_ENV=production"
|
Environment="RAILS_ENV=production"
|
||||||
Environment="DB_POOL=25"
|
Environment="DB_POOL=25"
|
||||||
Environment="MALLOC_ARENA_MAX=2"
|
Environment="MALLOC_ARENA_MAX=2"
|
||||||
|
|
|
@ -5,10 +5,10 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=__APP__
|
User=__APP__
|
||||||
WorkingDirectory=__FINALPATH__
|
WorkingDirectory=__INSTALL_DIR__
|
||||||
Environment="RAILS_ENV=production"
|
Environment="RAILS_ENV=production"
|
||||||
Environment="PORT=__PORT_WEB__"
|
Environment="PORT=__PORT_WEB__"
|
||||||
Environment=UNICORN_LISTENER=__FINALPATH__/tmp/sockets/unicorn.sock
|
Environment=UNICORN_LISTENER=__INSTALL_DIR__/tmp/sockets/unicorn.sock
|
||||||
ExecStart=__RBENV_ROOT__/versions/__APP__/bin/bundle exec unicorn --config config/unicorn.rb -E production
|
ExecStart=__RBENV_ROOT__/versions/__APP__/bin/bundle exec unicorn --config config/unicorn.rb -E production
|
||||||
ExecReload=/bin/kill -SIGUSR1 $MAINPID
|
ExecReload=/bin/kill -SIGUSR1 $MAINPID
|
||||||
TimeoutSec=60
|
TimeoutSec=60
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
SOURCE_URL=https://github.com/magicstone-dev/acropolis/archive/f586f64b4cee0b2a50f45b5cf6de4e1fd749def8.tar.gz
|
|
||||||
SOURCE_SUM=716d9c5e1e8e7d2694dbe6d2c1b5e48e5a5537a29ec8a8d0a722e6750fffae56
|
|
||||||
SOURCE_SUM_PRG=sha256sum
|
|
||||||
SOURCE_FORMAT=tar.gz
|
|
||||||
SOURCE_IN_SUBDIR=true
|
|
||||||
SOURCE_FILENAME=
|
|
||||||
SOURCE_EXTRACT=true
|
|
|
@ -2,7 +2,7 @@
|
||||||
client_max_body_size 100M;
|
client_max_body_size 100M;
|
||||||
|
|
||||||
# add to v1.4 assets
|
# add to v1.4 assets
|
||||||
root __FINALPATH__/public;
|
root __INSTALL_DIR__/public;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
|
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Acropolis",
|
|
||||||
"id": "acropolis",
|
|
||||||
"packaging_format": 1,
|
|
||||||
"description": {
|
|
||||||
"en": "Dynamic fork of diaspora*'s federated social network",
|
|
||||||
"fr": "Fourche dynamique du réseau social fédéré de diaspora*"
|
|
||||||
},
|
|
||||||
"version": "2022.01.29~ynh1",
|
|
||||||
"url": "https://github.com/magicstone-dev/acropolis",
|
|
||||||
"upstream": {
|
|
||||||
"license": "AGPL-3.0-or-later",
|
|
||||||
"website": "https://magicstone.dev",
|
|
||||||
"code": "https://github.com/magicstone-dev/acropolis"
|
|
||||||
},
|
|
||||||
"license": "AGPL-3.0-or-later",
|
|
||||||
"maintainer": {
|
|
||||||
"name": "weex"
|
|
||||||
},
|
|
||||||
"requirements": {
|
|
||||||
"yunohost": ">= 4.3.0"
|
|
||||||
},
|
|
||||||
"multi_instance": false,
|
|
||||||
"services": [
|
|
||||||
"nginx"
|
|
||||||
],
|
|
||||||
"arguments": {
|
|
||||||
"install": [
|
|
||||||
{
|
|
||||||
"name": "domain",
|
|
||||||
"type": "domain"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "is_public",
|
|
||||||
"type": "boolean",
|
|
||||||
"default": true,
|
|
||||||
"help": {
|
|
||||||
"en": "For federation to work, this needs to be true. False is ok if you want to run a private instance."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "admin",
|
|
||||||
"type": "user"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "password",
|
|
||||||
"type": "password"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "email",
|
|
||||||
"type": "string",
|
|
||||||
"ask": {
|
|
||||||
"en": "Enter email address for administative notifications."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
97
manifest.toml
Normal file
97
manifest.toml
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
|
||||||
|
|
||||||
|
packaging_format = 2
|
||||||
|
|
||||||
|
id = "acropolis"
|
||||||
|
name = "Acropolis"
|
||||||
|
description.en = "Dynamic fork of diaspora*'s federated social network"
|
||||||
|
description.fr = "Fourche dynamique du réseau social fédéré de diaspora*"
|
||||||
|
|
||||||
|
version = "2022.01.29~ynh2"
|
||||||
|
|
||||||
|
maintainers = ["weex"]
|
||||||
|
|
||||||
|
[upstream]
|
||||||
|
license = "AGPL-3.0-or-later"
|
||||||
|
website = "https://magicstone.dev"
|
||||||
|
code = "https://github.com/magicstone-dev/acropolis"
|
||||||
|
|
||||||
|
[integration]
|
||||||
|
yunohost = ">=11.2"
|
||||||
|
architectures = "all"
|
||||||
|
multi_instance = false
|
||||||
|
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.admin]
|
||||||
|
type = "user"
|
||||||
|
|
||||||
|
[install.init_main_permission]
|
||||||
|
help.en = "For federation to work, this needs to be true. False is ok if you want to run a private instance."
|
||||||
|
type = "group"
|
||||||
|
default = "visitors"
|
||||||
|
|
||||||
|
[install.email]
|
||||||
|
ask.en = "Enter email address for administative notifications."
|
||||||
|
type = "string"
|
||||||
|
|
||||||
|
[install.password]
|
||||||
|
type = "password"
|
||||||
|
|
||||||
|
[resources]
|
||||||
|
[resources.sources.main]
|
||||||
|
url = "https://github.com/magicstone-dev/acropolis/archive/f586f64b4cee0b2a50f45b5cf6de4e1fd749def8.tar.gz"
|
||||||
|
sha256 = "716d9c5e1e8e7d2694dbe6d2c1b5e48e5a5537a29ec8a8d0a722e6750fffae56"
|
||||||
|
|
||||||
|
autoupdate.strategy = "latest_github_commit"
|
||||||
|
|
||||||
|
[resources.system_user]
|
||||||
|
|
||||||
|
[resources.install_dir]
|
||||||
|
|
||||||
|
[resources.permissions]
|
||||||
|
main.url = "/"
|
||||||
|
|
||||||
|
[resources.ports]
|
||||||
|
web.default = 3000
|
||||||
|
|
||||||
|
[resources.apt]
|
||||||
|
packages = [
|
||||||
|
"g++",
|
||||||
|
# "libjemalloc1|libjemalloc2",
|
||||||
|
"libjemalloc-dev",
|
||||||
|
"zlib1g-dev",
|
||||||
|
"libreadline-dev",
|
||||||
|
"libpq-dev",
|
||||||
|
"libssl-dev",
|
||||||
|
"libyaml-dev",
|
||||||
|
"libcurl4-dev",
|
||||||
|
"libapr1-dev",
|
||||||
|
"libxslt1-dev",
|
||||||
|
"libidn11-dev",
|
||||||
|
"libxml2-dev",
|
||||||
|
"vim",
|
||||||
|
"imagemagick",
|
||||||
|
"postgresql",
|
||||||
|
"postgresql-server-dev-all",
|
||||||
|
"postgresql-contrib",
|
||||||
|
"optipng",
|
||||||
|
"jhead",
|
||||||
|
"jpegoptim",
|
||||||
|
"gifsicle",
|
||||||
|
"brotli",
|
||||||
|
"nodejs",
|
||||||
|
"cmake",
|
||||||
|
"pkg-config"
|
||||||
|
]
|
||||||
|
|
||||||
|
[resources.database]
|
||||||
|
type = "postgresql"
|
|
@ -4,8 +4,6 @@
|
||||||
# COMMON VARIABLES
|
# COMMON VARIABLES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
pkg_dependencies="g++ libjemalloc1|libjemalloc2 libjemalloc-dev zlib1g-dev libreadline-dev libpq-dev libssl-dev libyaml-dev libcurl4-dev libapr1-dev libxslt1-dev libidn11-dev libxml2-dev vim imagemagick postgresql postgresql-server-dev-all postgresql-contrib optipng jhead jpegoptim gifsicle brotli nodejs cmake pkg-config"
|
|
||||||
|
|
||||||
RUBY_VERSION="2.7.1"
|
RUBY_VERSION="2.7.1"
|
||||||
|
|
||||||
MEMORY_NEEDED="2560"
|
MEMORY_NEEDED="2560"
|
||||||
|
@ -14,15 +12,6 @@ MEMORY_NEEDED="2560"
|
||||||
# PERSONAL HELPERS
|
# PERSONAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Execute a command as another user with login
|
|
||||||
# (hence in user home dir, with prior loading of .profile, etc.)
|
|
||||||
# usage: exec_login_as USER COMMAND [ARG ...]
|
|
||||||
exec_login_as() {
|
|
||||||
local user=$1
|
|
||||||
shift 1
|
|
||||||
ynh_exec_as $user --login "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Returns true if a swap partition is enabled, false otherwise
|
# Returns true if a swap partition is enabled, false otherwise
|
||||||
# usage: is_swap_present
|
# usage: is_swap_present
|
||||||
is_swap_present() {
|
is_swap_present() {
|
||||||
|
@ -65,14 +54,6 @@ check_memory_requirements_upgrade() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_maintenance_mode_ON () {
|
ynh_maintenance_mode_ON () {
|
||||||
# Load value of $path_url and $domain from the config if their not set
|
|
||||||
if [ -z $path_url ]; then
|
|
||||||
path_url=$(ynh_app_setting_get $app path)
|
|
||||||
fi
|
|
||||||
if [ -z $domain ]; then
|
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create an html to serve as maintenance notice
|
# Create an html to serve as maintenance notice
|
||||||
echo "<!DOCTYPE html>
|
echo "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
@ -94,10 +75,10 @@ ynh_maintenance_mode_ON () {
|
||||||
</html>" > "/var/www/html/maintenance.$app.html"
|
</html>" > "/var/www/html/maintenance.$app.html"
|
||||||
|
|
||||||
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
|
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
|
||||||
echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
|
echo "# All request to the app will be redirected to ${path}_maintenance and fall on the maintenance notice
|
||||||
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
|
rewrite ^${path}/(.*)$ ${path}_maintenance/? redirect;
|
||||||
# Use another location, to not be in conflict with the original config file
|
# Use another location, to not be in conflict with the original config file
|
||||||
location ${path_url}_maintenance/ {
|
location ${path}_maintenance/ {
|
||||||
alias /var/www/html/ ;
|
alias /var/www/html/ ;
|
||||||
try_files maintenance.$app.html =503;
|
try_files maintenance.$app.html =503;
|
||||||
# Include SSOWAT user panel.
|
# Include SSOWAT user panel.
|
||||||
|
@ -106,7 +87,7 @@ include conf.d/yunohost_panel.conf.inc;
|
||||||
|
|
||||||
# The current config file will redirect all requests to the root of the app.
|
# The current config file will redirect all requests to the root of the app.
|
||||||
# To keep the full path, we can use the following rewrite rule:
|
# To keep the full path, we can use the following rewrite rule:
|
||||||
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
|
# rewrite ^${path}/(.*)$ ${path}_maintenance/\$1? redirect;
|
||||||
# The difference will be in the $1 at the end, which keep the following queries.
|
# The difference will be in the $1 at the end, which keep the following queries.
|
||||||
# But, if it works perfectly for a html request, there's an issue with any php files.
|
# But, if it works perfectly for a html request, there's an issue with any php files.
|
||||||
# This files are treated as simple files, and will be downloaded by the browser.
|
# This files are treated as simple files, and will be downloaded by the browser.
|
||||||
|
@ -116,16 +97,9 @@ include conf.d/yunohost_panel.conf.inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_maintenance_mode_OFF () {
|
ynh_maintenance_mode_OFF () {
|
||||||
# Load value of $path_url and $domain from the config if their not set
|
|
||||||
if [ -z $path_url ]; then
|
|
||||||
path_url=$(ynh_app_setting_get $app path)
|
|
||||||
fi
|
|
||||||
if [ -z $domain ]; then
|
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
|
# Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app.
|
||||||
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
|
echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
|
|
||||||
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
|
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
|
||||||
|
@ -145,310 +119,3 @@ ynh_maintenance_mode_OFF () {
|
||||||
#=================================================
|
#=================================================
|
||||||
# FUTURE OFFICIAL HELPERS
|
# FUTURE OFFICIAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RUBY HELPER
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_ruby_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
|
|
||||||
}
|
|
||||||
|
|
||||||
rbenv_install_dir="/opt/rbenv"
|
|
||||||
ruby_version_path="$rbenv_install_dir/versions"
|
|
||||||
# RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable.
|
|
||||||
export RBENV_ROOT="$rbenv_install_dir"
|
|
||||||
export rbenv_root="$rbenv_install_dir"
|
|
||||||
# Load the version of Ruby for an app, and set variables.
|
|
||||||
#
|
|
||||||
# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time.
|
|
||||||
# This helper will provide alias and variables to use in your scripts.
|
|
||||||
#
|
|
||||||
# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby`
|
|
||||||
# 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_ruby`
|
|
||||||
# And propagate $PATH to sudo with $ynh_ruby_load_path
|
|
||||||
# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install`
|
|
||||||
#
|
|
||||||
# $PATH contains the path of the requested version of Ruby.
|
|
||||||
# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH
|
|
||||||
# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version
|
|
||||||
# in $PATH for an usage into a separate script.
|
|
||||||
# Exemple: $ynh_ruby_load_path $final_path/script_that_use_gem.sh`
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Finally, to start a Ruby service with the correct version, 2 solutions
|
|
||||||
# Either the app is dependent of Ruby or gem, but does not called it directly.
|
|
||||||
# In such situation, you need to load PATH
|
|
||||||
# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"`
|
|
||||||
# `ExecStart=__FINALPATH__/my_app`
|
|
||||||
# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path
|
|
||||||
#
|
|
||||||
# Or Ruby start the app directly, then you don't need to load the PATH variable
|
|
||||||
# `ExecStart=__YNH_RUBY__ my_app run`
|
|
||||||
# You will replace __YNH_RUBY__ with $ynh_ruby
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# one other variable is also available
|
|
||||||
# - $ruby_path: The absolute path to Ruby binaries for the chosen version.
|
|
||||||
#
|
|
||||||
# usage: ynh_use_ruby
|
|
||||||
#
|
|
||||||
# Requires YunoHost version 2.7.12 or higher.
|
|
||||||
ynh_use_ruby () {
|
|
||||||
ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version)
|
|
||||||
|
|
||||||
# Get the absolute path of this version of Ruby
|
|
||||||
ruby_path="$ruby_version_path/$YNH_APP_INSTANCE_NAME/bin"
|
|
||||||
|
|
||||||
# Allow alias to be used into bash script
|
|
||||||
shopt -s expand_aliases
|
|
||||||
|
|
||||||
# Create an alias for the specific version of Ruby and a variable as fallback
|
|
||||||
ynh_ruby="$ruby_path/ruby"
|
|
||||||
alias ynh_ruby="$ynh_ruby"
|
|
||||||
# And gem
|
|
||||||
ynh_gem="$ruby_path/gem"
|
|
||||||
alias ynh_gem="$ynh_gem"
|
|
||||||
|
|
||||||
# Load the path of this version of Ruby in $PATH
|
|
||||||
if [[ :$PATH: != *":$ruby_path"* ]]; then
|
|
||||||
PATH="$ruby_path:$PATH"
|
|
||||||
fi
|
|
||||||
# Create an alias to easily load the PATH
|
|
||||||
ynh_ruby_load_path="PATH=$PATH"
|
|
||||||
|
|
||||||
# Sets the local application-specific Ruby version
|
|
||||||
pushd $final_path
|
|
||||||
$rbenv_install_dir/bin/rbenv local $ruby_version
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install a specific version of Ruby
|
|
||||||
#
|
|
||||||
# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv.
|
|
||||||
#
|
|
||||||
# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv
|
|
||||||
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
|
|
||||||
#
|
|
||||||
# Don't forget to execute ruby-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 rbenv shims (e.g. $RBENV_ROOT/shims/bundle)
|
|
||||||
#
|
|
||||||
# usage: ynh_install_ruby --ruby_version=ruby_version
|
|
||||||
# | arg: -v, --ruby_version= - Version of ruby to install.
|
|
||||||
#
|
|
||||||
# Requires YunoHost version 2.7.12 or higher.
|
|
||||||
ynh_install_ruby () {
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
local legacy_args=v
|
|
||||||
local -A args_array=( [v]=ruby_version= )
|
|
||||||
local ruby_version
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
# Load rbenv path in PATH
|
|
||||||
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
|
|
||||||
|
|
||||||
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
|
||||||
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
|
||||||
|
|
||||||
# Move an existing Ruby binary, to avoid to block rbenv
|
|
||||||
test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
|
|
||||||
|
|
||||||
# Install or update rbenv
|
|
||||||
rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)"
|
|
||||||
if [ -n "$rbenv" ]; then
|
|
||||||
ynh_print_info --message="rbenv already seems installed in \`$rbenv'."
|
|
||||||
pushd "${rbenv%/*/*}"
|
|
||||||
if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then
|
|
||||||
ynh_print_info --message="Trying to update with git..."
|
|
||||||
git pull -q --tags origin master
|
|
||||||
ynh_ruby_try_bash_extension
|
|
||||||
else
|
|
||||||
ynh_print_info --message="Reinstalling rbenv with git..."
|
|
||||||
cd ..
|
|
||||||
ynh_secure_remove --file=$rbenv_install_dir
|
|
||||||
mkdir -p $rbenv_install_dir
|
|
||||||
cd $rbenv_install_dir
|
|
||||||
git init -q
|
|
||||||
git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1
|
|
||||||
git checkout -q -b master origin/master
|
|
||||||
ynh_ruby_try_bash_extension
|
|
||||||
rbenv=$rbenv_install_dir/bin/rbenv
|
|
||||||
fi
|
|
||||||
popd
|
|
||||||
else
|
|
||||||
ynh_print_info --message="Installing rbenv with git..."
|
|
||||||
mkdir -p $rbenv_install_dir
|
|
||||||
pushd $rbenv_install_dir
|
|
||||||
git init -q
|
|
||||||
git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1
|
|
||||||
git checkout -q -b master origin/master
|
|
||||||
ynh_ruby_try_bash_extension
|
|
||||||
rbenv=$rbenv_install_dir/bin/rbenv
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
|
|
||||||
ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)"
|
|
||||||
if [ -n "$ruby_build" ]; then
|
|
||||||
ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'."
|
|
||||||
pushd "${ruby_build%/*/*}"
|
|
||||||
if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then
|
|
||||||
ynh_print_info --message="Trying to update rbenv with git..."
|
|
||||||
git pull -q origin master
|
|
||||||
fi
|
|
||||||
popd
|
|
||||||
else
|
|
||||||
ynh_print_info --message="Installing ruby-build with git..."
|
|
||||||
mkdir -p "${rbenv_install_dir}/plugins"
|
|
||||||
git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)"
|
|
||||||
if [ -n "$rbenv_alias" ]; then
|
|
||||||
ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'."
|
|
||||||
pushd "${rbenv_alias%/*/*}"
|
|
||||||
if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then
|
|
||||||
ynh_print_info --message="Trying to update rbenv-aliases with git..."
|
|
||||||
git pull -q origin master
|
|
||||||
fi
|
|
||||||
popd
|
|
||||||
else
|
|
||||||
ynh_print_info --message="Installing rbenv-aliases with git..."
|
|
||||||
mkdir -p "${rbenv_install_dir}/plugins"
|
|
||||||
git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)"
|
|
||||||
if [ -n "$rbenv_latest" ]; then
|
|
||||||
ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'."
|
|
||||||
pushd "${rbenv_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 "${rbenv_install_dir}/plugins"
|
|
||||||
git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Enable caching
|
|
||||||
mkdir -p "${rbenv_install_dir}/cache"
|
|
||||||
|
|
||||||
# Create shims directory if needed
|
|
||||||
mkdir -p "${rbenv_install_dir}/shims"
|
|
||||||
|
|
||||||
# Restore /usr/local/bin in PATH
|
|
||||||
PATH=$CLEAR_PATH
|
|
||||||
|
|
||||||
# And replace the old Ruby binary
|
|
||||||
test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
|
|
||||||
|
|
||||||
# Install the requested version of Ruby
|
|
||||||
local final_ruby_version=$(rbenv latest --print $ruby_version)
|
|
||||||
if ! [ -n "$final_ruby_version" ]; then
|
|
||||||
final_ruby_version=$ruby_version
|
|
||||||
fi
|
|
||||||
ynh_print_info --message="Installing Ruby-$final_ruby_version"
|
|
||||||
CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1
|
|
||||||
|
|
||||||
# Store ruby_version into the config of this app
|
|
||||||
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=ruby_version --value=$final_ruby_version
|
|
||||||
|
|
||||||
# Remove app virtualenv
|
|
||||||
if `rbenv alias --list | grep --quiet "$YNH_APP_INSTANCE_NAME " 1>/dev/null 2>&1`
|
|
||||||
then
|
|
||||||
rbenv alias $YNH_APP_INSTANCE_NAME --remove
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create app virtualenv
|
|
||||||
rbenv alias $YNH_APP_INSTANCE_NAME $final_ruby_version
|
|
||||||
|
|
||||||
# Cleanup Ruby versions
|
|
||||||
ynh_cleanup_ruby
|
|
||||||
|
|
||||||
# Set environment for Ruby users
|
|
||||||
echo "#rbenv
|
|
||||||
export RBENV_ROOT=$rbenv_install_dir
|
|
||||||
export PATH=\"$rbenv_install_dir/bin:$PATH\"
|
|
||||||
eval \"\$(rbenv init -)\"
|
|
||||||
#rbenv" > /etc/profile.d/rbenv.sh
|
|
||||||
|
|
||||||
# Load the environment
|
|
||||||
eval "$(rbenv init -)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove the version of Ruby used by the app.
|
|
||||||
#
|
|
||||||
# This helper will also cleanup Ruby versions
|
|
||||||
#
|
|
||||||
# usage: ynh_remove_ruby
|
|
||||||
ynh_remove_ruby () {
|
|
||||||
local ruby_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=ruby_version)
|
|
||||||
|
|
||||||
# Load rbenv path in PATH
|
|
||||||
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
|
|
||||||
|
|
||||||
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
|
||||||
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
|
||||||
|
|
||||||
rbenv alias $YNH_APP_INSTANCE_NAME --remove
|
|
||||||
|
|
||||||
# Remove the line for this app
|
|
||||||
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=ruby_version
|
|
||||||
|
|
||||||
# Cleanup Ruby versions
|
|
||||||
ynh_cleanup_ruby
|
|
||||||
}
|
|
||||||
|
|
||||||
# Remove no more needed versions of Ruby used by the app.
|
|
||||||
#
|
|
||||||
# This helper will check what Ruby version are no more required,
|
|
||||||
# and uninstall them
|
|
||||||
# If no app uses Ruby, rbenv will be also removed.
|
|
||||||
#
|
|
||||||
# usage: ynh_cleanup_ruby
|
|
||||||
ynh_cleanup_ruby () {
|
|
||||||
|
|
||||||
# List required Ruby versions
|
|
||||||
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
|
|
||||||
local required_ruby_versions=""
|
|
||||||
for installed_app in $installed_apps
|
|
||||||
do
|
|
||||||
local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version")
|
|
||||||
if [[ $installed_app_ruby_version ]]
|
|
||||||
then
|
|
||||||
required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Remove no more needed Ruby versions
|
|
||||||
local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/')
|
|
||||||
for installed_ruby_version in $installed_ruby_versions
|
|
||||||
do
|
|
||||||
if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1`
|
|
||||||
then
|
|
||||||
ynh_print_info --message="Removing of Ruby-$installed_ruby_version"
|
|
||||||
$rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# If none Ruby version is required
|
|
||||||
if [[ ! $required_ruby_versions ]]
|
|
||||||
then
|
|
||||||
# Remove rbenv environment configuration
|
|
||||||
ynh_print_info --message="Removing of rbenv-$rbenv_version"
|
|
||||||
ynh_secure_remove --file="$rbenv_install_dir"
|
|
||||||
ynh_secure_remove --file="/etc/profile.d/rbenv.sh"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,37 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source ../settings/scripts/ynh_ruby
|
||||||
source ../settings/scripts/ynh_add_swap
|
source ../settings/scripts/ynh_add_swap
|
||||||
source /usr/share/yunohost/helpers
|
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)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -41,29 +19,19 @@ ynh_print_info --message="Declaring files to be backed up..."
|
||||||
# BACKUP THE APP MAIN DIR
|
# BACKUP THE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="$final_path"
|
ynh_backup --src_path="$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE NGINX CONFIGURATION
|
# BACKUP THE SYSTEM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC BACKUP
|
|
||||||
#=================================================
|
|
||||||
# BACKUP LOGROTATE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/logrotate.d/$app"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# BACKUP SYSTEMD
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/systemd/system/$app-web.service"
|
ynh_backup --src_path="/etc/systemd/system/$app-web.service"
|
||||||
ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service"
|
ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service"
|
||||||
|
|
||||||
|
ynh_backup --src_path="/etc/logrotate.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE MYSQL DATABASE
|
# BACKUP THE MYSQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
232
scripts/install
232
scripts/install
|
@ -1,124 +1,21 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_ruby
|
||||||
source ynh_add_swap
|
source ynh_add_swap
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# MANAGE SCRIPT FAILURE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_clean_setup () {
|
|
||||||
ynh_clean_check_starting
|
|
||||||
}
|
|
||||||
# Exit if an error occurs during the execution of the script
|
|
||||||
ynh_abort_if_errors
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
|
||||||
path_url="/"
|
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
||||||
admin=$YNH_APP_ARG_ADMIN
|
|
||||||
password=$YNH_APP_ARG_PASSWORD
|
|
||||||
email=$YNH_APP_ARG_EMAIL
|
|
||||||
|
|
||||||
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=/var/www/$app
|
|
||||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
||||||
|
|
||||||
# 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=admin --value=$admin
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STANDARD MODIFICATIONS
|
|
||||||
#=================================================
|
|
||||||
# FIND AND OPEN A PORT
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Finding an available port..." --weight=1
|
|
||||||
|
|
||||||
# Find an available port
|
|
||||||
port_web=$(ynh_find_port --port=3000)
|
|
||||||
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing dependencies..." --weight=1
|
ynh_script_progression --message="Installing Ruby..." --weight=1
|
||||||
|
|
||||||
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION"
|
||||||
ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# 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 POSTGRESQL DATABASE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Creating a PostgreSQL database..."
|
|
||||||
|
|
||||||
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_app_setting_set --app=$app --key=db_user --value=$db_user
|
|
||||||
ynh_psql_test_if_first_run
|
|
||||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
|
||||||
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database=$db_name
|
|
||||||
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
||||||
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
||||||
|
|
||||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
|
||||||
ynh_setup_source --dest_dir="$final_path"
|
|
||||||
|
|
||||||
mkdir -p "$final_path/tmp/pids"
|
|
||||||
chmod 750 "$final_path"
|
|
||||||
chmod -R o-rwx "$final_path"
|
|
||||||
chown -R $app:www-data "$final_path"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# NGINX CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
|
||||||
|
|
||||||
# Create a dedicated NGINX config
|
|
||||||
ynh_add_nginx_config
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC SETUP
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD SWAP IF NEEDED
|
# ADD SWAP IF NEEDED
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -127,115 +24,94 @@ ynh_script_progression --message="Adding swap if needed..."
|
||||||
total_memory=$(ynh_get_ram --total)
|
total_memory=$(ynh_get_ram --total)
|
||||||
swap_needed=0
|
swap_needed=0
|
||||||
|
|
||||||
if [ $total_memory -lt $MEMORY_NEEDED ]; then
|
if (( MEMORY_NEEDED > total_memory )); then
|
||||||
# Need a minimum of 2.5Go of memory
|
# Need a minimum of 2.5Go of memory
|
||||||
swap_needed=$(($MEMORY_NEEDED - $total_memory))
|
swap_needed=$((MEMORY_NEEDED - total_memory))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
|
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
|
||||||
ynh_add_swap --size=$swap_needed
|
ynh_add_swap --size=$swap_needed
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALLING RUBY AND BUNDLER
|
# CREATE A POSTGRESQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Ruby..."
|
ynh_script_progression --message="Setting the PostgreSQL database..."
|
||||||
|
|
||||||
pushd "$final_path"
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database="$db_name"
|
||||||
ynh_use_ruby
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name"
|
||||||
ynh_gem install bundler:1.17.3 --no-document
|
|
||||||
ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
|
#=================================================
|
||||||
ynh_exec_as $app chmod +x script/server
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
popd
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
||||||
|
|
||||||
|
ynh_setup_source --dest_dir="$install_dir"
|
||||||
|
|
||||||
|
mkdir -p "$install_dir/tmp/pids"
|
||||||
|
|
||||||
|
chmod -R o-rwx "$install_dir"
|
||||||
|
chown -R "$app:www-data" "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD A CONFIGURATION
|
# ADD A CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||||
|
|
||||||
database_yml="$final_path/config/database.yml"
|
ynh_add_config --template="database.yml.example" --destination="$install_dir/config/database.yml"
|
||||||
diaspora_toml="$final_path/config/diaspora.toml"
|
ynh_add_config --template="diaspora.toml.example" --destination="$install_dir/config/diaspora.toml"
|
||||||
|
|
||||||
ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml"
|
chmod 400 "$install_dir/config/database.yml"
|
||||||
ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml"
|
chmod 400 "$install_dir/config/diaspora.toml"
|
||||||
|
chown "$app:$app" "$install_dir/config/database.yml"
|
||||||
chmod 400 "$database_yml"
|
chown "$app:$app" "$install_dir/config/diaspora.toml"
|
||||||
chown $app:$app "$database_yml"
|
|
||||||
|
|
||||||
chmod 400 "$diaspora_toml"
|
|
||||||
chown $app:$app "$diaspora_toml"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# INSTALLING RUBY AND BUNDLER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
ynh_script_progression --message="Building $app..."
|
||||||
|
|
||||||
ynh_add_systemd_config --service="$app-web" --template="$app-web.service"
|
pushd "$install_dir"
|
||||||
ynh_add_systemd_config --service="$app-sidekiq" --template="$app-sidekiq.service"
|
ynh_use_ruby
|
||||||
|
ynh_gem install bundler:1.17.3 --no-document
|
||||||
|
ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc"
|
||||||
|
ynh_exec_as "$app" chmod +x script/server
|
||||||
|
|
||||||
#=================================================
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" script/configure_bundler
|
||||||
# INSTALLING ACROPOLIS
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config set path 'vendor/bundle'
|
||||||
#=================================================
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle install --full-index
|
||||||
ynh_script_progression --message="Installing acropolis..."
|
|
||||||
|
|
||||||
pushd "$final_path"
|
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path script/configure_bundler
|
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config set path 'vendor/bundle'
|
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install --full-index
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
ynh_script_progression --message="Preparing the database and create initial admin user..."
|
ynh_script_progression --message="Preparing the database and create initial admin user..."
|
||||||
|
|
||||||
pushd "$final_path"
|
pushd "$install_dir"
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake db:migrate
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:precompile
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake "admin:create[$admin, $email, $password]"
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake "admin:create[$admin, $email, $password]"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# SYSTEM CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
ynh_add_systemd_config --service="$app-web" --template="$app-web.service"
|
||||||
|
yunohost service add "$app-web" --description="$app web service"
|
||||||
|
|
||||||
|
ynh_add_systemd_config --service="$app-sidekiq" --template="$app-sidekiq.service"
|
||||||
|
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
||||||
|
|
||||||
# Use logrotate to manage application logfile(s)
|
# Use logrotate to manage application logfile(s)
|
||||||
ynh_use_logrotate
|
ynh_use_logrotate
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
||||||
|
|
||||||
yunohost service add "$app-web" --description="$app web service"
|
|
||||||
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SYSTEMD SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||||
|
|
||||||
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="listening on"
|
ynh_systemd_action --service_name="${app}-web" --action="start" --log_path=systemd --line_match="listening on"
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Booted Rails"
|
ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path=systemd --line_match="Booted Rails"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# 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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -1,114 +1,45 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_ruby
|
||||||
source ynh_add_swap
|
source ynh_add_swap
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# REMOVE SYSTEM CONFIGURATIONS
|
||||||
#=================================================
|
|
||||||
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=$(ynh_app_setting_get --app=$app --key=db_user)
|
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
||||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STANDARD REMOVE
|
|
||||||
#=================================================
|
|
||||||
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
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`)
|
# 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-web" >/dev/null
|
if ynh_exec_warn_less yunohost service status "$app-web" >/dev/null; then
|
||||||
then
|
yunohost service remove "$app-web"
|
||||||
ynh_script_progression --message="Removing $app-web service integration..." --weight=1
|
|
||||||
yunohost service remove "$app-web"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null
|
|
||||||
then
|
|
||||||
ynh_script_progression --message="Removing $app-sidekiq service integration..." --weight=1
|
|
||||||
yunohost service remove "$app-sidekiq"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STOP AND REMOVE SERVICE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
|
|
||||||
|
|
||||||
ynh_remove_systemd_config --service="$app-web"
|
ynh_remove_systemd_config --service="$app-web"
|
||||||
|
|
||||||
|
if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null; then
|
||||||
|
yunohost service remove "$app-sidekiq"
|
||||||
|
fi
|
||||||
ynh_remove_systemd_config --service="$app-sidekiq"
|
ynh_remove_systemd_config --service="$app-sidekiq"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# REMOVE THE POSTGRESQL DATABASE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing the PostgreSQL database.."
|
|
||||||
|
|
||||||
ynh_psql_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 NGINX CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
|
|
||||||
|
|
||||||
# Remove the dedicated NGINX config
|
|
||||||
ynh_remove_nginx_config
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# REMOVE DEPENDENCIES
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing dependencies..." --weight=1
|
|
||||||
|
|
||||||
# Remove metapackage and its dependencies
|
|
||||||
ynh_remove_ruby
|
|
||||||
ynh_remove_app_dependencies
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC REMOVE
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE VARIOUS FILES
|
# REMOVE VARIOUS FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing various files..." --weight=1
|
|
||||||
|
|
||||||
# Remove a directory securely
|
|
||||||
ynh_secure_remove --file="/etc/$app"
|
ynh_secure_remove --file="/etc/$app"
|
||||||
|
|
||||||
# Remove the log files
|
|
||||||
ynh_secure_remove --file="/var/log/$app"
|
ynh_secure_remove --file="/var/log/$app"
|
||||||
|
|
||||||
# Remove swap
|
ynh_script_progression --message="Removing Swap..." --weight=1
|
||||||
ynh_del_swap
|
ynh_del_swap
|
||||||
|
|
||||||
#=================================================
|
ynh_script_progression --message="Uninstalling Ruby..." --weight=1
|
||||||
# GENERIC FINALIZATION
|
ynh_remove_ruby
|
||||||
#=================================================
|
|
||||||
# REMOVE DEDICATED USER
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
|
|
||||||
|
|
||||||
# Delete a system user
|
|
||||||
ynh_system_user_delete --username=$app
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
142
scripts/restore
142
scripts/restore
|
@ -1,79 +1,21 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
|
source ../settings/scripts/ynh_ruby
|
||||||
source ../settings/scripts/ynh_add_swap
|
source ../settings/scripts/ynh_add_swap
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# MANAGE SCRIPT FAILURE
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Reinstalling Ruby..." --weight=4
|
||||||
|
|
||||||
ynh_clean_setup () {
|
ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION"
|
||||||
ynh_clean_check_starting
|
|
||||||
}
|
|
||||||
# Exit if an error occurs during the execution of the script
|
|
||||||
ynh_abort_if_errors
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# 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=$(ynh_app_setting_get --app=$app --key=db_user)
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# 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
|
|
||||||
#=================================================
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESTORE THE APP MAIN DIR
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
|
||||||
|
|
||||||
ynh_restore_file --origin_path="$final_path"
|
|
||||||
|
|
||||||
mkdir -p "$final_path/tmp/pids"
|
|
||||||
chmod 750 "$final_path"
|
|
||||||
chmod -R o-rwx "$final_path"
|
|
||||||
chown -R $app:www-data "$final_path"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC RESTORATION
|
|
||||||
#=================================================
|
|
||||||
# REINSTALL DEPENDENCIES
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
|
||||||
|
|
||||||
# Define and install dependencies
|
|
||||||
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
||||||
ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD SWAP IF NEEDED
|
# ADD SWAP IF NEEDED
|
||||||
|
@ -83,82 +25,68 @@ ynh_script_progression --message="Adding swap if needed..."
|
||||||
total_memory=$(ynh_get_ram --total)
|
total_memory=$(ynh_get_ram --total)
|
||||||
swap_needed=0
|
swap_needed=0
|
||||||
|
|
||||||
if [ $total_memory -lt $MEMORY_NEEDED ]; then
|
if (( MEMORY_NEEDED > total_memory )); then
|
||||||
# Need a minimum of 8Go of memory
|
# Need a minimum of 2.5Go of memory
|
||||||
swap_needed=$(($MEMORY_NEEDED - $total_memory))
|
swap_needed=$((MEMORY_NEEDED - total_memory))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
|
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
|
||||||
ynh_add_swap --size=$swap_needed
|
ynh_add_swap --size=$swap_needed
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE NGINX CONFIGURATION
|
# RESTORE THE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_restore_file --origin_path="$install_dir"
|
||||||
|
|
||||||
|
mkdir -p "$install_dir/tmp/pids"
|
||||||
|
|
||||||
|
chmod -R o-rwx "$install_dir"
|
||||||
|
chown -R "$app:$app" "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE POSTGRESQL DATABASE
|
# RESTORE THE POSTGRESQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the PostgreSQL database..."
|
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
||||||
|
|
||||||
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
||||||
ynh_psql_test_if_first_run
|
|
||||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
||||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;"
|
|
||||||
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
|
|
||||||
|
|
||||||
|
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALLING RUBY AND BUNDLER
|
# INSTALLING RUBY AND BUNDLER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Ruby..."
|
ynh_script_progression --message="Rebuilding $app..."
|
||||||
|
|
||||||
pushd "$final_path"
|
pushd "$install_dir"
|
||||||
ynh_use_ruby
|
ynh_use_ruby
|
||||||
ynh_gem install bundler:1.17.3 --no-document
|
ynh_gem install bundler:1.17.3 --no-document
|
||||||
ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
|
ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE SYSTEMD
|
# RESTORE SYSTEM CONFIGURATIONS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
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-web.service"
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service"
|
||||||
ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service"
|
systemctl enable "$app-web" --quiet
|
||||||
systemctl enable "$app-web" "$app-sidekiq" --quiet
|
yunohost service add "$app-web" --description="$app web service"
|
||||||
|
|
||||||
#=================================================
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service"
|
||||||
# RESTORE THE LOGROTATE CONFIGURATION
|
systemctl enable "$app-sidekiq" --quiet
|
||||||
#=================================================
|
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
||||||
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
|
||||||
|
|
||||||
yunohost service add "$app-web" --description="$app web service"
|
ynh_systemd_action --service_name="${app}-web" --action="start" --log_path=systemd --line_match="listening on"
|
||||||
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path=systemd --line_match="Booted Rails"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# START SYSTEMD SERVICE
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
||||||
|
|
||||||
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="listening on"
|
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Booted Rails"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC FINALIZATION
|
|
||||||
#=================================================
|
|
||||||
# RELOAD NGINX
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Reloading NGINX web server..."
|
|
||||||
|
|
||||||
ynh_systemd_action --service_name=nginx --action=reload
|
ynh_systemd_action --service_name=nginx --action=reload
|
||||||
|
|
||||||
|
|
212
scripts/upgrade
212
scripts/upgrade
|
@ -1,218 +1,108 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_ruby
|
||||||
|
source ynh_add_swap
|
||||||
source /usr/share/yunohost/helpers
|
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)
|
|
||||||
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
||||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
||||||
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
|
|
||||||
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
||||||
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# 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=1
|
|
||||||
|
|
||||||
# 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
|
# 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}-web --action="stop" --log_path=systemd --line_match="Stopped"
|
ynh_systemd_action --service_name="${app}-web" --action="stop" --log_path=systemd
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped"
|
ynh_systemd_action --service_name="${app}-sidekiq" --action="stop" --log_path=systemd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Ensuring 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
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If port_web doesn't exist, create it, needed for old install
|
|
||||||
if [[ -z "$port_web" ]]; then
|
|
||||||
port_web=3000
|
|
||||||
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If db_pwd doesn't exist, create it, needed for old install
|
|
||||||
if [[ -z "$db_pwd" ]]; then
|
|
||||||
db_pwd=$(ynh_string_random)
|
|
||||||
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
|
||||||
ynh_psql_test_if_first_run
|
|
||||||
sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres
|
|
||||||
ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="$config"
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_remove_extra_repo
|
ynh_remove_extra_repo
|
||||||
ynh_app_setting_delete --app=$app --key=redis_namespace
|
ynh_app_setting_delete --app="$app" --key=redis_namespace
|
||||||
ynh_app_setting_delete --app=$app --key=secret_key_base
|
ynh_app_setting_delete --app="$app" --key=secret_key_base
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DEDICATED USER
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
ynh_script_progression --message="Updating Ruby..." --weight=1
|
||||||
|
|
||||||
|
ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION"
|
||||||
|
|
||||||
|
|
||||||
# Create a dedicated user (if not existing)
|
|
||||||
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
then
|
ynh_setup_source --dest_dir="$install_dir"
|
||||||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
chmod -R o-rwx "$install_dir"
|
||||||
ynh_setup_source --dest_dir="$final_path"
|
chown -R "$app:www-data" "$install_dir"
|
||||||
fi
|
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
|
||||||
chmod -R o-rwx "$final_path"
|
|
||||||
chown -R $app:www-data "$final_path"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# UPGRADE DEPENDENCIES
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
||||||
|
|
||||||
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
||||||
ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# NGINX CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
||||||
|
|
||||||
# Create a dedicated NGINX config
|
|
||||||
ynh_add_nginx_config
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC UPGRADE
|
|
||||||
#=================================================
|
|
||||||
# INSTALLING RUBY AND BUNDLER
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Installing Ruby..."
|
|
||||||
|
|
||||||
pushd "$final_path"
|
|
||||||
ynh_use_ruby
|
|
||||||
ynh_gem install bundler:1.17.3 --no-document
|
|
||||||
ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
|
|
||||||
popd
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# UPDATE A CONFIG FILE
|
# UPDATE A CONFIG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
ynh_script_progression --message="Updating $app's configuration files..." --weight=1
|
||||||
|
|
||||||
database_yml="$final_path/config/database.yml"
|
ynh_add_config --template="database.yml.example" --destination="$install_dir/config/database.yml"
|
||||||
diaspora_toml="$final_path/config/diaspora.toml"
|
ynh_add_config --template="diaspora.toml.example" --destination="$install_dir/config/diaspora.toml"
|
||||||
|
|
||||||
ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml"
|
chmod 400 "$install_dir/config/database.yml"
|
||||||
ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml"
|
chmod 400 "$install_dir/config/diaspora.toml"
|
||||||
|
chown "$app:$app" "$install_dir/config/database.yml"
|
||||||
chmod 400 "$database_yml"
|
chown "$app:$app" "$install_dir/config/diaspora.toml"
|
||||||
chown $app:$app "$database_yml"
|
|
||||||
|
|
||||||
chmod 400 "$diaspora_toml"
|
|
||||||
chown $app:$app "$diaspora_toml"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# INSTALLING RUBY AND BUNDLER
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
ynh_script_progression --message="Building $app..."
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
pushd "$install_dir"
|
||||||
ynh_add_systemd_config --service="$app-web" --template="acropolis-web.service"
|
ynh_use_ruby
|
||||||
ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.service"
|
ynh_gem install bundler:1.17.3 --no-document
|
||||||
|
ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc"
|
||||||
|
|
||||||
#=================================================
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config deployment 'true'
|
||||||
# UPGRADE ACROPOLIS
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle config without 'development test'
|
||||||
#=================================================
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
||||||
ynh_script_progression --message="Upgrading acropolis..."
|
|
||||||
|
|
||||||
pushd "$final_path"
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:clean
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config deployment 'true'
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake assets:precompile
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config without 'development test'
|
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" RAILS_ENV=production bin/rake db:migrate
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:clean
|
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile
|
|
||||||
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# REAPPLY SYSTEM CONFIGURATIONS
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
# Create a dedicated NGINX config
|
||||||
|
ynh_add_nginx_config
|
||||||
|
|
||||||
|
# Create a dedicated systemd config
|
||||||
|
ynh_add_systemd_config --service="$app-web" --template="acropolis-web.service"
|
||||||
|
yunohost service add "$app-web" --description="$app web service"
|
||||||
|
|
||||||
|
ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.service"
|
||||||
|
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
||||||
|
|
||||||
# Use logrotate to manage app-specific logfile(s)
|
# Use logrotate to manage app-specific logfile(s)
|
||||||
ynh_use_logrotate --non-append
|
ynh_use_logrotate --non-append
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
||||||
|
|
||||||
yunohost service add "$app-web" --description="$app web service"
|
|
||||||
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# 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}-web --action="start" --log_path=systemd --line_match="listening on"
|
ynh_systemd_action --service_name="${app}-web" --action="start" --log_path=systemd --line_match="listening on"
|
||||||
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Booted Rails"
|
ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path=systemd --line_match="Booted Rails"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RELOAD NGINX
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
||||||
|
|
||||||
ynh_systemd_action --service_name=nginx --action=reload
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
303
scripts/ynh_ruby
Normal file
303
scripts/ynh_ruby
Normal file
|
@ -0,0 +1,303 @@
|
||||||
|
|
||||||
|
ynh_ruby_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
|
||||||
|
}
|
||||||
|
|
||||||
|
rbenv_install_dir="/opt/rbenv"
|
||||||
|
ruby_version_path="$rbenv_install_dir/versions"
|
||||||
|
# RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable.
|
||||||
|
export RBENV_ROOT="$rbenv_install_dir"
|
||||||
|
export rbenv_root="$rbenv_install_dir"
|
||||||
|
# Load the version of Ruby for an app, and set variables.
|
||||||
|
#
|
||||||
|
# ynh_use_ruby has to be used in any app scripts before using Ruby for the first time.
|
||||||
|
# This helper will provide alias and variables to use in your scripts.
|
||||||
|
#
|
||||||
|
# To use gem or Ruby, use the alias `ynh_gem` and `ynh_ruby`
|
||||||
|
# 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_ruby`
|
||||||
|
# And propagate $PATH to sudo with $ynh_ruby_load_path
|
||||||
|
# Exemple: `ynh_exec_as $app $ynh_ruby_load_path $ynh_gem install`
|
||||||
|
#
|
||||||
|
# $PATH contains the path of the requested version of Ruby.
|
||||||
|
# However, $PATH is duplicated into $ruby_path to outlast any manipulation of $PATH
|
||||||
|
# You can use the variable `$ynh_ruby_load_path` to quickly load your Ruby version
|
||||||
|
# in $PATH for an usage into a separate script.
|
||||||
|
# Exemple: $ynh_ruby_load_path $install_dir/script_that_use_gem.sh`
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Finally, to start a Ruby service with the correct version, 2 solutions
|
||||||
|
# Either the app is dependent of Ruby or gem, but does not called it directly.
|
||||||
|
# In such situation, you need to load PATH
|
||||||
|
# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"`
|
||||||
|
# `ExecStart=__INSTALL_DIR__/my_app`
|
||||||
|
# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path
|
||||||
|
#
|
||||||
|
# Or Ruby start the app directly, then you don't need to load the PATH variable
|
||||||
|
# `ExecStart=__YNH_RUBY__ my_app run`
|
||||||
|
# You will replace __YNH_RUBY__ with $ynh_ruby
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# one other variable is also available
|
||||||
|
# - $ruby_path: The absolute path to Ruby binaries for the chosen version.
|
||||||
|
#
|
||||||
|
# usage: ynh_use_ruby
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 2.7.12 or higher.
|
||||||
|
ynh_use_ruby () {
|
||||||
|
ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version)
|
||||||
|
|
||||||
|
# Get the absolute path of this version of Ruby
|
||||||
|
ruby_path="$ruby_version_path/$app/bin"
|
||||||
|
|
||||||
|
# Allow alias to be used into bash script
|
||||||
|
shopt -s expand_aliases
|
||||||
|
|
||||||
|
# Create an alias for the specific version of Ruby and a variable as fallback
|
||||||
|
ynh_ruby="$ruby_path/ruby"
|
||||||
|
alias ynh_ruby="$ynh_ruby"
|
||||||
|
# And gem
|
||||||
|
ynh_gem="$ruby_path/gem"
|
||||||
|
alias ynh_gem="$ynh_gem"
|
||||||
|
|
||||||
|
# Load the path of this version of Ruby in $PATH
|
||||||
|
if [[ :$PATH: != *":$ruby_path"* ]]; then
|
||||||
|
PATH="$ruby_path:$PATH"
|
||||||
|
fi
|
||||||
|
# Create an alias to easily load the PATH
|
||||||
|
ynh_ruby_load_path="PATH=$PATH"
|
||||||
|
|
||||||
|
# Sets the local application-specific Ruby version
|
||||||
|
pushd $install_dir
|
||||||
|
$rbenv_install_dir/bin/rbenv local $ruby_version
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install a specific version of Ruby
|
||||||
|
#
|
||||||
|
# ynh_install_ruby will install the version of Ruby provided as argument by using rbenv.
|
||||||
|
#
|
||||||
|
# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv
|
||||||
|
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
|
||||||
|
#
|
||||||
|
# Don't forget to execute ruby-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 rbenv shims (e.g. $RBENV_ROOT/shims/bundle)
|
||||||
|
#
|
||||||
|
# usage: ynh_install_ruby --ruby_version=ruby_version
|
||||||
|
# | arg: -v, --ruby_version= - Version of ruby to install.
|
||||||
|
#
|
||||||
|
# Requires YunoHost version 2.7.12 or higher.
|
||||||
|
ynh_install_ruby () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=v
|
||||||
|
local -A args_array=( [v]=ruby_version= )
|
||||||
|
local ruby_version
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
|
# Load rbenv path in PATH
|
||||||
|
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
|
||||||
|
|
||||||
|
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
||||||
|
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
||||||
|
|
||||||
|
# Move an existing Ruby binary, to avoid to block rbenv
|
||||||
|
test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
|
||||||
|
|
||||||
|
# Install or update rbenv
|
||||||
|
rbenv="$(command -v rbenv $rbenv_install_dir/bin/rbenv | grep "$rbenv_install_dir/bin/rbenv" | head -1)"
|
||||||
|
if [ -n "$rbenv" ]; then
|
||||||
|
ynh_print_info --message="rbenv already seems installed in \`$rbenv'."
|
||||||
|
pushd "${rbenv%/*/*}"
|
||||||
|
if git remote -v 2>/dev/null | grep "https://github.com/rbenv/rbenv.git"; then
|
||||||
|
ynh_print_info --message="Trying to update with git..."
|
||||||
|
git pull -q --tags origin master
|
||||||
|
ynh_ruby_try_bash_extension
|
||||||
|
else
|
||||||
|
ynh_print_info --message="Reinstalling rbenv with git..."
|
||||||
|
cd ..
|
||||||
|
ynh_secure_remove --file=$rbenv_install_dir
|
||||||
|
mkdir -p $rbenv_install_dir
|
||||||
|
cd $rbenv_install_dir
|
||||||
|
git init -q
|
||||||
|
git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1
|
||||||
|
git checkout -q -b master origin/master
|
||||||
|
ynh_ruby_try_bash_extension
|
||||||
|
rbenv=$rbenv_install_dir/bin/rbenv
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
else
|
||||||
|
ynh_print_info --message="Installing rbenv with git..."
|
||||||
|
mkdir -p $rbenv_install_dir
|
||||||
|
pushd $rbenv_install_dir
|
||||||
|
git init -q
|
||||||
|
git remote add -f -t master origin https://github.com/rbenv/rbenv.git > /dev/null 2>&1
|
||||||
|
git checkout -q -b master origin/master
|
||||||
|
ynh_ruby_try_bash_extension
|
||||||
|
rbenv=$rbenv_install_dir/bin/rbenv
|
||||||
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
ruby_build="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-install rbenv-install | head -1)"
|
||||||
|
if [ -n "$ruby_build" ]; then
|
||||||
|
ynh_print_info --message="\`rbenv install' command already available in \`$ruby_build'."
|
||||||
|
pushd "${ruby_build%/*/*}"
|
||||||
|
if git remote -v 2>/dev/null | grep "https://github.com/rbenv/ruby-build.git"; then
|
||||||
|
ynh_print_info --message="Trying to update rbenv with git..."
|
||||||
|
git pull -q origin master
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
else
|
||||||
|
ynh_print_info --message="Installing ruby-build with git..."
|
||||||
|
mkdir -p "${rbenv_install_dir}/plugins"
|
||||||
|
git clone -q https://github.com/rbenv/ruby-build.git "${rbenv_install_dir}/plugins/ruby-build"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rbenv_alias="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-alias rbenv-alias | head -1)"
|
||||||
|
if [ -n "$rbenv_alias" ]; then
|
||||||
|
ynh_print_info --message="\`rbenv alias' command already available in \`$rbenv_alias'."
|
||||||
|
pushd "${rbenv_alias%/*/*}"
|
||||||
|
if git remote -v 2>/dev/null | grep "https://github.com/tpope/rbenv-aliases.git"; then
|
||||||
|
ynh_print_info --message="Trying to update rbenv-aliases with git..."
|
||||||
|
git pull -q origin master
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
else
|
||||||
|
ynh_print_info --message="Installing rbenv-aliases with git..."
|
||||||
|
mkdir -p "${rbenv_install_dir}/plugins"
|
||||||
|
git clone -q https://github.com/tpope/rbenv-aliases.git "${rbenv_install_dir}/plugins/rbenv-aliase"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rbenv_latest="$(command -v "$rbenv_install_dir"/plugins/*/bin/rbenv-latest rbenv-latest | head -1)"
|
||||||
|
if [ -n "$rbenv_latest" ]; then
|
||||||
|
ynh_print_info --message="\`rbenv latest' command already available in \`$rbenv_latest'."
|
||||||
|
pushd "${rbenv_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 "${rbenv_install_dir}/plugins"
|
||||||
|
git clone -q https://github.com/momo-lab/xxenv-latest.git "${rbenv_install_dir}/plugins/xxenv-latest"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable caching
|
||||||
|
mkdir -p "${rbenv_install_dir}/cache"
|
||||||
|
|
||||||
|
# Create shims directory if needed
|
||||||
|
mkdir -p "${rbenv_install_dir}/shims"
|
||||||
|
|
||||||
|
# Restore /usr/local/bin in PATH
|
||||||
|
PATH=$CLEAR_PATH
|
||||||
|
|
||||||
|
# And replace the old Ruby binary
|
||||||
|
test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
|
||||||
|
|
||||||
|
# Install the requested version of Ruby
|
||||||
|
local final_ruby_version=$(rbenv latest --print $ruby_version)
|
||||||
|
if ! [ -n "$final_ruby_version" ]; then
|
||||||
|
final_ruby_version=$ruby_version
|
||||||
|
fi
|
||||||
|
ynh_print_info --message="Installing Ruby-$final_ruby_version"
|
||||||
|
CONFIGURE_OPTS="--disable-install-doc --with-jemalloc" MAKE_OPTS="-j2" rbenv install --skip-existing $final_ruby_version > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Store ruby_version into the config of this app
|
||||||
|
ynh_app_setting_set --app=$app --key=ruby_version --value=$final_ruby_version
|
||||||
|
|
||||||
|
# Remove app virtualenv
|
||||||
|
if `rbenv alias --list | grep --quiet "$app " 1>/dev/null 2>&1`
|
||||||
|
then
|
||||||
|
rbenv alias $app --remove
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create app virtualenv
|
||||||
|
rbenv alias $app $final_ruby_version
|
||||||
|
|
||||||
|
# Cleanup Ruby versions
|
||||||
|
ynh_cleanup_ruby
|
||||||
|
|
||||||
|
# Set environment for Ruby users
|
||||||
|
echo "#rbenv
|
||||||
|
export RBENV_ROOT=$rbenv_install_dir
|
||||||
|
export PATH=\"$rbenv_install_dir/bin:$PATH\"
|
||||||
|
eval \"\$(rbenv init -)\"
|
||||||
|
#rbenv" > /etc/profile.d/rbenv.sh
|
||||||
|
|
||||||
|
# Load the environment
|
||||||
|
eval "$(rbenv init -)"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove the version of Ruby used by the app.
|
||||||
|
#
|
||||||
|
# This helper will also cleanup Ruby versions
|
||||||
|
#
|
||||||
|
# usage: ynh_remove_ruby
|
||||||
|
ynh_remove_ruby () {
|
||||||
|
local ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version)
|
||||||
|
|
||||||
|
# Load rbenv path in PATH
|
||||||
|
local CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
|
||||||
|
|
||||||
|
# Remove /usr/local/bin in PATH in case of Ruby prior installation
|
||||||
|
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
|
||||||
|
|
||||||
|
#REMOVEME? rbenv alias $app --remove
|
||||||
|
|
||||||
|
# Remove the line for this app
|
||||||
|
#REMOVEME? ynh_app_setting_delete --app=$app --key=ruby_version
|
||||||
|
|
||||||
|
# Cleanup Ruby versions
|
||||||
|
ynh_cleanup_ruby
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove no more needed versions of Ruby used by the app.
|
||||||
|
#
|
||||||
|
# This helper will check what Ruby version are no more required,
|
||||||
|
# and uninstall them
|
||||||
|
# If no app uses Ruby, rbenv will be also removed.
|
||||||
|
#
|
||||||
|
# usage: ynh_cleanup_ruby
|
||||||
|
ynh_cleanup_ruby () {
|
||||||
|
|
||||||
|
# List required Ruby versions
|
||||||
|
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
|
||||||
|
local required_ruby_versions=""
|
||||||
|
for installed_app in $installed_apps
|
||||||
|
do
|
||||||
|
local installed_app_ruby_version=$(ynh_app_setting_get --app=$installed_app --key="ruby_version")
|
||||||
|
if [[ $installed_app_ruby_version ]]
|
||||||
|
then
|
||||||
|
required_ruby_versions="${installed_app_ruby_version}\n${required_ruby_versions}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove no more needed Ruby versions
|
||||||
|
local installed_ruby_versions=$(rbenv versions --bare --skip-aliases | grep -Ev '/')
|
||||||
|
for installed_ruby_version in $installed_ruby_versions
|
||||||
|
do
|
||||||
|
if ! `echo ${required_ruby_versions} | grep "${installed_ruby_version}" 1>/dev/null 2>&1`
|
||||||
|
then
|
||||||
|
ynh_print_info --message="Removing of Ruby-$installed_ruby_version"
|
||||||
|
$rbenv_install_dir/bin/rbenv uninstall --force $installed_ruby_version
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If none Ruby version is required
|
||||||
|
if [[ ! $required_ruby_versions ]]
|
||||||
|
then
|
||||||
|
# Remove rbenv environment configuration
|
||||||
|
ynh_print_info --message="Removing of rbenv-$rbenv_version"
|
||||||
|
ynh_secure_remove --file="$rbenv_install_dir"
|
||||||
|
ynh_secure_remove --file="/etc/profile.d/rbenv.sh"
|
||||||
|
fi
|
||||||
|
}
|
19
tests.toml
Normal file
19
tests.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json
|
||||||
|
|
||||||
|
test_format = 1.0
|
||||||
|
|
||||||
|
[default]
|
||||||
|
|
||||||
|
args.email = "admin@domain.tld"
|
||||||
|
|
||||||
|
exclude = [
|
||||||
|
"install.subdir"
|
||||||
|
]
|
||||||
|
|
||||||
|
[default.test_upgrade_from.dc712d6bf6dd2f67b9863b03b8a6a3705713a81c]
|
||||||
|
name = "previous version"
|
||||||
|
|
||||||
|
args.admin = "package_checker"
|
||||||
|
args.email = "admin@domain.tld"
|
||||||
|
args.password = "1Strong-Password"
|
||||||
|
args.domain = "domain.tld"
|
Loading…
Reference in a new issue