Ver Fonte

Merge pull request #43 from YunoHost-Apps/Fix-linter

Fix linter
Alexandre Aubin há 4 anos atrás
pai
commit
ff6367a5cb
11 ficheiros alterados com 32 adições e 400 exclusões
  1. 1 3
      check_process
  2. 2 3
      conf/app.src
  3. 1 1
      config_panel.toml
  4. 7 7
      manifest.json
  5. 3 350
      scripts/_common.sh
  6. 0 4
      scripts/_variables
  7. 0 2
      scripts/actions/reset_default_app
  8. 2 5
      scripts/backup
  9. 2 7
      scripts/install
  10. 0 2
      scripts/restore
  11. 14 16
      scripts/upgrade

+ 1 - 3
check_process

@@ -27,7 +27,7 @@
         multi_instance=1
         port_already_use=0
         change_url=0
-        config_panel=1
+        config_panel=0
 ;; Test actions without encryption
 # Actions can't be tested with the encryption on, because LXC does not support fuse.
     ; Manifest
@@ -38,8 +38,6 @@
     ; Checks
         setup_nourl=1
         actions=1
-;;; Levels
-    Level 5=auto
 ;;; Options
 Email=
 Notification=change

+ 2 - 3
conf/app.src

@@ -1,6 +1,5 @@
 SOURCE_URL=https://github.com/maniackcrudelis/archivist/archive/refs/tags/v1.3.1.tar.gz
-SOURCE_SUM=e4237249f330391ebd055db86346b861
-SOURCE_SUM_PRG=md5sum
+SOURCE_SUM=1333254f3c2713aec5c802ba661788b12ca9261bce204476a0715a9205c74ec9
+SOURCE_SUM_PRG=sha256sum
 SOURCE_FORMAT=tar.gz
 SOURCE_IN_SUBDIR=true
-SOURCE_FILENAME=

+ 1 - 1
config_panel.toml

@@ -1,4 +1,4 @@
-version = "0.1"
+version = "1.0"
 name = "Archivist configuration panel"
 
 [main]

+ 7 - 7
manifest.json

@@ -3,8 +3,8 @@
     "id": "archivist",
     "packaging_format": 1,
     "description": {
-        "en": "Automatic backups.",
-        "fr": "Sauvegardes automatiques."
+        "en": "Automatic backups",
+        "fr": "Sauvegardes automatiques"
     },
     "version": "1.3.1~ynh1",
     "url": "https://github.com/maniackcrudelis/archivist",
@@ -18,7 +18,7 @@
         "email": "maniackc_dev@crudelis.fr"
     }],
     "requirements": {
-        "yunohost": ">= 4.1"
+        "yunohost": ">= 4.3.0"
     },
     "multi_instance": true,
     "services": [],
@@ -28,7 +28,7 @@
                 "name": "encrypt",
                 "type": "boolean",
                 "ask": {
-                    "en": "Do you want to encrypt your backups ?",
+                    "en": "Do you want to encrypt your backups?",
                     "fr": "Voulez-vous chiffrer vos sauvegardes ?"
                 },
                 "default": true
@@ -50,7 +50,7 @@
                 "name": "core_backup",
                 "type": "boolean",
                 "ask": {
-                    "en": "Would you like to backup your YunoHost core ?",
+                    "en": "Would you like to backup your YunoHost core?",
                     "fr": "Souhaitez-vous effectuer des sauvegardes du système YunoHost ?"
                 },
                 "default": true
@@ -59,7 +59,7 @@
                 "name": "apps_backup",
                 "type": "boolean",
                 "ask": {
-                    "en": "Would you like to backup your apps ?",
+                    "en": "Would you like to backup your apps?",
                     "fr": "Souhaitez-vous effectuer des sauvegardes de vos applications ?"
                 },
                 "default": true
@@ -68,7 +68,7 @@
                 "name": "frequency",
                 "type": "string",
                 "ask": {
-                    "en": "Choose the frequency of your backups ?",
+                    "en": "Choose the frequency of your backups?",
                     "fr": "Choississez la fréquence de votre backup ?"
                 },
                 "choices" : ["Daily", "Each 3 days", "Weekly", "Biweekly", "Monthly"],

+ 3 - 350
scripts/_common.sh

@@ -1,343 +1,11 @@
 #!/bin/bash
 
 #=================================================
-# FUTUR OFFICIAL HELPERS
+# COMMON VARIABLES
 #=================================================
 
-# Install or update the main directory yunohost.multimedia
-#
-# usage: ynh_multimedia_build_main_dir
-ynh_multimedia_build_main_dir () {
-	local ynh_media_release="v1.2"
-	local checksum="806a827ba1902d6911095602a9221181"
-
-	# Download yunohost.multimedia scripts
-	wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
-
-	# Check the control sum
-	echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
-		|| ynh_die "Corrupt source"
-
-	# Check if the package acl is installed. Or install it.
-	ynh_package_is_installed 'acl' \
-		|| ynh_package_install acl
-
-	# Extract
-	mkdir yunohost.multimedia-master
-	tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
-	./yunohost.multimedia-master/script/ynh_media_build.sh
-}
-
-# Add a directory in yunohost.multimedia
-# This "directory" will be a symbolic link to a existing directory.
-#
-# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
-#
-# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
-# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
-ynh_multimedia_addfolder () {
-	# Declare an array to define the options of this helper.
-	declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
-	local source_dir
-	local dest_dir
-	# Manage arguments with getopts
-	ynh_handle_getopts_args "$@"
-
-	./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
-}
-
-# Move a directory in yunohost.multimedia, and replace by a symbolic link
-#
-# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
-#
-# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
-# It will be moved to "Destination directory"
-# A symbolic link will replace it.
-# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
-ynh_multimedia_movefolder () {
-	# Declare an array to define the options of this helper.
-	declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
-	local source_dir
-	local dest_dir
-	# Manage arguments with getopts
-	ynh_handle_getopts_args "$@"
-
-	./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
-}
-
-# Allow an user to have an write authorisation in multimedia directories
-#
-# usage: ynh_multimedia_addaccess user_name
-#
-# | arg: -u, --user_name= - The name of the user which gain this access.
-ynh_multimedia_addaccess () {
-	# Declare an array to define the options of this helper.
-	declare -Ar args_array=( [u]=user_name=)
-	local user_name
-	# Manage arguments with getopts
-	ynh_handle_getopts_args "$@"
-
-	groupadd -f multimedia
-	usermod -a -G multimedia $user_name
-}
-
-#=================================================
-
-# Get the total or free amount of RAM+swap on the system
-#
-# usage: ynh_get_ram [--free|--total] [--ignore_swap|--only_swap]
-# | arg: -f, --free  - Count free RAM+swap
-# | arg: -t, --total - Count total RAM+swap
-# | arg: -s, --ignore_swap - Ignore swap, consider only real RAM
-# | arg: -o, --only_swap - Ignore real RAM, consider only swap
-ynh_get_ram () {
-	# Declare an array to define the options of this helper.
-	local legacy_args=ftso
-	declare -Ar args_array=( [f]=free [t]=total [s]=ignore_swap [o]=only_swap )
-	local free
-	local total
-	local ignore_swap
-	local only_swap
-	# Manage arguments with getopts
-	ynh_handle_getopts_args "$@"
-	ignore_swap=${ignore_swap:-0}
-	only_swap=${only_swap:-0}
-	free=${free:-0}
-	total=${total:-0}
-
-	local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}')
-	local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}')
-	local total_ram_swap=$(( total_ram + total_swap ))
-
-	local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}')
-	local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}')
-	local free_ram_swap=$(( free_ram + free_swap ))
-
-	# Use the total amount of ram
-	if [ $free -eq 1 ]
-	then
-		# Use the total amount of free ram
-		local ram=$free_ram_swap
-		if [ $ignore_swap -eq 1 ]
-		then
-			# Use only the amount of free ram
-			ram=$free_ram
-		elif [ $only_swap -eq 1 ]
-		then
-			# Use only the amount of free swap
-			ram=$free_swap
-		fi
-	elif [ $total -eq 1 ]
-	then
-		local ram=$total_ram_swap
-		if [ $ignore_swap -eq 1 ]
-		then
-			# Use only the amount of free ram
-			ram=$total_ram
-		elif [ $only_swap -eq 1 ]
-		then
-			# Use only the amount of free swap
-			ram=$total_swap
-		fi
-	else
-		ynh_print_warn --message="You have to choose --free or --total when using ynh_get_ram"
-		ram=0
-	fi
-
-    echo $ram
-}
-
-# Return 0 or 1 depending if the system has a given amount of RAM+swap free or total
-#
-# usage: ynh_require_ram --required=RAM required in Mb [--free|--total] [--ignore_swap|--only_swap]
-# | arg: -r, --required - The amount to require, in Mb
-# | arg: -f, --free  - Count free RAM+swap
-# | arg: -t, --total - Count total RAM+swap
-# | arg: -s, --ignore_swap - Ignore swap, consider only real RAM
-# | arg: -o, --only_swap - Ignore real RAM, consider only swap
-ynh_require_ram () {
-    # Declare an array to define the options of this helper.
-    local legacy_args=rftso
-    declare -Ar args_array=( [r]=required= [f]=free [t]=total [s]=ignore_swap [o]=only_swap )
-    local required
-    local free
-    local total
-    local ignore_swap
-    local only_swap
-    # Manage arguments with getopts
-    ynh_handle_getopts_args "$@"
-    # Dunno if that's the right way to do, but that's some black magic to be able to
-    # forward the bool args to ynh_get_ram easily?
-    # If the variable $free is not empty, set it to '--free'
-    free=${free:+--free}
-    total=${total:+--total}
-    ignore_swap=${ignore_swap:+--ignore_swap}
-    only_swap=${only_swap:+--only_swap}
-
-    local ram=$(ynh_get_ram $free $total $ignore_swap $only_swap)
-
-    if [ $ram -lt $required ]
-    then
-        return 1
-    else
-        return 0
-    fi
-}
-
-#=================================================
-
-# Define the values to configure php-fpm
-#
-# usage: ynh_get_scalable_phpfpm --usage=usage --footprint=footprint [--print]
-# | arg: -f, --footprint      - Memory footprint of the service (low/medium/high).
-# low    - Less than 20Mb of ram by pool.
-# medium - Between 20Mb and 40Mb of ram by pool.
-# high   - More than 40Mb of ram by pool.
-# Or specify exactly the footprint, the load of the service as Mb by pool instead of having a standard value.
-# To have this value, use the following command and stress the service.
-# watch -n0.5 ps -o user,cmd,%cpu,rss -u APP
-#
-# | arg: -u, --usage     - Expected usage of the service (low/medium/high).
-# low    - Personal usage, behind the sso.
-# medium - Low usage, few people or/and publicly accessible.
-# high   - High usage, frequently visited website.
-#
-# | arg: -p, --print - Print the result
-#
-#
-#
-# The footprint of the service will be used to defined the maximum footprint we can allow, which is half the maximum RAM.
-# So it will be used to defined 'pm.max_children'
-# A lower value for the footprint will allow more children for 'pm.max_children'. And so for
-#    'pm.start_servers', 'pm.min_spare_servers' and 'pm.max_spare_servers' which are defined from the
-#    value of 'pm.max_children'
-# NOTE: 'pm.max_children' can't exceed 4 times the number of processor's cores.
-#
-# The usage value will defined the way php will handle the children for the pool.
-# A value set as 'low' will set the process manager to 'ondemand'. Children will start only if the
-#   service is used, otherwise no child will stay alive. This config gives the lower footprint when the
-#   service is idle. But will use more proc since it has to start a child as soon it's used.
-# Set as 'medium', the process manager will be at dynamic. If the service is idle, a number of children
-#   equal to pm.min_spare_servers will stay alive. So the service can be quick to answer to any request.
-#   The number of children can grow if needed. The footprint can stay low if the service is idle, but
-#   not null. The impact on the proc is a little bit less than 'ondemand' as there's always a few
-#   children already available.
-# Set as 'high', the process manager will be set at 'static'. There will be always as many children as
-#   'pm.max_children', the footprint is important (but will be set as maximum a quarter of the maximum
-#   RAM) but the impact on the proc is lower. The service will be quick to answer as there's always many
-#   children ready to answer.
-ynh_get_scalable_phpfpm () {
-    local legacy_args=ufp
-    # Declare an array to define the options of this helper.
-    declare -Ar args_array=( [u]=usage= [f]=footprint= [p]=print )
-    local usage
-    local footprint
-    local print
-    # Manage arguments with getopts
-    ynh_handle_getopts_args "$@"
-    # Set all characters as lowercase
-    footprint=${footprint,,}
-    usage=${usage,,}
-    print=${print:-0}
-
-    if [ "$footprint" = "low" ]
-    then
-        footprint=20
-    elif [ "$footprint" = "medium" ]
-    then
-        footprint=35
-    elif [ "$footprint" = "high" ]
-    then
-        footprint=50
-    fi
-
-    # Define the way the process manager handle child processes.
-    if [ "$usage" = "low" ]
-    then
-        php_pm=ondemand
-    elif [ "$usage" = "medium" ]
-    then
-        php_pm=dynamic
-    elif [ "$usage" = "high" ]
-    then
-        php_pm=static
-    else
-        ynh_die --message="Does not recognize '$usage' as an usage value."
-    fi
-
-    # Get the total of RAM available, except swap.
-    local max_ram=$(ynh_get_ram --total --ignore_swap)
-
-    at_least_one() {
-        # Do not allow value below 1
-        if [ $1 -le 0 ]
-        then
-            echo 1
-        else
-            echo $1
-        fi
-    }
-
-    # Define pm.max_children
-    # The value of pm.max_children is the total amount of ram divide by 2 and divide again by the footprint of a pool for this app.
-    # So if php-fpm start the maximum of children, it won't exceed half of the ram.
-    php_max_children=$(( $max_ram / 2 / $footprint ))
-    # If process manager is set as static, use half less children.
-    # Used as static, there's always as many children as the value of pm.max_children
-    if [ "$php_pm" = "static" ]
-    then
-        php_max_children=$(( $php_max_children / 2 ))
-    fi
-    php_max_children=$(at_least_one $php_max_children)
-
-    # To not overload the proc, limit the number of children to 4 times the number of cores.
-    local core_number=$(nproc)
-    local max_proc=$(( $core_number * 4 ))
-    if [ $php_max_children -gt $max_proc ]
-    then
-        php_max_children=$max_proc
-    fi
-
-    if [ "$php_pm" = "dynamic" ]
-    then
-        # Define pm.start_servers, pm.min_spare_servers and pm.max_spare_servers for a dynamic process manager
-        php_min_spare_servers=$(( $php_max_children / 8 ))
-        php_min_spare_servers=$(at_least_one $php_min_spare_servers)
-
-        php_max_spare_servers=$(( $php_max_children / 2 ))
-        php_max_spare_servers=$(at_least_one $php_max_spare_servers)
-
-        php_start_servers=$(( $php_min_spare_servers + ( $php_max_spare_servers - $php_min_spare_servers ) /2 ))
-        php_start_servers=$(at_least_one $php_start_servers)
-    else
-        php_min_spare_servers=0
-        php_max_spare_servers=0
-        php_start_servers=0
-    fi
-
-    if [ $print -eq 1 ]
-    then
-        ynh_debug --message="Footprint=${footprint}Mb by pool."
-        ynh_debug --message="Process manager=$php_pm"
-        ynh_debug --message="Max RAM=${max_ram}Mb"
-        if [ "$php_pm" != "static" ]; then
-            ynh_debug --message="\nMax estimated footprint=$(( $php_max_children * $footprint ))"
-            ynh_debug --message="Min estimated footprint=$(( $php_min_spare_servers * $footprint ))"
-        fi
-        if [ "$php_pm" = "dynamic" ]; then
-            ynh_debug --message="Estimated average footprint=$(( $php_max_spare_servers * $footprint ))"
-        elif [ "$php_pm" = "static" ]; then
-            ynh_debug --message="Estimated footprint=$(( $php_max_children * $footprint ))"
-        fi
-        ynh_debug --message="\nRaw php-fpm values:"
-        ynh_debug --message="pm.max_children = $php_max_children"
-        if [ "$php_pm" = "dynamic" ]; then
-            ynh_debug --message="pm.start_servers = $php_start_servers"
-            ynh_debug --message="pm.min_spare_servers = $php_min_spare_servers"
-            ynh_debug --message="pm.max_spare_servers = $php_max_spare_servers"
-        fi
-    fi
-}
+# Dependencies
+app_depencencies="rsync encfs sshpass ccrypt lzop zstd lzip"
 
 #=================================================
 # EXPERIMENTAL HELPERS
@@ -700,18 +368,3 @@ ynh_app_changelog () {
         echo "No significative changes from the changelog..." > "${final_changelog}_lite"
     fi
 }
-
-#=================================================
-
-# Execute a command as another user
-# usage: exec_as USER COMMAND [ARG ...]
-ynh_exec_as() {
-  local USER=$1
-  shift 1
-
-  if [[ $USER = $(whoami) ]]; then
-    eval "$@"
-  else
-    sudo -u "$USER" "$@"
-  fi
-}

+ 0 - 4
scripts/_variables

@@ -1,4 +0,0 @@
-#!/bin/bash
-
-# Dependencies
-app_depencencies="rsync encfs sshpass ccrypt lzop zstd lzip"

+ 0 - 2
scripts/actions/reset_default_app

@@ -7,8 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source scripts/_variables
-
 source scripts/_common.sh
 source /usr/share/yunohost/helpers
 

+ 2 - 5
scripts/backup

@@ -19,7 +19,7 @@ ynh_abort_if_errors
 #=================================================
 # LOAD SETTINGS
 #=================================================
-ynh_script_progression --message="Loading installation settings..."
+ynh_print_info --message="Loading installation settings..."
 
 app=$YNH_APP_INSTANCE_NAME
 
@@ -30,7 +30,6 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
 #=================================================
 # BACKUP THE APP MAIN DIR
 #=================================================
-ynh_script_progression --message="Backing up the main app directory..."
 
 ynh_backup --src_path="$final_path"
 
@@ -39,14 +38,12 @@ ynh_backup --src_path="$final_path"
 #=================================================
 # BACKUP LOGROTATE
 #=================================================
-ynh_script_progression --message="Backing up logrotate configuration..."
 
 ynh_backup --src_path="/etc/logrotate.d/$app"
 
 #=================================================
 # BACKUP THE CRON FILE
 #=================================================
-ynh_script_progression --message="Backing up cron file..."
 
 ynh_backup --src_path="/etc/cron.d/$app"
 
@@ -54,4 +51,4 @@ ynh_backup --src_path="/etc/cron.d/$app"
 # END OF SCRIPT
 #=================================================
 
-ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last
+ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

+ 2 - 7
scripts/install

@@ -7,8 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source _variables
-
 source _common.sh
 source /usr/share/yunohost/helpers
 
@@ -129,7 +127,7 @@ then
     while read backup_app
     do
         ynh_replace_string --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&" --target_file="$config_file"
-    done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
+    done <<< "$(yunohost app list | grep 'id:' | sed 's/.*id: //')"
 fi
 
 # Calculate and store the config file checksum into the app settings
@@ -197,11 +195,10 @@ ynh_print_info --message="$Informations"
 
 if [ "$encrypt" = "true" ]
 then
-    ynh_print_OFF
     encrypt_message="Your password for encryption is '$encryption_pwd'
 
 "
-    ynh_print_ON
+
 else
     encrypt_message=""
 fi
@@ -209,7 +206,6 @@ fi
 # Get main domain and buid the url of the admin panel of the app.
 admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
 
-ynh_print_OFF
 echo "${encrypt_message}Archivist is going to run $run_freq.
 If you want to change the frequency, have a look to the file /etc/cron.d/$app.
 $Informations
@@ -219,7 +215,6 @@ You can configure this app easily by using the experimental __URL_TAG1__config-p
 You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
 
 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/archivist_ynh__URL_TAG3__." > mail_to_send
-ynh_print_ON
 
 ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
 

+ 0 - 2
scripts/restore

@@ -7,8 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source ../settings/scripts/_variables
-
 source ../settings/scripts/_common.sh
 source /usr/share/yunohost/helpers
 

+ 14 - 16
scripts/upgrade

@@ -7,8 +7,6 @@
 #=================================================
 
 # Load common variables for all scripts.
-source _variables
-
 source _common.sh
 source /usr/share/yunohost/helpers
 
@@ -32,6 +30,20 @@ overwrite_cron=$(ynh_app_setting_get --app=$app --key=overwrite_cron)
 
 upgrade_type=$(ynh_check_app_version_changed)
 
+#=================================================
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
+#=================================================
+ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=2
+
+# Backup the current version of the app
+ynh_backup_before_upgrade
+ynh_clean_setup () {
+    # restore it if the upgrade fails
+    ynh_restore_upgradebackup
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
 #=================================================
 # ENSURE DOWNWARD COMPATIBILITY
 #=================================================
@@ -73,20 +85,6 @@ if [ -z "$admin_mail_html" ]; then
     ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
 fi
 
-#=================================================
-# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
-#=================================================
-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
-ynh_clean_setup () {
-    # restore it if the upgrade fails
-    ynh_restore_upgradebackup
-}
-# Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
-
 #=================================================
 # STANDARD UPGRADE STEPS
 #=================================================