doc/packaging_apps.md

230 lines
9.7 KiB
Markdown
Raw Normal View History

2013-11-27 13:08:12 +01:00
# App packaging
2014-01-01 16:28:01 +01:00
There are few things you need to know if you want to package an application for YunoHost.
2013-11-27 13:08:12 +01:00
### Content
2014-11-04 09:39:30 +01:00
A YunoHost package is composed of:
2013-11-27 13:08:12 +01:00
* A JSON file `manifest.json`
* A `scripts` directory, which contains the `install`, `remove` and `upgrade` scripts
2014-01-01 16:28:01 +01:00
* Optional other directories, like `sources` or `conf` if you need them
2013-11-27 13:08:12 +01:00
2014-11-04 11:47:34 +01:00
An example package is available here: https://github.com/opi/example_ynh, feel free to use it as a framework.
2014-11-04 09:39:30 +01:00
2013-11-27 13:08:12 +01:00
### Manifest
The `manifest.json` file defines the app's constants, a bunch of values that YunoHost needs to identify the app and install it correctly. It looks like this :
```json
{
"name": "Roundcube",
"id": "roundcube",
"description": {
"en": "Open Source Webmail software",
"fr": "Webmail Open Source"
},
2014-06-04 12:35:52 +02:00
"license": "GPL-3",
2013-11-27 13:08:12 +01:00
"developer": {
"name": "kload",
"email": "kload@kload.fr",
"url": "http://kload.fr"
},
"multi_instance": "true",
"arguments": {
"install" : [
{
"name": "domain",
"ask": {
"en": "Choose a domain for Roundcube"
},
"example": "domain.org"
},
{
"name": "path",
"ask": {
"en": "Choose a path for Roundcube"
},
"example": "/webmail",
"default": "/webmail"
}
]
}
}
```
2014-06-04 12:37:46 +02:00
* **name**: The name of the app. It does not have to be unique, but it should be, since it is the name shown to all the YunoHost administrators in the app list.
2013-11-27 13:08:12 +01:00
2014-06-04 12:37:46 +02:00
* **id**: The unique ID of the app. You have to ensure that this ID is unique before submit an app integration request.
2013-11-27 13:08:12 +01:00
2014-06-04 12:37:46 +02:00
* **description**: The complete description of the app. You can make it as detailed as you feel it should be. Only `en` is required right now, but you can translate the description by prepending the locale prefix.
2013-11-27 13:08:12 +01:00
2014-06-04 12:37:46 +02:00
* **license**: The license under which the app is distributed. Please use the short name of the license, e.g. `GPL-3` for the GNU General Public License v3. You can find a list of standard abbreviations here: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/#license-short-name
2014-06-04 12:35:52 +02:00
2014-06-04 12:37:46 +02:00
* **developer**: Some information about the app maintainer (you!).
2013-11-27 13:08:12 +01:00
2014-06-04 12:37:46 +02:00
* **multi_instance**: This defines your app's ability to be installed multiple times. When YunoHost tries to install a second instance of your app, it will replace the `id` in your scripts by an `id__2`. It means that, if you want to be `multi_instance`, you have to put all the identifiers in the scripts.
2014-01-01 16:28:01 +01:00
<br><br>**E.g.** In my roundcube script, I have to call my database `roundcube`, my install directory `roundcube` and my nginx configuration `roundcube`. This way, the second instance of roundcube will not conflict, and will be installed in the `roundcube__2` database, in the `roundcube__2`directory, and with the `roundcube__2` nginx configuration.
2013-11-27 13:08:12 +01:00
2014-06-04 12:37:46 +02:00
* **arguments**: The settings for the YunoHost's administrator to enter at installation. You have to set a `name` (for argument identification), and a question in `ask` (at least in `en`) that you can translate like the description above. You can also set a `default` value and an `example` to help administrator to fill the input.
2013-11-27 13:08:12 +01:00
## Scripts
For now, a YunoHost package must contain 3 bash scripts: `install`, `remove`, and `upgrade`.
These scripts will be executed as `admin` on the YunoHost instances.
2014-06-04 12:37:46 +02:00
Here is an example:
2013-11-27 13:08:12 +01:00
```bash
# Retrieve arguments
domain=$1
path=$2
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a roundcube
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Generate random DES key & password
deskey=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
# Use 'roundcube' as database name and user
db_user=roundcube
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd -s $(readlink -e ../sources/SQL/mysql.initial.sql)
sudo yunohost app setting roundcube mysqlpwd -v $db_pwd
# Copy files to the right place
final_path=/var/www/roundcube
sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path
sudo cp ../conf/main.inc.php $final_path/config/
sudo cp ../conf/db.inc.php $final_path/config/
sudo mv $final_path/plugins/managesieve/config.inc.php.dist $final_path/plugins/managesieve/config.inc.php
# Change variables in Roundcube configuration
sudo sed -i "s/rcmail-ynhDESkeyTOchange/$deskey/g" $final_path/config/main.inc.php
sudo sed -i "s/yunouser/$db_user/g" $final_path/config/db.inc.php
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/config/db.inc.php
sudo sed -i "s/yunobase/$db_user/g" $final_path/config/db.inc.php
# Set permissions to roundcube directory
sudo chown -R www-data: $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/roundcube.conf
2014-01-01 16:28:01 +01:00
# Reload nginx and regenerate SSOwat conf
2013-11-27 13:08:12 +01:00
sudo service nginx reload
sudo yunohost app ssowatconf
```
2013-11-27 13:32:06 +01:00
### Usage
2014-01-01 16:28:01 +01:00
You have to put everything in the script in order for the app to install without issue. It means that you have to install dependencies, create required repositories, initialize potential databases, copy sources and configure everything in the single `install` script (and of course do the reverse process in the `remove` script).
2013-11-27 13:08:12 +01:00
2014-06-04 12:37:46 +02:00
**Be careful**: For security reasons, the script is executed as the **admin** user in YunoHost. Be sure to test it as **admin** and prepend `sudo` to commands that require it.
2013-11-27 13:08:12 +01:00
2013-11-27 13:32:06 +01:00
### Architecture and arguments
2014-01-01 16:28:01 +01:00
Since YunoHost has a unified architecture, you will be able to guess most of the settings you need. But if you need variable ones, like the domain or web path, you will have to ask the administrator at installation (see `arguments` section in the manifest above).
2013-11-27 13:08:12 +01:00
2014-01-01 16:28:01 +01:00
**Note**: The arguments will be passed in the order that they appear in the manifest. For example for **roundcube**, the `domain` argument will be referenced as `$1` in the script, and `path` as `$2`.
2013-11-27 13:08:12 +01:00
2013-12-12 18:11:03 +01:00
### Hooks
2014-01-01 16:28:01 +01:00
YunoHost provides a hook system, which is accessible via the packager's script callbacks in moulinette (CLI).
The scripts have to be placed in the `hooks` repository at the root of the YunoHost package, and must be named `priority-hook_name`, for example: `hooks/50-post_user_create` will be executed after each user creation.
2013-12-12 18:11:03 +01:00
2013-12-12 18:12:30 +01:00
**Note**: `priority` is optional, default is `50`.
2014-01-01 16:28:01 +01:00
Take a look at the [ownCloud package](https://github.com/Kloadut/owncloud_ynh) for a working example.
2013-12-12 18:11:03 +01:00
2013-11-27 13:32:06 +01:00
### Helpers
2014-02-22 16:03:43 +01:00
The CLI [moulinette](/moulinette) provides a few tools to make the packager's work easier:
2013-11-27 13:08:12 +01:00
2013-12-01 11:53:50 +01:00
<br>
```bash
sudo yunohost app checkport <port>
```
<blockquote>
2014-01-01 16:28:01 +01:00
This helper checks the port and returns an error if the port is already in use.
2013-12-01 11:53:50 +01:00
</blockquote>
<br>
2013-11-27 13:08:12 +01:00
```bash
sudo yunohost app setting <id> <key> [ -v <value> ]
```
<blockquote>
2013-11-27 15:11:39 +01:00
This is the most important helper of YunoHost. It allows you to store some settings for a specific app, in order to be either reused afterward or used for YunoHost configuration (**e.g.** for the SSO).
2013-11-27 13:08:12 +01:00
<br><br>
It sets the value if you append ```-v <value>```, and gets it otherwise.
<br><br>
** Some useful settings **<br><br>
```skipped_uris```<br><br>
Remove the protection on the uris list provided separated by commas.<br><br>
```protected_uris```<br><br>
Protects the uris list provided separated by commas. Only logged in users will have access.<br><br>
There are also `skipped_regex`, `protected_regex`, `unprotected_uris`, `unprotected_regex`.<br><br>
**Be careful** : you must run `yunohost app ssowatconf` to apply the effect. URIs will be converted into URLs and written to the file /etc/ssowat/conf.json.<br><br>
Example:<br>
```yunohost app setting myapp unprotected_urls -v "/"```<br>
```yunohost app ssowatconf```<br>
These commands will disable the SSO on the root of the aplication like domain.tld/myapp This is useful for public application.
2013-11-27 13:08:12 +01:00
</blockquote>
<br>
```bash
sudo yunohost app checkurl <domain><path> -a <id>
```
<blockquote>
2013-11-27 15:11:39 +01:00
This helper is useful for web apps and allows you to be sure that the web path is not taken by another app. If not, it "reserves" the path.
2013-11-27 13:08:12 +01:00
<br><br>
2014-06-04 12:37:46 +02:00
**Note**: Do not prepend `http://` or `https://` to the `<domain><path>`.
2013-11-27 13:08:12 +01:00
</blockquote>
<br>
```bash
sudo yunohost app initdb <db_user> [ -p <db_pwd> ] [ -s <SQL_file> ]
```
<blockquote>
2014-01-01 16:28:01 +01:00
This helper creates a MySQL database. If you do not append a password, it generates one and returns it. If you append a SQL file, it initializes your database with the SQL statements inside.
2013-11-27 13:08:12 +01:00
</blockquote>
<br>
```bash
sudo yunohost app ssowatconf
```
<blockquote>
This helper reloads the SSO configuration. You have to call it at the end of the script when you are packaging a web app.
2013-11-27 13:29:05 +01:00
</blockquote>
2014-01-01 16:28:01 +01:00
### Test it!
In order to test your package, you can execute your script standalone as `admin` (do not forget to append required arguments):
2013-11-27 13:29:05 +01:00
```bash
su - admin -c "/bin/bash /path/to/my/script my_arg1 my_arg2"
```
2014-01-01 16:28:01 +01:00
Or you can use moulinette:
2013-11-27 13:29:05 +01:00
```bash
yunohost app install /path/to/my/app/package
```
Note that it also works with a Git URL:
```bash
yunohost app install https://github.com/author/my_app_package.git
```
2014-11-09 13:16:25 +01:00
### Add your application to the work in progress list of applications
You can add your application to the [_Work in progress_ list](https://yunohost.org/#/apps_en).
### Ask integration of your application to the official list
If you want, you can ask integration of your application to officials applications. To do so, use button "New App Request" on http://app.yunohost.org.