From 6d3347948a51e81cf8f5cb5706e2efea29220a12 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 21:13:30 +0100 Subject: [PATCH 01/12] Adding ynh_systemd_action helper --- README.md | 2 +- conf/app.src | 4 +- manifest.json | 2 +- scripts/backup | 12 ++++- scripts/change_url | 31 ++++++++++--- scripts/detect_arch | 12 +++++ scripts/install | 27 ++++++++---- scripts/remove | 17 ++++++++ scripts/restore | 21 ++++++++- scripts/upgrade | 27 ++++++++++-- scripts/ynh_systemd_action | 89 ++++++++++++++++++++++++++++++++++++++ 11 files changed, 220 insertions(+), 24 deletions(-) create mode 100644 scripts/detect_arch create mode 100644 scripts/ynh_systemd_action diff --git a/README.md b/README.md index 41f3d59..fadd65a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Can be run as Single User Blog or Multi User Instance. Each User can be limited from 1 to unlimited blogs. -**Shipped version:** v0.8.0 +**Shipped version:** v0.8.1 ## Licence diff --git a/conf/app.src b/conf/app.src index 5f55950..8c1512a 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/writeas/writefreely/releases/download/v0.8.0/writefreely_0.8.0_linux_amd64.tar.gz -SOURCE_SUM=ed1020692bdb96e3d3fc52605d089f26153edfb5dc2822b4da03fcc351c1e841 +SOURCE_URL=https://github.com/writeas/writefreely/releases/download/v0.8.1/writefreely_0.8.1_linux_amd64.tar.gz +SOURCE_SUM=97fe8d2098f86eaa4a294e1d5845dafe7079e5502070ba3929f78abfbf9be371 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=false diff --git a/manifest.json b/manifest.json index 872da58..67083ed 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Write Freely is free and open source software for starting a minimalist, federated blog — or an entire community.", "fr": "Write Freely est un logiciel gratuit et à code source ouvert permettant de créer un blog fédéré minimaliste ou une communauté entière." }, - "version": "0.8.0~ynh2", + "version": "0.8.1~ynh1", "url": "https://writefreely.org", "license": "free", "maintainer": { diff --git a/scripts/backup b/scripts/backup index fc5c764..5db9479 100755 --- a/scripts/backup +++ b/scripts/backup @@ -7,15 +7,25 @@ #================================================= source ../settings/scripts/_common.sh +source ../settings/scripts/detect_arch source /usr/share/yunohost/helpers +#================================================= +# MANAGE APPLICATION NOT COMPATIBLE WITH ARM +#================================================= + +if [ $architecture = "arm" ] +then + ynh_die "WriteFreely not available on Arm" +fi + #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors diff --git a/scripts/change_url b/scripts/change_url index 7f71444..ff6fa1b 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -6,9 +6,19 @@ # IMPORT GENERIC HELPERS #================================================= +source detect_arch source _common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE APPLICATION NOT COMPATIBLE WITH ARM +#================================================= + +if [ $architecture = "arm" ] +then + ynh_die "WriteFreely not available on Arm" +fi + #================================================= # RETRIEVE ARGUMENTS #================================================= @@ -90,18 +100,27 @@ fi #================================================= # SPECIFIC MODIFICATIONS #================================================= -# ... +# STOP SERVICE #================================================= -# Stop writefreely for modification -yunohost service stop "$app" +ynh_systemd_action --action=stop --service_name=$app + +#================================================= +# MODIFY A CONFIG FILE +#================================================= ynh_replace_string "host =.*" "host =https://$new_domain$new_path" "$final_path/config.ini" -# Start writefreely after modification -yunohost service start $app +#================================================= +# START SERVICE +#================================================= -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. +ynh_systemd_action --action=start --service_name=$app + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= +fy the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ynh_backup_if_checksum_is_different "$final_path/config.ini" # Recalculate and store the checksum of the file for the next upgrade. diff --git a/scripts/detect_arch b/scripts/detect_arch new file mode 100644 index 0000000..4e258d9 --- /dev/null +++ b/scripts/detect_arch @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -n "$(uname -m | grep 64)" ]; then + architecture="x86-64" +elif [ -n "$(uname -m | grep 86)" ]; then + architecture="i386" +elif [ -n "$(uname -m | grep arm)" ]; then + architecture="arm" +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 diff --git a/scripts/install b/scripts/install index bca64e6..4686697 100755 --- a/scripts/install +++ b/scripts/install @@ -7,25 +7,30 @@ #================================================= source _common.sh +source detect_arch +source ynh_systemd_action source /usr/share/yunohost/helpers +#================================================= +# MANAGE APPLICATION NOT COMPATIBLE WITH ARM +#================================================= + +if [ $architecture = "arm" ] +then + ynh_die "WriteFreely not available on Arm" +fi + #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors -arch=$(uname -m) -if [[ $arch == arm* ]] -then - ynh_die "WriteFreely not available on Arm" -fi - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= @@ -362,4 +367,10 @@ systemctl reload nginx # START SERVICE #================================================= -yunohost service start $app +ynh_systemd_action --action=start --service_name=$app + +#================================================= +# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting +#================================================= + +ynh_clean_check_starting diff --git a/scripts/remove b/scripts/remove index 79cb21c..df1d506 100755 --- a/scripts/remove +++ b/scripts/remove @@ -6,9 +6,20 @@ # IMPORT GENERIC HELPERS #================================================= +source detect_arch source _common.sh +source ynh_systemd_action source /usr/share/yunohost/helpers +#================================================= +# MANAGE APPLICATION NOT COMPATIBLE WITH ARM +#================================================= + +if [ $architecture = "arm" ] +then + ynh_die "WriteFreely not available on Arm" +fi + #================================================= # LOAD SETTINGS #================================================= @@ -116,3 +127,9 @@ ynh_secure_remove "/var/log/$app/" # Delete a system user ynh_system_user_delete $app + +#================================================= +# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting +#================================================= + +ynh_clean_check_starting diff --git a/scripts/restore b/scripts/restore index a427469..9eacdc0 100755 --- a/scripts/restore +++ b/scripts/restore @@ -7,15 +7,26 @@ #================================================= source ../settings/scripts/_common.sh +source ../settings/scripts/detect_arch +source ../settings/scripts/ynh_systemd_action source /usr/share/yunohost/helpers +#================================================= +# MANAGE APPLICATION NOT COMPATIBLE WITH ARM +#================================================= + +if [ $architecture = "arm" ] +then + ynh_die "WriteFreely not available on Arm" +fi + #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { #### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -129,4 +140,10 @@ systemctl reload nginx # START SERVICE #================================================= -yunohost service start $app +ynh_systemd_action --action=start --service_name=$app + +#================================================= +# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting +#================================================= + +ynh_clean_check_starting diff --git a/scripts/upgrade b/scripts/upgrade index ebdca4f..4158fff 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,8 +7,19 @@ #================================================= source _common.sh +source detect_arch +source ynh_systemd_action source /usr/share/yunohost/helpers +#================================================= +# MANAGE APPLICATION NOT COMPATIBLE WITH ARM +#================================================= + +if [ $architecture = "arm" ] +then + ynh_die "WriteFreely not available on Arm" +fi + #================================================= # LOAD SETTINGS #================================================= @@ -58,12 +69,16 @@ ynh_backup_before_upgrade ynh_clean_setup () { # restore it if the upgrade fails ynh_restore_upgradebackup + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Stop writefreely for upgrade -yunohost service stop "$app" +#================================================= +# STOP SERVICE +#================================================= + +ynh_systemd_action --action=stop --service_name=$app #================================================= # CHECK THE PATH @@ -178,4 +193,10 @@ systemctl reload nginx # START SERVICE #================================================= -yunohost service start $app +ynh_systemd_action --action=start --service_name=$app + +#================================================= +# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting +#================================================= + +ynh_clean_check_starting diff --git a/scripts/ynh_systemd_action b/scripts/ynh_systemd_action new file mode 100644 index 0000000..6bed6be --- /dev/null +++ b/scripts/ynh_systemd_action @@ -0,0 +1,89 @@ +#!/bin/bash + +# Start (or other actions) a service, print a log in case of failure and optionnaly wait until the service is completely started +# +# usage: ynh_systemd_action [-n service_name] [-a action] [ [-l "line to match"] [-p log_path] [-t timeout] [-e length] ] +# | arg: -n, --service_name= - Name of the service to reload. Default : $app +# | arg: -a, --action= - Action to perform with systemctl. Default: start +# | arg: -l, --line_match= - Line to match - The line to find in the log to attest the service have finished to boot. +# If not defined it don't wait until the service is completely started. +# | arg: -p, --log_path= - Log file - Path to the log file. Default : /var/log/$app/$app.log +# | arg: -t, --timeout= - Timeout - The maximum time to wait before ending the watching. Default : 300 seconds. +# | arg: -e, --length= - Length of the error log : Default : 20 +ynh_systemd_action() { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [n]=service_name= [a]=action= [l]=line_match= [p]=log_path= [t]=timeout= [e]=length= ) + local service_name + local action + local line_match + local length + local log_path + local timeout + + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + local service_name="${service_name:-$app}" + local action=${action:-start} + local log_path="${log_path:-/var/log/$service_name/$service_name.log}" + local length=${length:-20} + local timeout=${timeout:-300} + + # Start to read the log + if [[ -n "${line_match:-}" ]] + then + local templog="$(mktemp)" + # Following the starting of the app in its log + if [ "$log_path" == "systemd" ] ; then + # Read the systemd journal + journalctl -u $service_name -f --since=-45 > "$templog" & + else + # Read the specified log file + tail -F -n0 "$log_path" > "$templog" & + fi + # Get the PID of the tail command + local pid_tail=$! + fi + + echo "${action^} the service $service_name" >&2 + systemctl $action $service_name \ + || ( journalctl --lines=$length -u $service_name >&2 \ + ; test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 \ + ; false ) + + # Start the timeout and try to find line_match + if [[ -n "${line_match:-}" ]] + then + local i=0 + for i in $(seq 1 $timeout) + do + # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout + if grep --quiet "$line_match" "$templog" + then + echo "The service $service_name has correctly started." >&2 + break + fi + echo -n "." >&2 + sleep 1 + done + if [ $i -eq $timeout ] + then + echo "The service $service_name didn't fully started before the timeout." >&2 + journalctl --lines=$length -u $service_name >&2 + test -n "$log_path" && echo "--" && tail --lines=$length "$log_path" >&2 + fi + + echo "" + ynh_clean_check_starting + fi +} + +# Clean temporary process and file used by ynh_check_starting +# (usually used in ynh_clean_setup scripts) +# +# usage: ynh_clean_check_starting +ynh_clean_check_starting () { + # Stop the execution of tail. + kill -s 15 $pid_tail 2>&1 + ynh_secure_remove "$templog" 2>&1 +} From ec389fe702dfbcd0740ce6971bf2c69e5075acde Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 21:31:53 +0100 Subject: [PATCH 02/12] Fix ynh_clean_check_starting --- scripts/install | 6 ------ scripts/remove | 6 ------ scripts/restore | 6 ------ scripts/upgrade | 6 ------ 4 files changed, 24 deletions(-) diff --git a/scripts/install b/scripts/install index 4686697..cf25ee1 100755 --- a/scripts/install +++ b/scripts/install @@ -368,9 +368,3 @@ systemctl reload nginx #================================================= ynh_systemd_action --action=start --service_name=$app - -#================================================= -# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting -#================================================= - -ynh_clean_check_starting diff --git a/scripts/remove b/scripts/remove index df1d506..c7fe936 100755 --- a/scripts/remove +++ b/scripts/remove @@ -127,9 +127,3 @@ ynh_secure_remove "/var/log/$app/" # Delete a system user ynh_system_user_delete $app - -#================================================= -# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting -#================================================= - -ynh_clean_check_starting diff --git a/scripts/restore b/scripts/restore index 9eacdc0..33fa19a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -141,9 +141,3 @@ systemctl reload nginx #================================================= ynh_systemd_action --action=start --service_name=$app - -#================================================= -# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting -#================================================= - -ynh_clean_check_starting diff --git a/scripts/upgrade b/scripts/upgrade index 4158fff..ab6de99 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -194,9 +194,3 @@ systemctl reload nginx #================================================= ynh_systemd_action --action=start --service_name=$app - -#================================================= -# CLEAN TEMPORARY PROCESS AND FILE USED BY ynh_check_starting -#================================================= - -ynh_clean_check_starting From 636181fca399041c0421dfcb1ccd333b06d2ab5b Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 21:51:51 +0100 Subject: [PATCH 03/12] Add ynh_systemd_action for backup --- conf/nginx.conf | 3 --- scripts/backup | 1 + scripts/install | 4 ---- scripts/upgrade | 2 -- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 4899948..19cfa5b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,5 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; - location ~ ^/.well-known/(webfinger|nodeinfo|host-meta) { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -15,8 +14,6 @@ location ~ ^/(css|img|js|fonts)/ { # expires 12M; } - - location __PATH__/ { proxy_pass http://localhost:__PORT__/; diff --git a/scripts/backup b/scripts/backup index 5db9479..e35094e 100755 --- a/scripts/backup +++ b/scripts/backup @@ -8,6 +8,7 @@ source ../settings/scripts/_common.sh source ../settings/scripts/detect_arch +source ../settings/scripts/ynh_systemd_action source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/install b/scripts/install index cf25ee1..c40b5d9 100755 --- a/scripts/install +++ b/scripts/install @@ -58,7 +58,6 @@ then admin="test" fi - ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID ### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) @@ -251,7 +250,6 @@ ynh_add_systemd_config # ynh_app_setting_delete $app skipped_uris #fi - #================================================= # MODIFY A CONFIG FILE #================================================= @@ -298,7 +296,6 @@ ynh_store_file_checksum "$final_path/config.ini" ( cd $final_path && $final_path/writefreely --gen-keys ) ( cd $final_path && $final_path/writefreely --create-admin $admin:$password ) - #================================================= # GENERIC FINALIZATION #================================================= @@ -345,7 +342,6 @@ chown -R $app: /var/log/$app/ # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added yunohost service add $app --description "$app daemon for WriteFreely" --log "/var/log/$app/$app.log" - #================================================= # SETUP SSOWAT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index ab6de99..87319e5 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -137,7 +137,6 @@ ynh_backup_if_checksum_is_different "$final_path/config.ini" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "$final_path/config.ini" - #================================================= # CLOSE A PORT #================================================= @@ -148,7 +147,6 @@ then yunohost firewall disallow TCP $port 2>&1 fi - #================================================= # SETUP LOGROTATE #================================================= From cfbdd934ca0e9330e0f34e9af29a18c551081381 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 22:18:23 +0100 Subject: [PATCH 04/12] Add ynh_check_app_version_changed Helper --- scripts/upgrade | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 87319e5..00d5bda 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,6 +9,7 @@ source _common.sh source detect_arch source ynh_systemd_action +source ynh_check_app_version_changed source /usr/share/yunohost/helpers #================================================= @@ -35,6 +36,12 @@ final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get $app db_name) port=$(ynh_app_setting_get $app port) +#================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -93,8 +100,11 @@ path_url=$(ynh_normalize_url_path $path_url) # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +if [ "$upgrade_type" == "UPGRADE_APP" ] +then # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" +fi #================================================= # NGINX CONFIGURATION From 97bb5e9c711760ec85fa94eb0e85ed538defc463 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 22:18:48 +0100 Subject: [PATCH 05/12] add ynh_check_app_version_changed file --- scripts/ynh_check_app_version_changed | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/ynh_check_app_version_changed diff --git a/scripts/ynh_check_app_version_changed b/scripts/ynh_check_app_version_changed new file mode 100644 index 0000000..641815c --- /dev/null +++ b/scripts/ynh_check_app_version_changed @@ -0,0 +1,46 @@ +#!/bin/bash + +# Checks the app version to upgrade with the existing app version and returns: +# - UPGRADE_APP if the upstream app version has changed +# - UPGRADE_PACKAGE if only the YunoHost package has changed +# +## It stops the current script without error if the package is up-to-date +# +# This helper should be used to avoid an upgrade of an app, or the upstream part +# of it, when it's not needed +# +# To force an upgrade, even if the package is up to date, +# you have to set the variable YNH_FORCE_UPGRADE before. +# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp + +# usage: ynh_check_app_version_changed +ynh_check_app_version_changed () { + local force_upgrade=${YNH_FORCE_UPGRADE:-0} + local package_check=${PACKAGE_CHECK_EXEC:-0} + + # By default, upstream app version has changed + local return_value="UPGRADE_APP" + + local current_version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0) + local current_upstream_version="${current_version/~ynh*/}" + local update_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0) + local update_upstream_version="${update_version/~ynh*/}" + + if [ "$current_version" == "$update_version" ] ; then + # Complete versions are the same + if [ "$force_upgrade" != "0" ] + then + echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2 + unset YNH_FORCE_UPGRADE + elif [ "$package_check" != "0" ] + then + echo "Upgrade forced for package check." >&2 + else + ynh_die "Up-to-date, nothing to do" 0 + fi + elif [ "$current_upstream_version" == "$update_upstream_version" ] ; then + # Upstream versions are the same, only YunoHost package versions differ + return_value="UPGRADE_PACKAGE" + fi + echo $return_value +} From 3ff2047a4b3e77a6a5c5bcc2ddb33af515bb36d2 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 23:40:03 +0100 Subject: [PATCH 06/12] Fix Log output --- conf/systemd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/systemd.service b/conf/systemd.service index e480739..b2cdfdf 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/writefreely >> /var/log/__APP__/__APP__.log 2>&1 +ExecStart=/bin/sh -c '__FINALPATH__/writefreely >> /var/log/__APP__/__APP__.log 2>&1' [Install] WantedBy=multi-user.target From 3ccc5600257788c7c4fcba648ccc9eee1e927a24 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 1 Feb 2019 23:58:45 +0100 Subject: [PATCH 07/12] Create log folder --- scripts/install | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c40b5d9..b81cf59 100755 --- a/scripts/install +++ b/scripts/install @@ -292,6 +292,9 @@ ynh_store_file_checksum "$final_path/config.ini" # ... #================================================= +mkdir -p "/var/log/$app" +chown -R "$app":"$app" "/var/log/$app" + ( cd $final_path && $final_path/writefreely --init-db ) ( cd $final_path && $final_path/writefreely --gen-keys ) ( cd $final_path && $final_path/writefreely --create-admin $admin:$password ) @@ -323,7 +326,6 @@ chown -R "$app":"$app" "$final_path" # Use logrotate to manage application logfile(s) ynh_use_logrotate -chown -R $app: /var/log/$app/ #================================================= # ADVERTISE SERVICE IN ADMIN PANEL From ac30311f2710063bd018a8c643d5d629b33f114c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 2 Feb 2019 00:16:11 +0100 Subject: [PATCH 08/12] Fix log folder --- scripts/install | 6 +++++- scripts/restore | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index b81cf59..e010efb 100755 --- a/scripts/install +++ b/scripts/install @@ -289,12 +289,16 @@ ynh_store_file_checksum "$final_path/config.ini" #================================================= # SPECIFIC SETUP #================================================= -# ... +# CREATE LOG FOLDER #================================================= mkdir -p "/var/log/$app" chown -R "$app":"$app" "/var/log/$app" +#================================================= +# MAKE SETUP +#================================================= + ( cd $final_path && $final_path/writefreely --init-db ) ( cd $final_path && $final_path/writefreely --gen-keys ) ( cd $final_path && $final_path/writefreely --create-admin $admin:$password ) diff --git a/scripts/restore b/scripts/restore index 33fa19a..d9c3c46 100755 --- a/scripts/restore +++ b/scripts/restore @@ -136,6 +136,13 @@ ynh_restore_file "/etc/logrotate.d/$app" #systemctl reload php5-fpm systemctl reload nginx +#================================================= +# CREATE LOG FOLDER +#================================================= + +mkdir -p "/var/log/$app" +chown -R "$app":"$app" "/var/log/$app" + #================================================= # START SERVICE #================================================= From 1b33686467d2defc86182af88ce346e32dd7e49f Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 2 Feb 2019 00:32:44 +0100 Subject: [PATCH 09/12] Add daemon reload --- scripts/restore | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/restore b/scripts/restore index d9c3c46..06a1fb5 100755 --- a/scripts/restore +++ b/scripts/restore @@ -108,6 +108,7 @@ chown -R "$app":"$app" "$final_path" ynh_restore_file "/etc/systemd/system/$app.service" systemctl enable $app.service +systemctl daemon-reload #================================================= # ADVERTISE SERVICE IN ADMIN PANEL From f8b3b9aeb4772ba6d6326d114eb028580c24b439 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 2 Feb 2019 03:03:14 +0100 Subject: [PATCH 10/12] removing not need db_user --- scripts/remove | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/remove b/scripts/remove index c7fe936..e2cca67 100755 --- a/scripts/remove +++ b/scripts/remove @@ -29,7 +29,6 @@ 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=$db_name final_path=$(ynh_app_setting_get $app final_path) #================================================= @@ -64,7 +63,7 @@ ynh_remove_systemd_config #================================================= # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name +ynh_mysql_remove_db $db_name $db_name #================================================= # REMOVE APP MAIN DIR From 097c138c719be3eb6ae08ea3eb415717c24e3701 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 2 Feb 2019 03:03:50 +0100 Subject: [PATCH 11/12] adding pushd / popd --- conf/config.ini | 2 +- scripts/install | 14 ++++++++------ scripts/upgrade | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index cf164d0..feccda9 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -17,7 +17,7 @@ port = 3306 [app] site_name = __SITENAME__ site_description = __SITEDESCRIPTION__ -host = https://your-writefreely-url-instance.com +host = __DOMAIN_URL__ theme = write disable_js = false webfonts = true diff --git a/scripts/install b/scripts/install index e010efb..912cab0 100755 --- a/scripts/install +++ b/scripts/install @@ -76,7 +76,7 @@ app=$YNH_APP_INSTANCE_NAME ### 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 +final_path="/var/www/$app" test ! -e "$final_path" || ynh_die "This path already contains a folder" # Normalize the url path syntax @@ -258,13 +258,13 @@ ynh_add_systemd_config ### (It's compatible with sed regular expressions syntax) # setup application config -sudo cp ../conf/config.ini $final_path/config.ini +sudo cp "../conf/config.ini" "$final_path/config.ini" ynh_replace_string "__DBNAME__" "$db_name" "$final_path/config.ini" ynh_replace_string "__DBUSER__" "$db_name" "$final_path/config.ini" ynh_replace_string "__DBPWD__" "$db_pwd" "$final_path/config.ini" ynh_replace_string "__PORT__" "$port" "$final_path/config.ini" -ynh_replace_string "https://your-writefreely-url-instance.com" "https://$domain$path_url" "$final_path/config.ini" +ynh_replace_string "__DOMAIN_URL__" "https://$domain$path_url" "$final_path/config.ini" ynh_replace_string "__SINGLEUSER__" "$single_user" "$final_path/config.ini" ynh_replace_string "__SITENAME__" "$site_name" "$final_path/config.ini" ynh_replace_string "__SITEDESCRIPTION__" "$site_description" "$final_path/config.ini" @@ -299,9 +299,11 @@ chown -R "$app":"$app" "/var/log/$app" # MAKE SETUP #================================================= -( cd $final_path && $final_path/writefreely --init-db ) -( cd $final_path && $final_path/writefreely --gen-keys ) -( cd $final_path && $final_path/writefreely --create-admin $admin:$password ) +pushd $final_path + sudo -u $app ./writefreely --init-db + sudo -u $app ./writefreely --gen-keys + sudo -u $app ./writefreely --create-admin "$admin":"$password" +popd #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 00d5bda..437464b 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -139,7 +139,9 @@ ynh_system_user_create "$app" "$final_path" # MAKE UPGRADE #================================================= -( cd $final_path && $final_path/writefreely --migrate ) +pushd $final_path + sudo -u $app ./writefreely --migrate +popd ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. From 3b4603a338e2914d584a4ac1f3cd6f02d3056a81 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 2 Feb 2019 03:40:38 +0100 Subject: [PATCH 12/12] Fix path owner --- scripts/install | 2 ++ scripts/upgrade | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scripts/install b/scripts/install index 912cab0..6318705 100755 --- a/scripts/install +++ b/scripts/install @@ -299,6 +299,8 @@ chown -R "$app":"$app" "/var/log/$app" # MAKE SETUP #================================================= +chown -R "$app":"$app" "$final_path" + pushd $final_path sudo -u $app ./writefreely --init-db sudo -u $app ./writefreely --gen-keys diff --git a/scripts/upgrade b/scripts/upgrade index 437464b..c248a83 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -139,6 +139,8 @@ ynh_system_user_create "$app" "$final_path" # MAKE UPGRADE #================================================= +chown -R "$app":"$app" "$final_path" + pushd $final_path sudo -u $app ./writefreely --migrate popd