1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/huginn_ynh.git synced 2024-09-03 19:26:13 +02:00

Apply example_ynh

This commit is contained in:
yalh76 2022-03-25 01:57:12 +01:00
parent 8729f3aee3
commit 18f75334d1
24 changed files with 1592 additions and 259 deletions

55
.github/ISSUE_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,55 @@
---
name: Bug report
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
**How to post a meaningful bug report**
1. *Read this whole template first.*
2. *Determine if you are on the right place:*
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!*
- *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
### Describe the bug
*A clear and concise description of what the bug is.*
### Context
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes*
- If yes, please explain:
- Using, or trying to install package version/branch:
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install the_app
```
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
- *If the error occurs in your browser, explain what you did:*
1. *Go to '...'*
2. *Click on '...'*
3. *Scroll down to '...'*
4. *See error*
### Expected behavior
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
### Logs
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

16
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished and ready to be reviewed/tested
- [ ] The fix/enhancement were manually tested (if applicable)
## Automatic tests
Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)

View file

@ -1,4 +1,3 @@
The MIT License
Copyright (c) 2013, Andrew Cantino (Iteration Labs, LLC)
@ -19,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.

24
check_process Normal file
View file

@ -0,0 +1,24 @@
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
is_public=1
admin="john"
password="1Strong-Password"
invitation="invitationcode"
; Checks
pkg_linter=1
setup_sub_dir=1
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=CommitHash
backup_restore=1
multi_instance=1
port_already_use=0
change_url=1
;;; Options
Email=
Notification=none

263
conf/.env.example Normal file
View file

@ -0,0 +1,263 @@
# ==== Required configuration settings for Huginn ====
# Replace the following with the output from "rake secret"
APP_SECRET_TOKEN=__SECRET__
# This is the domain where your Huginn instance will be running. The default should work
# for development, but it needs to be changed to your Huginn domain when you deploy to a
# production environment (e.g., yourdomain.com, possibly including a port).
DOMAIN=__DOMAIN__
PORT=__PORT__
# Optionally set an asset host
# ASSET_HOST=http://assets.example.com
############################
# Database Setup #
############################
DATABASE_ADAPTER=mysql2
DATABASE_ENCODING=utf8
DATABASE_RECONNECT=true
DATABASE_NAME=__DB_NAME__
DATABASE_POOL=20
DATABASE_USERNAME=__DB_USER__
DATABASE_PASSWORD="__DB_PWD__"
#DATABASE_HOST=your-domain-here.com
#DATABASE_PORT=3306
#DATABASE_SOCKET=/tmp/mysql.sock
# MySQL only: If you are running a MySQL server >=5.5.3, you should
# set DATABASE_ENCODING to utf8mb4 instead of utf8 so that the
# database can hold 4-byte UTF-8 characters like emoji.
#DATABASE_ENCODING=utf8mb4
# ==== Additional required production settings ====
# Configure Rails environment. This should only be needed in production and may cause errors in development.
RAILS_ENV=production
# Should Rails force all requests to use SSL?
FORCE_SSL=false
################################################
# User authentication and registration #
################################################
# This invitation code will be required for users to signup with your Huginn installation.
# You can see its use in user.rb. PLEASE CHANGE THIS!
INVITATION_CODE=__INVITATION__
# If you don't want to require new users to have an invitation code in order to sign up, set this to true.
SKIP_INVITATION_CODE=false
# If you'd like to require new users to confirm their email address after sign up, set this to true.
REQUIRE_CONFIRMED_EMAIL=false
# If REQUIRE_CONFIRMED_EMAIL is true, set this to the duration in which a user needs to confirm their email address.
ALLOW_UNCONFIRMED_ACCESS_FOR=2.days
# Duration for which the above confirmation token is valid
CONFIRM_WITHIN=3.days
# Minimum password length
MIN_PASSWORD_LENGTH=8
# Duration for which the reset password token is valid
RESET_PASSWORD_WITHIN=6.hours
# Set to 'failed_attempts' to lock user accounts for the UNLOCK_AFTER period they fail MAX_FAILED_LOGIN_ATTEMPTS login attempts. Set to 'none' to allow unlimited failed login attempts.
LOCK_STRATEGY=failed_attempts
# After how many failed login attempts the account is locked when LOCK_STRATEGY is set to failed_attempts.
MAX_FAILED_LOGIN_ATTEMPTS=10
# Can be set to 'email', 'time', 'both' or 'none'. 'none' requires manual unlocking of your users!
UNLOCK_STRATEGY=both
# Duration after which the user is unlocked when UNLOCK_STRATEGY is 'both' or 'time' and LOCK_STRATEGY is 'failed_attempts'
UNLOCK_AFTER=1.hour
# Duration for which the user will be remembered without asking for credentials again.
REMEMBER_FOR=4.weeks
# Set to 'true' if you would prefer new users to start with a default set of agents
IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS=true
# Users can be given a default set of agents to get them started
# You can override this scenario with your own scenario via file path or URL
# DEFAULT_SCENARIO_FILE=path-or-url-to-scenario.json
#############################
# Email Configuration #
#############################
# Outgoing email settings. To use Gmail or Google Apps, put your Google Apps domain or gmail.com
# as the SMTP_DOMAIN and your Gmail username and password as the SMTP_USER_NAME and SMTP_PASSWORD.
#
# PLEASE NOTE: In order to enable sending real emails via SMTP locally (e.g., when not in the production Rails environment),
# you must also set SEND_EMAIL_IN_DEVELOPMENT to true below.
#
# If you have trouble with port 587 on Gmail, you can also try setting
# SMTP_AUTHENTICATION to login and the SMTP_PORT to 465.
#
# If you use a local SMTP server without authentication such as Postfix,
# SMTP_USER_NAME must be set to none or else you will receive
# errors that AUTH not enabled.
# Uncomment if you want to use `/usr/sbin/sendmail` to send email instead of SMTP.
# This option is ignored unless RAILS_ENV=production, and setting it to `sendmail` causes the settings in the rest of this section (except EMAIL_FROM_ADDRESS) to be ignored.
# SMTP_DELIVERY_METHOD=sendmail
SMTP_DOMAIN=__DOMAIN__
SMTP_USER_NAME=
SMTP_PASSWORD=
SMTP_SERVER=localhost
SMTP_PORT=25
SMTP_AUTHENTICATION=none
SMTP_ENABLE_STARTTLS_AUTO=false
SMTP_SSL=false
# Set to true to send real emails via SMTP when running in the development Rails environment.
# Set to false to have emails intercepted in development and displayed at http://localhost:3000/letter_opener
SEND_EMAIL_IN_DEVELOPMENT=false
# The address from which system emails will appear to be sent.
EMAIL_FROM_ADDRESS=__APP__@__DOMAIN__
###########################
# Agent Logging #
###########################
# Number of lines of log messages to keep per Agent
AGENT_LOG_LENGTH=200
#######################################################################################################
# OAuth Configuration #
# More information at the wiki: https://github.com/huginn/huginn/wiki/Configuring-OAuth-applications #
#######################################################################################################
TWITTER_OAUTH_KEY=
TWITTER_OAUTH_SECRET=
THIRTY_SEVEN_SIGNALS_OAUTH_KEY=
THIRTY_SEVEN_SIGNALS_OAUTH_SECRET=
GITHUB_OAUTH_KEY=
GITHUB_OAUTH_SECRET=
TUMBLR_OAUTH_KEY=
TUMBLR_OAUTH_SECRET=
DROPBOX_OAUTH_KEY=
DROPBOX_OAUTH_SECRET=
EVERNOTE_OAUTH_KEY=
EVERNOTE_OAUTH_SECRET=
# Set to true in development, false in production
USE_EVERNOTE_SANDBOX=true
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
#############################
# AWS and Mechanical Turk #
#############################
# AWS Credentials for MTurk
AWS_ACCESS_KEY_ID="your aws access key id"
AWS_ACCESS_KEY="your aws access key"
# Set AWS_SANDBOX to true if you're developing Huginn code.
AWS_SANDBOX=false
#########################
# Additional Agent gems #
#########################
# Agent gems can be added to Huginn by specifying them in a comma separated
# list, the gem version and arguments for the gem command are optional.
# When not providing a git(hub) repository the gem needs to be published to
# https://rubygems.org.
# Check http://bundler.io/v1.11/git.html for a list of valid arguments.
#
# Configuration examples:
#
# ADDITIONAL_GEMS=huginn_nlp_agents,test_agent
# ADDITIONAL_GEMS=huginn_nlp_agents(~> 0.2.1),test_agent
# ADDITIONAL_GEMS=huginn_nlp_agents(git: https://github.com/kreuzwerker/DKT.huginn_nlp_agents.git),test_agent
# ADDITIONAL_GEMS=huginn_nlp_agents(github: kreuzwerker/DKT.huginn_nlp_agents),test_agent
# ADDITIONAL_GEMS=huginn_nlp_agents(~> 0.2.1, git: https://github.com/kreuzwerker/DKT.huginn_nlp_agents.git),test_agent
########################
# Various Settings #
########################
# Specify the HTTP backend library for Faraday, commonly used by
# WebsiteAgent, RssAgent and PostAgent. You can change this depending
# on the performance and stability you need for your service. Any
# choice other than "typhoeus", "net_http", or "em_http" should
# require you to bundle a corresponding gem via Gemfile.
FARADAY_HTTP_BACKEND=typhoeus
# Specify the default User-Agent header value for HTTP requests made
# by Agents that allow overriding the User-Agent header value.
DEFAULT_HTTP_USER_AGENT="Huginn - https://github.com/huginn/huginn"
# Enable this setting to allow insecure Agents like the ShellCommandAgent. Only do this
# when you trust everyone using your Huginn installation.
ENABLE_INSECURE_AGENTS=false
# Enable this setting to allow second precision schedule in
# SchedulerAgent. By default, the use of the "second" field is
# restricted so that any value other than a single zero (which means
# "on the minute") is disallowed to prevent abuse of service.
ENABLE_SECOND_PRECISION_SCHEDULE=false
# Specify the scheduler frequency in seconds (default: 0.3).
# Increasing this value will help reduce the use of system resources
# at the expense of time accuracy.
SCHEDULER_FREQUENCY=0.3
# Specify the frequency with which the scheduler checks for and cleans up expired events.
# You can use `m` for minutes, `h` for hours, and `d` for days.
EVENT_EXPIRATION_CHECK=6h
# Enable JqAgent which uses jq. Specify a file path to the jq(1)
# command or just `jq`. This is not enabled by default because jq can
# cause infinite loop and is not suitable for public service.
# Only uncomment this when you trust everyone using your Huginn
# installation.
#USE_JQ=jq
# Use Graphviz for generating diagrams instead of using Google Chart
# Tools. Specify a dot(1) command path built with SVG support
# enabled.
#USE_GRAPHVIZ_DOT=dot
# Default layout for agent flow diagrams generated by Graphviz.
# Choose from `circo`, `dot` (default), `fdp`, `neato`, `osage`,
# `patchwork`, `sfdp`, or `twopi`. Note that not all layouts are
# supported by Graphviz depending on the build options.
#DIAGRAM_DEFAULT_LAYOUT=dot
# Timezone. Use `rake time:zones:local` or `rake time:zones:all` to get your zone name
TIMEZONE="Pacific Time (US & Canada)"
# Number of failed jobs to keep in the database
FAILED_JOBS_TO_KEEP=100
# Maximum runtime of background jobs in minutes
DELAYED_JOB_MAX_RUNTIME=2
# Amount of seconds for delayed_job to sleep before checking for new jobs
DELAYED_JOB_SLEEP_DELAY=10
################################################################################
# Capistrano deployment, read the documentation: #
# https://github.com/huginn/huginn/blob/master/doc/manual/capistrano.md#readme #
################################################################################
#CAPISTRANO_DEPLOY_SERVER=
#CAPISTRANO_DEPLOY_USER=
#CAPISTRANO_DEPLOY_REPO_URL=

View file

@ -1,50 +0,0 @@
###############################
# DEVELOPMENT #
###############################
# Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job)
#web: bundle exec rails server -b0.0.0.0
#jobs: bundle exec rails runner bin/threaded.rb
# Old version with separate processes (use this if you have issues with the threaded version)
# web: bundle exec rails server
# schedule: bundle exec rails runner bin/schedule.rb
# twitter: bundle exec rails runner bin/twitter_stream.rb
# dj: bundle exec script/delayed_job run
###############################
# PRODUCTION #
###############################
# You need to copy or link config/unicorn.rb.example to config/unicorn.rb for both production versions.
# Have a look at the deployment guides, if you want to set up huginn on your server:
# https://github.com/cantino/huginn/doc
# Using the threaded worker (consumes less RAM but can run slower)
web: bundle exec unicorn -c config/unicorn.rb
jobs: bundle exec rails runner bin/threaded.rb
# Old version with separate processes (use this if you have issues with the threaded version)
# web: bundle exec unicorn -c config/unicorn.rb
# schedule: bundle exec rails runner bin/schedule.rb
# twitter: bundle exec rails runner bin/twitter_stream.rb
# dj: bundle exec script/delayed_job run
###############################
# Multiple DelayedJob workers #
###############################
# Per default Huginn can just run one agent at a time. Using a lot of agents or calling slow
# external services frequently might require more DelayedJob workers (an indicator for this is
# a backlog in your 'Job Management' page).
# Every uncommented line starts an additional DelayedJob worker. This works for development, production
# and for the threaded and separate worker processes. Keep in mind one worker needs about 300MB of RAM.
#
#dj2: bundle exec script/delayed_job -i 2 run
#dj3: bundle exec script/delayed_job -i 3 run
#dj4: bundle exec script/delayed_job -i 4 run
#dj5: bundle exec script/delayed_job -i 5 run
#dj6: bundle exec script/delayed_job -i 6 run
#dj7: bundle exec script/delayed_job -i 7 run
#dj8: bundle exec script/delayed_job -i 8 run
#dj9: bundle exec script/delayed_job -i 9 run
#dj10: bundle exec script/delayed_job -i 10 run

7
conf/app.src Normal file
View file

@ -0,0 +1,7 @@
SOURCE_URL=https://codeload.github.com/huginn/huginn/tar.gz/c68274384cc7e7d2ab24ef70e5280bcbd5ca57c6
SOURCE_SUM=5794a7a1b230ebac01b3d409eb40d90f68c1646e4f042777134499c68315f72e
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

16
conf/jobs.service Normal file
View file

@ -0,0 +1,16 @@
[Unit]
Description=__APP__-jobs service
After=network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
EnvironmentFile=__FINALPATH__/.env
ExecStart=/opt/rbenv/versions/__RUBY_VERSION__/bin/bundle exec rails runner bin/threaded.rb
StandardOutput=append:/var/log/__APP__/__APP__-jobs.log
StandardError=inherit
[Install]
WantedBy=multi-user.target

View file

@ -1,45 +1,31 @@
location YNH_WWW_PATH {
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Path to source
root /home/huginn/huginn/public;
## @huginn is a named location for the upstream fallback, see below.
try_files $uri $uri/index.html $uri.html @huginn;
alias __FINALPATH__/public/;
## @huginn is a named location for the upstream fallback, see below.
try_files $uri $uri/index.html $uri.html @huginn;
# Include SSOWAT user panel.
#include conf.d/yunohost_panel.conf.inc;
}
location @huginn {
## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
gzip off;
location @huginn {
## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://unix:/home/huginn/huginn/tmp/sockets/unicorn.socket;
}
## Enable gzip compression as per rails guide:
## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
location ~ ^/(assets)/ {
root /home/huginn/huginn/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
proxy_pass http://unix:/__FINALPATH__/tmp/sockets/unicorn.socket;
}

16
conf/web.service Normal file
View file

@ -0,0 +1,16 @@
[Unit]
Description=__APP__-web service
After=network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
EnvironmentFile=__FINALPATH__/.env
ExecStart=/opt/rbenv/versions/__RUBY_VERSION__/bin/bundle exec unicorn -c config/unicorn.rb
StandardOutput=append:/var/log/__APP__/__APP__-web.log
StandardError=inherit
[Install]
WantedBy=multi-user.target

0
doc/.gitkeep Normal file
View file

1
doc/DESCRIPTION.md Normal file
View file

@ -0,0 +1 @@
Huginn is a system for building agents that perform automated tasks for you online. They can read the web, watch for events, and take actions on your behalf. Huginn's Agents create and consume events, propagating them along a directed graph. Think of it as a hackable version of IFTTT or Zapier on your own server. You always know who has your data. You do.

0
doc/DISCLAIMER.md Normal file
View file

0
doc/screenshots/.gitkeep Normal file
View file

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

View file

@ -1,62 +1,64 @@
{
"name": "Huginn",
"id": "huginn",
"packaging_format": 1,
"description": {
"en": " Build agents that monitor and act on your behalf. Your agents are standing by!"
},
"licence": "free",
"version": "2022.03.24~ynh1",
"url": "https://github.com/huginn/hugin",
"upstream": {
"license": "MIT",
"website": "https://github.com/huginn/hugin",
"code": "https://github.com/huginn/huginn"
},
"license": "MIT",
"maintainer": {
"name": "aurel",
"email": "aurel@grudu.ovh",
"url": "https://github.com/onde2rock/huginn_ynh"
},
"multi_instance": "false",
"requirements": {
"yunohost": ">= 4.3.0"
},
"multi_instance": true,
"services": [
"nginx",
"php7.3-fpm",
"mysql"
],
"arguments": {
"install" : [
"install": [
{
"name": "domain",
"ask": {
"en": "Choose a domain for huginn"
},
"example": "example.com"
"type": "domain"
},
{
"name": "path",
"ask": {
"en": "Choose a path for huginn"
},
"example": "/example",
"choices": ["/"],
"default": "/"
"type": "path",
"example": "/huginn",
"default": "/huginn"
},
{
"name": "is_public",
"type": "boolean",
"default": true
},
{
"name": "admin",
"ask": {
"en": "Choose an admin user"
},
"example": "johndoe"
"type": "user"
},
{
"name": "password",
"ask": {
"en": "Choose an admin password"
},
"example": "supersecretpassword"
"type": "password"
},
{
{
"name": "invitation",
"type": "string",
"ask": {
"en": "Choose an invitation code for new users"
},
"example": "invitationcode"
},
{
"name": "is_public",
"ask": {
"en": "Is it a public application ?"
},
"choices": ["Yes", "No"],
"default": "No"
}
]
}

23
scripts/_common.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies=""
build_pkg_dependencies="default-libmysqlclient-dev libyaml-dev libgdbm-dev libncurses5-dev libffi-dev libcurl4-openssl-dev libicu-dev python-docutils pkg-config cmake nodejs graphviz jq"
ruby_version=2.6
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

71
scripts/backup Normal file
View file

@ -0,0 +1,71 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app-web.service"
ynh_backup --src_path="/etc/systemd/system/$app-jobs.service"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

149
scripts/change_url Normal file
View file

@ -0,0 +1,149 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
port=$(ynh_app_setting_get --app=$app --key=port)
secret=$(ynh_app_setting_get --app=$app --key=secret)
invitation=$(ynh_app_setting_get --app=$app --key=invitation)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app-web --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app-jobs --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..."
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
domain=$new_domain
path_url=$new_path
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app-web" --action="start" --log_path="/var/log/$app/$app-web.log" --line_match="Started"
ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="/var/log/$app/$app-jobs.log" --line_match="Started"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app"

View file

@ -1,162 +1,208 @@
#!/bin/bash
old_pwd=$(pwd)
APP=huginn
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Retrieve arguments
domain=$1
path=$2
admin=$3
admin_pwd=$4
invitation=$5
is_public=$6
source _common.sh
source ynh_install_ruby__2
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Save APP settings
sudo yunohost app setting $APP admin -v "$admin"
sudo yunohost app setting $APP is_public -v "$is_public"
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $APP
if [[ ! $? -eq 0 ]]; then
exit 1
fi
#Import node.js repository (can be skipped on Ubuntu and Debian Jessie):
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
# Install dependencies
sudo apt-get update -qq
sudo apt-get install -y runit build-essential git zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs graphviz -qq
#Remove the old Ruby versions if present:
sudo apt-get remove -y ruby1.8 ruby1.9 -qq
#Download Ruby and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
curl -L --silent http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.bz2 | tar xj
cd ruby-2.2.3
./configure --disable-install-rdoc > /dev/null
make -j -s `nproc`
sudo make install
#Install the bundler and foreman gems:
sudo gem install bundler foreman --no-ri --no-rdoc
#Create a user for Huginn:
sudo adduser --disabled-login --gecos 'Huginn' huginn
#Install the database packages
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev -qq
# Initialize database and store mysql password for upgrade
db_pwd=$(sudo yunohost app initdb huginn -d huginn_production)
sudo yunohost app setting huginn mysqlpwd -v $db_pwd
# Delete db and user if exit with an error
function exit_properly
{
set +e
root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE huginn_production ; DROP USER $APP@localhost ;"
sudo userdel $APP
sudo rm -rf /home/huginn
exit 1
ynh_clean_setup () {
ynh_clean_check_starting
}
trap exit_properly ERR
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# We'll install Huginn into the home directory of the user "huginn"
cd /home/huginn
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
invitation=$YNH_APP_ARG_INVITATION
# Clone Huginn repository
sudo sudo -u huginn -H git clone https://github.com/cantino/huginn.git -b master huginn
app=$YNH_APP_INSTANCE_NAME
# Go to Huginn installation folder
cd /home/huginn/huginn
secret=$(ynh_string_random --length=16)
# Copy the example Huginn config
sudo sudo -u huginn -H cp .env.example .env
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
# Create the log/, tmp/pids/ and tmp/sockets/ directories
sudo sudo -u huginn mkdir -p log tmp/pids tmp/sockets
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Make sure Huginn can write to the log/ and tmp/ directories
sudo chown -R huginn log/ tmp/
sudo chmod -R u+rwX,go-w log/ tmp/
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
# Make sure permissions are set correctly
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/
sudo sudo -u huginn -H chmod o-rwx .env
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
# Copy the example Unicorn config
sudo sudo -u huginn -H cp config/unicorn.rb.example config/unicorn.rb
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
ynh_app_setting_set --app=$app --key=invitation --value=$invitation
ynh_app_setting_set --app=$app --key=secret --value=$secret
#Install Gems
sudo sudo -u huginn -H bundle install --deployment --without development test
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..."
#rake secret
RAKE_SECRET=$(sudo sudo -u huginn -H rake secret)
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
#Edit .env
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
sudo sudo -u huginn -H sed -i "s/\(DATABASE_PASSWORD *= *\).*/\1\"$db_pwd\"/" .env
sudo sudo -u huginn -H sed -i "s/\(DATABASE_USERNAME *= *\).*/\1\"huginn\"/" .env
sudo sudo -u huginn -H sed -i "s/\(DATABASE_NAME *= *\).*/\1huginn_production/" .env
sudo sudo -u huginn -H sed -i "s/\(APP_SECRET_TOKEN *= *\).*/\1$RAKE_SECRET/" .env
sudo sudo -u huginn -H sed -i "s/\(INVITATION_CODE *= *\).*/\1$invitation/" .env
ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
ynh_install_ruby --ruby_version=$ruby_version
#uncomment RAILS_ENV
sudo sudo -u huginn -H sed -i '/# RAILS_ENV=production/s/^# //' .env
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
# Create the database
sudo sudo -u huginn -H bundle exec rake db:create RAILS_ENV=production
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
# Migrate to the latest version
sudo sudo -u huginn -H bundle exec rake db:migrate RAILS_ENV=production
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
# Create admin user and example agents
sudo sudo -u huginn -H bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=$admin SEED_PASSWORD=$admin_pwd
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
# Compile Assets
sudo sudo -u huginn -H bundle exec rake assets:precompile RAILS_ENV=production
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"
#Edit the `Procfile`
cd $old_pwd
sudo cp ../conf/Procfile /home/huginn/huginn/
cd /home/huginn/huginn/
mkdir -p "$final_path/log" "$final_path/tmp/pids" "$final_path/tmp/sockets"
#Export the init scripts:
sudo rake production:export
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
### Setup Logrotate
sudo cp deployment/logrotate/huginn /etc/logrotate.d/huginn
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Modify Nginx configuration file and copy it to Nginx conf directory
cd $old_pwd
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
# Create a dedicated NGINX config
ynh_add_nginx_config
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$APP.conf
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
# If APP is public, add url to SSOWat conf as skipped_uris
if [ "$is_public" = "Yes" ];
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..."
pushd $final_path
ynh_use_ruby
cp config/unicorn.rb.example config/unicorn.rb
chown -R $app:www-data "$final_path/config/unicorn.rb"
#ynh_gem update --system
ynh_gem install bundler foreman --no-document
bundle install --deployment --without development test
bundle exec rake db:create RAILS_ENV=production
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=$admin SEED_PASSWORD=$password
bundle exec rake assets:precompile RAILS_ENV=production
popd
ynh_install_app_dependencies $pkg_dependencies
chmod 750 "$final_path/public"
chmod -R o-rwx "$final_path/public"
chown -R $app:www-data "$final_path/public"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-web" --template="web.service"
ynh_add_systemd_config --service="$app-jobs" --template="jobs.service"
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add "$app-web" --log="/var/log/$app/$app-web.log"
yunohost service add "$app-jobs" --log="/var/log/$app/$app-jobs.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app-web" --action="start" --log_path="/var/log/$app/$app-web.log" --line_match="Started"
ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="/var/log/$app/$app-jobs.log" --line_match="Started"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
sudo yunohost app setting $APP unprotected_uris -v "/"
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
#don't know where to desactivate the default in nginx, so i just delete it
sudo rm /usr/share/nginx/html/index.html
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"

View file

@ -1,30 +1,107 @@
#!/bin/bash
app=huginn
# Retrieve arguments
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
admin=$(sudo yunohost app setting $app admin)
is_public=$(sudo yunohost app setting $app is_public)
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_install_ruby__2
source /usr/share/yunohost/helpers
cd /home/huginn/huginn/
sudo rake production:stop
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
# Remove sources
sudo rm -rf /home/$app
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE huginn_production ; DROP USER $APP@localhost ;"
sudo userdel huginn
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove configuration files
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
# 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
then
ynh_script_progression --message="Removing $app-web service integration..."
yunohost service remove "$app-web"
fi
if ynh_exec_warn_less yunohost service status "$app-jobs" >/dev/null
then
ynh_script_progression --message="Removing $app-jobs service integration..."
yunohost service remove "$app-jobs"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config
ynh_remove_systemd_config --service="$app-web"
ynh_remove_systemd_config --service="$app-jobs"
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..."
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..."
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies
ynh_remove_ruby
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed"

135
scripts/restore Normal file
View file

@ -0,0 +1,135 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# 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/ynh_install_ruby__2
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
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..."
# 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..."
ynh_restore_file --origin_path="$final_path"
mkdir -p "$final_path/log" "$final_path/tmp/pids" "$final_path/tmp/sockets"
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..."
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
ynh_install_ruby --ruby_version=$ruby_version
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..."
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service"
systemctl enable $app-web.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/$app-jobs.service"
systemctl enable $app-jobs.service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
ynh_add_systemd_config --service="$app-web" --template="web.service"
ynh_add_systemd_config --service="$app-jobs" --template="jobs.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
yunohost service add "$app-web" --log="/var/log/$app/$app-web.log"
yunohost service add "$app-jobs" --log="/var/log/$app/$app-jobs.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app"

188
scripts/upgrade Normal file
View file

@ -0,0 +1,188 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_install_ruby__2
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
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=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
port=$(ynh_app_setting_get --app=$app --key=port)
secret=$(ynh_app_setting_get --app=$app --key=secret)
invitation=$(ynh_app_setting_get --app=$app --key=invitation)
#=================================================
# 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)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app-web --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app-jobs --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --keep=".env"
mkdir -p "$final_path/log" "$final_path/tmp/pids" "$final_path/tmp/sockets"
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
ynh_install_ruby --ruby_version=$ruby_version
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..."
pushd $final_path
ynh_use_ruby
cp -f config/unicorn.rb.example config/unicorn.rb
chown -R $app:www-data "$final_path/config/unicorn.rb"
#ynh_gem update --system
ynh_gem install bundler foreman --no-document
bundle install --deployment --without development test
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
popd
ynh_install_app_dependencies $pkg_dependencies
chmod 750 "$final_path/public"
chmod -R o-rwx "$final_path/public"
chown -R $app:www-data "$final_path/public"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-web" --template="web.service"
ynh_add_systemd_config --service="$app-jobs" --template="jobs.service"
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add "$app-web" --log="/var/log/$app/$app-web.log"
yunohost service add "$app-jobs" --log="/var/log/$app/$app-jobs.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name="$app-web" --action="start" --log_path="/var/log/$app/$app-web.log" --line_match="Started"
ynh_systemd_action --service_name="$app-jobs" --action="start" --log_path="/var/log/$app/$app-jobs.log" --line_match="Started"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed"

309
scripts/ynh_install_ruby__2 Normal file
View file

@ -0,0 +1,309 @@
#!/bin/bash
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"
ruby_dependencies=""
build_ruby_dependencies="libjemalloc-dev curl build-essential libreadline-dev zlib1g-dev libsqlite3-dev libssl-dev libxml2-dev libxslt-dev autoconf automake bison libtool"
pkg_dependencies="$pkg_dependencies $ruby_dependencies"
build_pkg_dependencies="$build_pkg_dependencies $build_ruby_dependencies"
# 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_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_RUBY_LOAD_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 3.2.2 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 3.2.2 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
}