1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/codimd_ynh.git synced 2024-09-03 18:16:32 +02:00
This commit is contained in:
ericgaspar 2020-05-21 12:49:24 +02:00
parent eef6a1ef3c
commit 40933628a1
No known key found for this signature in database
GPG key ID: 574F281483054D44
15 changed files with 881 additions and 204 deletions

View file

@ -1,28 +1,70 @@
# CodiMD for YunoHost
A collaborative editor to work on notes written in Markdown
[![Integration level](https://dash.yunohost.org/integration/codimd.svg)](https://dash.yunohost.org/appci/app/codimd) ![](https://ci-apps.yunohost.org/ci/badges/codimd.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/codimd.maintain.svg)
[![Install CodiMD with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=codimd)
*[Lire ce readme en français.](./README_fr.md)*
> *This package allow you to install CodiMD quickly and simply on a YunoHost server.
If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.*
## Overview
Collaborative editor to work on notes written in Markdown.
**Shipped version:** 1.6.0
**Status**: In progress, do *not* consider this app as stable and fully working (yet)
**To be implemented**:
- Upgrade (right now you need to remove the app and install its new version - your documents are likely to be lost…)
- Backup and restore system
Links:
- [Yunohost project](https://yunohost.org)
- [CodiMD website](https://github.com/codimd/server/)
- [Demo](https://demo.codimd.org/)
[![Install CodiMD with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=codimd)
### Screenshot
## Screenshots
![](https://demo.codimd.org/screenshot.png)
### Advanced configuration
## Demo
If you need to configure your CodiMD, you can tweak your `config.json` file, using this documentation: https://github.com/codimd/server/blob/master/docs/configuration-config-file.md
* [Official demo](https://demo.codimd.org/)
## Configuration
If you need to configure CodiMD, you can tweak /var/www/codimd/config.json file using this [documentation](https://github.com/codimd/server/blob/master/docs/configuration-config-file.md)
## Documentation
* Official documentation: https://hackmd.io/c/codimd-documentation/
* YunoHost documentation: If specific documentation is needed, feel free to contribute.
## YunoHost specific features
#### Multi-users support
* Is LDAP supported? No
* Can the app be used by multiple users? Yes
#### Supported architectures
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/codimd/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/codimd/)
## Limitations
**Status**: In progress, do *not* consider this app as stable and fully working (yet)
## Additional information
## Links
* Report a bug: https://github.com/YunoHost-Apps/codimd_ynh/issues
* Upstream app repository: https://github.com/codimd/server/
* YunoHost website: https://yunohost.org/
---
Developers info
----------------
Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/codimd_ynh/tree/testing).
To try the testing branch, please proceed like that.
```
sudo yunohost app install https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
or
sudo yunohost app upgrade codimd -u https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
```

71
README_fr.md Normal file
View file

@ -0,0 +1,71 @@
# CodiMD pour YunoHost
[![Niveau dintégration](https://dash.yunohost.org/integration/codimd.svg)](https://dash.yunohost.org/appci/app/codimd) ![](https://ci-apps.yunohost.org/ci/badges/codimd.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/codimd.maintain.svg)
[![Installer CodiMD avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=codimd)
*[Read this readme in english.](./README.md)*
> *Ce package vous permet dinstaller CodiMD rapidement et simplement sur un serveur Yunohost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment linstaller et en profiter.*
## Vue densemble
Éditeur collaboratif pour travailler sur des notes en Markdown.
**Version incluse:** 1.6.0
## Captures décran
![](https://demo.codimd.org/screenshot.png)
## Démo
* [Démo officielle](https://demo.codimd.org/)
## Configuration
Français
Si vous voulez configurer CodiMD, vous pouvez modifier votre fichier /var/www/codimd/config.json en vous aidant de la [documentation](https://github.com/codimd/server/blob/master/docs/configuration-config-file.md)
## Documentation
* Documentation officielle : https://hackmd.io/c/codimd-documentation/
* Documentation YunoHost : Si une documentation spécifique est nécessaire, nhésitez pas à contribuer.
## Caractéristiques spécifiques YunoHost
#### Support multi-utilisateurs
* Lauthentification LDAP est-elle prise en charge ? Non
* Lapplication peut-elle être utilisée par plusieurs utilisateurs ? Oui
#### Architectures supportées
* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/codimd/)
* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/codimd%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/codimd/)
## Limitations
**Statut** : En cours, ne *pas encore* considérer cette application comme stable et fonctionnant.
## Informations additionnelles
## Liens
* Signaler un bug : https://github.com/YunoHost-Apps/codimd_ynh/issues
* Dépôt de lapplication principale : https://github.com/codimd/server/
* Site web YunoHost : https://yunohost.org/
---
Informations pour les développeurs
----------------
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/codimd_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit.
```
sudo yunohost app install https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
ou
sudo yunohost app upgrade codimd -u https://github.com/YunoHost-Apps/codimd_ynh/tree/testing --debug
```

View file

@ -1,9 +1,8 @@
var path = require('path');
module.exports = {
'config': path.resolve('config.json'),
'migrations-path': path.resolve('lib', 'migrations'),
'models-path': path.resolve('lib', 'models'),
'url': 'postgres://__DB_USER__:__DB_PASS__@localhost:5432/__DB_NAME__'
'url': 'mysql://__DB_USER__:__DB_PASS__@localhost:3306/__DB_NAME__'
}

View file

@ -3,4 +3,4 @@ SOURCE_SUM=3639eaf70a37ee0513c75259c70b3d0c2c10116e9b2989dc9c571f98017120bd
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=codimd.tar.gz
SOURCE_FILENAME=codimd.tar.gz

View file

@ -1,4 +1,3 @@
{
"production": {
"protocolUseSSL": true,
@ -7,7 +6,7 @@
"loglevel": "info",
"useCDN": false,
"allowGravatar": false,
"allowPDFExport": true,
"allowPDFExport": false,
"hsts": {
"enable": true,
"maxAgeSeconds": 31536000,
@ -21,15 +20,19 @@
"upgradeInsecureRequests": "auto",
"addDefaults": true,
"addDisqus": true,
"addGoogleAnalytics": true
"addGoogleAnalytics": false
},
"db": {
"username": "__DB_USER__",
"password": "__DB_PASS__",
"database": "__DB_NAME__",
"host": "localhost",
"port": "5432",
"dialect": "postgres"
}
"port": "3306",
"dialect": "mysql"
},
# "github": {
# "clientID": "YOUR_clientID",
# "clientSecret": "YOUR_clientSecret"
# }
}
}
}

View file

@ -4,7 +4,7 @@ location ^~ / {
rewrite ^ https://$server_name$request_uri? permanent;
}
proxy_pass http://127.0.0.1:__PORT__/;
proxy_pass http://127.0.0.1:__PORT__;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@ -15,4 +15,11 @@ location ^~ / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# setup for image upload
client_max_body_size 8192m;
proxy_max_temp_file_size 8192m;
proxy_read_timeout 300;
proxy_connect_timeout 300;
}

View file

@ -1,16 +1,17 @@
[Unit]
Description=__APP__ daemon
After=syslog.target network.target
After=network.target
After=mysql.service
[Service]
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__
Environment="PATH=__ENV_PATH__"
Environment="NODE_ENV=production"
ExecStart=/usr/bin/yarn start
Restart=always
PrivateTmp=true
PrivateDevices=true
[Install]
WantedBy=multi-user.target

View file

@ -3,21 +3,22 @@
"id": "codimd",
"packaging_format": 1,
"description": {
"en": "A collaborative editor to work on notes written in Markdown",
"fr": "Un éditeur collaboratif pour travailler sur des notes en Markdown"
"en": "Collaborative editor to work on notes written in Markdown",
"fr": "Éditeur collaboratif pour travailler sur des notes en Markdown"
},
"version": "1.6.0~ynh1",
"url": "https://github.com/codimd/server",
"license": "AGPL-v3",
"license": "AGPL-3.0-only",
"maintainer": {
"name": "liberodark"
},
"requirements": {
"yunohost": ">= 3.6"
"yunohost": ">= 3.7.0"
},
"multi_instance": false,
"multi_instance": true,
"services": [
"nginx"
"nginx",
"mysql"
],
"arguments": {
"install": [{
@ -27,15 +28,19 @@
"en": "Choose a domain name for CodiMD",
"fr": "Choisissez un nom de domaine pour CodiMD"
},
"example": "example.com"
"example": "codimd.domaim.org"
},
{
"name": "is_public",
"type": "boolean",
"ask": {
"en": "Is it a public site ?",
"en": "Is it a public site?",
"fr": "Est-ce un site public ?"
},
"help": {
"en": "If enabled, CodiMD will be accessible by people who doesnt have an account. This can be changed later via the webadmin.",
"fr": "Si cette case est cochée, CodiMD sera accessible aux personnes nayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin."
},
"default": true
}
]

View file

@ -1,5 +1,23 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="apt-transport-https"
nodejs_version="10"
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#!/bin/bash
# Pin a repository.
#
# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append]
@ -36,8 +54,8 @@ ynh_pin_repo () {
mkdir -p "/etc/apt/preferences.d"
echo "Package: $package
Pin: $pin
Pin-Priority: $priority" \
Pin: $pin
Pin-Priority: $priority" \
| $append "/etc/apt/preferences.d/$name"
}
@ -209,65 +227,6 @@ ynh_install_extra_app_dependencies () {
ynh_remove_extra_repo --name="$app"
}
#=================================================
# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
# Define and install dependencies with a equivs control file
# This helper can/should only be called once per app
#
# usage: ynh_install_app_dependencies dep [dep [...]]
# | arg: dep - the package name to install in dependence
# You can give a choice between some package with this syntax : "dep1|dep2"
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
#
# Requires YunoHost version 2.6.4 or higher.
ynh_install_app_dependencies () {
local dependencies=$@
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
dependencies=${dependencies//|/ | }
local manifest_path="../manifest.json"
if [ ! -e "$manifest_path" ]; then
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi
local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file.
if [ ${#version} -eq 0 ]; then
version="1.0"
fi
local dep_app=${app//_/-} # Replace all '_' by '-'
# Handle specific versions
if [[ "$dependencies" =~ [\<=\>] ]]
then
# Replace version specifications by relationships syntax
# https://www.debian.org/doc/debian-policy/ch-relationships.html
# Sed clarification
# [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice.
# [\<=\>] matches < = or >
# \+ matches one or more occurence of the previous characters, for >= or >>.
# [^,]\+ matches all characters except ','
# Ex: package>=1.0 will be replaced by package (>= 1.0)
dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')"
fi
cat > /tmp/"${dep_app}"-ynh-deps.control << EOF # Make a control file for equivs-build
Section: misc
Priority: optional
Package: ${dep_app}-ynh-deps
Version: ${version}
Depends: ${dependencies}
Architecture: all
Description: Fake package for $app (YunoHost app) dependencies
This meta-package is only responsible of installing its dependencies.
EOF
ynh_package_install_from_equivs /tmp/"${dep_app}"-ynh-deps.control \
|| ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies
rm /tmp/"${dep_app}"-ynh-deps.control
ynh_app_setting_set --app="$app" --key=apt_dependencies --value="$dependencies"
}
ynh_add_app_dependencies () {
# Declare an array to define the options of this helper.
local legacy_args=pr

91
scripts/backup Normal file
View file

@ -0,0 +1,91 @@
#!/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 () {
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
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)
#db_user=$(ynh_app_setting_get --app=$app --key=db_user)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Backing up the main app directory..." --weight=1
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Backing up Nginx web server configuration..." --weight=1
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Backing up the MySQL database..." --weight=1
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_script_progression --message="Backing up logrotate configuration..." --weight=2
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_script_progression --message="Backing up systemd configuration..." --weight=1
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="HTTP Server listening"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last

128
scripts/change_url Normal file
View file

@ -0,0 +1,128 @@
#!/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..." --weight=1
# 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=db_pwd)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# 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..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating nginx web server configuration..." --weight=1
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
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -6,13 +6,17 @@
# IMPORT GENERIC HELPERS
#=================================================
source ynh_add_extra_apt_repos__3
source _common.sh
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
@ -20,15 +24,16 @@ ynh_abort_if_errors
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path_url="/"
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
@ -36,151 +41,148 @@ test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Register (book) web path
ynh_webpath_register "$app" "$domain" $path_url
port=$(ynh_find_port 3000)
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..." --weight=2
db_user=$app
db_name=$app
db_pass=$(ynh_string_random 20)
# Find an available port
port=$(ynh_find_port --port=3002)
ynh_app_setting_set --app="$app" --key="port" --value="$port"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_script_progression --message="Storing installation settings..." --weight=2
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path $path_url
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" port "$port"
ynh_app_setting_set "$app" db_pass "$db_pass"
ynh_app_setting_set "$app" final_path "$final_path"
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="is_public" --value="$is_public"
ynh_app_setting_set --app="$app" --key="final_path" --value="$final_path"
#==============================================
# INSTALL POSTGRES
# INSTALL DEPENDENCIES
#==============================================
ynh_script_progression --message="Installing dependencies..."
ynh_script_progression --message="Installing dependencies..." --weight=20
ynh_install_app_dependencies postgresql apt-transport-https
ynh_install_app_dependencies $pkg_dependencies
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
ynh_install_nodejs 10
#==============================================
# CREATE DB
#==============================================
ynh_script_progression --message="Creating a database..."
ynh_script_progression --message="Creating a database..." --weight=2
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pass"
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"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_script_progression --message="Setting up source files..." --weight=2
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
ynh_setup_source --dest_dir="$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
# Main config File
ynh_replace_string "__PORT__" "$port" "../conf/config.json.example"
ynh_replace_string "__DOMAIN__" "$domain" "../conf/config.json.example"
ynh_replace_string "__PATH__" "${path_url:1}" "../conf/config.json.example"
ynh_replace_string "__DB_USER__" "$db_user" "../conf/config.json.example"
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/config.json.example"
ynh_replace_string "__DB_PASS__" "$db_pass" "../conf/config.json.example"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/config.json.example"
cp ../conf/config.json.example "$final_path"/config.json
ynh_store_file_checksum "$final_path/config.json"
# DB Config File
ynh_replace_string "__DB_USER__" "$db_user" "../conf/.sequelizerc.example"
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/.sequelizerc.example"
ynh_replace_string "__DB_PASS__" "$db_pass" "../conf/.sequelizerc.example"
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/.sequelizerc.example"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/.sequelizerc.example"
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/.sequelizerc.example"
cp ../conf/.sequelizerc.example "$final_path"/.sequelizerc
#==============================================
# INSTALL CODIMD
#==============================================
ynh_script_progression --message="Building application... (this will take some time and resources!)"
ynh_script_progression --message="Building application... (this will take some time and resources!)" --weight=240
pushd "$final_path" || exit
pushd "$final_path" || ynh_die
# ---- This is copypasta from https://raw.githubusercontent.com/codimd/server/master/bin/setup
if [ ! -f config.json ]; then
cp config.json.example config.json
fi
yarn install --frozen-lockfile && ynh_exec_warn_less yarn run build
if [ ! -f .sequelizerc ]; then
cp .sequelizerc.example .sequelizerc
fi
yarn install --non-interactive
yarn install --non-interactive --production=false # FIXME: this doesn't sounds like what we want to have for a real deployment ? idk
# ---- End copypasta from https://raw.githubusercontent.com/codimd/server/master/bin/setup
yarn run build
#node_modules/.bin/sequelize db:migrate
popd || exit
popd || ynh_die
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
# GENERIC FINALIZATION
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create "$app"
chown -R "$app":"$app" "$final_path"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=2
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
ynh_replace_string "__APP__" "$app" "../conf/systemd.service"
ynh_replace_string "__FINALPATH__" "$final_path" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
ynh_add_systemd_config
yunohost service add "$app" --description "CodiMD daemon"
yunohost service add "$app" --description "CodiMD daemon" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app..." --weight=2
ynh_script_progression --message="Starting $app..."
ynh_systemd_action --service_name="$app" --action="start"
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="HTTP Server listening"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=1
ynh_script_progression --message="Configuring SSOwat..."
# If app is public, add url to SSOWat conf as skipped_uris
if [ "$is_public" -eq 1 ]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
# Make app public if necessary or protect it
[ $is_public -eq 0 ] || ynh_permission_update --permission "main" --add "visitors"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_script_progression --message="Reloading nginx web server..." --weight=2
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -6,85 +6,97 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get "$app" domain)
db_name=$app
db_user=$app
final_path=$(ynh_app_setting_get "$app" final_path)
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)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status "$app" >/dev/null 2>&1
then
ynh_script_progression --message="Removing $app service"
yunohost service remove "$app"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service"
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE THE POSTGRESQL DATABASE
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the PostgreSQL database"
ynh_script_progression --message="Removing the MySQL database..." --weight=2
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db "$db_name" "$db_name"
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies"
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory"
ynh_script_progression --message="Removing app main directory..." --weight=6
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing nginx web server configuration"
ynh_script_progression --message="Removing Nginx web server configuration..." --weight=5
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# GENERIC FINALIZATION
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..." --weight=1
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user"
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete "$app"
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed"
ynh_script_progression --message="Removal of $app completed" --last

141
scripts/restore Normal file
View file

@ -0,0 +1,141 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
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 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)
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)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=2
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=60
ynh_restore_file --origin_path="$final_path"
#=================================================
# 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
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R "$app":"$app" "$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=7
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=6
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..." --weight=5
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
yunohost service add $app --description "collaborative Markdown editor" --log "/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="HTTP Server listening"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=5
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading Nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last

216
scripts/upgrade Normal file
View file

@ -0,0 +1,216 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=app)
db_user=$(ynh_app_setting_get --app=$app --key=app)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/var/www/$app
mkdir -p $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=120
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# 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..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=160
# Create a temporary directory
tmpdir="$(mktemp -d)"
# Backup the config file in the temp dir
cp -a "$final_path/config.json" "$tmpdir/config.json"
cp -a "$final_path/.sequelizerc" "$tmpdir/.sequelizerc"
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
#Copy the admin saved settings from tmp directory to final path
cp -a "$tmpdir/config.json" "$final_path/config.json"
cp -a "$tmpdir/.sequelizerc" "$final_path/.sequelizerc"
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading Nginx web server configuration..." --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=18
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_app_dependencies $pkg_dependencies
#==============================================
# INSTALL CODIMD
#==============================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Building application... (this will take some time and resources!)" --weight=160
pushd "$final_path"
yarn install --frozen-lockfile && ynh_exec_warn_less yarn run build
popd
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=2
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
ynh_add_systemd_config
#yunohost service add "$app" --description "CodiMD daemon"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R "$app":"$app" "$final_path"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=2
# Make app public if necessary or protect it
[ $is_public -eq 0 ] || ynh_permission_update --permission "main" --add "visitors"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="HTTP Server listening"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last