This app has been put under maintenance by your administrator at $(date)
-Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.
- - -" > "/var/www/html/maintenance.$app.html" - - # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. - echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice -rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect; -# Use another location, to not be in conflict with the original config file -location ${path_url}_maintenance/ { -alias /var/www/html/ ; - -try_files maintenance.$app.html =503; - -# Include SSOWAT user panel. -include conf.d/yunohost_panel.conf.inc; -}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - - # The current config file will redirect all requests to the root of the app. - # To keep the full path, we can use the following rewrite rule: - # rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect; - # The difference will be in the $1 at the end, which keep the following queries. - # But, if it works perfectly for a html request, there's an issue with any php files. - # This files are treated as simple files, and will be downloaded by the browser. - # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. - - systemctl reload nginx -} - -ynh_maintenance_mode_OFF () { - # Load value of $path_url and $domain from the config if their not set - if [ -z $path_url ]; then - path_url=$(ynh_app_setting_get $app path) - fi - if [ -z $domain ]; then - domain=$(ynh_app_setting_get $app domain) - fi - - # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. - echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - systemctl reload nginx - - # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. - sleep 4 - - # Then remove the temporary files used for the maintenance. - rm "/var/www/html/maintenance.$app.html" - rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - - systemctl reload nginx -} - -#================================================= - -# Download and check integrity of a file from app.src_file +# Create a changelog for an app after an upgrade from the file CHANGELOG.md. # -# The file conf/app.src_file need to contains: +# usage: ynh_app_changelog [--format=markdown/html/plain] [--output=changelog_file] --changelog=changelog_source] +# | arg: -f --format= - Format in which the changelog will be printed +# markdown: Default format. +# html: Turn urls into html format. +# plain: Plain text changelog +# | arg: -o --output= - Output file for the changelog file (Default ./changelog) +# | arg: -c --changelog= - CHANGELOG.md source (Default ../CHANGELOG.md) # -# FILE_URL=Address to download the file -# FILE_SUM=Control sum -# # (Optional) Program to check the integrity (sha256sum, md5sum...) -# # default: sha256 -# FILE_SUM_PRG=sha256 -# # (Optionnal) Name of the local archive (offline setup support) -# # default: Name of the downloaded file. -# FILENAME=example.deb -# -# usage: ynh_download_file --dest_dir="/destination/directory" [--source_id=myfile] -# | arg: -d, --dest_dir= - Directory where to download the file -# | arg: -s, --source_id= - Name of the source file 'app.src_file' if it isn't '$app' -ynh_download_file () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [d]=dest_dir= [s]=source_id= ) - local dest_dir - local source_id - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - source_id=${source_id:-app} # If the argument is not given, source_id equals "$app" - - # Load value from configuration file (see above for a small doc about this file - # format) - local src_file="$YNH_CWD/../conf/${source_id}.src_file" - # If the src_file doesn't exist, use the backup path instead, with a "settings" directory - if [ ! -e "$src_file" ] - then - src_file="$YNH_CWD/../settings/conf/${source_id}.src_file" - fi - local file_url=$(grep 'FILE_URL=' "$src_file" | cut -d= -f2-) - local file_sum=$(grep 'FILE_SUM=' "$src_file" | cut -d= -f2-) - local file_sumprg=$(grep 'FILE_SUM_PRG=' "$src_file" | cut -d= -f2-) - local filename=$(grep 'FILENAME=' "$src_file" | cut -d= -f2-) - - # Default value - file_sumprg=${file_sumprg:-sha256sum} - if [ "$filename" = "" ] ; then - filename="$(basename "$file_url")" - fi - local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${filename}" - - if test -e "$local_src" - then # Use the local source file if it is present - cp $local_src $filename - else # If not, download the source - local out=`wget -nv -O $filename $file_url 2>&1` || ynh_print_err $out - fi - - # Check the control sum - echo "${file_sum} ${filename}" | ${file_sumprg} -c --status \ - || ynh_die "Corrupt file" - - # Create the destination directory, if it's not already. - mkdir -p "$dest_dir" - - # Move the file to its destination - mv $filename $dest_dir -} - -#================================================= - -# Create a changelog for an app after an upgrade. -# -# The changelog is printed into the file ./changelog for the time of the upgrade. -# -# In order to create a changelog, ynh_app_changelog will get info from /etc/yunohost/apps/$app/status.json -# In order to find the current commit use by the app. -# The remote repository, and the branch. -# The changelog will be only the commits since the current revision. -# -# Because of the need of those info, ynh_app_changelog works only -# with apps that have been installed from a list. -# -# usage: ynh_app_changelog +# The changelog is printed into the file ./changelog and ./changelog_lite ynh_app_changelog () { - get_value_from_settings () - { - local value="$1" - # Extract a value from the status.json file of an installed app. + # Declare an array to define the options of this helper. + local legacy_args=foc + declare -Ar args_array=( [f]=format= [o]=output= [c]=changelog= ) + local format + local output + local changelog + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + format=${format:-markdown} + output=${output:-changelog} + changelog=${changelog:-../CHANGELOG.md} - grep "$value\": \"" /etc/yunohost/apps/$app/status.json | sed "s/.*$value\": \"\([^\"]*\).*/\1/" - } + local original_changelog="$changelog" + local temp_changelog="changelog_temp" + local final_changelog="$output" - local current_revision="$(get_value_from_settings revision)" - local repo="$(get_value_from_settings url)" - local branch="$(get_value_from_settings branch)" - # ynh_app_changelog works only with an app installed from a list. - if [ -z "$current_revision" ] || [ -z "$repo" ] || [ -z "$branch" ] - then - ynh_print_warn "Unable to build the changelog..." - touch changelog - return 0 - fi + if [ ! -n "$original_changelog" ] + then + echo "No changelog available..." > "$final_changelog" + echo "No changelog available..." > "${final_changelog}_lite" + return 0 + fi - # Fetch the history of the repository, without cloning it - mkdir git_history - (cd git_history - ynh_exec_warn_less git init - ynh_exec_warn_less git remote add -f origin $repo - # Get the line of the current commit of the installed app in the history. - local line_to_head=$(git log origin/$branch --pretty=oneline | grep --line-number "$current_revision" | cut -d':' -f1) - # Cut the history before the current commit, to keep only newer commits. - # Then use sed to reorganise each lines and have a nice list of commits since the last upgrade. - # This list is redirected into the file changelog - git log origin/$branch --pretty=oneline | head --lines=$(($line_to_head-1)) | sed 's/^\([[:alnum:]]*\)\(.*\)/*(\1) -> \2/g' > ../changelog) - # Remove 'Merge pull request' commits - sed -i '/Merge pull request #[[:digit:]]* from/d' changelog - # As well as conflict resolving commits - sed -i '/Merge branch .* into/d' changelog + local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version") + local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version") - # Get the value of admin_mail_html - admin_mail_html=$(ynh_app_setting_get $app admin_mail_html) - admin_mail_html="${admin_mail_html:-0}" + # Get the line of the version to update to into the changelog + local update_version_line=$(grep --max-count=1 --line-number "^## \[$update_version" "$original_changelog" | cut -d':' -f1) + # If there's no entry for this version yet into the changelog + # Get the first available version + if [ -z "$update_version_line" ] + then + update_version_line=$(grep --max-count=1 --line-number "^##" "$original_changelog" | cut -d':' -f1) + fi - # If a html email is required. Apply html to the changelog. - if [ "$admin_mail_html" -eq 1 ] - then - sed -in-place "s@\*(\([[:alnum:]]*\)) -> \(.*\)@* __URL_TAG1__\2__URL_TAG2__${repo}/commit/\1__URL_TAG3__@g" changelog - fi + # Get the length of the complete changelog. + local changelog_length=$(wc --lines "$original_changelog" | awk '{print $1}') + # Cut the file before the version to update to. + tail --lines=$(( $changelog_length - $update_version_line + 1 )) "$original_changelog" > "$temp_changelog" + + # Get the length of the troncated changelog. + changelog_length=$(wc --lines "$temp_changelog" | awk '{print $1}') + # Get the line of the current version into the changelog + # Keep only the last line found + local current_version_line=$(grep --line-number "^## \[$current_version" "$temp_changelog" | cut -d':' -f1 | tail --lines=1) + # If there's no entry for this version into the changelog + # Get the last available version + if [ -z "$current_version_line" ] + then + current_version_line=$(grep --line-number "^##" "$original_changelog" | cut -d':' -f1 | tail --lines=1) + fi + # Cut the file before the current version. + # Then grep the previous version into the changelog to get the line number of the previous version + local previous_version_line=$(tail --lines=$(( $changelog_length - $current_version_line )) \ + "$temp_changelog" | grep --max-count=1 --line-number "^## " | cut -d':' -f1) + # If there's no previous version into the changelog + # Go until the end of the changelog + if [ -z "$previous_version_line" ] + then + previous_version_line=$changelog_length + fi + + # Cut the file after the previous version to keep only the changelog between the current version and the version to update to. + head --lines=$(( $current_version_line + $previous_version_line - 1 )) "$temp_changelog" | tee "$final_changelog" + + if [ "$format" = "html" ] + then + # Replace markdown links by html links + ynh_replace_string --match_string="\[\(.*\)\](\(.*\)))" --replace_string="\1)" --target_file="$final_changelog" + ynh_replace_string --match_string="\[\(.*\)\](\(.*\))" --replace_string="\1" --target_file="$final_changelog" + elif [ "$format" = "plain" ] + then + # Change title format. + ynh_replace_string --match_string="^##.*\[\(.*\)\](\(.*\)) - \(.*\)$" --replace_string="## \1 (\3) - \2" --target_file="$final_changelog" + # Change modifications lines format. + ynh_replace_string --match_string="^\([-*]\).*\[\(.*\)\]\(.*\)" --replace_string="\1 \2 \3" --target_file="$final_changelog" + fi + # else markdown. As the file is already in markdown, nothing to do. + + # Keep only important changes into the changelog + # Remove all minor changes + sed '/^-/d' "$final_changelog" > "${final_changelog}_lite" + # Remove all blank lines (to keep a clear workspace) + sed --in-place '/^$/d' "${final_changelog}_lite" + # Add a blank line at the end + echo "" >> "${final_changelog}_lite" + + # Clean titles if there's no significative changes + local line + local previous_line="" + while read line <&3 + do + if [ -n "$previous_line" ] + then + # Remove the line if it's a title or a blank line, and the previous one was a title as well. + if ( [ "${line:0:1}" = "#" ] || [ ${#line} -eq 0 ] ) && [ "${previous_line:0:1}" = "#" ] + then + ynh_replace_special_string --match_string="${previous_line//[/.}" --replace_string="" --target_file="${final_changelog}_lite" + fi + fi + previous_line="$line" + done 3< "${final_changelog}_lite" + + # Remove all blank lines again + sed --in-place '/^$/d' "${final_changelog}_lite" + + # Restore changelog format with blank lines + ynh_replace_string --match_string="^##.*" --replace_string="\n\n&\n" --target_file="${final_changelog}_lite" + # Remove the 2 first blank lines + sed --in-place '1,2d' "${final_changelog}_lite" + # Add a blank line at the end + echo "" >> "${final_changelog}_lite" + + # If changelog are empty, add an info + if [ $(wc --words "$final_changelog" | awk '{print $1}') -eq 0 ] + then + echo "No changes from the changelog..." > "$final_changelog" + fi + if [ $(wc --words "${final_changelog}_lite" | awk '{print $1}') -eq 0 ] + then + echo "No significative changes from the changelog..." > "${final_changelog}_lite" + fi +} + +#================================================= + +# Execute a command as another user +# usage: exec_as USER COMMAND [ARG ...] +exec_as() { + local USER=$1 + shift 1 + + if [[ $USER = $(whoami) ]]; then + eval "$@" + else + sudo -u "$USER" "$@" + fi } diff --git a/scripts/actions/install_backports b/scripts/actions/install_backports deleted file mode 100755 index f30c2bf..0000000 --- a/scripts/actions/install_backports +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= -ynh_script_progression --message="Retrieve arguments from the manifest" - -app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} - -#================================================= -# CHECK IF ARGUMENTS ARE CORRECT -#================================================= - -#================================================= -# CHECK IF AN ACTION HAS TO BE DONE -#================================================= - -if [ -e /etc/apt/sources.list.d/minidlna.list ] -then - ynh_die "You are already using the version from backports repository." 0 -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# RE-INSTALL MINIDLNA FROM BACKPORTS -#================================================= -ynh_script_progression --message="Re-install minidlna from backports" --weight=9 - -# Remove the current version of minidlna -ynh_package_remove minidlna - -# Then install the version from backports -codename=$(ynh_debian_release) -test -z "$codename" && (ynh_die "codename empty") - -ynh_replace_string "__CODENAME__" "$codename" /etc/yunohost/apps/$app/conf/minidlna.list -cp -a /etc/yunohost/apps/$app/conf/minidlna.list /etc/apt/sources.list.d/ -ynh_apt update -ynh_package_install -t $codename-backports minidlna - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/actions/install_standard b/scripts/actions/install_standard deleted file mode 100755 index a361a31..0000000 --- a/scripts/actions/install_standard +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source scripts/_common.sh -source /usr/share/yunohost/helpers - -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -#================================================= -# CHECK IF ARGUMENTS ARE CORRECT -#================================================= - -#================================================= -# CHECK IF AN ACTION HAS TO BE DONE -#================================================= - -if [ ! -e /etc/apt/sources.list.d/minidlna.list ] -then - ynh_die "You are already using the version from the stable repository." 0 -fi - -#================================================= -# SPECIFIC ACTION -#================================================= -# RE-INSTALL MINIDLNA FROM STABLE -#================================================= -ynh_script_progression --message="Re-install minidlna from stable" --weight=9 - -# Remove the current version of minidlna -ynh_package_remove minidlna -ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list" - -ynh_apt update -ynh_package_install minidlna - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Execution completed" --last diff --git a/scripts/actions/reset_db b/scripts/actions/reset_db index 2e608aa..fb43cd2 100755 --- a/scripts/actions/reset_db +++ b/scripts/actions/reset_db @@ -12,7 +12,6 @@ source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS #================================================= -ynh_script_progression --message="Retrieve arguments from the manifest" app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} @@ -29,13 +28,13 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} #================================================= # RESET THE DATABASE #================================================= -ynh_script_progression --message="Reset the database" --weight=9 +ynh_script_progression --message="Resetting the database..." --weight=9 # Get the last value for `db_dir` in the config file of minidlna db_directory=$(tac /etc/minidlna.conf | grep --max-count=1 "db_dir=" | cut -d'=' -f 2) ynh_systemd_action --action=stop --service_name=minidlna -ynh_secure_remove "$db_directory/files.db" +ynh_secure_remove --file="$db_directory/files.db" ynh_systemd_action --action=start --service_name=minidlna #================================================= diff --git a/scripts/backup b/scripts/backup index cd1d53f..c13a19f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -19,40 +19,29 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Load settings" +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -version=$(ynh_app_setting_get $app version) - #================================================= -# SPECIFIC BACKUP +# DECLARE DATA AND CONF FILES TO BACKUP #================================================= -# BACKUP OF THE APT SOURCE -#================================================= - -if [ $version = "B" ] -then - ynh_script_progression --message="Backup of the APT source" - ynh_backup "/etc/apt/sources.list.d/minidlna.list" -fi +ynh_print_info --message="Declaring files to be backed up..." #================================================= # BACKUP OF INOTIFY'S CONFIG #================================================= -ynh_script_progression --message="Backup of inotify's config" -ynh_backup "/etc/sysctl.d/90-inotify_minidlna.conf" +ynh_backup --src_path="/etc/sysctl.d/90-inotify_minidlna.conf" #================================================= # BACKUP OF MINIDLNA CONFIGURATION #================================================= -ynh_script_progression --message="Backup of minidlna configuration" -ynh_backup "/etc/minidlna.conf" +ynh_backup --src_path="/etc/minidlna.conf" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup completed" --last +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/config b/scripts/config index 504dbf7..1056658 100644 --- a/scripts/config +++ b/scripts/config @@ -47,13 +47,11 @@ old_friendly_name="$(get_config_value friendly_name)" friendly_name="${YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_FRIENDLY_NAME:-$old_friendly_name}" # Overwrite settings.json file -old_overwrite_settings="$(ynh_app_setting_get $app overwrite_settings)" -old_overwrite_settings=$(bool_to_true_false $old_overwrite_settings) +old_overwrite_settings="$(ynh_app_setting_get --app=$app --key=overwrite_settings)" overwrite_settings="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS:-$old_overwrite_settings}" # Type of admin mail configuration -old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)" -old_admin_mail_html=$(bool_to_true_false $old_admin_mail_html) +old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)" admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}" #================================================= @@ -75,12 +73,12 @@ show_config() { elif [ "$root_container" = "V" ]; then root_container="Video" fi - echo "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_ROOT_CONTAINER=$root_container" - echo "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_FRIENDLY_NAME=$friendly_name" + ynh_return "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_ROOT_CONTAINER=$root_container" + ynh_return "YNH_CONFIG_MAIN_MINIDLNA_CONFIGURATION_FRIENDLY_NAME=$friendly_name" - echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings" + ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETTINGS=$overwrite_settings" - echo "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" + ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html" } #================================================= @@ -105,16 +103,16 @@ apply_config() { fi if [ "$root_container" != "$old_root_container" ] then - ynh_replace_string "root_container=.*" "root_container=$root_container" "$config_file" - ynh_app_setting_set $app root_container "$root_container" + ynh_replace_string --match_string="root_container=.*" --replace_string="root_container=$root_container" --target_file="$config_file" + ynh_app_setting_set --app=$app --key=root_container --value="$root_container" restart_minidlna=1 fi # friendly_name if [ "$friendly_name" != "$old_friendly_name" ] then - ynh_replace_string "friendly_name=.*" "friendly_name=$friendly_name" "$config_file" - ynh_app_setting_set $app friendly_name "$friendly_name" + ynh_replace_string --match_string="friendly_name=.*" --replace_string="friendly_name=$friendly_name" --target_file="$config_file" + ynh_app_setting_set --app=$app --key=friendly_name --value="$friendly_name" restart_minidlna=1 fi @@ -124,12 +122,10 @@ apply_config() { fi # Set overwrite_settings - overwrite_settings=$(bool_to_01 $overwrite_settings) - ynh_app_setting_set $app overwrite_settings "$overwrite_settings" + ynh_app_setting_set --app=$app --key=overwrite_settings --value="$overwrite_settings" # Set admin_mail_html - admin_mail_html=$(bool_to_01 $admin_mail_html) - ynh_app_setting_set $app admin_mail_html "$admin_mail_html" + ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html" } #================================================= diff --git a/scripts/install b/scripts/install index 1b8344c..31b2a6a 100644 --- a/scripts/install +++ b/scripts/install @@ -19,49 +19,37 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -ynh_script_progression --message="Retrieve arguments from the manifest" -version="$YNH_APP_ARG_VERSION" app=$YNH_APP_INSTANCE_NAME #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Store settings from manifest" --weight=2 +ynh_script_progression --message="Storing installation settings..." --weight=2 -ynh_app_setting_set $app version ${version:0:1} - -ynh_app_setting_set $app overwrite_settings "1" -ynh_app_setting_set $app admin_mail_html "1" - -#================================================= -# CHECK DEBIAN'S CODENAME -#================================================= -ynh_script_progression --message="Check debian's codename" - -codename=$(ynh_debian_release) -test -z "$codename" && (ynh_die "codename empty") +ynh_app_setting_set --app=$app --key=overwrite_settings --value=1 +ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Find and open a port" --weight=15 +ynh_script_progression --message="Configuring firewall..." --weight=15 # Find a free port -port=$(ynh_find_port 48200) +port=$(ynh_find_port --port=48200) # Open ports ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port # Discovery Protocol SSDP for UPNP. ynh_exec_fully_quiet yunohost firewall allow --no-upnp UDP 1900 -ynh_app_setting_set $app port $port +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # CREATE YUNOHOST.MULTIMEDIA DIRECTORY #================================================= -ynh_script_progression --message="Create yunohost.multimedia directory" --weight=8 +ynh_script_progression --message="Creating yunohost.multimedia directory..." --weight=8 ynh_multimedia_build_main_dir @@ -70,31 +58,20 @@ ynh_multimedia_build_main_dir #================================================= # INSTALL MINIDLNA #================================================= -ynh_script_progression --message="Install minidlna" --weight=45 +ynh_script_progression --message="Installing MiniDLNA..." --weight=45 -if [ ${version:0:1} = "B" ] -then - # Install the backport version. (If you have issues with the standard version from the stable repository) - ynh_replace_string "__CODENAME__" "$codename" ../conf/minidlna.list - cp -a ../conf/minidlna.list /etc/apt/sources.list.d/ - ynh_apt update - ynh_package_install -t $codename-backports minidlna -else - # Install the standard version from debian repository - ynh_apt update - ynh_package_install minidlna -fi -ynh_app_setting_set $app version ${version:0:1} +ynh_install_app_dependencies minidlna #================================================= # INCREASE INOTIFY'S LIMITS #================================================= -ynh_script_progression --message="Increase inotify's limits" +ynh_script_progression --message="Increasing inotify's limits..." # Increase the maximum number of files inotify can monitor. cp -a ../conf/90-inotify_minidlna.conf /etc/sysctl.d/ # Then, reload the kernel configuration. -if ! IS_PACKAGE_CHECK; then +if ! IS_PACKAGE_CHECK # LXC doesn't allow sysctl to play with kernel options. +then sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf fi @@ -107,25 +84,25 @@ yunohost service add minidlna --log "/var/log/minidlna.log" #================================================= # CONFIGURE MINIDLNA #================================================= -ynh_script_progression --message="Configure MiniDLNA" --weight=2 +ynh_script_progression --message="Configuring MiniDLNA..." --weight=2 -ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf -ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf +ynh_replace_string --match_string="^#*media_dir=.*" --replace_string="media_dir=/home/yunohost.multimedia/share" --target_file=/etc/minidlna.conf +ynh_replace_string --match_string="^#*port=.*" --replace_string="port=$port" --target_file=/etc/minidlna.conf friendly_name="Yunohost DLNA" -ynh_app_setting_set $app friendly_name "$friendly_name" -ynh_replace_string "^#*friendly_name=.*" "friendly_name=$friendly_name" /etc/minidlna.conf +ynh_app_setting_set --app=$app --key=friendly_name --value="$friendly_name" +ynh_replace_string --match_string="^#*friendly_name=.*" --replace_string="friendly_name=$friendly_name" --target_file=/etc/minidlna.conf root_container="B" -ynh_replace_string "^#*root_container=.*" "root_container=$root_container" /etc/minidlna.conf -ynh_app_setting_set $app root_container "$root_container" -ynh_replace_string "^#wide_links=.*" "wide_links=yes" /etc/minidlna.conf +ynh_replace_string --match_string="^#*root_container=.*" --replace_string="root_container=$root_container" --target_file=/etc/minidlna.conf +ynh_app_setting_set --app=$app --key=root_container --value="$root_container" +ynh_replace_string --match_string="^#wide_links=.*" --replace_string="wide_links=yes" --target_file=/etc/minidlna.conf # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "/etc/minidlna.conf" +ynh_store_file_checksum --file="/etc/minidlna.conf" #================================================= # RESTART MINIDLNA #================================================= -ynh_script_progression --message="Restart MiniDLNA" --weight=4 +ynh_script_progression --message="Restarting MiniDLNA..." --weight=4 ynh_systemd_action --action=restart --service_name=minidlna @@ -147,10 +124,10 @@ You can also find some specific actions for this app by using the experimental _ If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/minidlna_ynh__URL_TAG3__." > mail_to_send -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="install" +ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation completed" --last +ynh_script_progression --message="Installation of MiniDLNA completed" --last diff --git a/scripts/remove b/scripts/remove index 942e5ab..8281d88 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,11 +12,11 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Load settings" --weight=2 +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME -port=$(ynh_app_setting_get $app port) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # STANDARD REMOVE @@ -25,16 +25,16 @@ port=$(ynh_app_setting_get $app port) #================================================= # Check if the service is declared in YunoHost -if yunohost service status | grep -q minidlna +if ynh_exec_fully_quiet yunohost service status minidlna then - ynh_print_info "Remove minidlna service" >&2 + ynh_script_progression --message="Removing MiniDLNA service..." yunohost service remove minidlna fi #================================================= # CLOSE PORTS #================================================= -ynh_script_progression --message="Close ports" --weight=15 +ynh_script_progression --message="Closing ports $port and 1900..." --weight=15 ynh_exec_fully_quiet yunohost firewall disallow TCP $port ynh_exec_fully_quiet yunohost firewall disallow UDP 1900 @@ -44,21 +44,20 @@ ynh_exec_fully_quiet yunohost firewall disallow UDP 1900 #================================================= # REMOVE MINIDNLA #================================================= -ynh_script_progression --message="Remove MiniDLNA" --weight=6 +ynh_script_progression --message="Removing MiniDLNA..." --weight=6 -ynh_apt purge minidlna -ynh_secure_remove "/etc/apt/sources.list.d/minidlna.list" +ynh_remove_app_dependencies #================================================= # REMOVE INOTIFY'S CONFIG #================================================= -ynh_script_progression --message="Remove inotify's config" +ynh_script_progression --message="Removing inotify's config..." if [ -e "/etc/sysctl.d/90-inotify_minidlna.conf" ]; then - ynh_print_info "Delete kernel config" >&2 - ynh_secure_remove "/etc/sysctl.d/90-inotify_minidlna.conf" + ynh_secure_remove --file="/etc/sysctl.d/90-inotify_minidlna.conf" # Reload the kernel configuration. - if ! IS_PACKAGE_CHECK; then + if ! IS_PACKAGE_CHECK # LXC doesn't allow sysctl to play with kernel options. + then sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf fi fi @@ -67,4 +66,4 @@ fi # END OF SCRIPT #================================================= -ynh_script_progression --message="Deletion completed" --last +ynh_script_progression --message="Removal of MiniDLNA completed" --last diff --git a/scripts/restore b/scripts/restore index fb97f4a..a405df0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -19,19 +19,18 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Load settings" +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME -version=$(ynh_app_setting_get $app version) -port=$(ynh_app_setting_get $app port) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # SPECIFIC RESTORE #================================================= # OPEN PORTS #================================================= -ynh_script_progression --message="Open ports" --weight=15 +ynh_script_progression --message="Configuring firewall..." --weight=15 ynh_exec_fully_quiet yunohost firewall allow --no-upnp TCP $port # Discovery Protocol SSDP for UPNP. @@ -40,47 +39,36 @@ ynh_exec_fully_quiet yunohost firewall allow --no-upnp UDP 1900 #================================================= # CREATE YUNOHOST.MULTIMEDIA DIRECTORY #================================================= -ynh_script_progression --message="Create yunohost.multimedia directory" --weight=6 +ynh_script_progression --message="Creating yunohost.multimedia directory..." --weight=6 ynh_multimedia_build_main_dir #================================================= # INSTALL MINIDLNA #================================================= -ynh_script_progression --message="Install minidlna" --weight=45 +ynh_script_progression --message="Installing MiniDLNA" --weight=45 -if [ ${version:0:1} = "B" ] -then - # Install the backport version. (If you have issues with the standard version from the stable repository) - codename=$(ynh_debian_release) - ynh_restore_file "/etc/apt/sources.list.d/minidlna.list" - ynh_replace_string " [a-z]*-backports" " $codename-backports" /etc/apt/sources.list.d/minidlna.list - ynh_apt update - ynh_package_install -t $codename-backports minidlna -else - # Install the standard version from debian repository - ynh_apt update - ynh_package_install minidlna -fi +ynh_install_app_dependencies minidlna #================================================= # RESTORE INOTIFY'S CONFIG #================================================= -ynh_script_progression --message="Restore inotify's config" +ynh_script_progression --message="Restoring inotify's config..." -ynh_restore_file "/etc/sysctl.d/90-inotify_minidlna.conf" -if ! IS_PACKAGE_CHECK; then +ynh_restore_file --origin_path="/etc/sysctl.d/90-inotify_minidlna.conf" +if ! IS_PACKAGE_CHECK # LXC doesn't allow sysctl to play with kernel options. +then sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf fi #================================================= # RESTORE MINIDLNA CONFIGURATION #================================================= -ynh_script_progression --message="Restore MiniDLNA configuration" --weight=7 +ynh_script_progression --message="Restoring MiniDLNA configuration..." --weight=7 # Delete the current config of minidlna, in order to replace it by the version from the backup -ynh_secure_remove "/etc/minidlna.conf" -ynh_restore_file "/etc/minidlna.conf" +ynh_secure_remove --file="/etc/minidlna.conf" +ynh_restore_file --origin_path="/etc/minidlna.conf" ynh_systemd_action --action=restart --service_name=minidlna #================================================= @@ -107,10 +95,10 @@ You can also find some specific actions for this app by using the experimental _ If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/minidlna_ynh__URL_TAG3__." > mail_to_send -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="restore" +ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed" --last +ynh_script_progression --message="Restoration completed for MiniDLNA" --last diff --git a/scripts/upgrade b/scripts/upgrade index 04f45aa..f2157dd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,15 +12,15 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Load settings" --weight=2 +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME -version=$(ynh_app_setting_get $app version) -port=$(ynh_app_setting_get $app port) -overwrite_settings=$(ynh_app_setting_get $app overwrite_settings) -root_container=$(ynh_app_setting_get $app root_container) -friendly_name=$(ynh_app_setting_get $app friendly_name) +version=$(ynh_app_setting_get --app=$app --key=version) +port=$(ynh_app_setting_get --app=$app --key=port) +overwrite_settings=$(ynh_app_setting_get --app=$app --key=overwrite_settings) +root_container=$(ynh_app_setting_get --app=$app --key=root_container) +friendly_name=$(ynh_app_setting_get --app=$app --key=friendly_name) #================================================= # CHECK VERSION @@ -31,30 +31,36 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensure downward compatibility" +ynh_script_progression --message="Ensuring downward compatibility..." # If overwrite_settings doesn't exist, create it if [ -z "$overwrite_settings" ]; then overwrite_settings=1 - ynh_app_setting_set $app overwrite_settings $overwrite_settings + ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings fi # If root_container doesn't exist, create it if [ -z "$root_container" ]; then root_container="B" - ynh_app_setting_set $app root_container $root_container + ynh_app_setting_set --app=$app --key=root_container --value=$root_container fi # If friendly_name doesn't exist, create it if [ -z "$friendly_name" ]; then friendly_name="Yunohost DLNA" - ynh_app_setting_set $app friendly_name $friendly_name + ynh_app_setting_set --app=$app --key=friendly_name --value=$friendly_name +fi + +# If version exists, remove the backport source list, as it's no longer used. +if [ -n "$version" ]; then + ynh_secure_remove --file="/etc/apt/sources.list.d/minidlna.list" + ynh_app_setting_delete --app=$app --key=version fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backup the app before upgrading" --weight=2 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=2 # Backup the current version of the app ynh_backup_before_upgrade @@ -68,38 +74,27 @@ ynh_abort_if_errors #================================================= # UPGRADE THE YUNOHOST.MULTIMEDIA DIRECTORY #================================================= -ynh_script_progression --message="Upgrade the yunohost.multimedia directory" --weight=3 +ynh_script_progression --message="Upgrading the yunohost.multimedia directory..." --weight=3 ynh_multimedia_build_main_dir #================================================= # UPGRADE MINIDLNA #================================================= -ynh_script_progression --message="Upgrade MiniDLNA" --weight=3 +ynh_script_progression --message="Upgrading MiniDLNA..." --weight=3 -if [ $version = "B" ] -then - # Install the backport version. (If you have issues with the standard version from the stable repository) - codename=$(ynh_debian_release) - ynh_replace_string "__CODENAME__" "$codename" ../conf/minidlna.list - cp -a ../conf/minidlna.list /etc/apt/sources.list.d/ - ynh_apt update - ynh_package_install -t $codename-backports minidlna -else - # Install the standard version from debian repository - ynh_apt update - ynh_package_install minidlna -fi +ynh_install_app_dependencies minidlna #================================================= # INCREASE INOTIFY'S LIMITS #================================================= -ynh_script_progression --message="Increase inotify's limits" --weight=2 +ynh_script_progression --message="Increasing inotify's limits..." --weight=2 # Increase the maximum number of files inotify can monitor. cp -a ../conf/90-inotify_minidlna.conf /etc/sysctl.d/ # Then, reload the kernel configuration. -if ! IS_PACKAGE_CHECK; then +if ! IS_PACKAGE_CHECK # LXC doesn't allow sysctl to play with kernel options. +then sysctl -p /etc/sysctl.d/90-inotify_minidlna.conf fi @@ -112,28 +107,28 @@ yunohost service add minidlna --log "/var/log/minidlna.log" #================================================= # CONFIGURE MINIDLNA #================================================= -ynh_script_progression --message="Reconfigure MiniDLNA" --weight=2 +ynh_script_progression --message="Reconfiguring MiniDLNA..." --weight=2 # Overwrite the settings config file only if it's allowed if [ $overwrite_settings -eq 1 ] then # Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. - ynh_backup_if_checksum_is_different "/etc/minidlna.conf" + ynh_backup_if_checksum_is_different --file="/etc/minidlna.conf" - ynh_replace_string "^#*media_dir=.*" "media_dir=/home/yunohost.multimedia/share" /etc/minidlna.conf - ynh_replace_string "^#*port=.*" "port=$port" /etc/minidlna.conf - ynh_replace_string "^#*friendly_name=.*" "friendly_name=$friendly_name" /etc/minidlna.conf - ynh_replace_string "^#*root_container=.*" "root_container=$root_container" /etc/minidlna.conf - ynh_replace_string "^#wide_links=.*" "wide_links=yes" /etc/minidlna.conf + ynh_replace_string --match_string="^#*media_dir=.*" --replace_string="media_dir=/home/yunohost.multimedia/share" --target_file=/etc/minidlna.conf + ynh_replace_string --match_string="^#*port=.*" --replace_string="port=$port" --target_file=/etc/minidlna.conf + ynh_replace_string --match_string="^#*friendly_name=.*" --replace_string="friendly_name=$friendly_name" --target_file=/etc/minidlna.conf + ynh_replace_string --match_string="^#*root_container=.*" --replace_string="root_container=$root_container" --target_file=/etc/minidlna.conf + ynh_replace_string --match_string="^#wide_links=.*" --replace_string="wide_links=yes" --target_file=/etc/minidlna.conf # Calculate and store the config file checksum into the app settings - ynh_store_file_checksum "/etc/minidlna.conf" + ynh_store_file_checksum --file="/etc/minidlna.conf" fi #================================================= # RESTART MINIDLNA'S SERVICE #================================================= -ynh_script_progression --message="Restart MiniDLNA" --weight=7 +ynh_script_progression --message="Restarting MiniDLNA..." --weight=7 ynh_systemd_action --action=restart --service_name=minidlna @@ -163,10 +158,10 @@ If you're facing an issue or want to improve this app, please open a new issue i Changelog since your last upgrade: $(cat changelog)" > mail_to_send -ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type="upgrade" +ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade completed" --last +ynh_script_progression --message="Upgrade of MiniDLNA completed" --last