diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh new file mode 100644 index 0000000..72888b0 --- /dev/null +++ b/.github/workflows/updater.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +#================================================= +# PACKAGE UPDATING HELPER +#================================================= + +# This script is meant to be run by GitHub Actions +# The YunoHost-Apps organisation offers a template Action to run this script periodically +# Since each app is different, maintainers can adapt its contents so as to perform +# automatic actions when a new upstream release is detected. + +#================================================= +# FETCHING LATEST RELEASE AND ITS ASSETS +#================================================= + +# Fetching information +current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') +repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') +# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) +version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) +assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'")) + +# Later down the script, we assume the version has only digits and dots +# Sometimes the release name starts with a "v", so let's filter it out. +# You may need more tweaks here if the upstream repository has different naming conventions. +if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then + version=${version:1} +fi + +# Setting up the environment variables +echo "Current version: $current_version" +echo "Latest release from upstream: $version" +echo "VERSION=$version" >> $GITHUB_ENV +echo "REPO=$repo" >> $GITHUB_ENV +# For the time being, let's assume the script will fail +echo "PROCEED=false" >> $GITHUB_ENV + +# Proceed only if the retrieved version is greater than the current one +if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then + echo "::warning ::No new version available" + exit 0 +# Proceed only if a PR for this new version does not already exist +elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then + echo "::warning ::A branch already exists for this update" + exit 0 +fi + +# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.) +echo "${#assets[@]} available asset(s)" + +#================================================= +# UPDATE SOURCE FILES +#================================================= + +# Here we use the $assets variable to get the resources published in the upstream release. +# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like. + +# Let's loop over the array of assets URLs +for asset_url in ${assets[@]}; do + + echo "Handling asset at $asset_url" + + # Assign the asset to a source file in conf/ directory + # Here we base the source file name upon a unique keyword in the assets url (admin vs. update) + # Leave $src empty to ignore the asset + case $asset_url in + *"linux-386"*) + src="i386" + ;; + *"linux-amd64"*) + src="amd64" + ;; + *"linux-arm-7"*) + src="arm7" + ;; + *"linux-arm64"*) + src="arm64" + ;; + *) + src="" + ;; + esac + + # If $src is not empty, let's process the asset + if [ ! -z "$src" ]; then + + # Create the temporary directory + tempdir="$(mktemp -d)" + + # Download sources and calculate checksum + filename=${asset_url##*/} + curl --silent -4 -L $asset_url -o "$tempdir/$filename" + checksum=$(sha256sum "$tempdir/$filename" | head -c 64) + + # Delete temporary directory + rm -rf $tempdir + + # Get extension + if [[ $filename == *.tar.gz ]]; then + extension=tar.gz + else + extension=${filename##*.} + fi + + # Rewrite source file + cat < conf/$src.src +SOURCE_URL=$asset_url +SOURCE_SUM=$checksum +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=$extension +SOURCE_IN_SUBDIR=false +SOURCE_FILENAME= +SOURCE_EXTRACT=true +EOT + echo "... conf/$src.src updated" + + else + echo "... asset ignored" + fi + +done + +#================================================= +# SPECIFIC UPDATE STEPS +#================================================= + +# Any action on the app's source code can be done. +# The GitHub Action workflow takes care of committing all changes after this script ends. + +#================================================= +# GENERIC FINALIZATION +#================================================= + +# Replace new version in manifest +echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json + +# No need to update the README, yunohost-bot takes care of it + +# The Action will proceed only if the PROCEED environment variable is set to true +echo "PROCEED=true" >> $GITHUB_ENV +exit 0 diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml new file mode 100644 index 0000000..fb72ba0 --- /dev/null +++ b/.github/workflows/updater.yml @@ -0,0 +1,49 @@ +# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected. +# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization. +# This file should be enough by itself, but feel free to tune it to your needs. +# It calls updater.sh, which is where you should put the app-specific update steps. +name: Check for new upstream releases +on: + # Allow to manually trigger the workflow + workflow_dispatch: + # Run it every day at 6:00 UTC + schedule: + - cron: '0 6 * * *' +jobs: + updater: + runs-on: ubuntu-latest + steps: + - name: Fetch the source code + uses: actions/checkout@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run the updater script + id: run_updater + run: | + # Setting up Git user + git config --global user.name 'yunohost-bot' + git config --global user.email 'yunohost-bot@users.noreply.github.com' + # Run the updater script + /bin/bash .github/workflows/updater.sh + - name: Commit changes + id: commit + if: ${{ env.PROCEED == 'true' }} + run: | + git commit -am "Upgrade to v$VERSION" + - name: Create Pull Request + id: cpr + if: ${{ env.PROCEED == 'true' }} + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: Update to version ${{ env.VERSION }} + committer: 'yunohost-bot ' + author: 'yunohost-bot ' + signoff: false + base: testing + branch: ci-auto-update-v${{ env.VERSION }} + delete-branch: true + title: 'Upgrade to version ${{ env.VERSION }}' + body: | + Upgrade to v${{ env.VERSION }} + draft: false diff --git a/conf/arm-7.src b/conf/arm7.src similarity index 100% rename from conf/arm-7.src rename to conf/arm7.src diff --git a/conf/config.yml b/conf/config.yml index b742dce..babe9b0 100644 --- a/conf/config.yml +++ b/conf/config.yml @@ -12,11 +12,11 @@ server: database: # for database see (configure database section) dialect: mysql - connection: __APP__:__DBPASS__@unix(/var/run/mysqld/mysqld.sock)/__DBNAME__?charset=utf8&parseTime=True&loc=Local + connection: __DB_USER__:__DB_PWD__@unix(/var/run/mysqld/mysqld.sock)/__DB_NAME__?charset=utf8&parseTime=True&loc=Local defaultuser: # on database creation, gotify creates an admin user - name: __ADMINUSER__ # the username of the default user - pass: __ADMINPASS__ # the password of the default user + name: __ADMIN__ # the username of the default user + pass: __PASSWORD__ # the password of the default user passstrength: 12 # the bcrypt password strength (higher = better but also slower) uploadedimagesdir: data/images # the directory for storing uploaded images pluginsdir: data/plugins # the directory where plugin resides diff --git a/conf/nginx.conf b/conf/nginx.conf index 4963313..e8585ff 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,33 +1,24 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/stream { - proxy_pass http://127.0.0.1:__PORT__/stream; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; + proxy_pass http://127.0.0.1:__PORT__/stream; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; - proxy_connect_timeout 7m; - proxy_send_timeout 7m; - proxy_read_timeout 7m; - - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } + proxy_connect_timeout 7m; + proxy_send_timeout 7m; + proxy_read_timeout 7m; } location __PATH__/ { - proxy_pass http://127.0.0.1:__PORT__/; - #sub_path_only rewrite ^/__PATH__(/.*) $1 break; - proxy_set_header Host $host; - proxy_buffering off; - fastcgi_param REMOTE_USER $remote_user; - client_max_body_size 50M; - more_set_input_headers 'Authorization: $http_authorization'; - proxy_set_header Authorization $http_authorization; - - # Force https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } + proxy_pass http://127.0.0.1:__PORT__/; + #sub_path_only rewrite ^/__PATH__(/.*) $1 break; + proxy_set_header Host $host; + proxy_buffering off; + fastcgi_param REMOTE_USER $remote_user; + client_max_body_size 50M; + more_set_input_headers 'Authorization: $http_authorization'; + proxy_set_header Authorization $http_authorization; } diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..052f6b8 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +Gotify is a simple server for sending and receiving messages in real-time per web socket. (Includes a sleek web-ui) diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..5759a6a --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1 @@ +Gotify est un serveur simple permettant d'envoyer et de recevoir des messages via websocket. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..c6d5587 --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,4 @@ +## Configuration + +How to configure this app: +> Edit `config.yml` file via SSH. diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md new file mode 100644 index 0000000..87a3a71 --- /dev/null +++ b/doc/DISCLAIMER_fr.md @@ -0,0 +1,4 @@ +## Configuration + +Pour configurer Gotify : +> Éditer le fichier `config.yml` avec SSH. diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/screenshots/ui.png b/doc/screenshots/ui.png new file mode 100644 index 0000000..b28f6bb Binary files /dev/null and b/doc/screenshots/ui.png differ diff --git a/manifest.json b/manifest.json index bd6309f..d1355c2 100644 --- a/manifest.json +++ b/manifest.json @@ -6,15 +6,21 @@ "en": "A simple server for sending and receiving messages.", "fr": "Un simple serveur pour envoyer et recevoir des messages." }, - "version": "2.1.4~ynh1", + "version": "2.1.4~ynh2", "url": "http://gotify.net", + "upstream": { + "license": "MIT", + "website": "http://gotify.net", + "admindoc": "https://gotify.net/docs/index", + "code": "https://github.com/gotify/server" + }, "license": "MIT", "maintainer": { "name": "plopoyop", "email": "plopoyop@gmail.com" }, "requirements": { - "yunohost": ">= 3.8.1" + "yunohost": ">= 4.3.0" }, "multi_instance": true, "services": [ @@ -22,34 +28,20 @@ "mysql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", - "type": "domain", - "ask": { - "en": "Choose a domain name for gotify", - "fr": "Choisissez un nom de domaine pour gotify" - }, - "example": "example.com" + "type": "domain" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for Gotify", - "fr": "Choisissez un chemin pour Gotify" - }, "example": "/gotify", "default": "/gotify" }, { "name": "admin", - "type": "user", - "ask": { - "en": "Choose an admin user", - "fr": "Choisissez l’administrateur" - }, - "example": "johndoe" + "type": "user" }, { "name": "password", diff --git a/scripts/_common.sh b/scripts/_common.sh index 8c4da07..944a65e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,14 +15,3 @@ #================================================= # FUTURE OFFICIAL HELPERS #================================================= - -if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then - architecture="arm64" -elif [ -n "$(uname -m | grep 64)" ]; then - architecture="amd64" -elif [ -n "$(uname -m | grep arm)" ]; then - architecture="arm-7" -else - ynh_die "Unable to detect your achitecture, please open a bug describing \ - your hardware and the result of the command \"uname -m\"." 1 -fi \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 9f59389..6098c7a 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,6 +14,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= @@ -22,9 +24,9 @@ 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) -db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -43,6 +45,12 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= # BACKUP THE MYSQL DATABASE #================================================= @@ -50,12 +58,6 @@ ynh_print_info --message="Backing up the MySQL database..." ynh_mysql_dump_db --database="$db_name" > db.sql -#================================================= -# BACKUP SYSTEMD -#================================================= - -ynh_backup --src_path="/etc/systemd/system/$app.service" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 2378050..4fb219d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,19 +24,23 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +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) -port=$(ynh_app_setting_get $app port) + +# Add settings here as needed by your application +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --time --weight=1 +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 () { + ynh_clean_check_starting # 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" @@ -67,14 +71,14 @@ fi #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --time --weight=1 +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -100,24 +104,20 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi -#================================================= -# SPECIFIC MODIFICATIONS -#================================================= -#================================================= - #================================================= # GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1 +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -125,4 +125,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --time --last \ No newline at end of file +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index b016ecb..172afd8 100755 --- a/scripts/install +++ b/scripts/install @@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -23,7 +26,6 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN -is_public=1 password=$YNH_APP_ARG_PASSWORD app=$YNH_APP_INSTANCE_NAME @@ -34,63 +36,31 @@ app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Validating installation parameters..." final_path=/opt/yunohost/$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) - -# 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..." -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app password $password +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=password --value=$password #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Finding an available port..." -# Find a free port -port=$(ynh_find_port 8080) -# Open this port -ynh_app_setting_set $app port $port - -#================================================= -# CREATE A MYSQL DATABASE -#================================================= -ynh_script_progression --message="Creating a MySQL database..." --weight=10 - -db_name=$(ynh_sanitize_dbid $app) -ynh_app_setting_set $app db_name $db_name -ynh_mysql_setup_db $db_name $db_name - -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_script_progression --message="Setting up source files..." --weight=6 - -ynh_app_setting_set $app final_path $final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" $architecture - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=2 - -# Create a dedicated nginx config -ynh_add_nginx_config +# Find an available port +port=$(ynh_find_port --port=8080) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # CREATE DEDICATED USER @@ -98,70 +68,97 @@ ynh_add_nginx_config ynh_script_progression --message="Configuring system user..." --weight=2 # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app --home_dir="$final_path" + +#================================================= +# CREATE A MYSQL DATABASE +#================================================= +ynh_script_progression --message="Creating a MySQL database..." --weight=10 + +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Setting up source files..." --weight=6 + +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" --source_id="$YNH_ARCH" + +mkdir -p $final_path/data + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." --weight=2 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +#================================================= +# SPECIFIC SETUP +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="../conf/config.yml" --destination="$final_path/config.yml" + +chmod 400 "$final_path/config.yml" +chown $app:$app "$final_path/config.yml" #================================================= # SETUP SYSTEMD #================================================= +ynh_script_progression --message="Configuring a systemd service..." # Create a dedicated systemd config -ynh_replace_string "__ARCHITECTURE__" $architecture "../conf/systemd.service" +architecture=$YNH_ARCH ynh_add_systemd_config -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Create config file..." --weight=1 - -cp ../conf/config.yml "$final_path/config.yml" -ynh_replace_string "__APP__" $app "$final_path/config.yml" -ynh_replace_string "__PORT__" $port "$final_path/config.yml" -ynh_replace_string "__DBNAME__" $db_name "$final_path/config.yml" -ynh_replace_string "__DBPASS__" $db_pwd "$final_path/config.yml" -ynh_replace_string "__ADMINUSER__" $admin "$final_path/config.yml" -ynh_replace_string "__ADMINPASS__" $password "$final_path/config.yml" -ynh_replace_string "__DOMAIN__" $domain "$final_path/config.yml" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/config.yml" - #================================================= # GENERIC FINALIZATION #================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions to app files -chown -R root:$app $final_path -mkdir -p $final_path/data -chown -R $app: $final_path/data/ -chmod o-rwx $final_path/ -R - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" + #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=1 +ynh_script_progression --message="Configuring permissions..." --weight=1 -# Make app public if necessary -ynh_permission_update --permission "main" --add visitors +# Everyone can access the app. +# The "main" permission is automatically created before the install script. +ynh_permission_update --permission="main" --add="visitors" #================================================= # 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 +#================================================= -systemctl start $app ynh_script_progression --message="Installation of $app completed" --last -ynh_print_warn "Change the admin password after the first login or delete it in the config file (stored in plain text)" diff --git a/scripts/remove b/scripts/remove index 71a1cb5..f5feef2 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,43 +12,44 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) -db_name=$(ynh_app_setting_get $app db_name) -db_user=$app -final_path=$(ynh_app_setting_get $app final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -if yunohost service status | grep -q $app +# 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="Remove $app service" --weight=1 + ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= +ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config - #================================================= # REMOVE THE MYSQL DATABASE #================================================= ynh_script_progression --message="Removing the MySQL database..." --weight=6 # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE APP MAIN DIR @@ -56,14 +57,14 @@ ynh_mysql_remove_db $db_user $db_name ynh_script_progression --message="Removing app main directory..." --weight=10 # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Removing NGINX web server configuration..." --weight=2 -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= diff --git a/scripts/restore b/scripts/restore index b60a9e4..2b92272 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,97 +14,104 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings.." +ynh_script_progression --message="Loading installation settings..." 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) -db_name=$(ynh_app_setting_get $app db_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_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters.." --weight=1 +ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= -# RESTORE THE NGINX CONFIGURATION +# RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Restoring NGINX configuration..." --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory.." --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the MySQL database.." --weight=20 - -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql - -#================================================= -# 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 - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files -chown -R root:$app $final_path -mkdir -p $final_path/data -chown -R $app: $final_path/data/ -chmod o-rwx $final_path/ -R +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 -yunohost service add $app +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the MySQL database..." --weight=20 + +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring service..." --weight=10 +ynh_script_progression --message="Restoring the systemd configuration..." -ynh_restore_file "/etc/systemd/system/$app.service" +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -systemctl start $app + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" #================================================= # GENERIC FINALIZATION #================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 28df7fd..4885da2 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,24 +12,55 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings.." --weight=1 +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) -admin=$(ynh_app_setting_get $app admin) -is_public=$(ynh_app_setting_get $app is_public) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -port=$(ynh_app_setting_get $app port) -password=$(ynh_app_setting_get $app password) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +port=$(ynh_app_setting_get --app=$app --key=port) +password=$(ynh_app_setting_get --app=$app --key=password) + +#================================================= +# CHECK VERSION +#================================================= +ynh_script_progression --message="Checking version..." + +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=30 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + ynh_clean_check_starting + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility.." --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then @@ -52,49 +83,13 @@ if [ -z $final_path ]; then ynh_app_setting_set $app final_path $final_path fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=30 - -# 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 - -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) - -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_script_progression --message="Upgrading source files..." --weight=6 - -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" $architecture - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 - -# Create a dedicated NGINX config -if [ "$path_url" != "/" ] -then - ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" +# If data directory doesn't exists +if [ -z $final_path/data ]; then + mkdir $final_path/data fi -ynh_add_nginx_config +# check data directory permission +chown -R $app: $final_path/data #================================================= # CREATE DEDICATED USER @@ -104,75 +99,67 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # Create a dedicated user (if not existing) ynh_system_user_create $app +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Upgrading source files..." --weight=6 + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading source files..." + + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" --source_id="$YNH_ARCH" +fi + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + +#================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 + +# Create a dedicated NGINX config +ynh_add_nginx_config + #================================================= # SPECIFIC UPGRADE #================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." -ynh_backup_if_checksum_is_different "$final_path/config.yml" +ynh_add_config --template="../conf/config.yml" --destination="$final_path/config.yml" -cp ../conf/config.yml "$final_path/config.yml" -ynh_replace_string "__APP__" $app "$final_path/config.yml" -ynh_replace_string "__PORT__" $port "$final_path/config.yml" -ynh_replace_string "__DBNAME__" $db_name "$final_path/config.yml" -ynh_replace_string "__DBPASS__" $db_pwd "$final_path/config.yml" -ynh_replace_string "__ADMINUSER__" $admin "$final_path/config.yml" -ynh_replace_string "__ADMINPASS__" $password "$final_path/config.yml" -ynh_replace_string "__DOMAIN__" $domain "$final_path/config.yml" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum "$final_path/config.yml" +chmod 400 "$final_path/config.yml" +chown $app:$app "$final_path/config.yml" #================================================= # SETUP SYSTEMD #================================================= +ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config -ynh_replace_string "__ARCHITECTURE__" $architecture "../conf/systemd.service" +architecture=$YNH_ARCH ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions on app files -chown -R root:$app $final_path/ -chown -R $app: $final_path/data/ -chmod o-rwx $final_path/ -R - -# If data directory doesn't exists -if [ -z $final_path/data ]; then - mkdir $final_path/data -fi - -# check data directory permission -chown -R $app: $final_path/data - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app #================================================= -# SETUP SSOWAT +# START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=1 +ynh_script_progression --message="Starting a systemd service..." -unprotected_uris=$(ynh_app_setting_get --app=$app --key=unprotected_uris) -if [ ! -z "$unprotected_uris" ]; then - ynh_app_setting_delete --app=$app --key=unprotected_uris -fi - -ynh_permission_update --permission "main" --add visitors - -#================================================= -# RELOAD SERVICE -#================================================= -ynh_script_progression --message="Reloading service..." --weight=1 - -systemctl restart $app +ynh_systemd_action --service_name=$app --action="start" #================================================= # RELOAD NGINX