diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op] diff --git a/README.md b/README.md index 93a79af..1598caf 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,78 @@ # Haste for YunoHost -Haste is an open-source pastebin software written in node.js. +[](https://dash.yunohost.org/appci/app/haste)   +[](https://install-app.yunohost.org/?app=haste) -[Haste Github repository](https://github.com/seejohnrun/haste-server) +*[Lire ce readme en français.](./README_fr.md)* -A publicly available version can be found at [http://hastebin.com/](http://hastebin.com/) +> *This package allows you to install Haste quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* -## Requirements -- Functionnal instance of [YunoHost](https://yunohost.org) +## Overview +Haste is an open-source pastebin software written in node.js, which is easily installable in any network. YunoHost Project uses Haste as pastebin for log sharing: [paste.yunohost.org](https://paste.yunohost.org/) + +**Shipped version:** 0.1.0 + +## Screenshots + + + +## Demo + +* [Official demo](http://hastebin.com/) + +## Configuration + +How to configure this app: a plain file with SSH. + +## Documentation + + * Official documentation: https://hastebin.com/about.md + * YunoHost documentation: If specific documentation is needed, feel free to contribute. + +## YunoHost specific features + +#### Multi-user support + +* Are LDAP and HTTP auth supported? **No** +* Can the app be used by multiple users? **Yes** + +#### Supported architectures + +* x86-64 - [](https://ci-apps.yunohost.org/ci/apps/haste/) +* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/haste/) + +## Limitations + +* Any known limitations. + +## Additional information ## `haste` command -With this package is included the `haste` command based on this: -https://github.com/diethnis/standalones/blob/master/hastebin.sh - -This allow to pipe text to it and upload the text on your haste instance. You can also install it on your local computer by copying the file /usr/bin/haste on a computer that has bash and curl. +This Haste package for Yunohost includes the [`haste` command](https://github.com/diethnis/standalones/blob/master/hastebin.sh), allowing you to share content from terminal: ```bash -cat LICENSE | haste -######################################################################## 100,0% +cat something | haste https://haste.example.com/zuyejeduzu ``` +The [Haste-client](https://github.com/seejohnrun/haste-client) is a simple client for uploading data to you Haste server. -## Installation -From command line: +## Links -`sudo yunohost app install -l Haste https://github.com/YunoHost-Apps/haste_ynh` + * Report a bug: https://github.com/YunoHost-Apps/haste_ynh/issues + * Upstream app repository: https://github.com/seejohnrun/haste-server + * YunoHost website: https://yunohost.org/ -## Upgrade -From command line: +--- -`sudo yunohost app upgrade -u https://github.com/YunoHost-Apps/haste_ynh haste` +## Developer info -## Infos +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/haste_ynh/tree/testing). -- [YunoHost forum thread](https://forum.yunohost.org/t/haste-package-pastebin-software/2038) - -## License - -Both Haste and this package are published under MIT License +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/haste_ynh/tree/testing --debug +or +sudo yunohost app upgrade haste -u https://github.com/YunoHost-Apps/haste_ynh/tree/testing --debug +``` diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..1b03b9b --- /dev/null +++ b/README_fr.md @@ -0,0 +1,79 @@ +# Haste pour YunoHost + +[](https://dash.yunohost.org/appci/app/haste)   +[](https://install-app.yunohost.org/?app=haste) + +*[Read this readme in english.](./README.md)* + +> *Ce package vous permet d'installer Haste rapidement et simplement sur un serveur YunoHost. +Si vous n'avez pas YunoHost, consultez [le guide](https://yunohost.org/#/install) pour apprendre comment l'installer.* + +## Vue d'ensemble +Haste est un logiciel pastebin open-source écrit en node.js, facilement installable sur n'importe quel réseau. Le projet YunoHost utilise Haste comme pastebin pour le partage de log : [paste.yunohost.org](https://paste.yunohost.org/) + +**Version incluse :** 0.1.0 + +## Captures d'écran + + + +## Démo + +* [Démo officielle](http://hastebin.com/) + +## Configuration + +Comment configurer cette application: un fichier brut en SSH. + +## Documentation + + * Documentation officielle: https://hastebin.com/about.md + * Documentation YunoHost: Si une documentation spécifique est nécessaire, n'hésitez pas à contribuer. + +## Caractéristiques spécifiques YunoHost + +#### Support multi-utilisateur + +* L'authentification LDAP et HTTP est-elle prise en charge ? **Non** +* L'application peut-elle être utilisée par plusieurs utilisateurs ? **Oui** + +#### Architectures supportées + +* x86-64 - [](https://ci-apps.yunohost.org/ci/apps/haste/) +* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/haste/) + +## Limitations + +* Limitations connues. + +## Informations additionnelles + +## `haste` command + +Ce paquet de Haste pour YunoHost comprend une commande [`haste`](https://github.com/diethnis/standalones/blob/master/hastebin.sh), vous permettant de partager du contenu avec le terminal : + +```bash +cat something | haste +https://haste.example.com/zuyejeduzu +``` + +Le [client Haste](https://github.com/seejohnrun/haste-client) est un client simple pour télécharger des données sur votre serveur Haste. + +## Liens + + * Signaler un bug : https://github.com/YunoHost-Apps/haste_ynh/issues + * Dépôt de l'application principale : https://github.com/seejohnrun/haste-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/haste_ynh/tree/testing). + +Pour essayer la branche testing, procédez comme suit. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/haste_ynh/tree/testing --debug +ou +sudo yunohost app upgrade haste -u https://github.com/YunoHost-Apps/haste_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index 69bfea0..0365448 100644 --- a/check_process +++ b/check_process @@ -3,6 +3,7 @@ domain="domain.tld" (DOMAIN) path="/" (PATH) is_public=1 (PUBLIC|public=1|private=0) + port="7777" (PORT) ; Checks pkg_linter=1 setup_sub_dir=0 @@ -13,8 +14,8 @@ upgrade=1 backup_restore=1 multi_instance=0 - incorrect_path=0 - port_already_use=1 (7777) + # incorrect_path=0 + port_already_use=1 change_url=0 ;;; Levels Level 1=auto diff --git a/conf/app.src b/conf/app.src index 5b0660a..8e67786 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/seejohnrun/haste-server/archive/f19c5d10498e214b8323fff9e5eab77cbb7eebff.tar.gz -SOURCE_SUM=6e67fd09bc7782d23d612c209a2de39212682239018a1bd2618c120f9cc36a47 +SOURCE_URL=https://github.com/seejohnrun/haste-server/archive/master.tar.gz +SOURCE_SUM=71d1f09b5c46d3054075fd706c8f75284bafc4b09e2df612a641c4f30837b11f SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/config.js b/conf/config.js index daafea6..ba29d25 100644 --- a/conf/config.js +++ b/conf/config.js @@ -1,6 +1,7 @@ { "host": "127.0.0.1", + "port": __PORT__, "keyLength": 10, @@ -40,5 +41,5 @@ "documents": { "about": "./about.md" } - + } diff --git a/conf/nginx.conf b/conf/nginx.conf index cffa451..0579767 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,14 +1,15 @@ -location __PATH__ { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } - proxy_pass http://localhost:__PORT__; - proxy_set_header Host $host; + proxy_pass http://localhost:__PORT__; + proxy_set_header Host $host; proxy_buffering off; - client_max_body_size 50M; + client_max_body_size 50M; # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; diff --git a/conf/systemd.service b/conf/systemd.service index b529260..c8af1d9 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,16 +1,16 @@ [Unit] Description=Haste is an open-source pastebin software -After=syslog.target -After=network.target +After=network.target syslog.target [Service] Type=simple User=__APP__ Group=__APP__ -ExecStartPre=__NODEJS__ WorkingDirectory=__FINALPATH__ Environment="PATH=__ENV_PATH__" -ExecStart=__NODEPATH__/npm start +ExecStart=__YNH_NPM__ start +StandardOutput=append:/var/log/__APP__/__APP__.log +StandardError=inherit Restart=always [Install] diff --git a/manifest.json b/manifest.json index 8d06bce..fecbfb6 100644 --- a/manifest.json +++ b/manifest.json @@ -3,10 +3,10 @@ "id": "haste", "packaging_format": 1, "description": { - "en": "Haste is an open-source pastebin software written in node.js", - "fr": "Haste is an open-source pastebin software written in node.js" + "en": "Open-source pastebin allowing to upload texts", + "fr": "Pastebin open-source permettant de mettre en ligne du texte" }, - "version": "f19c5d10498e214b8323fff9e5eab77cbb7eebff", + "version": "0.1.0~ynh1", "url": "https://github.com/seejohnrun/haste-server", "license": "MIT", "maintainer": { @@ -14,7 +14,7 @@ "email": "maxime.bugeia@gmail.com" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.8.1" }, "multi_instance": false, "services": [ @@ -45,8 +45,8 @@ "name": "is_public", "type": "boolean", "ask": { - "en": "Is it a public site? (you won't be able to use haste command easily if not)", - "fr": "Est-ce un site publique ? (si non, vous ne pourrez pas utiliser la commande haste facilement)" + "en": "Is it a public site? (you won't be able to use Haste command easily if not)", + "fr": "Est-ce un site publique ? (si non, vous ne pourrez pas utiliser la commande Haste facilement)" }, "default": true } diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..3cf2e53 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,18 @@ +## Problem +- *Description of why you made this PR* + +## Solution +- *And how do you fix that problem* + +## PR Status +- [ ] Code finished. +- [ ] Tested with Package_check. +- [ ] Fix or enhancement tested. +- [ ] Upgrade from last version tested. +- [ ] Can be reviewed and tested. + +## Package_check results +--- +*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* + +[/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/haste_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index 8fe185d..ac79128 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,173 +1,19 @@ -# 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 -# 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" -node_version_path="/opt/node_n/n/versions/node" -# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n. -export N_PREFIX="$n_install_dir" - -ynh_install_n () { - echo "Installation of N - Node.js version management" >&2 - # Build an app.src for n - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz -SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src" - # Download and extract n - ynh_setup_source "$n_install_dir/git" n - # Install n - (cd "$n_install_dir/git" - PREFIX=$N_PREFIX make install 2>&1) -} - -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\"; N_PREFIX="$n_install_dir"" - - nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version" - - # "Load" a version of node - eval $load_n_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" -} - -ynh_install_nodejs () { - # Use n, https://github.com/tj/n to manage the nodejs versions - nodejs_version="$1" - local n_install_script="https://git.io/n-install" - - # Create $n_install_dir - 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 && mv /usr/bin/node /usr/bin/node_n - test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n - - # If n is not previously setup, install it - if ! test n --version > /dev/null 2>&1 - then - ynh_install_n - fi - - # Modify the default N_PREFIX in n script - ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n" - - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH - - # And replace the old node binary. - test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node - test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm - - # Install the requested version of nodejs - n $nodejs_version - - # Find the last "real" version for this major version of node. - real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1) - real_nodejs_version=$(basename $real_nodejs_version) - - # Create a symbolic link for this major version. If the file doesn't already exist - if [ ! -e "$node_version_path/$nodejs_version" ] - then - ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version - fi - - # Store the ID of this app and the version of node requested for it - echo "$YNH_APP_ID:$nodejs_version" | 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 - - # Build the update script and set the cronjob - ynh_cron_upgrade_node - - ynh_use_nodejs -} - -ynh_remove_nodejs () { - ynh_use_nodejs - - # Remove the line for this app - 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" - ynh_secure_remove "/usr/local/n" - sed --in-place "/N_PREFIX/d" /root/.bashrc - fi -} - -ynh_cron_upgrade_node () { - # Build the update script - cat > "$n_install_dir/node_update.sh" << EOF #!/bin/bash -version_path="$node_version_path" -n_install_dir="$n_install_dir" +#================================================= +# COMMON VARIABLES +#================================================= -# Log the date -date +nodejs_version=12 -# List all real installed version of node -all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")" +#================================================= +# PERSONAL HELPERS +#================================================= -# Keep only the major version number of each line -all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//') +#================================================= +# EXPERIMENTAL HELPERS +#================================================= -# Remove double entries -all_real_version=\$(echo "\$all_real_version" | sort --unique) - -# Read each major version -while read version -do - echo "Update of the version \$version" - sudo \$n_install_dir/bin/n \$version - - # Find the last "real" version for this major version of node. - real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1) - real_nodejs_version=\$(basename \$real_nodejs_version) - - # Update the symbolic link for this version - sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version -done <<< "\$(echo "\$all_real_version")" -EOF - - chmod +x "$n_install_dir/node_update.sh" - - # Build the cronjob - cat > "/etc/cron.daily/node_update" << EOF -#!/bin/bash - -$n_install_dir/node_update.sh >> $n_install_dir/node_update.log -EOF - - chmod +x "/etc/cron.daily/node_update" -} +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup old mode 100755 new mode 100644 index b85e9d0..e75918d --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,8 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +#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 #================================================= @@ -24,11 +20,17 @@ 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 final_path) -domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." #================================================= # STANDARD BACKUP STEPS @@ -36,13 +38,13 @@ domain=$(ynh_app_setting_get $app domain) # BACKUP THE APP MAIN DIR #================================================= -ynh_backup "$final_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP @@ -50,23 +52,28 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP LOGROTATE #================================================= -# FIXME Currently, the log is only redirected to syslog. -# ynh_backup "/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP DATADIR DIRECTORY #================================================= -ynh_backup "/home/yunohost.app/$app" +ynh_backup --src_path="/home/yunohost.app/$app" #================================================= # BACKUP BINARY #================================================= -ynh_backup "/usr/bin/$app" +ynh_backup --src_path="/usr/bin/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup "/etc/systemd/system/$app.service" +ynh_backup --src_path="/etc/systemd/system/$app.service" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install old mode 100755 new mode 100644 index 5ff7485..ab1fb44 --- a/scripts/install +++ b/scripts/install @@ -21,7 +21,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH +path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME @@ -29,76 +29,75 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS #================================================= +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" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) - -if [ "$path_url" != "/" ]; then - ynh_die "Only / is allowed" -fi - -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." --weight=2 -ynh_app_setting_set $app domain "$domain" -ynh_app_setting_set $app is_public "$is_public" -ynh_app_setting_set $app path_url "$path_url" +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=path_url --value=$path_url #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Configuring firewall..." --weight=2 -# Find a free port -port=$(ynh_find_port 7777) -ynh_app_setting_set $app port $port +# Find an available port +port=$(ynh_find_port --port=7777) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # 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 "$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 +# 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 #================================================= # SPECIFIC SETUP #================================================= # INSTALL NODEJS #================================================= +ynh_script_progression --message="Installing dependencies..." --weight=10 -ynh_install_nodejs 4 +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # ADD SYSTEMD SERVICE #================================================= -ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" -ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" -ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service" +ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service" +ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="../conf/systemd.service" ynh_add_systemd_config @@ -106,39 +105,51 @@ ynh_add_systemd_config # INSTALL HASTEBIN #================================================= -ynh_use_nodejs - -(cd "$final_path" -chown -R $app: "$final_path" -npm install) +pushd "$final_path" || ynh_die + ynh_use_nodejs + ynh_exec_warn_less ynh_npm install +popd || ynh_die #================================================= # CREATE DIRECTORY FOR DATA #================================================= +ynh_script_progression --message="Creating the data directory..." -data_path="/home/yunohost.app/$app" +# Define app's data directory +data_path="/home/yunohost.app/${app}" + +# Create app folders mkdir -p "$data_path" +# Give permission to the datadir +chown -R $app:$app "$data_path" + #================================================= # CONFIGURE HASTE #================================================= cp ../conf/config.js "$final_path/config.js" -ynh_replace_string "__PORT__" "$port" "$final_path/config.js" -ynh_replace_string "__YNH_DATA_PATH__" "$data_path" "$final_path/config.js" + +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.js" +ynh_replace_string --match_string="__YNH_DATA_PATH__" --replace_string="$data_path" --target_file="$final_path/config.js" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/config.js" +# Replace ajax.googleapis by local file +cp ../sources/jquery.min.js "$final_path/static/jquery.min.js" + +ynh_replace_string --match_string="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" --replace_string="jquery.min.js" --target_file="$final_path/static/index.html" + #================================================= # ADD HASTE AS A BINARY FILE #================================================= -ynh_replace_string "__YNH_HASTE_URL__" "${domain}${path_url%/}" "../conf/haste.sh" -ynh_replace_string "__PORT__" "$port" "../conf/haste.sh" -sudo cp ../conf/haste.sh /usr/bin/$app -sudo chmod +x /usr/bin/"$app" -echo "Please use 'cmd | $app' to paste the output of the command to your Haste server." >&2 +ynh_replace_string --match_string="__YNH_HASTE_URL__" --replace_string="${domain}${path_url%/}" --target_file="../conf/haste.sh" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/haste.sh" + +cp ../conf/haste.sh /usr/bin/$app +chmod +x /usr/bin/$app #================================================= # GENERIC FINALIZATION @@ -148,41 +159,52 @@ echo "Please use 'cmd | $app' to paste the output of the command to your Haste s chown -R root: $final_path chown -R $app "$final_path/static" -chown -R $app "$data_path" #================================================= # HANDLE LOG FILES AND SETUP LOGROTATE #================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 # FIXME Currently, the log is only redirected to syslog. -# mkdir -p /var/log/$app -# touch /var/log/$app/$app.log -# chown $app -R /var/log/$app -# ynh_use_logrotate +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown $app -R /var/log/$app + +ynh_use_logrotate #================================================= -# ENABLE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= -yunohost service add $app --log "/var/log/$app/$app.log" +yunohost service add $app --description "Haste is an open-source pastebin software" --log "/var/log/$app/$app.log" #================================================= -# START HASTEBIN +# START SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=2 -systemctl start $app +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." --weight=1 -if [ $is_public -eq 1 ]; +if [ $is_public -eq 1 ] then - ynh_app_setting_set $app skipped_uris "/" + ynh_permission_update --permission "main" --add "visitors" fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index d124c1d..8e9913e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,46 +12,54 @@ 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 domain) -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE +#================================================= +# REMOVE SERVICE INTEGRATION IN YUNOHOST +#================================================= + +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null +then + ynh_script_progression --message="Removing $app service integration..." --weight=1 + yunohost service remove $app +fi + #================================================= # STOP AND REMOVE SERVICE #================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE SERVICE FROM ADMIN PANEL -#================================================= - -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi - #================================================= # REMOVE APP MAIN DIR #================================================= +ynh_script_progression --message="Removing app main directory..." --weight=2 -ynh_secure_remove "$final_path" +# Remove the app directory securely +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 # FIXME Currently, the log is only redirected to syslog. # ynh_remove_logrotate @@ -62,13 +70,13 @@ ynh_remove_nginx_config # REMOVE HASTE BINARY #================================================= -ynh_secure_remove "/usr/bin/$app" +ynh_secure_remove --file="/usr/bin/$app" #================================================= # REMOVE DATADIR DIRECTORY #================================================= -ynh_secure_remove "/home/yunohost.app/$app" +ynh_secure_remove --file="/home/yunohost.app/$app" #================================================= # REMOVE NODEJS @@ -81,6 +89,13 @@ ynh_remove_nodejs #================================================= # REMOVE DEDICATED 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" --last diff --git a/scripts/restore b/scripts/restore old mode 100755 new mode 100644 index 6f6fc87..d408ca5 --- a/scripts/restore +++ b/scripts/restore @@ -1,4 +1,3 @@ - #!/bin/bash #================================================= @@ -7,34 +6,34 @@ # IMPORT GENERIC HELPERS #================================================= -if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory - cp ../settings/scripts/_common.sh ./_common.sh - chmod a+rx _common.sh -fi -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + 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 domain) -path_url=$(ynh_app_setting_get $app path) -final_path=$(ynh_app_setting_get $app final_path) +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) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." --weight=2 ynh_webpath_available $domain $path_url \ || ynh_die "Path not available: ${domain}${path_url}" @@ -47,55 +46,41 @@ test ! -d $final_path \ # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +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=6 -ynh_restore_file "$final_path" +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 $app +ynh_system_user_create --username=$app #================================================= # SPECIFIC RESTORE -#================================================= -# HANDLE LOG FILES AND RESTORE LOGROTATE -#================================================= - -# FIXME Currently, the log is only redirected to syslog. -# mkdir -p /var/log/$app -# touch /var/log/$app/$app.log -# chown $app -R /var/log/$app - -# ynh_restore_file "/etc/logrotate.d/$app" - #================================================= # INSTALL NODEJS #================================================= -ynh_install_nodejs 4 - -#================================================= -# ENABLE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --log "/var/log/$app/$app.log" +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # RESTORE SYSTEMD #================================================= +ynh_script_progression --message="Restoring the systemd configuration..." --weight=2 -ynh_restore_file "/etc/systemd/system/$app.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service #================================================= -# RESTORE DATADIR DIRECTORY +# RESTORE VARIOUS FILES #================================================= ynh_restore_file "/home/yunohost.app/$app" @@ -109,15 +94,35 @@ chown -R $app "$final_path/static" chown -R $app "/home/yunohost.app/$app" #================================================= -# START HASTEBIN +# INTEGRATE SERVICE IN YUNOHOST #================================================= -systemctl start $app +yunohost service add $app --description "Haste is an open-source pastebin software" --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="/var/log/$app/$app.log" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT #================================================= -systemctl reload nginx +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 0ca63f9..cfd132d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,34 +15,42 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path_url) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) -port=$(ynh_app_setting_get $app port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path_url) +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) + +#================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set $app final_path $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=4 # Backup the current version of the app ynh_backup_before_upgrade @@ -58,33 +66,44 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) - -#================================================= -# STOP HASTE -#================================================= - -systemctl stop $app +path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # 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="/var/log/$app/$app.log" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_setup_source "$final_path" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." --weight=7 + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" +fi #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2 -ynh_system_user_create $app +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= # SPECIFIC UPGRADE @@ -92,29 +111,32 @@ ynh_system_user_create $app # UPGRADE NODEJS #================================================= -ynh_install_nodejs 4 +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # UPGRADE NPM MODULES #================================================= -npm cache clean -npm update +pushd "$final_path" || ynh_die + ynh_use_nodejs + ynh_exec_warn_less ynh_npm install +popd || ynh_die #================================================= # SETUP LOGROTATE #================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # FIXME Currently, the log is only redirected to syslog. -# ynh_use_logrotate +ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 -ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service" -ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" -ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service" +ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service" +ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="../conf/systemd.service" ynh_add_systemd_config @@ -126,20 +148,30 @@ ynh_add_systemd_config ynh_backup_if_checksum_is_different "$final_path/config.js" cp ../conf/config.js "$final_path/config.js" -ynh_replace_string "__PORT__" "$port" "$final_path/config.js" -data_path="/home/yunohost.app/$app" -ynh_replace_string "__YNH_DATA_PATH__" "$data_path" "$final_path/config.js" + +# Define app's data directory +data_path="/home/yunohost.app/${app}" + +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.js" +ynh_replace_string --match_string="__YNH_DATA_PATH__" --replace_string="$data_path" --target_file="$final_path/config.js" # Recalculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/config.js" +# Replace ajax.googleapis by local file +cp ../sources/jquery.min.js "$final_path/static/jquery.min.js" + +ynh_replace_string --match_string="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" --replace_string="jquery.min.js" --target_file="$final_path/static/index.html" + #================================================= # UPGRADE HASTE BINARY #================================================= -ynh_replace_string "__YNH_HASTE_URL__" "${domain}${path_url}" "../conf/haste.sh" -sudo cp ../conf/haste.sh /usr/bin/$app -sudo chmod +x /usr/bin/"$app" +ynh_replace_string --match_string="__YNH_HASTE_URL__" --replace_string="${domain}${path_url}" --target_file="../conf/haste.sh" + +cp ../conf/haste.sh /usr/bin/$app + +chmod +x /usr/bin/$app #================================================= # GENERIC FINALIZATION @@ -152,22 +184,21 @@ chown -R $app "$final_path/static" chown -R $app "$data_path" #================================================= -# START HASTEBIN +# START SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 -systemctl start $app - -#================================================= -# SETUP SSOWAT -#================================================= - -if [ $is_public -eq 1 ]; -then - ynh_app_setting_set $app skipped_uris "/" -fi +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/sources/jquery.min.js b/sources/jquery.min.js new file mode 100644 index 0000000..ee02337 --- /dev/null +++ b/sources/jquery.min.js @@ -0,0 +1,4 @@ +/*! jQuery v1.7.1 jquery.com | jquery.org/license */ +(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"":"")+"
"),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!=="border")for(;gt |