mirror of
https://github.com/YunoHost/doc.git
synced 2024-09-03 20:06:26 +02:00
61 lines
2.6 KiB
Markdown
61 lines
2.6 KiB
Markdown
|
<a class="btn btn-lg btn-default" href="packaging_apps_en">Application packaging</a>
|
||
|
|
||
|
## Scripts
|
||
|
|
||
|
For now, a YunoHost package must contain five Shell scripts: `install`, `remove`, `upgrade`, `backup` and `restore`.
|
||
|
These scripts will be executed as `admin` on the YunoHost instances.
|
||
|
|
||
|
Here is an example:
|
||
|
```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
|
||
|
|
||
|
# Reload nginx and regenerate SSOwat conf
|
||
|
sudo service nginx reload
|
||
|
sudo yunohost app ssowatconf
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
You have to put everything in the `install` script in order to get 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).
|
||
|
|
||
|
**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.
|