diff --git a/README.md b/README.md index 0bad02a..5952490 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,27 @@ -![Misskey](https://raw.githubusercontent.com/syuilo/misskey/develop/assets/title.png) -================================================================ -# Misskey for Yunohost - -[![Integration level](https://dash.yunohost.org/integration/misskey.svg)](https://dash.yunohost.org/appci/app/misskey) ![](https://ci-apps.yunohost.org/ci/badges/misskey.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/misskey.maintain.svg) - -[![Install Misskey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=misskey) - +# Misskey for YunoHost +[![Integration level](https://dash.yunohost.org/integration/misskey.svg)](https://dash.yunohost.org/appci/app/misskey) ![](https://ci-apps.yunohost.org/ci/badges/misskey.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/misskey.maintain.svg) +[![Install misskey with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=misskey) > *This package allows you to install Misskey 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.* -![](https://藍.moe/aiart/31.png) - - ## Overview - [Misskey](https://join.misskey.page/en/) is a forever evolving, sophisticated microblogging platform that support Fediverse. It provide another flavour to decentralised network. Why don't you take a short break from the hustle and bustle of the city, and dive into a new Internet? -**Shipped version:** 12.69.0 +**Shipped version:** 12.81.0 ## Screenshots ![](https://raw.githubusercontent.com/syuilo/misskey/develop/assets/ss/user.jpg) - - ## Other instances to join * [Instances](https://join.misskey.page/en/wiki/instances/) ## Important points to read before installing -1. **Misskey** require a dedicated **root domain**, eg. misskey.domain.tldYunoHost +1. **Misskey** require a dedicated **root domain**, eg. misskey.domain.tldYunoHost 2. **Misskey** can take quite some time to install( **more then 30 minutes** ). So take out some time and grab yourself a coffee. 3. If installing from command line use of **screen is rerecorded** to avoid disconnection.See below. 4. After installation first page can take time to load and may show timeout error. Give it time to make itself ready for you. **Refresh page after 2-3 minutes**. @@ -40,8 +29,8 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in #### Support -LDAP supported : **No** -Can the app be used by multiple users ? : **Yes** + * LDAP supported: **No** + * Can the app be used by multiple users?: **Yes** #### Using *screen* in case of disconnects @@ -67,15 +56,13 @@ $ screen -r --- -Developer info ----------------- +## Developer info -**Only if you want to use a testing branch for coding, instead of merging directly into master.** Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/misskey_ynh/tree/testing). To try the testing branch, please proceed like that. ``` sudo yunohost app install https://github.com/YunoHost-Apps/misskey_ynh/tree/testing --debug or -sudo yunohost app upgrade REPLACEBYYOURAPP -u https://github.com/YunoHost-Apps/misskey_ynh/tree/testing --debug +sudo yunohost app upgrade misskey -u https://github.com/YunoHost-Apps/misskey_ynh/tree/testing --debug ``` diff --git a/check_process b/check_process index b592b09..ce8e10f 100644 --- a/check_process +++ b/check_process @@ -1,28 +1,19 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - is_public=1 (PUBLIC|public=1|private=0) + domain="domain.tld" + is_public=1 ; Checks pkg_linter=1 setup_sub_dir=0 setup_root=1 setup_nourl=0 - setup_private=0 + setup_private=1 setup_public=1 upgrade=1 #upgrade=0 from_commit=CommitHash backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=1 -;;; Levels - # If the level 5 (Package linter) is forced to 1. Please add justifications here. - Level 5=auto + multi_instance=0 + change_url=0 ;;; Options Email= Notification= diff --git a/conf/app.src b/conf/app.src index 0bcd834..ba373ff 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/syuilo/misskey/archive/12.47.1.tar.gz -SOURCE_SUM=59154273ae1f20187cc69689f4c03eb230c2d3a47e830affb0aaa57b71c49b0b +SOURCE_URL=https://github.com/syuilo/misskey/archive/12.81.0.tar.gz +SOURCE_SUM=7534060ef796398650ca2f105bc51024ac1cefc6b1702dafd25101e7ccc6a929 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/default.yml b/conf/default.yml index 5e7b32b..bf55dca 100644 --- a/conf/default.yml +++ b/conf/default.yml @@ -62,7 +62,7 @@ db: db: __DB_NAME__ # Auth - user: __DB_USER__ + user: __DB_NAME__ pass: __DB_PWD__ # Whether disable Caching queries @@ -139,7 +139,7 @@ id: "aid" # port: 514 # Proxy for HTTP/HTTPS -#proxy: http://127.0.0.1:3128 +proxy: http://127.0.0.1:__PORT__ #proxyBypassHosts: [ # 'example.com', diff --git a/conf/nginx.conf b/conf/nginx.conf index e678dec..82bf4b1 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,38 +1,30 @@ - location / { - # Force usage of https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - - - - # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file - #client_max_body_size 50M; - - - proxy_pass http://127.0.0.1:__PORT__; - proxy_set_header Host $host; - proxy_http_version 1.1; - proxy_redirect off; - - # If it's behind another reverse proxy or CDN, remove the following. - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - - - # For WebSocket - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - - # Cache settings - #proxy_cache cache1; - proxy_cache_lock on; - proxy_cache_use_stale updating; - add_header X-Cache $upstream_cache_status; - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # Force usage of https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; } + + #client_max_body_size 50M; + + proxy_pass http://127.0.0.1:__PORT__; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_http_version 1.1; + proxy_redirect off; + + # For WebSocket + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + + # Cache settings + #proxy_cache cache1; + proxy_cache_lock on; + proxy_cache_use_stale updating; + more_set_headers "X-Cache: $upstream_cache_status"; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/conf/systemd.service b/conf/systemd.service index b752416..9540e71 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,15 +1,15 @@ [Unit] Description=__APP__ daemon running + [Service] Type=simple User=__APP__ -ExecStart=__YNH_NPM__ start +Group=__APP__ WorkingDirectory=__FINALPATH__ -Environment="__YNH_NODE_LOAD_PATH__=production" +Environment=__YNH_NODE_LOAD_PATH__ +Environment="NODE_ENV=production" +ExecStart=__YNH_NPM__ start TimeoutSec=60 -StandardOutput=syslog -StandardError=syslog -SyslogIdentifier=__APP__ Restart=always [Install] diff --git a/issue_template.md b/issue_template.md index 87b88d4..4f952c5 100644 --- a/issue_template.md +++ b/issue_template.md @@ -31,7 +31,7 @@ about: When creating a bug report, please use the following template to provide - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh - sudo yunohost app install REPLACEBYYOURAPP + sudo yunohost app install misskey ``` - *If you used the webadmin, please perform the equivalent command from the CLI first.* - *If the error occurs in your browser, explain what you did:* diff --git a/manifest.json b/manifest.json index a417237..c4e38ab 100644 --- a/manifest.json +++ b/manifest.json @@ -3,37 +3,40 @@ "id": "misskey", "packaging_format": 1, "description": { - "en": "Microblogging platform" + "en": "Microblogging platform", + "fr": "Platforme de Microblogging" }, - "version": "12.69.0~ynh1", + "version": "12.81.0~ynh1", "url": "https://join.misskey.page/en/", + "upstream": { + "license": "AGPL-3.0", + "website": "https://join.misskey.page", + "userdoc": "https://yunohost.org/apps", + "code": "https://github.com/syuilo/misskey" + }, "license": "AGPL-3.0", "maintainer": { "name": "Anmol Sharma" }, "requirements": { - "yunohost": ">= 4.0" + "yunohost": ">= 4.2.4" }, - "multi_instance": true, + "multi_instance": false, "services": ["nginx"], "arguments": { "install": [ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain name for Misskey", - "fr": "Choisissez un nom de domaine pour Misskey" - }, "example": "example.com" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, + "help": { + "en": "If enabled, Misskey will be accessible by people who do not have an account. This can be changed later via the webadmin.", + "fr": "Si cette case est cochée, Misskey sera accessible aux personnes n’ayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin." + }, "default": true } ] diff --git a/pull_request_template.md b/pull_request_template.md index 5d5c08b..6c28fc5 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -13,6 +13,4 @@ ## 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* - -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/misskey_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/misskey_ynh%20PR-NUM-%20(USERNAME)/) +* An automatic package_check will be launch at https://ci-apps-dev.yunohost.org/, when you add a specific comment to your Pull Request: "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!"* diff --git a/scripts/_common.sh b/scripts/_common.sh index e7669fb..59495c0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,10 +3,14 @@ #================================================= # COMMON VARIABLES #================================================= + MEMORY_NEEDED="2560" + # dependencies used by the app -pkg_dependencies=" build-essential python ffmpeg redis-server redis-tools postgresql postgresql-contrib" +pkg_dependencies="build-essential python ffmpeg redis-server redis-tools postgresql postgresql-contrib" + NODEJS_VERSION="12" + #================================================= # PERSONAL HELPERS #================================================= @@ -18,3 +22,95 @@ NODEJS_VERSION="12" #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +# Add swap +# +# usage: ynh_add_swap --size=SWAP in Mb +# | arg: -s, --size= - Amount of SWAP to add in Mb. +ynh_add_swap () { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [s]=size= ) + local size + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local swap_max_size=$(( $size * 1024 )) + + local free_space=$(df --output=avail / | sed 1d) + # Because we don't want to fill the disk with a swap file, divide by 2 the available space. + local usable_space=$(( $free_space / 2 )) + + SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} + + # Swap on SD card only if it's is specified + if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] + then + ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" + return + fi + + # Compare the available space with the size of the swap. + # And set a acceptable size from the request + if [ $usable_space -ge $swap_max_size ] + then + local swap_size=$swap_max_size + elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] + then + local swap_size=$(( $swap_max_size / 2 )) + elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] + then + local swap_size=$(( $swap_max_size / 3 )) + elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] + then + local swap_size=$(( $swap_max_size / 4 )) + else + echo "Not enough space left for a swap file" >&2 + local swap_size=0 + fi + + # If there's enough space for a swap, and no existing swap here + if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] + then + # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case + if ! fallocate -l ${swap_size}K /swap_$app + then + dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} + fi + chmod 0600 /swap_$app + # Create the swap + mkswap /swap_$app + # And activate it + swapon /swap_$app + # Then add an entry in fstab to load this swap at each boot. + echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab + fi +} + +ynh_del_swap () { + # If there a swap at this place + if [ -e /swap_$app ] + then + # Clean the fstab + sed -i "/#Swap added by $app/d" /etc/fstab + # Desactive the swap file + swapoff /swap_$app + # And remove it + rm /swap_$app + fi +} + +# Check if the device of the main mountpoint "/" is an SD card +# +# [internal] +# +# return 0 if it's an SD card, else 1 +ynh_is_main_device_a_sd_card () { + local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) + + if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] + then + return 0 + else + return 1 + fi +} diff --git a/scripts/backup b/scripts/backup index 38ccd53..a64c9b1 100755 --- a/scripts/backup +++ b/scripts/backup @@ -37,11 +37,6 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= ynh_print_info --message="Declaring files to be backed up..." -### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs -### to be backuped and not an actual copy of any file. The actual backup that -### creates and fill the archive with the files happens in the core after this -### script is called. Hence ynh_backups calls takes basically 0 seconds to run. - #================================================= # BACKUP THE APP MAIN DIR #================================================= @@ -54,17 +49,12 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= - #================================================= # BACKUP SYSTEMD #================================================= ynh_backup --src_path="/etc/systemd/system/$app.service" - #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index fe2b785..78fa0ed 100755 --- a/scripts/install +++ b/scripts/install @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source ynh_add_swap #================================================= # MANAGE SCRIPT FAILURE @@ -29,14 +28,13 @@ domain=$YNH_APP_ARG_DOMAIN path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC - app=$YNH_APP_INSTANCE_NAME +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= +ynh_script_progression --message="Validating installation parameters..." --weight=1 -ynh_script_progression --message="Validating installation parameters..." - -### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". -### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -46,157 +44,94 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=is_public --value=$is_public - #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." - - +ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port port=$(ynh_find_port --port=3020) ynh_app_setting_set --app=$app --key=port --value=$port - #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." --weight=3 ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_use_nodejs -ynh_install_app_dependencies $pkg_dependencies + +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a POSTGRESQL database..." +ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 # Create postgresql database -db_name="${app}" -db_user=$app -db_pwd=$(ynh_string_random --length=8) +db_name=$(ynh_sanitize_dbid --db_name=$app) ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;" - -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= -ynh_script_progression --message="Setting up source files..." - - -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" - -git clone -b master git://github.com/syuilo/misskey.git "$final_path" - -#================================================= -# SPECIFIC SETUP -#================================================= -# ADD SWAP IF NEEDED -#================================================= -ynh_script_progression --message="Adding swap is needed..." - -total_memory=$(ynh_get_ram --total) -swap_needed=0 - -if [ $total_memory -lt $MEMORY_NEEDED ]; then - # Need a minimum of 2.5Go of memory - swap_needed=$(($MEMORY_NEEDED - $total_memory)) -fi - -ynh_script_progression --message="Adding $swap_needed Mo to swap..." -ynh_add_swap --size=$swap_needed - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring nginx web server..." - -### `ynh_add_nginx_config` will use the file conf/nginx.conf - -# Create a dedicated nginx config -ynh_add_nginx_config 'port' +ynh_psql_setup_db --db_user=$db_name --db_name=$db_name #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." +ynh_script_progression --message="Configuring system user..." --weight=2 # Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - +ynh_system_user_create --username=$app #================================================= -# SPECIFIC SETUP +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -# ... +ynh_script_progression --message="Setting up source files..." --weight=3 + +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$final_path" + #================================================= +# NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring NGINX web server..." --weight=3 + +# Create a dedicated nginx config +ynh_add_nginx_config #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config - -# Set right permissions for curl install -chown -R $app: $final_path - - -# Remove the public access -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete --app=$app --key=skipped_uris -fi - -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) - -config="$final_path/.config/default.yml" -cp -f ../conf/default.yml "$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" - - -#================================================= -# INSTALLING MISKKEY -#================================================= -pushd "$final_path" - ynh_use_nodejs - yarn add ts-node webpack - ynh_node_load_PATH=production yarn build - yarn run init -popd - #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -ynh_store_file_checksum --file="$config" +ynh_add_config --template="../conf/default.yml" --destination="$final_path/.config/default.yml" + +#================================================= +# INSTALLING MISKKEY +#================================================= +ynh_script_progression --message="Installing Misskey..." --weight=15 + +pushd "$final_path" + ynh_exec_warn_less yarn add ts-node webpack + ynh_exec_warn_less NODE_ENV=production yarn build + ynh_exec_warn_less yarn run init +popd #================================================= # GENERIC FINALIZATION @@ -204,42 +139,39 @@ ynh_store_file_checksum --file="$config" # SECURE FILES AND DIRECTORIES #================================================= - +# Set permissions to app files chown -R $app: $final_path +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="A interplanetary blogging platform" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." - -ynh_add_systemd_config --service="$app" --template="systemd.service" --others_var="ynh_node_load_PATH ynh_npm" - -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add "$app" --description "$app service" --log_type "systemd" - -ynh_script_progression --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="All workers started" - +ynh_script_progression --message="Starting a systemd service..." --weight=1 +# Start a systemd service +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="All workers started" #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring permissions..." --weight=1 + # Make app public if necessary if [ $is_public -eq 1 ] then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" + ynh_permission_update --permission="main" --add="visitors" fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -247,4 +179,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" \ No newline at end of file +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 725672b..bc1e879 100755 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,6 @@ source _common.sh source /usr/share/yunohost/helpers -source ynh_add_swap #================================================= # LOAD SETTINGS @@ -32,14 +31,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # 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..." + 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..." +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 # Remove the dedicated systemd config ynh_remove_systemd_config --service="$app" @@ -47,7 +46,7 @@ ynh_remove_systemd_config --service="$app" #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." +ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" @@ -55,16 +54,17 @@ ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --time --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies + ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --time --weight=1 +ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -72,25 +72,11 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config - -# Remove swap -ynh_del_swap - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - #================================================= # SPECIFIC REMOVE #================================================= @@ -105,7 +91,7 @@ ynh_secure_remove --file="/var/log/$app/" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user ynh_system_user_delete --username=$app @@ -114,4 +100,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 8b8caef..fdd0dcc 100755 --- a/scripts/restore +++ b/scripts/restore @@ -9,7 +9,6 @@ #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 -source ../settings/scripts/ynh_add_swap #================================================= # MANAGE SCRIPT FAILURE @@ -34,37 +33,39 @@ 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=$app -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --weight=1 ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " -#================================================= # STANDARD RESTORATION STEPS #================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE USER RIGHTS @@ -73,87 +74,60 @@ ynh_system_user_create --username=$app # Restore permissions on app files chown -R $app: $final_path -#================================================= -# SPECIFIC RESTORATION -#================================================= -# ADD SWAP IF NEEDED -#================================================= -ynh_script_progression --message="Adding swap if needed..." - -total_memory=$(ynh_get_ram --total) -swap_needed=0 - -if [ $total_memory -lt $MEMORY_NEEDED ]; then - # Need a minimum of 8Go of memory - swap_needed=$(($MEMORY_NEEDED - $total_memory)) -fi - - #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;" -ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" - -#================================================= -# INSTALLING MISKKEY -#================================================= -pushd "$final_path" - ynh_use_nodejs - yarn add ts-node webpack - ynh_node_load_PATH=production yarn build -popd - +ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 + ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service +systemctl enable $app.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "$app service" --log "systemd" +yunohost service add $app --description="A interplanetary blogging platform" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="All workers started" +ynh_systemd_action --service_name=$app --action=start --log_path="systemd" --line_match="All workers started" +#================================================= +# 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 #================================================= -#=============================================== -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_script_progression --message="Reloading nginx web server..." - -ynh_systemd_action --service_name=nginx --action=reload - -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 2b6d866..81932fe 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,39 +8,31 @@ source _common.sh source /usr/share/yunohost/helpers -source ynh_add_swap #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) port=$(ynh_app_setting_get --app=$app --key=port) -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +#================================================= +# CHECK VERSION +#================================================= upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." - -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 -fi +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If db_name doesn't exist, create it if [ -z "$db_name" ]; then @@ -54,10 +46,17 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -68,17 +67,22 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors - -path_url=$(ynh_normalize_url_path --path_url=$path_url) - #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped" +ynh_systemd_action --service_name=$app --action=stop --log_path=systemd --line_match="Stopped" + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -89,20 +93,16 @@ 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" - pushd "$final_path" - git checkout master - git pull - popd + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/.config/default.yml" fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 # Create a dedicated nginx config -ynh_add_nginx_config 'port' +ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES @@ -110,75 +110,30 @@ ynh_add_nginx_config 'port' ynh_script_progression --message="Upgrading dependencies..." ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies + +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# ADD SWAP IF NEEDED -#================================================= -ynh_script_progression --message="Adding swap if needed..." - -total_memory=$(ynh_get_ram --total) -swap_needed=0 - -if [ $total_memory -lt $MEMORY_NEEDED ]; then - # Need a minimum of 8Go of memory - swap_needed=$(($MEMORY_NEEDED - $total_memory)) -fi - -ynh_script_progression --message="Adding $swap_needed Mo to swap..." -ynh_add_swap --size=$swap_needed - -#================================================= -# SPECIFIC UPGRADE -#================================================= - -config="$final_path/.config/default.yml" -cp -f ../conf/default.yml "$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$app" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" - #================================================= # Updating process MISSKEY #================================================= -pushd "$final_path" - yarn install - ynh_node_load_PATH=production yarn build - yarn migrate -popd +pushd "$final_path" + ynh_exec_warn_less yarn install + ynh_exec_warn_less NODE_ENV=production yarn build + ynh_exec_warn_less yarn migrate +popd #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 + # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# MODIFY A CONFIG FILE -#================================================= - - -ynh_backup_if_checksum_is_different --file="$config" - -# ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/.config/default.yml.backup" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$config" - #================================================= # GENERIC FINALIZATION #================================================= @@ -191,35 +146,21 @@ chown -R $app: $final_path #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -ynh_add_systemd_config --service="$app" --template="systemd.service" --others_var="ynh_node_load_PATH ynh_npm" - -yunohost service add $app --description "$app service" ---log_type "systemd" +yunohost service add $app --description="A interplanetary blogging platform" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="All workers started" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -fi +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="All workers started" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -227,4 +168,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/scripts/ynh_add_swap b/scripts/ynh_add_swap deleted file mode 100644 index 2fd2d8c..0000000 --- a/scripts/ynh_add_swap +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash - -# Add swap -# -# usage: ynh_add_swap --size=SWAP in Mb -# | arg: -s, --size= - Amount of SWAP to add in Mb. -ynh_add_swap () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=size= ) - local size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local swap_max_size=$(( $size * 1024 )) - - local free_space=$(df --output=avail / | sed 1d) - # Because we don't want to fill the disk with a swap file, divide by 2 the available space. - local usable_space=$(( $free_space / 2 )) - - SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} - - # Swap on SD card only if it's is specified - if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] - then - ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" - return - fi - - # Compare the available space with the size of the swap. - # And set a acceptable size from the request - if [ $usable_space -ge $swap_max_size ] - then - local swap_size=$swap_max_size - elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] - then - local swap_size=$(( $swap_max_size / 2 )) - elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] - then - local swap_size=$(( $swap_max_size / 3 )) - elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] - then - local swap_size=$(( $swap_max_size / 4 )) - else - echo "Not enough space left for a swap file" >&2 - local swap_size=0 - fi - - # If there's enough space for a swap, and no existing swap here - if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] - then - # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case - if ! fallocate -l ${swap_size}K /swap_$app - then - dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} - fi - chmod 0600 /swap_$app - # Create the swap - mkswap /swap_$app - # And activate it - swapon /swap_$app - # Then add an entry in fstab to load this swap at each boot. - echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab - fi -} - -ynh_del_swap () { - # If there a swap at this place - if [ -e /swap_$app ] - then - # Clean the fstab - sed -i "/#Swap added by $app/d" /etc/fstab - # Desactive the swap file - swapoff /swap_$app - # And remove it - rm /swap_$app - fi -} - -# Check if the device of the main mountpoint "/" is an SD card -# -# [internal] -# -# return 0 if it's an SD card, else 1 -ynh_is_main_device_a_sd_card () { - local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) - - if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] - then - return 0 - else - return 1 - fi -} \ No newline at end of file