diff --git a/conf/systemd.service b/conf/systemd.service index 3766f3f..70c6294 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,12 +1,14 @@ [Unit] -Description=Run Ethercalc, the collaborative spreadsheet editor. +Description=Ethercalc, the collaborative spreadsheet editor. After=network.target [Service] Type=simple User=__APP__ Group=__APP__ -ExecStart=/opt/node_n/n/versions/node/__NODE_VERSION__/bin/ethercalc --port __PORT__ --expire __EXPIRE__ +Environment="NODE_ENV=production" +Environment="__YNH_NODE_LOAD_PATH__" +ExecStart=/usr/bin/ethercalc --port __PORT__ --expire __EXPIRE__ EnvironmentFile=/etc/systemd/system/ethercalc.env RuntimeMaxSec=86400 Restart=always diff --git a/manifest.json b/manifest.json index 58fb394..cc2362b 100644 --- a/manifest.json +++ b/manifest.json @@ -2,11 +2,12 @@ "name": "EtherCalc", "id": "ethercalc", "packaging_format": 1, - "version": "0.20170704.0~ynh1", "description": { "en": "Online web spreadsheet editor providing collaborative editing in really real-time", "fr": "Feuille de calcul collaborative en ligne" }, + "version": "0.20170704.0~ynh1", + "url": "https://ethercalc.net/", "license": "CPAL-1.0&Artistic-2.0", "maintainer": { "name": "ljf", @@ -14,9 +15,8 @@ "url": "https://reflexlibre.net" }, "multi_instance": true, - "url": "https://ethercalc.net/", "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 4.0.0" }, "services": [ "nginx", @@ -50,8 +50,6 @@ }, "default": "0" } - - ] } } diff --git a/scripts/_common.sh b/scripts/_common.sh index 7c0c3d4..6f3384f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,223 +6,8 @@ pkg_dependencies="redis-server" -node_version="4.8.7" +nodejs_version=12 # ============================================================================= # YUNOHOST 2.7 FORTHCOMING HELPERS # ============================================================================= - -# Create a dedicated nginx config -# -# usage: ynh_add_nginx_config -ynh_add_nginx_config () { - finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalnginxconf" - sudo cp ../conf/nginx.conf "$finalnginxconf" - - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${path_url:-}"; then - ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf" - fi - if test -n "${domain:-}"; then - ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf" - fi - if test -n "${port:-}"; then - ynh_replace_string "__PORT__" "$port" "$finalnginxconf" - fi - if test -n "${app:-}"; then - ynh_replace_string "__NAME__" "$app" "$finalnginxconf" - fi - if test -n "${final_path:-}"; then - ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf" - fi - ynh_store_file_checksum "$finalnginxconf" - - sudo systemctl reload nginx -} - -# Remove the dedicated nginx config -# -# usage: ynh_remove_nginx_config -ynh_remove_nginx_config () { - ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf" - sudo systemctl reload nginx -} - -# Create a dedicated php-fpm config -# -# usage: ynh_add_fpm_config -ynh_add_fpm_config () { - finalphpconf="/etc/php5/fpm/pool.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalphpconf" - sudo cp ../conf/php-fpm.conf "$finalphpconf" - ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf" - ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf" - ynh_replace_string "__USER__" "$app" "$finalphpconf" - sudo chown root: "$finalphpconf" - ynh_store_file_checksum "$finalphpconf" - - if [ -e "../conf/php-fpm.ini" ] - then - finalphpini="/etc/php5/fpm/conf.d/20-$app.ini" - ynh_backup_if_checksum_is_different "$finalphpini" - sudo cp ../conf/php-fpm.ini "$finalphpini" - sudo chown root: "$finalphpini" - ynh_store_file_checksum "$finalphpini" - fi - - sudo systemctl reload php5-fpm -} - -# Remove the dedicated php-fpm config -# -# usage: ynh_remove_fpm_config -ynh_remove_fpm_config () { - ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf" - ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1 - sudo systemctl reload php5-fpm -} - -# Create a dedicated systemd config -# -# usage: ynh_add_systemd_config -ynh_add_systemd_config () { - finalsystemdconf="/etc/systemd/system/$app.service" - ynh_backup_if_checksum_is_different "$finalsystemdconf" - sudo cp ../conf/systemd.service "$finalsystemdconf" - - # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. - # Substitute in a nginx config file only if the variable is not empty - if test -n "${final_path:-}"; then - ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf" - fi - if test -n "${app:-}"; then - ynh_replace_string "__APP__" "$app" "$finalsystemdconf" - fi - ynh_store_file_checksum "$finalsystemdconf" - - sudo chown root: "$finalsystemdconf" - sudo systemctl enable $app - sudo systemctl daemon-reload -} - -# Remove the dedicated systemd config -# -# usage: ynh_remove_systemd_config -ynh_remove_systemd_config () { - finalsystemdconf="/etc/systemd/system/$app.service" - if [ -e "$finalsystemdconf" ]; then - sudo systemctl stop $app - sudo systemctl disable $app - ynh_secure_remove "$finalsystemdconf" - fi -} -#================================================= -# NODEJS -#================================================= - -sudo_path () { - sudo env "PATH=$PATH" $@ -} - -# INFOS -# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser. -# C'est ainsi qu'il change de version -# En attendant une généralisation de root, il est possible d'utiliser sudo avec le helper temporaire sudo_path -# Il permet d'utiliser sudo en gardant le $PATH modifié -# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n -# ynh_use_nodejs active une version de nodejs dans le script courant -# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app -# - nodejs_path: Le chemin absolu de cette version de node -# Utilisé pour des appels directs à node. -# - nodejs_version: Simplement le numéro de version de nodejs pour cette application -# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant. -# Utilisé pour démarrer un service ou un script qui utilise node ou npm -# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire. - -n_install_dir="/opt/node_n" -ynh_use_nodejs () { - nodejs_version=$(ynh_app_setting_get $app nodejs_version) - - load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"" - - nodejs_use_version="n $nodejs_version" - - # "Load" a version of node - eval $load_n_path; $nodejs_use_version - eval $load_n_path; sudo env "PATH=$PATH" $nodejs_use_version - - # Get the absolute path of this version of node - nodejs_path="$(n bin $nodejs_version)" - - # Make an alias for node use - ynh_node_exec="eval $load_n_path; n use $nodejs_version" - sudo_ynh_node_exec="eval $load_n_path; sudo env \"PATH=$PATH\" n use $nodejs_version" -} - -ynh_install_nodejs () { - # Use n, https://github.com/tj/n to manage the nodejs versions - local nodejs_version="$1" - local n_install_script="https://git.io/n-install" - - # Create $n_install_dir - sudo mkdir -p "$n_install_dir" - - # Load n path in PATH - CLEAR_PATH="$n_install_dir/bin:$PATH" - # Remove /usr/local/bin in PATH in case of node has already setup. - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Move an existing node binary, to avoid to block n. - test -x /usr/bin/node && sudo mv /usr/bin/node /usr/bin/node_n - test -x /usr/bin/npm && sudo mv /usr/bin/npm /usr/bin/npm_n - - # If n is not previously setup, install it - n --version > /dev/null 2>&1 || \ - ( echo "Installation of N - Node.js version management" >&2; \ - curl -sL $n_install_script | sudo env "PATH=$PATH" N_PREFIX="$n_install_dir" bash -s -- -y $nodejs_version ) - - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH - - # And replace the old node binary. - test -x /usr/bin/node_n && sudo mv /usr/bin/node_n /usr/bin/node - test -x /usr/bin/npm_n && sudo mv /usr/bin/npm_n /usr/bin/npm - - # Install the requested version of nodejs (except for the first installation of n, which installed the requested version of node.) - sudo env "PATH=$PATH" n $nodejs_version - - # Use the real installed version. Sometimes slightly different - nodejs_version=$(node --version | cut -c2-) - - # Store the ID of this app and the version of node requested for it - echo "$YNH_APP_ID:$nodejs_version" | sudo tee --append "$n_install_dir/ynh_app_version" - - # Store nodejs_version into the config of this app - ynh_app_setting_set $app nodejs_version $nodejs_version - - ynh_use_nodejs -} - -ynh_remove_nodejs () { - ynh_use_nodejs - - # Remove the line for this app - sudo sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version" - - # If none another app uses this version of nodejs, remove it. - if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version" - then - n rm $nodejs_version - fi - - # If none another app uses n, remove n - if [ ! -s "$n_install_dir/ynh_app_version" ] - then - ynh_secure_remove "$n_install_dir" - sudo sed --in-place "/N_PREFIX/d" /root/.bashrc - fi -} - - diff --git a/scripts/install b/scripts/install index ec99121..e7bed57 100644 --- a/scripts/install +++ b/scripts/install @@ -29,74 +29,83 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= - -ynh_webpath_available $domain $path_url -ynh_webpath_register $app $domain $path_url +ynh_script_progression --message="Validating installation parameters..." --time --weight=1 final_path=/var/www/$app -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" + +# Register (book) web path +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app expire $expire +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=expire --value=$expire #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Configuring firewall..." --time --weight=1 -port=$(ynh_find_port 8095) -sudo yunohost firewall allow --no-upnp TCP $port 2>&1 -ynh_app_setting_set $app port $port - -#================================================= -# INSTALL NODEJS -#================================================= - -ynh_install_nodejs $node_version - -ynh_app_setting_set $app node_version $node_version +port=$(ynh_find_port --port=8095) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." --weight=20 ynh_install_app_dependencies $pkg_dependencies +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Setting up source files..." --weight=2 -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir=$final_path #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configuring NGINX web server..." --weight=2 +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Configuring system user..." --weight=3 -ynh_system_user_create $app +# Create a system user +ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # INSTALL ETHERCALC #================================================= +ynh_script_progression --message="Building CodiMD... (this will take some time and resources!)" --weight=240 -ynh_use_nodejs - -npm install -g ethercalc +pushd "$final_path" || ynh_die + ynh_use_nodejs + ynh_exec_warn_less npm install -g ethercalc +popd || ynh_die #================================================= # SETUP SYSTEMD BASED SERVICES #================================================= +ynh_script_progression --message="Configuring a systemd service..." --weight=1 ynh_add_systemd_config @@ -133,19 +142,25 @@ sudo yunohost service add $app --log "/var/log/ethercalc.log" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." --weight=1 -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete $app skipped_uris -fi - +# Make app public if necessary or protect it if [ $is_public -eq 1 ] then - ynh_app_setting_set $app unprotected_uris "/" + # 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=2 ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of EtherCalc completed" --last