1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dont-code_ynh.git synced 2024-09-03 18:26:34 +02:00

Merge pull request #34 from YunoHost-Apps/manifestv2

manifestv2 part 1
This commit is contained in:
Salamandar 2024-01-05 23:59:08 +01:00 committed by GitHub
commit 7408f00316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 341 additions and 1289 deletions

View file

@ -41,17 +41,6 @@ This Yunohost app installs the server part (services + mongo database) needed to
![Screenshot of Dont-code Services](./doc/screenshots/previewer.gif)
![Screenshot of Dont-code Services](./doc/screenshots/ide.gif)
## Disclaimers / important information
* This application is installing services and mongo databases on top of Yunohost services
* They are not integrated with yunohost sso or LDAP: Any client application can call the installed services
* etc...
* After installation of these services
* You must change the configuration of the Builder and Previewer to point to these services.
* You can update the services themselves by configuring a proper ssh public key when installing the app. You'll then be able to upload the .jar files
## Documentation and resources
* Official app website: <https://dont-code.net>

View file

@ -41,17 +41,6 @@ This Yunohost app installs the server part (services + mongo database) needed to
![Capture décran de Dont-code Services](./doc/screenshots/previewer.gif)
![Capture décran de Dont-code Services](./doc/screenshots/ide.gif)
## Avertissements / informations importantes
* This application is installing services and mongo databases on top of Yunohost services
* They are not integrated with yunohost sso or LDAP: Any client application can call the installed services
* etc...
* After installation of these services
* You must change the configuration of the Builder and Previewer to point to these services.
* You can update the services themselves by configuring a proper ssh public key when installing the app. You'll then be able to upload the .jar files
## Documentations et ressources
* Site officiel de lapp : <https://dont-code.net>

View file

@ -1,29 +0,0 @@
# See here for more information
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Trying again
;; Test complet
; Manifest
domain="domain.tld"
path="/path"
public_key="dummy public key"
is_public=1
; 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=7852cc4bf44ff20ee51fe35f3f53dc105e0f6d79
backup_restore=1
multi_instance=0
port_already_use=1 (8083)
change_url=1
;;; Options
Email=ger@shared.collin.best
Notification=Down
;;; Upgrade options
; commit=7852cc4bf44ff20ee51fe35f3f53dc105e0f6d79
name=2023-01-07 - Added Ssh support for dev.
manifest_arg=domain=DOMAIN&path=PATH&is_public=1&language=fr&admin=USER&password=pass&port=666&

View file

@ -5,5 +5,5 @@ projects_database_name=dontCodeProjects
quarkus_mongodb_data_connection_string=mongodb://localhost:27017
data_database_name=dontCodeData
document_directory=__DOCUMENT_PATH__
document_directory=__DOCUMENT_DIR__
document_external_url=__DOCUMENT_URL__

View file

@ -1,6 +0,0 @@
SOURCE_URL=https://github.com/dont-code/release/releases/download/v0.2.10/dont-code-release-runners.zip
SOURCE_SUM=f20bfa0423d48015a3507b0555d30d57fa594657a4bca55ad869fca8fbad125d
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=zip
SOURCE_IN_SUBDIR=false
SOURCE_EXTRACT=true

View file

@ -3,7 +3,7 @@
location __PATH__/ {
# Path to source
alias __HTML_PATH__/;
alias __DATA_DIR__/;
index index.html;

View file

@ -8,7 +8,7 @@ Type=simple
User=__APP__
Group=__APP__
Environment="quarkus_http_port=__PORT__"
WorkingDirectory=__FINALPATH__/
WorkingDirectory=__INSTALL_DIR__/
ExecStart=__YNH_JAVA__ -jar __SERVICE_NAME__-services-runner.jar
StandardOutput=append:/var/log/__APP__/__SERVICE_NAME__-__APP__.log
StandardError=inherit
@ -19,7 +19,7 @@ StandardError=inherit
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
# Enable the writing of uploaded documents
ReadWritePaths=__DOCUMENT_PATH__
ReadWritePaths=__DOCUMENT_DIR__
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes

View file

@ -5,4 +5,3 @@
* After installation of these services
* You must change the configuration of the Builder and Previewer to point to these services.
* You can update the services themselves by configuring a proper ssh public key when installing the app. You'll then be able to upload the .jar files

View file

@ -1,60 +0,0 @@
{
"name": "Dont-code Services",
"id": "dont-code",
"packaging_format": 1,
"description": {
"en": "Install services and databases needed to support Dont-code platform",
"fr": "Installe les services et base de données nécessaires pour utiliser la plateforme Dont-code"
},
"version": "0.2~ynh5",
"url": "https://dont-code.net",
"upstream": {
"license": "AGPL-3.0-or-later",
"website": "https://dont-code.net",
"demo": "https://dont-code.net/apps.html",
"admindoc": "https://dont-code.net/developers.html",
"userdoc": "https://dont-code.net/news.html",
"code": "https://github.com/dont-code"
},
"license": "AGPL-3.0-or-later",
"maintainer": {
"name": "Dont-code Team",
"email": "developer@dont-code.net"
},
"requirements": {
"yunohost": ">= 11.0.0"
},
"multi_instance": false,
"services": [
"nginx",
"mongod"
],
"arguments": {
"install": [
{
"name": "domain",
"type": "domain"
},
{
"name": "path",
"type": "path",
"example": "/dont-code",
"default": "/dont-code"
},
{
"name": "public_key",
"type": "string",
"optional": true,
"ask": {
"en": "SSH Public key to allow service updates as part of delivery process, leave empty to disable.",
"fr": "Clef publique SSH permettant la mise à jour des services via une deploiement automatique, inactif si non renseigné."
}
},
{
"name": "is_public",
"type": "boolean",
"default": true
}
]
}
}

81
manifest.toml Normal file
View file

@ -0,0 +1,81 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "dont-code"
name = "Dont-code Services"
description.en = "Install services and databases needed to support Dont-code platform"
description.fr = "Installe les services et base de données nécessaires pour utiliser la plateforme Dont-code"
version = "0.2~ynh5"
maintainers = ["Dont-code Team"]
[upstream]
license = "AGPL-3.0-or-later"
website = "https://dont-code.net"
demo = "https://dont-code.net/apps.html"
admindoc = "https://dont-code.net/developers.html"
userdoc = "https://dont-code.net/news.html"
code = "https://github.com/dont-code"
[integration]
yunohost = ">= 11.0.0"
architectures = "all"
multi_instance = false
ldap = false
sso = false
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.domain]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "domain"
[install.path]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "path"
default = "/dont-code"
[install.public_key]
ask.en = "SSH Public key to allow service updates as part of delivery process, leave empty to disable."
ask.fr = "Clef publique SSH permettant la mise à jour des services via une deploiement automatique, inactif si non renseigné."
type = "string"
optional = true
[install.init_main_permission]
type = "group"
default = "visitors"
[resources]
[resources.sources.main]
url = "https://github.com/dont-code/release/releases/download/v0.2.10/dont-code-release-runners.zip"
sha256 = "f20bfa0423d48015a3507b0555d30d57fa594657a4bca55ad869fca8fbad125d"
in_subdir = false
autoupdate.strategy = "latest_github_release"
autoupdate.asset = "dont-code-release-runners.zip"
[resources.system_user]
[resources.install_dir]
[resources.data_dir]
subdirs = ["docs"]
owner = "__APP__:rwx"
group = "www-data:rwx"
[resources.permissions]
main.url = "/"
[resources.ports]
preview.default = 8081
ide.default = 8082
project.default = 8083
data.default = 8084
[resources.apt]
packages = [
"openjdk-17-jre",
]

View file

@ -3,30 +3,50 @@
#=================================================
# COMMON VARIABLES
#=================================================
java_version=17
mongo_version=6.0
# Java dependencies used by the app will be installed through the Java helper
pkg_dependencies=""
# List of services to be installed
SERVICES_LIST=(ide preview project data)
# List of Mongo databases to manage
MONGO_DB_LIST=(dontCodeProjects dontCodeDemoProjects dontCodeData dontCodeTestProjects)
# The list of port in the same order than the list of services
PORT_LIST=("$port_ide" "$port_preview" "$port_project" "$port_data")
java_version=17
ynh_java="/usr/lib/jvm/java-${java_version}-openjdk-amd64/bin/java"
#=================================================
# PERSONAL HELPERS
#=================================================
append_uri() {
local return="";
if [[ $1 == */ ]]; then
return=$1$2;
else
return=$1/$2
fi
echo "$return";
local return="";
if [[ $1 == */ ]]; then
return=$1$2;
else
return=$1/$2
fi
echo "$return";
}
_install_restart_script_and_sudoers() {
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$install_dir/restart-services.sh"
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
}
_remove_restart_script_and_sudoers() {
if [ -f "/etc/sudoers.d/$app-sudoers" ]; then
ynh_secure_remove --file="/etc/sudoers.d/$app-sudoers"
fi
}
#=================================================

View file

@ -11,51 +11,22 @@ source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_mongo_db__2
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
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)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs
### to be backuped and not an actual copy of any file. The actual backup that
### creates and fill the archive with the files happens in the core after this
### script is called. Hence ynh_backups calls takes basically 0 seconds to run.
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$install_dir"
#=================================================
# BACKUP THE HTML AND DOCUMENT DIR
#=================================================
ynh_backup --src_path="$html_path" --is_big
ynh_backup --src_path="$data_dir" --is_big
#=================================================
# BACKUP THE NGINX CONFIGURATION
@ -66,12 +37,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
if [ -n "$public_key" ]
then
ynh_backup --src_path="/etc/sudoers.d/$app-sudoers"
fi
# BACKUP LOGROTATE
#=================================================
@ -81,24 +46,23 @@ ynh_backup --src_path="/etc/logrotate.d/$app"
# BACKUP SYSTEMD services
#=================================================
for service_name in "${SERVICES_LIST[@]}"
do
for service_name in "${SERVICES_LIST[@]}"; do
ynh_backup --src_path="/etc/systemd/system/${app}-${service_name}.service"
done
#=================================================
# BACKUP VARIOUS FILES
# SPECIFIC BACKUP
#=================================================
# ynh_backup --src_path="/etc/cron.d/$app"
if [ -n "$public_key" ]; then
ynh_backup --src_path="/etc/sudoers.d/$app-sudoers"
fi
#=================================================
# BACKUP THE MONGO DATABASES
#=================================================
ynh_print_info --message="Backing up the Mongo databases..."
for db_name in "${MONGO_DB_LIST[@]}"
do
for db_name in "${MONGO_DB_LIST[@]}"; do
ynh_mongo_dump_db --database=$db_name > ./dump-${db_name}.bson
done

View file

@ -9,69 +9,6 @@
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
path_url=$(ynh_app_setting_get --app=$app --key=path)
port_ide=$(ynh_app_setting_get --app=$app --key=port_ide)
port_preview=$(ynh_app_setting_get --app=$app --key=port_preview)
port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
document_url=$(ynh_app_setting_get --app=$app --key=document_url)
#=================================================
# BACKUP BEFORE CHANGE URL 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
#=================================================
@ -79,8 +16,7 @@ fi
#=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="stop" --log_path="/var/log/$app/$app.log"
done
@ -89,29 +25,7 @@ done
#=================================================
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
ynh_change_url_nginx_config
#=================================================
# SPECIFIC MODIFICATIONS
@ -121,12 +35,11 @@ fi
ynh_script_progression --message="Updating .env configuration..."
new_document_url=$(append_uri "https://${new_domain}${new_path}" "docs")
ynh_app_setting_set --app=$app --key=document_url --value=$new_document_url
ynh_app_setting_set --app="$app" --key=document_url --value="$new_document_url"
ynh_backup_if_checksum_is_different --file="$final_path/.env"
ynh_replace_string --match_string="$document_url" --replace_string="$new_document_url" --target_file="$final_path/.env"
ynh_store_file_checksum --file="$final_path/.env"
document_url=new_document_url
ynh_backup_if_checksum_is_different --file="$install_dir/.env"
ynh_replace_string --match_string="$document_url" --replace_string="$new_document_url" --target_file="$install_dir/.env"
ynh_store_file_checksum --file="$install_dir/.env"
#=================================================
# GENERIC FINALISATION
@ -135,18 +48,10 @@ document_url=new_document_url
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
done
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -8,418 +8,115 @@
source _common.sh
source ynh_mongo_db__2
source ynh_install_java
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
public_key=$YNH_APP_ARG_PUBLIC_KEY
### If it's a multi-instance app, meaning it can be installed several times independently
### The id of the app as stated in the manifest is available as $YNH_APP_ID
### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2"...)
### The app instance name is available as $YNH_APP_INSTANCE_NAME
### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
### - ynhexample__{N} for the subsequent installations, with N=3,4...
### The app instance name is probably what interests you most, since this is
### guaranteed to be unique. This is a good unique identifier to define installation path,
### db names...
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
### About --weight and --time
### ynh_script_progression will show to your final users the progression of each scripts.
### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script.
### --time is a packager option, it will show you the execution time since the previous call.
### This option is implied when running in CI_package_check, you can manually add it if you are manually testing the app.
### Use the execution time displayed in the CI report or by adding --time to the command, to estimate the weight of a step.
### A common way to do it is to set a weight equal to the execution time in second +1.
### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call.
final_path=/opt/yunohost/$app
html_path=/usr/share/nginx/html/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
test ! -e "$html_path" || ynh_die --message="This path already contains a html folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding available ports..." --weight=1
### Use these lines if you have to open a port for the application
### `ynh_find_port` will find the first available port starting from the given port.
### If you're not using these lines:
### - Remove the section "CLOSE A PORT" in the remove script
# Find an available port
port_preview=$(ynh_find_port --port=8081)
ynh_app_setting_set --app=$app --key=port_preview --value=$port_preview
port_ide=$(ynh_find_port --port=8082)
ynh_app_setting_set --app=$app --key=port_ide --value=$port_ide
port_project=$(ynh_find_port --port=8083)
ynh_app_setting_set --app=$app --key=port_project --value=$port_project
port_data=$(ynh_find_port --port=8084)
ynh_app_setting_set --app=$app --key=port_data --value=$port_data
# define the list of port in the same order than the list of services
PORT_LIST=($port_ide $port_preview $port_project $port_data)
# Optional: Expose this port publicly
# (N.B.: you only need to do this if the app actually needs to expose the port publicly.
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# Open the port
# ynh_script_progression --message="Configuring firewall..." --weight=1
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=1
# Install the required version of Java
ynh_install_java --java_version=$java_version --jdk_type=jre
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
### Those deb packages will be installed as dependencies of this package.
### If you're not using this helper:
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - Remove the variable "pkg_dependencies" in _common.sh
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_install_app_dependencies $pkg_dependencies
# Install the required version of Mongo
ynh_install_mongo --mongo_version=$mongo_version
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell --groups="ssh.app"
#=================================================
# CREATE A Mongo DATABASE
#=================================================
ynh_script_progression --message="Creating the Mongo databases..." --weight=1
#db_project_name=$(ynh_sanitize_dbid --db_name="${app}-projects")
#db_demo_project_name=$(ynh_sanitize_dbid --db_name="${app}-demo-projects")
#db_data_name=$(ynh_sanitize_dbid --db_name="${app}-data")
db_user=$(ynh_sanitize_dbid --db_name="${app}")
#ynh_app_setting_set --app=$app --key=db_project_name --value=$db_project_name
#ynh_app_setting_set --app=$app --key=db_demo_project_name --value=$db_demo_project_name
#ynh_app_setting_set --app=$app --key=db_data_name --value=$db_data_name
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
#We should probably enable databases to the user, but for now, we connect through admin
ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]}
#No need to create other databases: Mongo creates them on the fly
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
mkdir --parents $final_path
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
ynh_setup_source --dest_dir="$install_dir"
if [ -n "$public_key" ]
then
ynh_script_progression --message="Enabling ssh access for dev..." --weight=1
#enable ssh access to the files for updates
#todo: Secure it more with https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh
mkdir --parents $final_path/.ssh
ynh_add_config --template="authorized_keys" --destination="$final_path/.ssh/authorized_keys"
ynh_app_setting_set --app=$app --key=public_key --value=$public_key
chown -R $app:$app "$final_path/.ssh"
chmod 700 "$final_path/.ssh"
chmod 600 "$final_path/.ssh/authorized_keys"
#=================================================
# Create restart services file
#=================================================
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$final_path/restart-services.sh"
# Enable root ownership to be able to call systemctl
chown $app:$app "$final_path/restart-services.sh"
chmod o-rwx,gu=rwx "$final_path/restart-services.sh"
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
fi
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
mkdir /var/log/$app
chown "$app:$app" /var/log/$app
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
### `ynh_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# Create document storage
# Configure document storage
#=================================================
ynh_script_progression --message="Configuring document storage..." --weight=1
document_path=$html_path/docs
test ! -e "$document_path" || ynh_die --message="This path already contains a folder"
mkdir --parents $document_path
ynh_app_setting_set --app=$app --key=html_path --value=$html_path
ynh_app_setting_set --app=$app --key=document_path --value=$document_path
document_dir=$data_dir/docs
ynh_app_setting_set --app="$app" --key=document_dir --value="$document_dir"
document_url=$(append_uri "https://${domain}${path}" "docs")
ynh_app_setting_set --app="$app" --key=document_url --value="$document_url"
# Add the status page
ynh_add_config --template="index.html" --destination="$html_path/index.html"
ynh_add_config --template="index.html" --destination="$data_dir/index.html"
chmod 750 "$html_path"
chmod -R o-rwx "$html_path"
chown -R $app:www-data "$html_path"
document_url=$(append_uri "https://${domain}${path_url}" "docs")
ynh_app_setting_set --app=$app --key=document_url --value=$document_url
#=================================================
# DONT CREATE A DATA DIRECTORY
#=================================================
#ynh_script_progression --message="Creating a data directory..." --weight=1
### Use these lines if you need to create a directory to store "persistent files" for the application.
### Usually this directory is used to store uploaded files or any file that won't be updated during
### an upgrade and that won't be deleted during app removal unless "--purge" option is used.
### If you're not using these lines:
### - Remove the section "BACKUP THE DATA DIR" in the backup script
### - Remove the section "RESTORE THE DATA DIRECTORY" in the restore script
### - As well as the section "REMOVE DATA DIR" in the remove script
#datadir=/home/yunohost.app/$app
#ynh_app_setting_set --app=$app --key=datadir --value=$datadir
#mkdir -p $datadir
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
#chmod 750 "$datadir"
#chmod -R o-rwx "$datadir"
#chown -R $app:www-data "$datadir"
chmod -R o-rwx "$data_dir"
chown -R $app:www-data "$data_dir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
### You can add specific configuration files.
###
### Typically, put your template conf file in ../conf/your_config_file
### The template may contain strings such as __FOO__ or __FOO_BAR__,
### which will automatically be replaced by the values of $foo and $foo_bar
###
### ynh_add_config will also keep track of the config file's checksum,
### which later during upgrade may allow to automatically backup the config file
### if it's found that the file was manually modified
###
### Check the documentation of `ynh_add_config` for more info.
ynh_add_config --template=".env" --destination="$install_dir/.env"
ynh_add_config --template=".env" --destination="$final_path/.env"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
### For more complex cases where you want to replace stuff using regexes,
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
### When doing so, you also need to manually call ynh_store_file_checksum
###
### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
### ynh_store_file_checksum --file="$final_path/some_config_file"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# SETUP SYSTEMD
# ADD SSH ACCESS
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
### `ynh_systemd_config` is used to configure a systemd script for an app.
### It can be used for apps that use sysvinit (with adaptation) or systemd.
### Have a look at the app to be sure this app needs a systemd script.
### `ynh_systemd_config` will use the file conf/systemd.service
### If you're not using these lines:
### - You can remove those files in conf/.
### - Remove the section "BACKUP SYSTEMD" in the backup script
### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script
### - As well as the section "RESTORE SYSTEMD" in the restore script
### - And the section "SETUP SYSTEMD" in the upgrade script
if [ -n "$public_key" ]; then
ynh_script_progression --message="Enabling ssh access for dev..." --weight=1
# enable ssh access to the files for updates
# todo: Secure it more with https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh
mkdir --parents "$install_dir/.ssh"
ynh_add_config --template="authorized_keys" --destination="$install_dir/.ssh/authorized_keys"
# Create a dedicated systemd config for each service
service_list_length=${#SERVICES_LIST[@]}
for (( j=0; j<${service_list_length}; j++ ))
do
service_name=${SERVICES_LIST[$j]}
port=${PORT_LIST[$j]}
ynh_add_systemd_config --service="${app}-${service_name}"
done
chown -R "$app:$app" "$install_dir/.ssh"
chmod 700 "$install_dir/.ssh"
chmod 600 "$install_dir/.ssh/authorized_keys"
_install_restart_script_and_sudoers
fi
#=================================================
# GENERIC FINALIZATION
# INSTALL MONGO
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
ynh_script_progression --message="Installing MongoDB..." --weight=1
### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
### Use this helper only if there is effectively a log file for this app.
### If you're not using this helper:
### - Remove the section "BACKUP LOGROTATE" in the backup script
### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
### - And the section "SETUP LOGROTATE" in the upgrade script
# Install the required version of Mongo
ynh_install_mongo --mongo_version=$mongo_version
#=================================================
# CREATE A MONGO DATABASE
#=================================================
ynh_script_progression --message="Creating the Mongo databases..." --weight=1
db_user=$(ynh_sanitize_dbid --db_name="${app}")
ynh_app_setting_set --app="$app" --key=db_user --value="$db_user"
# We should probably enable databases to the user, but for now, we connect through admin
# No need to create other databases: Mongo creates them on the fly
ynh_mongo_setup_db --db_user="$db_user" --db_name="${MONGO_DB_LIST[0]}"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
### `yunohost service add` integrates a service in YunoHost. It then gets
### displayed in the admin interface and through the others `yunohost service` commands.
### (N.B.: this line only makes sense if the app adds a service to the system!)
### If you're not using these lines:
### - You can remove these files in conf/.
### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script
### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script
### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script
for service_name in "${SERVICES_LIST[@]}"
do
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
for i in "${!SERVICES_LIST[@]}"; do
service_name="${SERVICES_LIST[i]}"
port="${PORT_LIST[i]}"
ynh_add_systemd_config --service="${app}-${service_name}"
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
done
### Additional options starting with 3.8:
###
### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed
### which will then be checked by YunoHost's diagnosis system
### (N.B. DO NOT USE THIS is the port is only internal!!!)
###
### --test_status "some command" a custom command to check the status of the service
### (only relevant if 'systemctl status' doesn't do a good job)
###
### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service
###
### Re-calling 'yunohost service add' during the upgrade script is the right way
### to proceed if you later realize that you need to enable some flags that
### weren't enabled on old installs (be careful it'll override the existing
### service though so you should re-provide all relevant flags when doing so)
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
### `ynh_systemd_action` is used to start a systemd service for an app.
### Only needed if you have configure a systemd service
### If you're not using these lines:
### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
### - As well as the section "START SYSTEMD SERVICE" in the restore script
### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
# Start a systemd service
for service_name in "${SERVICES_LIST[@]}"
do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
done
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -8,157 +8,45 @@
source _common.sh
source ynh_mongo_db__2
source ynh_install_java
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
port_ide=$(ynh_app_setting_get --app=$app --key=port_ide)
port_preview=$(ynh_app_setting_get --app=$app --key=port_preview)
port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
PORT_LIST=($port_ide $port_preview $port_project $port_data)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
ynh_script_progression --message="Removing $app services..." --weight=1
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
for service_name in "${SERVICES_LIST[@]}"
do
if ynh_exec_warn_less yunohost service status "${app}-${service_name}" >/dev/null
then
yunohost service remove "${app}-${service_name}"
fi
for service_name in "${SERVICES_LIST[@]}"; do
if ynh_exec_warn_less yunohost service status "${app}-${service_name}" >/dev/null; then
yunohost service remove "${app}-${service_name}"
fi
done
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
for service_name in "${SERVICES_LIST[@]}"
do
ynh_remove_systemd_config --service="${app}-${service_name}"
for service_name in "${SERVICES_LIST[@]}"; do
ynh_remove_systemd_config --service="${app}-${service_name}"
done
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE THE MONGO DATABASE
#=================================================
ynh_script_progression --message="Removing the Mongo databases..." --weight=1
# Remove a database if it exists, along with the associated user
for db_name in "${MONGO_DB_LIST[@]}"
do
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
done
# Remove mongo itself if not used anymore
ynh_remove_mongo
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DOCUMENT DIR
#=================================================
ynh_script_progression --message="Removing html directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$html_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
if [ -n "$public_key" ]
then
ynh_secure_remove --file="/etc/sudoers.d/$app-sudoers"
fi
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove java
ynh_remove_java
# Remove apackage and its dependencies, including Java if needed
ynh_remove_app_dependencies
#=================================================
# CLOSE ALL PORTS
#=================================================
for port in "${PORT_LIST[@]}"
do
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 a database if it exists, along with the associated user
for db_name in "${MONGO_DB_LIST[@]}"; do
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name
done
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..." --weight=1
# Remove mongo itself if not used anymore
ynh_remove_mongo
_remove_restart_script_and_sudoers
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
if [ -n "$public_key" ]
then
ynh_script_progression --message="Removing ssh dev access" --weight=1
ynh_secure_remove --file="/etc/sudoers.d/$app-sudoers"
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -9,195 +9,92 @@
# 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_mongo_db__2
source ../settings/scripts/ynh_install_java
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell --groups="ssh.app"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
ynh_restore_file --origin_path="$install_dir"
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#Make sure the .ssh and files have the correct access rights
if [ -n "$public_key" ]
then
chown -R $app:$app "$final_path/.ssh"
chmod 700 "$final_path/.ssh"
chmod 600 "$final_path/.ssh/authorized_keys"
# Enable restart of services for the dont-code user
chown $app:$app "$final_path/restart-services.sh"
chmod o-rwx,gu=rwx "$final_path/restart-services.sh"
ynh_restore_file --origin_path="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
fi
mkdir /var/log/$app
chown "$app:$app" /var/log/$app
#=================================================
# RESTORE THE DOCUMENTS DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the html directory..." --weight=1
ynh_script_progression --message="Restoring the document storage..." --weight=1
ynh_restore_file --origin_path="$html_path" --not_mandatory
ynh_restore_file --origin_path="$data_dir" --not_mandatory
mkdir -p $document_path
mkdir -p $document_dir
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$html_path"
chmod -R o-rwx "$html_path"
chown -R $app:www-data "$html_path"
chmod -R o-rwx "$data_dir"
chown -R $app:www-data "$data_dir"
#=================================================
# SPECIFIC RESTORATION
# ADD SSH ACCESS
#=================================================
# REINSTALL DEPENDENCIES
# Make sure the .ssh and files have the correct access rights
if [ -n "$public_key" ]; then
ynh_script_progression --message="Restoring ssh access for dev..." --weight=1
chown -R "$app:$app" "$install_dir/.ssh"
chmod 700 "$install_dir/.ssh"
chmod 600 "$install_dir/.ssh/authorized_keys"
_install_restart_script_and_sudoers
fi
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
# Install the required version of Java
ynh_install_java --java_version=$java_version --jdk_type=jre
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
# INSTALL MONGO
#=================================================
ynh_script_progression --message="Reinstalling MongoDB..." --weight=1
# Install the required version of Mongo
ynh_install_mongo --mongo_version=$mongo_version
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE MONGO DATABASES
#=================================================
ynh_script_progression --message="Restoring the Mongo databases..." --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]} --db_pwd=$db_pwd
for db_name in "${MONGO_DB_LIST[@]}"
do
ynh_mongo_restore_db --database="$db_name" < ./dump-${db_name}.bson
for db_name in "${MONGO_DB_LIST[@]}"; do
ynh_mongo_restore_db --database="$db_name" < "./dump-${db_name}.bson"
done
#=================================================
# RESTORE VARIOUS FILES
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
# ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
ynh_restore_file --origin_path="/etc/systemd/system/${app}-${service_name}.service"
systemctl enable "${app}-${service_name}.service" --quiet
done
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
mkdir --parents /var/log/$app
chown $app:adm /var/log/$app
#=================================================
# INTEGRATE SERVICES IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating services in YunoHost..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
done
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
for service_name in "${SERVICES_LIST[@]}"; do
ynh_restore_file --origin_path="/etc/systemd/system/${app}-${service_name}.service"
systemctl enable "${app}-${service_name}.service" --quiet
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
done
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_script_progression --message="Reloading NGINX web server and $app's services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
done
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -8,57 +8,10 @@
source _common.sh
source ynh_mongo_db__2
source ynh_install_java
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
port_ide=$(ynh_app_setting_get --app=$app --key=port_ide)
port_preview=$(ynh_app_setting_get --app=$app --key=port_preview)
port_project=$(ynh_app_setting_get --app=$app --key=port_project)
port_data=$(ynh_app_setting_get --app=$app --key=port_data)
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
document_path=$(ynh_app_setting_get --app=$app --key=document_path)
document_url=$(ynh_app_setting_get --app=$app --key=document_url)
html_path=$(ynh_app_setting_get --app=$app --key=html_path)
public_key=$(ynh_app_setting_get --app=$app --key=public_key)
PORT_LIST=($port_ide $port_preview $port_project $port_data)
#=================================================
# CHECK VERSION
#=================================================
### This helper will compare the version of the currently installed app and the version of the upstream package.
### $upgrade_type can have 2 different values
### - UPGRADE_APP if the upstream app version has changed
### - UPGRADE_PACKAGE if only the YunoHost package has changed
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# 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
#=================================================
@ -66,209 +19,117 @@ ynh_abort_if_errors
#=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="stop" --log_path="/var/log/$app/$app.log"
done
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Create html_path if needed
if [ -z "$html_path" ]; then
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
html_path=/usr/share/nginx/html/$app
ynh_app_setting_set --app=$app --key=html_path --value=$html_path
mkdir --parents $html_path
chmod 750 "$html_path"
chmod -R o-rwx "$html_path"
chown -R $app:www-data "$html_path"
# Missing settings ?
if [ -z "${public_key+x}" ]; then
public_key=""
ynh_app_setting_set --app="$app" --key=public_key --value="$public_key"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
if [[ -n "${document_path:-}" ]]; then
# Renamed setting key
document_dir="$document_path"
ynh_app_setting_delete --app="$app" --key=document_path
ynh_app_setting_set --app="$app" --key=document_dir --value="$document_dir"
fi
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell --groups="ssh.app"
if [[ -n "${html_path:-}" ]]; then
# Migrate html_path to data_dir
mv "$html_path/index.html" "$html_path/docs" "$data_dir"
old_doc_dir="$html_path/docs"
ynh_secure_remove --file="$html_path"
ynh_app_setting_delete --app="$app" --key=html_path
# FIXME: other settings
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
# Update the path in .env file
ynh_backup_if_checksum_is_different --file="$install_dir/.env"
ynh_replace_string --match_string="$old_doc_dir" --replace_string="$document_dir" --target_file="$install_dir/.env"
ynh_store_file_checksum --file="$install_dir/.env"
fi
# Regenerate the .env file if the document_url was incorrectly set before
correct_document_url=$(append_uri "https://${domain}${path}" "docs")
if [ "$correct_document_url" != "$document_url" ]; then
ynh_script_progression --message="Updading url for documents" --weight=1
old_doc_url=$document_url
document_url=$correct_document_url
ynh_app_setting_set --app=$app --key=document_url --value=$document_url
ynh_add_config --template=".env" --destination="$install_dir/.env"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
fi
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# UPGRADE DEPENDENCIES
# Configure document storage
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=1
ynh_script_progression --message="Configuring document storage..." --weight=1
# Install the required version of Java
ynh_install_java --java_version=$java_version --jdk_type=jre
ynh_add_config --template="index.html" --destination="$data_dir/index.html"
ynh_install_app_dependencies $pkg_dependencies
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
#=================================================
# ADD SSH ACCESS
#=================================================
if [ -n "$public_key" ]; then
ynh_script_progression --message="Upgrading ssh access for dev..." --weight=1
_install_restart_script_and_sudoers
fi
#=================================================
# UPGRADE MongoDB
#=================================================
ynh_script_progression --message="Upgrading MongoDB..." --weight=1
# Install the required version of Mongo
ynh_install_mongo --mongo_version=$mongo_version
#=================================================
# NGINX CONFIGURATION
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Do we need to upgrade the status index ? Do it now as html_path variable is needed for nginx file
# Always Upgrade the status page
ynh_add_config --template="index.html" --destination="$html_path/index.html"
chmod 750 "$html_path/index.html"
chmod o-rwx "$html_path/index.html"
chown $app:www-data "$html_path/index.html"
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Create document storage
#=================================================
# The document path has changed => Copy all the files
if [ "$document_path" != "/usr/share/nginx/html/$app/docs" ]; then
ynh_script_progression --message="Moving the document path to its new dir" --weight=8
old_doc_path=$document_path
document_path=/usr/share/nginx/html/$app/docs
test ! -e "$document_path" || ynh_die --message="This path already contains a folder"
mkdir --parents $document_path
mv $old_doc_path/* $document_path/*
ynh_secure_remove --file=$old_doc_path
ynh_app_setting_set --app=$app --key=document_path --value=$document_path
chmod 750 "$document_path"
chmod -R o-rwx "$document_path"
chown -R $app:www-data "$document_path"
# Update the path in .env file
ynh_backup_if_checksum_is_different --file="$final_path/.env"
ynh_replace_string --match_string="$old_doc_path" --replace_string="$document_path" --target_file="$final_path/.env"
ynh_store_file_checksum --file="$final_path/.env"
fi
# Regenerate the .env file if the document_url was incorrectly set before
correct_document_url=$(append_uri "https://${domain}${path_url}" "docs")
if [ "$correct_document_url" != "$document_url" ]; then
ynh_script_progression --message="Updading url for documents" --weight=1
old_doc_url=$document_url
document_url=$correct_document_url
ynh_app_setting_set --app=$app --key=document_url --value=$document_url
ynh_add_config --template=".env" --destination="$final_path/.env"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
fi
if [ -n "$public_key" ] && [ ! -f "$final_path/restart-services.sh" ];
then
ynh_script_progression --message="Upgrading ssh access for dev..." --weight=1
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$final_path/restart-services.sh"
# Enable root ownership to be able to call systemctl
chown $app:$app "$final_path/restart-services.sh"
chmod o-rwx,gu=rwx "$final_path/restart-services.sh"
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
fi
#=================================================
# UPDATE A CONFIG FILE
#=================================================
# ynh_script_progression --message="Updating a configuration file..." --weight=1
### Same as during install
###
### The file will automatically be backed-up if it's found to be manually modified (because
### ynh_add_config keeps track of the file's checksum)
# ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
# chmod 400 "$final_path/some_config_file"
# chown $app:$app "$final_path/some_config_file"
### For more complex cases where you want to replace stuff using regexes,
### you shoud rely on ynh_replace_string (which is basically a wrapper for sed)
### When doing so, you also need to manually call ynh_store_file_checksum
###
### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
### ynh_store_file_checksum --file="$final_path/some_config_file"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config for each service
service_list_length=${#SERVICES_LIST[@]}
for (( j=0; j<${service_list_length}; j++ ))
do
service_name=${SERVICES_LIST[$j]}
port=${PORT_LIST[$j]}
ynh_add_systemd_config --service="${app}-${service_name}"
done
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
for i in "${!SERVICES_LIST[@]}"; do
service_name="${SERVICES_LIST[i]}"
port="${PORT_LIST[i]}"
ynh_add_systemd_config --service="${app}-${service_name}"
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
done
#=================================================
@ -276,18 +137,10 @@ done
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"
do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
done
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -1,143 +0,0 @@
#!/bin/bash
# Enable the version of java for an app, and set variables.
#
# usage: ynh_use_java
#
# `ynh_use_java` has to be used in any app scripts before using java for the first time.
# This helper will provide alias and variables to use in your scripts.
#
# To use java, use the alias `ynh_java`.
#
# Those alias will use the correct version installed for the app.
# For example: use `ynh_java -jar your-app.jar` instead of `java -jar your-app.jar`
#
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_java`
# And propagate $PATH to sudo with $ynh_java_load_PATH
# Example: `ynh_exec_as $app $ynh_java_load_PATH $ynh_java -jar yuor-app.jar`
#
# $PATH contains the path of the requested version of java.
# However, $PATH is duplicated into $java_PATH to outlast any manipulation of `$PATH`
# You can use the variable `$ynh_java_load_PATH` to quickly load your java version
# in $PATH for an usage into a separate script.
# Example: $ynh_java_load_PATH $final_path/script_that_use_java.sh`
#
#
# Finally, to start a java service with the correct version, 2 solutions
# Either the app is dependent of java but does not call it directly.
# In such situation, you need to load PATH :
# ```
# Environment="__JAVA_ENV_PATH__"
# ExecStart=__FINALPATH__/my_app
# ```
# You will replace __JAVA_ENV_PATH__ with $ynh_java_load_PATH.
#
# Or java starts the app directly, then you don't need to load the PATH variable
# ```
# ExecStart=__YNH_JAVA__ -jar your-app.jar
# ```
# You will replace __YNH_JAVA__ with $ynh_java
#
#
# 2 other variables are also available
# - $java_path: The absolute path to java binaries for the chosen version.
# - $java_version: Just the version number of java for this app. Stored as 'java_version' in settings.yml.
#
# Requires YunoHost version 11 or higher.
ynh_use_java() {
java_version=$(ynh_app_setting_get --app=$app --key=java_version)
#get the architecture: amd or arm ?
ynh_get_architecture
# Get the absolute path of this version of java
java_path="/usr/lib/jvm/java-$java_version-openjdk-$ynh_architecture/bin"
# Allow alias to be used into bash script
shopt -s expand_aliases
# Create an alias for the specific version of node and a variable as fallback
ynh_java="$java_path/java"
alias ynh_java="$ynh_java"
# Load the path of this version of node in $PATH
if [[ :$PATH: != *":$java_path"* ]]; then
PATH="$java_path:$PATH"
fi
java_PATH="$PATH"
# Create an alias to easily load the PATH
ynh_java_load_PATH="PATH=$java_PATH"
# Same var but in lower case to be compatible with ynh_replace_vars...
ynh_java_load_path="PATH=$java_PATH"
}
# Install a specific version of java
#
# ynh_install_java will install the version of Java provided as arguments.
#
# usage: ynh_install_java --java_version=java_version --jdk_type=jre --java_engine=headless
# | arg: -j, --java_version= - Version of java to install: 17 (default) or 11. Use major version only.
# | arg: -t, --jdk_type= - Select the type of jdk to install: jre (default) or jdk.
# | arg: -e, --java_engine= - Select the engine to use: headless (default), zero, dcevm or leave empty for full
#
# Please look at the available Debian Openjdk packages to see the possible combinations of values. You can do so by running `apt-cache search openjdk`
# No default ones are set, please use ynh_use_java to setup environment variables to ensure the version of Java is correct
#
# Requires YunoHost version 11 or higher.
ynh_install_java() {
# Use debian packages to install the requested Java version
# Declare an array to define the options of this helper.
local legacy_args=jte
local -A args_array=([j]=java_version= [t]=jdk_type= [e]=java_engine)
local java_version
local jdk_type
local java_engine
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
java_version="${java_version:-17}"
jdk_type="${jdk_type:-jre}"
java_engine="${java_engine:-}"
package_name=openjdk-${java_version}-${jdk_type}
if [ -n "$java_engine" ]; then
package_name=${package_name}-${java_engine}
fi
ynh_install_app_dependencies ${package_name}
# Store java_version into the config of this app
ynh_app_setting_set --app=$app --key=java_version --value=$java_version
ynh_app_setting_set --app=$app --key=jdk_type --value=$jdk_type
ynh_app_setting_set --app=$app --key=java_engine --value=$java_engine
ynh_use_java
}
# Remove the version of Java used by the app.
#
# As Java is installed using ynh_install_app_dependencies, it will be removed as well when you call ynh_remove_app_dependencies in your remove script
#
# usage: ynh_remove_java
ynh_remove_java () {
local java_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=java_version)
# Remove the lines for this app
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=java_version
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=jdk_type
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=java_engine
}
# Extract the architecture used to run this script
# sets ynh_architecture as arm64 or amd64
#
ynh_get_architecture() {
uname=$(uname --machine)
if [[ $uname =~ aarch64 || $uname =~ arm64 ]]; then
ynh_architecture="arm64"
else
ynh_architecture="amd64"
fi
}

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

12
tests.toml Normal file
View file

@ -0,0 +1,12 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json
test_format = 1.0
[default]
args.public_key = ""
# -------------------------------
# Commits to test upgrade from
# -------------------------------
test_upgrade_from.7852cc4bf44ff20ee51fe35f3f53dc105e0f6d79.name= "2023-01-07 - Added Ssh support for dev."