mirror of
https://github.com/YunoHost-Apps/flohmarkt_ynh.git
synced 2024-09-03 18:36:30 +02:00
[autopatch] Automatic patch attempt for helpers 2.1
This commit is contained in:
parent
6364e57085
commit
6b27c84674
9 changed files with 247 additions and 233 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
README*
|
||||
scripts/test_local_curl.sh
|
||||
*~
|
||||
*.sw[op]
|
||||
.DS_Store
|
||||
|
|
|
@ -26,7 +26,8 @@ code = "https://codeberg.org/flohmarkt/flohmarkt"
|
|||
# fund = "???"
|
||||
|
||||
[integration]
|
||||
yunohost = ">= 11.2.11"
|
||||
yunohost = ">= 11.2.18"
|
||||
helpers_version = "2.1"
|
||||
architectures = "all"
|
||||
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/11
|
||||
multi_instance = true
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
# COMMON VARIABLES AND CUSTOM HELPERS
|
||||
#=================================================
|
||||
|
||||
## new filenames starting 0.00~ynh5
|
||||
# make a filename/service name from domain/path
|
||||
if [[ "$path" == /* ]]; then
|
||||
|
||||
url_path="${path:1}"
|
||||
fi
|
||||
if [[ "__${url_path}__" == '____' ]]; then
|
||||
|
@ -31,7 +30,7 @@ flohmarkt_urlwatch_dir="${flohmarkt_install}/urlwatch"
|
|||
flohmarkt_log_dir="/var/log/${app}"
|
||||
flohmarkt_sym_log_dir="/var/log/${flohmarkt_filename}"
|
||||
# filename for logfiles - ¡ojo! if not ends with .log will be interpreted
|
||||
# as a directory by ynh_use_logrotate
|
||||
# as a directory by ynh_config_add_logrotate
|
||||
# https://github.com/YunoHost/issues/issues/2383
|
||||
flohmarkt_logfile="${flohmarkt_log_dir}/app.log"
|
||||
# flohmarkt data_dir
|
||||
|
@ -89,18 +88,23 @@ flohmarkt_old_service="flohmarkt"
|
|||
#
|
||||
# Also, in the previous example, finalpath has a '=' at the end. That means this option need a value.
|
||||
# So, the helper has to be call with --finalpath /final/path, --finalpath=/final/path or -f /final/path,
|
||||
|
||||
# the variable $finalpath will get the value /final/path
|
||||
# If there's many values for an option, -f /final /path, the value will be separated by a ';' $finalpath=/final;/path
|
||||
# For an option without value, like --user in the example, the helper can be called only with --user or -u. $user
|
||||
|
||||
# will then get the value 1.
|
||||
#
|
||||
# To keep a retrocompatibility, a package can still call a helper, using getopts, with positional arguments.
|
||||
# The "legacy mode" will manage the positional arguments and fill the variable in the same order than they are given
|
||||
|
||||
# in $args_array. e.g. for `my_helper "val1" val2`, arg1 will be filled with val1, and arg2 with val2.
|
||||
|
||||
# Positional parameters (used to be the only way to use ynh_handle_getopts_args once upon a time) can be
|
||||
|
||||
# used also:
|
||||
#
|
||||
|
||||
# '--' start processing the rest of the arguments as positional parameters
|
||||
# $legacy_args The arguments positional parameters will be assign to
|
||||
# Needs to be composed of array keys of args_array. If a key for a predefined variable
|
||||
|
@ -108,6 +112,7 @@ flohmarkt_old_service="flohmarkt"
|
|||
# If the long option variable to contain the data is predefined as an array (e.g. using
|
||||
# `local -a arg1` then multiple values will be assigned to its cells.
|
||||
# If the last positional parameter defined in legacy_args is defined as an array all
|
||||
|
||||
# the leftover positional parameters will be assigned to its cells.
|
||||
# (it is named legacy_args, because the use of positional parameters was about to be
|
||||
# deprecated before the last re-design of this sub)
|
||||
|
@ -118,7 +123,7 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
# Manage arguments only if there's some provided
|
||||
set +o xtrace # set +x
|
||||
if [ $# -eq 0 ]; then
|
||||
ynh_print_warn --message="ynh_handle_getopts_args called without arguments"
|
||||
ynh_print_warn "ynh_handle_getopts_args called without arguments"
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -136,10 +141,12 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
for option_flag in "${!args_array[@]}"; do
|
||||
# TODO refactor: Now I'm not sure anymore this part belongs here. To make the
|
||||
# this all less hard to read and understand I'm thinking at the moment that it
|
||||
|
||||
# would be good to split the different things done here into their own loops:
|
||||
#
|
||||
# 1. build the option string $getopts_parameters
|
||||
# 2. go through the arguments and add empty arguments where needed to
|
||||
|
||||
# allow for cases like '--arg= --value' where 'value' is a valid option, too
|
||||
# 3. replace long option names by short once
|
||||
# 4. (possibly add empty parameters for '-a -v' in cases where -a expects a value
|
||||
|
@ -148,6 +155,7 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
# Concatenate each option_flags of the array to build the string of arguments for getopts
|
||||
# Will looks like 'abcd' for -a -b -c -d
|
||||
# If the value of an option_flag finish by =, it's an option with additionnal values.
|
||||
|
||||
# (e.g. --user bob or -u bob)
|
||||
# Check the last character of the value associate to the option_flag
|
||||
flohmarkt_print_debug "compare to '${args_array[$option_flag]: -1}'"
|
||||
|
@ -174,9 +182,10 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
# but if exists '[v]=value=' this is not the expected behavior:
|
||||
# → then $arg is expected to contain an empty value and '-v' or '--value'
|
||||
# is expected to be interpreted as its own valid argument
|
||||
# (found in use of ynh_replace_string called by ynh_add_config)
|
||||
# (found in use of ynh_replace called by ynh_config_add)
|
||||
# solution:
|
||||
# insert an empty arg into array arguments to be later interpreted by
|
||||
|
||||
# getopts as the missing value to --arg=
|
||||
if [[ -v arguments[arg+1] ]] && [[ ${arguments[arg]: -1} == '=' ]]; then
|
||||
# arg ends with a '='
|
||||
|
@ -188,6 +197,7 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
|
||||
# check if next_argument is a value in args_array
|
||||
# → starts with '--' and the rest of the argument excluding optional trailing '='
|
||||
|
||||
# of the string is a value in associative array args_array
|
||||
# → or starts with '-' and the rest of the argument is a valid key in args_array
|
||||
# (long argument could already have been replaced by short version before)
|
||||
|
@ -231,11 +241,11 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
flohmarkt_print_debug "after getopts - parameter='$parameter', OPTIND='${OPTIND:-none}', OPTARG='${OPTARG:-none}'"
|
||||
|
||||
if [ "$parameter" = "?" ]; then
|
||||
ynh_die --message="Invalid argument: -${OPTARG:-}"
|
||||
ynh_die "Invalid argument: -${OPTARG:-}"
|
||||
flohmarkt_print_debug "Invalid argument: -${OPTARG:-}"
|
||||
exit 255
|
||||
elif [ "$parameter" = ":" ]; then
|
||||
ynh_die --message="-$OPTARG parameter requires an argument."
|
||||
ynh_die "-$OPTARG parameter requires an argument."
|
||||
echo "-$OPTARG parameter requires an argument."
|
||||
exit 255
|
||||
else
|
||||
|
@ -269,6 +279,7 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
local option_var='' # the variable name to be filled
|
||||
# Try to use legacy_args as a list of option_flag of the array args_array
|
||||
# Otherwise, fill it with getopts_parameters to get the option_flag.
|
||||
|
||||
# (But an associative arrays isn't always sorted in the correct order...)
|
||||
# Remove all ':' in getopts_parameters, if used.
|
||||
legacy_args=${legacy_args:-${getopts_parameters//:/}}
|
||||
|
@ -292,11 +303,14 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
flohmarkt_print_debug "positional parameter, argument='$argument'"
|
||||
|
||||
# Get the option_flag from getopts_parameters by using the option_flag according to the
|
||||
|
||||
# position of the argument.
|
||||
option_flag=${legacy_args:$positional_count:1}
|
||||
|
||||
# increment counter for legacy_args if still args left. If no args left check if the
|
||||
|
||||
# last arg is a predefined array and let it cells be filled. Otherwise complain and
|
||||
|
||||
# return.
|
||||
flohmarkt_print_debug "positional_counter='$positional_count', max positional_counter='$(( ${#legacy_args} -1 ))'"
|
||||
if [[ $positional_count -le $((${#legacy_args} - 1)) ]]; then
|
||||
|
@ -310,10 +324,11 @@ flohmarkt_ynh_handle_getopts_args() {
|
|||
# The variable name will be stored in 'option_var'
|
||||
option_var="${args_array[$option_flag]%=}"
|
||||
elif [[ $positional_count -ge $((${#legacy_args} - 1)) ]] &&
|
||||
|
||||
! declare -p ${option_var} | grep '^declare -a'
|
||||
then
|
||||
# no more legacy_args to fill - legacy behaviour: complain and return
|
||||
ynh_print_warn --message="Too many arguments ! \"${arguments[$i]}\" will be ignored."
|
||||
ynh_print_warn "Too many arguments ! \"${arguments[$i]}\" will be ignored."
|
||||
return
|
||||
else
|
||||
flohmarkt_print_debug "array found - keep going"
|
||||
|
@ -371,7 +386,7 @@ flohmarkt_ynh_local_curl() {
|
|||
# Curl abstraction to help with POST requests to local pages (such as installation forms)
|
||||
#
|
||||
# usage: ynh_local_curl [--option [-other_option […]]] "page" "key1=value1" "key2=value2" ...
|
||||
# | arg: -l --line_match: check answer against an extended regex
|
||||
# | arg: -l --wait_until: check answer against an extended regex
|
||||
# | arg: -m --method: request method to use: POST (default), PUT, GET, DELETE
|
||||
# | arg: -H --header: add a header to the request (can be used multiple times)
|
||||
# | arg: -d --data: data to be PUT or POSTed. Can be used multiple times.
|
||||
|
@ -388,6 +403,7 @@ flohmarkt_ynh_local_curl() {
|
|||
# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"
|
||||
# → will open a POST request to "https://$domain/$path/install.php?installButton" posting "foo=$var1" and "bar=$var2"
|
||||
# example: ynh_local_curl -m POST --header "Accept: application/json" \
|
||||
|
||||
# -H "Content-Type: application/json" \
|
||||
# --data "{\"members\":{\"names\": [\"${app}\"],\"roles\": [\"editor\"]}}" -l '"ok":true' \
|
||||
# "http://localhost:5984/"
|
||||
|
@ -399,23 +415,26 @@ flohmarkt_ynh_local_curl() {
|
|||
#
|
||||
# `$domain` and `$path_url` need to be defined externally if the first form for the 'page' argument is used.
|
||||
#
|
||||
# The return code of this function will vary depending of the use of --line_match:
|
||||
|
||||
# The return code of this function will vary depending of the use of --wait_until:
|
||||
#
|
||||
# If --line_match has been used the return code will be the one of the grep checking line_match
|
||||
|
||||
# If --wait_until has been used the return code will be the one of the grep checking line_match
|
||||
# against the output of curl. The output of curl will not be returned.
|
||||
#
|
||||
# If --line_match has not been provided the return code will be the one of the curl command and
|
||||
# If --wait_until has not been provided the return code will be the one of the curl command and
|
||||
# the output of curl will be echoed.
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
|
||||
# Declare an array to define the options of this helper.a
|
||||
local -A supported_methods=( [PUT]=1 [POST]=1 [GET]=1 [DELETE]=1 )
|
||||
local legacy_args=Ld
|
||||
#REMOVEME? local legacy_args=Ld
|
||||
local -A args_array=( [l]=line_match= [m]=method= [H]=header= [n]=no_sleep [L]=location= [d]=data= [u]=user= [p]=password= [s]=seperator= )
|
||||
local line_match
|
||||
local method
|
||||
local -a header
|
||||
|
||||
local no_sleep
|
||||
local location
|
||||
local user
|
||||
|
@ -428,7 +447,7 @@ flohmarkt_ynh_local_curl() {
|
|||
|
||||
# make sure method is a supported one
|
||||
if ! [[ -v supported_methods[$method] ]]; then
|
||||
ynh_die --message="method $method not supported by flohmarkt_ynh_local_curl"
|
||||
ynh_die "method $method not supported by flohmarkt_ynh_local_curl"
|
||||
fi
|
||||
|
||||
# linter doesn't want that the internal function is used anymore
|
||||
|
@ -488,10 +507,11 @@ flohmarkt_ynh_local_curl() {
|
|||
done
|
||||
|
||||
# build --user for curl
|
||||
|
||||
if [[ -n "$user" ]] && [[ -n "$password" ]]; then
|
||||
curl_opt_args+=('--user' "$user:$password")
|
||||
elif [[ -n "$user" ]] && [[ -z "$password" ]]; then
|
||||
ynh_die --message="user provided via '-u/--user' needs password specified via '-p/--password'"
|
||||
ynh_die "user provided via '-u/--user' needs password specified via '-p/--password'"
|
||||
fi
|
||||
|
||||
flohmarkt_print_debug "long string curl_opt_args='${curl_opt_args[@]}'"
|
||||
|
@ -534,13 +554,13 @@ flohmarkt_ynh_local_curl() {
|
|||
local curl_error=$?
|
||||
flohmarkt_print_debug "curl_result='$curl_result' ($curl_error)"
|
||||
|
||||
# check result agains --line_match if provided
|
||||
# check result agains --wait_until if provided
|
||||
if [[ -v line_match ]] && [[ -n $line_match ]]; then
|
||||
printf '%s' "$curl_result" | grep "$line_match" > /dev/null
|
||||
# will return the error code of the above grep
|
||||
curl_error=$?
|
||||
else
|
||||
# no --line_match, return curls error code and output
|
||||
# no --wait_until, return curls error code and output
|
||||
echo $curl_result
|
||||
fi
|
||||
|
||||
|
@ -551,10 +571,6 @@ flohmarkt_ynh_local_curl() {
|
|||
return $curl_error
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# debug output for flohmarkt_ynh_handle_getopts_args and flohmarkt_ynh_local_curl
|
||||
# otherwise not needed TODO delete after development of the two is done
|
||||
flohmarkt_debug=0
|
||||
|
@ -581,28 +597,28 @@ flohmarkt_ynh_set_permission() {
|
|||
|
||||
# start flohmarkt service
|
||||
flohmarkt_ynh_start_service() {
|
||||
ynh_systemd_action --service_name=$flohmarkt_filename --action="start" \
|
||||
--line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" \
|
||||
ynh_systemctl --service=$flohmarkt_filename --action="start" \
|
||||
--wait_until='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" \
|
||||
--timeout=30
|
||||
}
|
||||
|
||||
# stop flohmarkt service
|
||||
flohmarkt_ynh_stop_service() {
|
||||
ynh_systemd_action --service_name=$flohmarkt_filename --action="stop"
|
||||
ynh_systemctl --service=$flohmarkt_filename --action="stop"
|
||||
}
|
||||
|
||||
# start couchdb and wait for success
|
||||
flohmarkt_ynh_start_couchdb() {
|
||||
ynh_systemd_action --service_name=couchdb --action="start" --timeout=30 \
|
||||
ynh_systemctl --service=couchdb --action="start" --timeout=30 \
|
||||
--log_path="/var/log/couchdb/couchdb.log" \
|
||||
--line_match='Apache CouchDB has started on http://127.0.0.1'
|
||||
--wait_until='Apache CouchDB has started on http://127.0.0.1'
|
||||
}
|
||||
|
||||
# stop couchdb
|
||||
flohmarkt_ynh_stop_couchdb() {
|
||||
ynh_systemd_action --service_name=couchdb --action="stop" --timeout=30 \
|
||||
ynh_systemctl --service=couchdb --action="stop" --timeout=30 \
|
||||
--log_path="/var/log/couchdb/couchdb.log" \
|
||||
--line_match='SIGTERM received - shutting down'
|
||||
--wait_until='SIGTERM received - shutting down'
|
||||
}
|
||||
|
||||
# install or upgrade couchdb
|
||||
|
@ -618,7 +634,7 @@ flohmarkt_ynh_up_inst_couchdb() {
|
|||
couchdb couchdb/adminpass_again password $password_couchdb_admin
|
||||
couchdb couchdb/adminpass_again seen true" | debconf-set-selections
|
||||
DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
|
||||
ynh_install_extra_app_dependencies \
|
||||
ynh_apt_install_dependencies_from_extra_repository \
|
||||
--repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
|
||||
--key="https://couchdb.apache.org/repo/keys.asc" \
|
||||
--package="couchdb"
|
||||
|
@ -659,7 +675,7 @@ flohmarkt_ynh_delete_couchdb_user() {
|
|||
flohmarkt_ynh_local_curl -n -m DELETE -u admin -p ${password_couchdb_admin} -l '"ok":true' \
|
||||
"http://127.0.0.1:5984/_users/org.couchdb.user%3A${app}?rev=${couchdb_user_revision}"
|
||||
else
|
||||
ynh_die --message "couchdb_user_revision is empty (${couchdb_user_revision})"
|
||||
ynh_die "couchdb_user_revision is empty (${couchdb_user_revision})"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -669,7 +685,7 @@ flohmarkt_ynh_create_couchdb_user() {
|
|||
-d '{' \
|
||||
-d "\"name\": \"${app}\", \"password\": \"${password_couchdb_flohmarkt}\"," \
|
||||
-d '"roles": [], "type": "user"}' \
|
||||
--line_match='"ok":true' \
|
||||
--wait_until='"ok":true' \
|
||||
"http://127.0.0.1:5984/_users/org.couchdb.user:${app}"
|
||||
}
|
||||
|
||||
|
@ -677,7 +693,7 @@ flohmarkt_ynh_couchdb_user_permissions() {
|
|||
flohmarkt_ynh_local_curl -n -m PUT -u admin -p "$password_couchdb_admin" \
|
||||
-H "Accept: application/json" -H "Content-Type: application/json" \
|
||||
-d "{\"members\":{\"names\": [\"${app}\"],\"roles\": [\"editor\"]}}" \
|
||||
--line_match='"ok":true' \
|
||||
--wait_until='"ok":true' \
|
||||
"http://127.0.0.1:5984/${app}/_security"
|
||||
}
|
||||
|
||||
|
@ -692,18 +708,18 @@ flohmarkt_ynh_exists_couchdb_db() {
|
|||
}
|
||||
|
||||
flohmarkt_ynh_delete_couchdb_db() {
|
||||
local legacy_args='n'
|
||||
#REMOVEME? local legacy_args='n'
|
||||
local -A args_array=( [n]=name= )
|
||||
flohmarkt_ynh_handle_getopts_args "$@"
|
||||
local name=${name:-${app}}
|
||||
|
||||
flohmarkt_ynh_local_curl -n -m DELETE -u admin -p "$password_couchdb_admin" \
|
||||
--line_match='"ok":true' "http://127.0.0.1:5984/${name}"
|
||||
--wait_until='"ok":true' "http://127.0.0.1:5984/${name}"
|
||||
}
|
||||
|
||||
# replicate couchdb to a new database
|
||||
flohmarkt_ynh_copy_couchdb() {
|
||||
local legacy_args='on'
|
||||
#REMOVEME? local legacy_args='on'
|
||||
local -A args_array=( [o]=old_name= [n]=new_name= )
|
||||
local new_name
|
||||
local old_name
|
||||
|
@ -714,12 +730,12 @@ flohmarkt_ynh_copy_couchdb() {
|
|||
-H "Accept: application/json" -H "Content-Type: application/json" \
|
||||
-d '{ "create_target":true,"source" : "' -d"${old_name}" -d'",' \
|
||||
-d '"target":"' -d "${new_name}" -d'"}' --seperator=none \
|
||||
--line_match='"ok":true' "http://127.0.0.1:5984/_replicate"
|
||||
--wait_until='"ok":true' "http://127.0.0.1:5984/_replicate"
|
||||
}
|
||||
|
||||
# copy couchdb to new name and delete source
|
||||
flohmarkt_ynh_rename_couchdb() {
|
||||
local legacy_args='on'
|
||||
#REMOVEME? local legacy_args='on'
|
||||
local -A args_array=( [o]=old_name= [n]=new_name= )
|
||||
local new_name
|
||||
local old_name
|
||||
|
@ -733,9 +749,9 @@ flohmarkt_ynh_rename_couchdb() {
|
|||
flohmarkt_ynh_backup_old_couchdb() {
|
||||
flohmarkt_couchdb_rename_to="${app}_$(date '+%Y-%m-%d_%H-%M-%S_%N')"
|
||||
if flohmarkt_ynh_rename_couchdb "${app}" "${flohmarkt_couchdb_rename_to}"; then
|
||||
ynh_print_warn --message="renamed existing database ${app} to ${flohmarkt_couchdb_rename_to}"
|
||||
ynh_print_warn "renamed existing database ${app} to ${flohmarkt_couchdb_rename_to}"
|
||||
else
|
||||
ynh_die --message="could not rename existing couchdb database and cannot overwrite it"
|
||||
ynh_die "could not rename existing couchdb database and cannot overwrite it"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -751,14 +767,13 @@ flohmarkt_ynh_create_venv() {
|
|||
}
|
||||
|
||||
flohmarkt_ynh_venv_upgrade() {
|
||||
ynh_print_warn --message="flohmarkt_ynh_venv_upgrade: I'll sit here and do nothing without @grindholds confirmation"
|
||||
ynh_print_warn "flohmarkt_ynh_venv_upgrade: I'll sit here and do nothing without @grindholds confirmation"
|
||||
return
|
||||
(
|
||||
$flohmarkt_venv_dir/bin/python3 -m venv --upgrade-deps
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
# install requirements.txt in venv
|
||||
flohmarkt_ynh_venv_requirements() {
|
||||
(
|
||||
|
@ -774,24 +789,26 @@ flohmarkt_ynh_venv_requirements() {
|
|||
flohmarkt_ynh_urlwatch_cron() {
|
||||
mkdir -m 750 -p "${flohmarkt_urlwatch_dir}"
|
||||
chown ${app}:root "${flohmarkt_urlwatch_dir}"
|
||||
ynh_add_config --template="../conf/urlwatch_config.yaml" \
|
||||
ynh_config_add --template="urlwatch_config.yaml" \
|
||||
--destination="${flohmarkt_urlwatch_dir}/config.yaml"
|
||||
ynh_add_config --template="../conf/urlwatch_urls.yaml" \
|
||||
ynh_config_add --template="urlwatch_urls.yaml" \
|
||||
--destination="${flohmarkt_urlwatch_dir}/urls.yaml"
|
||||
ynh_add_config --template="../conf/urlwatch.cron" \
|
||||
ynh_config_add --template="urlwatch.cron" \
|
||||
--destination="${flohmarkt_cron_job}"
|
||||
chown root:root "${flohmarkt_cron_job}"
|
||||
chmod 755 "${flohmarkt_cron_job}"
|
||||
# run urlwatch once to initialize if cache file does not exist,
|
||||
|
||||
# but if sending email fails (like on CI) just warn. We do not want
|
||||
# to show the output that might contain passwords
|
||||
if ! [[ -s ${flohmarkt_urlwatch_dir}/cache.file ]] &&
|
||||
! ynh_exec_fully_quiet sudo -u ${app} urlwatch \
|
||||
! sudo -u ${app} urlwatch \
|
||||
--config=${flohmarkt_urlwatch_dir}/config.yaml \
|
||||
--urls=${flohmarkt_urlwatch_dir}/urls.yaml \
|
||||
--cache=${flohmarkt_urlwatch_dir}/cache.file
|
||||
|
||||
then
|
||||
ynh_print_warn --message="initial call to urlwatch failed"
|
||||
ynh_print_warn "initial call to urlwatch failed"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -799,6 +816,7 @@ flohmarkt_initialized() {
|
|||
flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \
|
||||
-l '"initialized":true' \
|
||||
"http://127.0.0.1:5984/${app}/instance_settings"
|
||||
|
||||
}
|
||||
|
||||
flohmarkt_ynh_get_initialization_key() {
|
||||
|
@ -817,39 +835,31 @@ flohmarkt_ynh_upgrade_path_ynh5() {
|
|||
# yunohost seems to move the venv dir automatically, but this
|
||||
# doesn't work, because the paths inside the venv are not adjusted
|
||||
# delete the old, not working venv and create a new one:
|
||||
ynh_secure_remove --file="$flohmarkt_venv_dir"
|
||||
ynh_safe_rm "$flohmarkt_venv_dir"
|
||||
flohmarkt_ynh_create_venv
|
||||
flohmarkt_ynh_venv_requirements
|
||||
# remove old $install_dir
|
||||
ynh_secure_remove --file="$flohmarkt_old_install"
|
||||
ynh_safe_rm "$flohmarkt_old_install"
|
||||
|
||||
# move logfile directory
|
||||
mkdir -p "$flohmarkt_log_dir"
|
||||
|
||||
# remove systemd.service - will be generated newly by upgrade
|
||||
# ynh_remove_systemd_config --service="$flohmarkt_old_service"
|
||||
ynh_systemd_action --action=stop --service_name="$flohmarkt_old_service"
|
||||
ynh_systemd_action --action=disable --service_name="$flohmarkt_old_service"
|
||||
ynh_secure_remove --file="/etc/systemd/system/multi-user.target.wants/flohmarkt.service"
|
||||
ynh_secure_remove --file="/etc/systemd/system/flohmarkt.service"
|
||||
# ynh_config_remove_systemd"$flohmarkt_old_service"
|
||||
ynh_systemctl --action=stop --service="$flohmarkt_old_service"
|
||||
ynh_systemctl --action=disable --service="$flohmarkt_old_service"
|
||||
ynh_safe_rm "/etc/systemd/system/multi-user.target.wants/flohmarkt.service"
|
||||
ynh_safe_rm "/etc/systemd/system/flohmarkt.service"
|
||||
# funktioniert nicht? issue?
|
||||
#ynh_systemd_action --action=daemon-reload
|
||||
#ynh_systemctl --action=daemon-reload
|
||||
# DEBUG + systemctl daemon-reload flohmarkt
|
||||
# WARNING Too many arguments.
|
||||
systemctl daemon-reload
|
||||
# unit flohmarkt is automatically appended and therefor this fails:
|
||||
#ynh_systemd_action --action=reset-failed
|
||||
#ynh_systemctl --action=reset-failed
|
||||
systemctl reset-failed
|
||||
|
||||
# create symlinks
|
||||
ln -s "$flohmarkt_install" "$flohmarkt_sym_install"
|
||||
ln -s "$flohmarkt_data_dir" "$flohmarkt_sym_data_dir"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -3,37 +3,40 @@
|
|||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
ynh_print_info --message="Declaring files to be backed up..."
|
||||
ynh_backup --src_path="$flohmarkt_install"
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_backup --src_path="/etc/logrotate.d/$app"
|
||||
ynh_backup --src_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
ynh_backup --src_path="/etc/systemd/system/$flohmarkt_filename.service"
|
||||
ynh_backup --src_path="${flohmarkt_cron_job}"
|
||||
ynh_backup --src_path="${flohmarkt_log_dir}"
|
||||
ynh_print_info "Declaring files to be backed up..."
|
||||
ynh_backup "$flohmarkt_install"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup "/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_backup "/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_backup "/etc/logrotate.d/$app"
|
||||
ynh_backup "/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
ynh_backup "/etc/systemd/system/$flohmarkt_filename.service"
|
||||
ynh_backup "${flohmarkt_cron_job}"
|
||||
ynh_backup "${flohmarkt_log_dir}"
|
||||
|
||||
# for the following backups we'll want to stop flohmarkt and couchdb
|
||||
# to guarentee a consistant state
|
||||
ynh_print_info --message="Stopping flohmarkt to backup data..."
|
||||
ynh_print_info "Stopping flohmarkt to backup data..."
|
||||
flohmarkt_ynh_stop_service
|
||||
|
||||
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/24
|
||||
# since this might be re-installed as a dependency during 'remove' and
|
||||
|
||||
# 'install' anew (like after a failed upgrade) we do not want to use
|
||||
# --is_big even thought the directories might be big because:
|
||||
# even thought the directories might be big because:
|
||||
# "don't want that your package does backup that part during ynh_backup_before_upgrade"
|
||||
# https://yunohost.org/en/packaging_apps_scripts_helpers#ynh-backup
|
||||
#
|
||||
# if this becomes a pain we'll need to stop deleting this directories on 'remove'
|
||||
# ynh_backup --src_path="$data_dir" --is_big
|
||||
ynh_backup --src_path="$flohmarkt_data_dir"
|
||||
|
||||
ynh_print_info --message="Dumping couchdb..."
|
||||
# if this becomes a pain we'll need to stop deleting this directories on 'remove'
|
||||
# ynh_backup "$data_dir"
|
||||
|
||||
ynh_backup "$flohmarkt_data_dir"
|
||||
|
||||
ynh_print_info "Dumping couchdb..."
|
||||
flohmarkt_ynh_dump_couchdb
|
||||
|
||||
ynh_print_info --message="Starting flohmarkt..."
|
||||
ynh_print_info "Starting flohmarkt..."
|
||||
flohmarkt_ynh_start_service
|
||||
|
||||
ynh_print_info --message="Backup script completed for $app."
|
||||
ynh_print_info "Backup script completed for $app."
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
source /etc/yunohost/apps/$app/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
ynh_abort_if_errors
|
||||
#REMOVEME? ynh_abort_if_errors
|
||||
|
||||
# my code starts here:
|
||||
|
||||
|
@ -11,7 +11,9 @@ get__flohmarkt_initial_setup_url(){
|
|||
local init_key="$(flohmarkt_ynh_get_initialization_key)"
|
||||
# TODO: wenn leer, dann etwas anderes zurückgeben
|
||||
if ! [[ -v init_key ]] ||
|
||||
|
||||
[[ "${init_key}" == 'null' ]] ||
|
||||
|
||||
[[ -z "${init_key}" ]]
|
||||
then
|
||||
if flohmarkt_initialized; then
|
||||
|
|
|
@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers
|
|||
if [[ -e /opt/couchdb ]] || pgrep epmd > /dev/null || pgrep beam.smp || dpkg-query -W couchdb > /dev/null 2>&1 \
|
||||
&& ! [[ -e /opt/couchdb/etc/local.d/05-flohmarkt.ini ]];
|
||||
then
|
||||
ynh_die --message="CouchDB already installed on this host - will not proceed."
|
||||
ynh_die "CouchDB already installed on this host - will not proceed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -21,17 +21,17 @@ fi
|
|||
# → there's no way to get the admin password later if sometimes in the future deleting
|
||||
# the app will delete its specific database only (instead of the whole couchdb server as
|
||||
# of now in the earliest versions of the integration).
|
||||
ynh_app_setting_set --app=$app --key=password_couchdb_admin --value="$password_couchdb_admin"
|
||||
ynh_app_setting_set --key=password_couchdb_admin --value="$password_couchdb_admin"
|
||||
|
||||
# get port, admin_pw for already installed couchdb
|
||||
# skip the installation steps below
|
||||
ynh_script_progression --message="Installing CouchDB..." --weight=60
|
||||
ynh_script_progression "Installing CouchDB..."
|
||||
|
||||
# A CouchDB node has an Erlang magic cookie value set at startup.
|
||||
# This value must match for all nodes in the cluster. If they do not match,
|
||||
# attempts to connect the node to the cluster will be rejected.
|
||||
couchdb_magic_cookie=$(ynh_string_random --length=23 --filter='A-Za-z0-9_')
|
||||
ynh_app_setting_set --app=$app --key=couchdb_magic_cookie --value="$couchdb_magic_cookie"
|
||||
ynh_app_setting_set --key=couchdb_magic_cookie --value="$couchdb_magic_cookie"
|
||||
|
||||
# update couchdb dpkg
|
||||
flohmarkt_ynh_up_inst_couchdb
|
||||
|
@ -40,24 +40,24 @@ flohmarkt_ynh_up_inst_couchdb
|
|||
flohmarkt_ynh_stop_couchdb
|
||||
|
||||
# add couchdb configuration
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=2
|
||||
ynh_script_progression "Adding $app's configuration..."
|
||||
# customize couchdb config
|
||||
ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
ynh_config_add --template="05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
|
||||
chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
|
||||
|
||||
# restart couchdb to pick up changes
|
||||
ynh_script_progression --message="Starting CouchDB..." --weight=2
|
||||
ynh_script_progression "Starting CouchDB..."
|
||||
flohmarkt_ynh_start_couchdb
|
||||
|
||||
# get flohmarkt
|
||||
# suspecting that this deletes all other sources for YNH_APP_ID
|
||||
ynh_script_progression --message="Downloading flohmarkt..." --weight=2
|
||||
ynh_script_progression "Downloading flohmarkt..."
|
||||
ynh_setup_source --dest_dir="$flohmarkt_app_dir"
|
||||
|
||||
# setup python environment for flohmarkt
|
||||
ynh_script_progression --message="Creating python venv..." --weight=2
|
||||
ynh_secure_remove "$flohmarkt_venv_dir"
|
||||
ynh_script_progression "Creating python venv..."
|
||||
ynh_safe_rm "$flohmarkt_venv_dir"
|
||||
flohmarkt_ynh_create_venv
|
||||
flohmarkt_ynh_venv_upgrade
|
||||
flohmarkt_ynh_venv_requirements
|
||||
|
@ -65,65 +65,65 @@ flohmarkt_ynh_venv_requirements
|
|||
# JwtSecret
|
||||
# workaround for https://github.com/YunoHost/issues/issues/2379
|
||||
jwtsecret=$(ynh_string_random -l 200 -f 'a-zA-Z0-9/+'; ynh_string_random -l 142 -f 'a-zA-Z0-9/+'; echo -n '==')
|
||||
ynh_app_setting_set --app=$app --key=jwtsecret --value="$jwtsecret"
|
||||
ynh_app_setting_set --key=jwtsecret --value="$jwtsecret"
|
||||
|
||||
password_couchdb_flohmarkt=$(ynh_string_random --length=31 --filter='A-Za-z0-9_.:,')
|
||||
ynh_app_setting_set --app=$app --key=password_couchdb_flohmarkt --value="$password_couchdb_flohmarkt"
|
||||
ynh_app_setting_set --key=password_couchdb_flohmarkt --value="$password_couchdb_flohmarkt"
|
||||
|
||||
# generate flohmarkt.conf
|
||||
ynh_script_progression --message="Adding flohmarkt.conf configuration..." --weight=2
|
||||
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
|
||||
ynh_script_progression "Adding flohmarkt.conf configuration..."
|
||||
ynh_config_add --template="flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
|
||||
|
||||
# setup couchdb
|
||||
ynh_script_progression --message="Setup couchdb database and user for flohmarkt..." --weight=2
|
||||
ynh_script_progression "Setup couchdb database and user for flohmarkt..."
|
||||
flohmarkt_ynh_initialize_couchdb
|
||||
|
||||
# SETUP LOGROTATE
|
||||
ynh_script_progression --message="Configuring log rotation..." --weight=2
|
||||
ynh_script_progression "Configuring log rotation..."
|
||||
# Use logrotate to manage application logfile(s)
|
||||
ynh_use_logrotate --logfile=$flohmarkt_logfile
|
||||
ynh_config_add_logrotate $flohmarkt_logfile
|
||||
|
||||
# NGINX CONFIGURATION
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=3
|
||||
ynh_script_progression "Configuring NGINX web server..."
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
ynh_config_add_nginx
|
||||
|
||||
# systemd.service
|
||||
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
||||
ynh_script_progression "Configuring $app's systemd service..."
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config --service=$flohmarkt_filename
|
||||
ynh_config_add_systemd --service=$flohmarkt_filename
|
||||
# integrate into yunohost
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
ynh_script_progression "Integrating service in YunoHost..."
|
||||
yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
|
||||
|
||||
# logfile contains possibly the secret setup URL
|
||||
ynh_script_progression --message="Setting permissions on logfile..." --weight=2
|
||||
ynh_script_progression "Setting permissions on logfile..."
|
||||
mkdir -m755 -p "$flohmarkt_log_dir"
|
||||
touch "$flohmarkt_logfile"
|
||||
chown root:$app "$flohmarkt_logfile"
|
||||
chmod 660 "$flohmarkt_logfile"
|
||||
|
||||
# set file permissions for install dir
|
||||
ynh_script_progression --message="Setting permissions on install directory..." --weight=2
|
||||
ynh_script_progression "Setting permissions on install directory..."
|
||||
flohmarkt_ynh_set_permission
|
||||
|
||||
# SETUP FAIL2BAN
|
||||
ynh_script_progression --message="Configuring Fail2Ban..." --weight=3
|
||||
ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
|
||||
ynh_script_progression "Configuring Fail2Ban..."
|
||||
ynh_config_add_fail2ban --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden'
|
||||
|
||||
# symlink data_dir and install_dir to make it easier to find the
|
||||
# files for a certain domain/path
|
||||
ynh_script_progression --message="Creating symlinks..." --weight=1
|
||||
ynh_script_progression "Creating symlinks..."
|
||||
flohmarkt_ynh_create_symlinks
|
||||
|
||||
# start service
|
||||
ynh_script_progression --message="Debug before starting flohmarkt..." --weight=1
|
||||
ynh_script_progression "Debug before starting flohmarkt..."
|
||||
ls -l $flohmarkt_logfile /bin/bash /usr/bin/bash || true
|
||||
ynh_script_progression --message="Starting flohmarkt..." --weight=10
|
||||
ynh_script_progression "Starting flohmarkt..."
|
||||
flohmarkt_ynh_start_service
|
||||
|
||||
# integrate urlwatch
|
||||
ynh_script_progression --message="Configure urlwatch and its cron job..." --weight=1
|
||||
ynh_script_progression "Configure urlwatch and its cron job..."
|
||||
flohmarkt_ynh_urlwatch_cron
|
||||
|
||||
ynh_script_progression --message="Installation of $id completed" --last
|
||||
ynh_script_progression "Installation of $id completed"
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
@ -14,53 +8,54 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
# REMOVE SERVICE INTEGRATION IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing system configurations related to $app..." --weight=5
|
||||
ynh_script_progression "Removing system configurations related to $app..."
|
||||
|
||||
# Stop flohmarkt service
|
||||
ynh_script_progression --message="Stopping $app..." --weight=2
|
||||
ynh_script_progression "Stopping $app..."
|
||||
yunohost service stop $flohmarkt_filename
|
||||
|
||||
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
|
||||
if ynh_exec_warn_less yunohost service status $flohmarkt_filename >/dev/null; then
|
||||
ynh_script_progression --message="Removing $app service integration..." --weight=2
|
||||
ynh_remove_systemd_config --service=$flohmarkt_filename
|
||||
if ynh_hide_warnings yunohost service status $flohmarkt_filename >/dev/null; then
|
||||
ynh_script_progression "Removing $app service integration..."
|
||||
ynh_config_remove_systemd$flohmarkt_filename
|
||||
yunohost service remove $flohmarkt_filename
|
||||
fi
|
||||
|
||||
# remove DB user for this instance - a new install will create a new user and permissions
|
||||
ynh_script_progression --message="Removing couchdb user..." --weight=2
|
||||
ynh_script_progression "Removing couchdb user..."
|
||||
flohmarkt_ynh_delete_couchdb_user
|
||||
|
||||
if [[ $YNH_APP_PURGE -eq 1 ]]; then
|
||||
ynh_script_progression --message="Purging couchdb database ..." --weight=2
|
||||
ynh_script_progression "Purging couchdb database ..."
|
||||
# remove DB
|
||||
flohmarkt_ynh_delete_couchdb_db
|
||||
# remove logfiles directory
|
||||
ynh_script_progression --message="Purging logfiles..." --weight=2
|
||||
ynh_secure_remove --file="${flohmarkt_log_dir}"
|
||||
ynh_script_progression "Purging logfiles..."
|
||||
ynh_safe_rm "${flohmarkt_log_dir}"
|
||||
else
|
||||
ynh_script_progression --message="Purge not selected - not deleting couchdb and logfiles..." --weight=1
|
||||
ynh_script_progression "Purge not selected - not deleting couchdb and logfiles..."
|
||||
fi
|
||||
|
||||
# Remove the app-specific logrotate config
|
||||
ynh_script_progression --message="Removing logrotate configuration..." --weight=2
|
||||
ynh_remove_logrotate
|
||||
ynh_script_progression "Removing logrotate configuration..."
|
||||
ynh_config_remove_logrotate
|
||||
|
||||
# Remove the dedicated NGINX config
|
||||
ynh_script_progression --message="Removing nginx configuration..." --weight=2
|
||||
ynh_remove_nginx_config
|
||||
ynh_script_progression "Removing nginx configuration..."
|
||||
ynh_config_remove_nginx
|
||||
|
||||
# Remove the dedicated Fail2Ban config
|
||||
ynh_script_progression --message="Removing fail2ban configuration..." --weight=2
|
||||
ynh_remove_fail2ban_config
|
||||
ynh_script_progression "Removing fail2ban configuration..."
|
||||
ynh_config_remove_fail2ban
|
||||
|
||||
# remove systemd service
|
||||
ynh_script_progression --message="Removing systemd.service directory..." --weight=2
|
||||
ynh_remove_systemd_config
|
||||
ynh_script_progression "Removing systemd.service directory..."
|
||||
ynh_config_remove_systemd
|
||||
|
||||
# remove symlinks
|
||||
ynh_script_progression --message="Removing symlinks..." --weight=2
|
||||
# no ynh_secure_remove:
|
||||
ynh_script_progression "Removing symlinks..."
|
||||
# no ynh_safe_rm :
|
||||
|
||||
# https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/52
|
||||
rm "$flohmarkt_sym_install" || true
|
||||
rm "$flohmarkt_sym_data_dir" || true
|
||||
|
@ -70,4 +65,4 @@ rm "$flohmarkt_sym_log_dir" || true
|
|||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removal of $app completed" --last
|
||||
ynh_script_progression "Removal of $app completed"
|
||||
|
|
|
@ -4,42 +4,43 @@ source ../settings/scripts/_common.sh
|
|||
source /usr/share/yunohost/helpers
|
||||
|
||||
# reinstall couchdb
|
||||
ynh_script_progression --message="Reinstalling couchdb..." --weight=40
|
||||
ynh_script_progression "Reinstalling couchdb..."
|
||||
flohmarkt_ynh_up_inst_couchdb
|
||||
|
||||
# add couchdb configuration
|
||||
if ! [[ -e /opt/couchdb/etc/local.d/05-flohmarkt.ini ]]; then
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=2
|
||||
ynh_script_progression "Adding $app's configuration..."
|
||||
|
||||
flohmarkt_ynh_stop_couchdb
|
||||
|
||||
ynh_restore_file --origin_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
ynh_restore "/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
|
||||
chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
|
||||
|
||||
ynh_script_progression --message="Starting couchdb..." --weight=4
|
||||
ynh_script_progression "Starting couchdb..."
|
||||
flohmarkt_ynh_start_couchdb
|
||||
else
|
||||
ynh_script_progression --message="CouchDB configuration file already exists." --weight=1
|
||||
ynh_script_progression "CouchDB configuration file already exists."
|
||||
fi
|
||||
|
||||
# if exists rename existing couchdb
|
||||
ynh_script_progression --message="Check if old database exists..." --weight=1
|
||||
ynh_script_progression "Check if old database exists..."
|
||||
if flohmarkt_ynh_exists_couchdb_db; then
|
||||
|
||||
flohmarkt_ynh_backup_old_couchdb
|
||||
fi
|
||||
|
||||
# restore couchdb from json
|
||||
ynh_script_progression --message="Importing couchdb from json backup..." --weight=8
|
||||
ynh_script_progression "Importing couchdb from json backup..."
|
||||
flohmarkt_ynh_restore_couchdb
|
||||
|
||||
# RESTORE THE APP MAIN DIR
|
||||
ynh_script_progression --message="Restoring the app main directory..." --weight=10
|
||||
ynh_restore_file --origin_path="$flohmarkt_install"
|
||||
ynh_script_progression "Restoring the app main directory..."
|
||||
ynh_restore "$flohmarkt_install"
|
||||
|
||||
# RESTORE THE DATA DIRECTORY
|
||||
ynh_script_progression --message="Restoring the data directory..." --weight=1
|
||||
ynh_restore_file --origin_path="$flohmarkt_data_dir" --not_mandatory
|
||||
ynh_script_progression "Restoring the data directory..."
|
||||
ynh_restore "$flohmarkt_data_dir" || true
|
||||
mkdir -p $data_dir
|
||||
|
||||
# restore logfiles
|
||||
|
@ -48,44 +49,44 @@ mkdir -p $data_dir
|
|||
# directory and file so that the systemd.service can redirect STDOUT to the file.
|
||||
# If the logfile(or maybe just -directory?) is missing the service will not start
|
||||
# on a fresh install, because directory and/or file do not exist.
|
||||
ynh_script_progression --message="Restoring log directory and logfiles..." --weight=1
|
||||
ynh_restore_file --origin_path="$flohmarkt_log_dir" --not_mandatory
|
||||
ynh_script_progression "Restoring log directory and logfiles..."
|
||||
ynh_restore "$flohmarkt_log_dir" || true
|
||||
mkdir -p -m755 "$flohmarkt_log_dir"
|
||||
touch "$flohmarkt_logfile"
|
||||
# logfile contains possibly the secret setup URL
|
||||
chmod 640 "$flohmarkt_logfile"
|
||||
|
||||
# RESTORE FAIL2BAN CONFIGURATION
|
||||
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=2
|
||||
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_systemd_action --action=restart --service_name=fail2ban
|
||||
ynh_script_progression "Restoring the Fail2Ban configuration..."
|
||||
ynh_restore "/etc/fail2ban/jail.d/$app.conf"
|
||||
ynh_restore "/etc/fail2ban/filter.d/$app.conf"
|
||||
ynh_systemctl --action=restart --service=fail2ban
|
||||
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_script_progression "Restoring the NGINX web server configuration..."
|
||||
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||
ynh_script_progression "Restoring the logrotate configuration..."
|
||||
ynh_restore "/etc/logrotate.d/$app"
|
||||
|
||||
# restore flohmarkt systemd service and integrate service into yunohost
|
||||
ynh_script_progression --message="Restoring flohmarkt.service and integrating service into YunoHost..." --weight=1
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$flohmarkt_filename.service"
|
||||
ynh_systemd_action --action=enable --service_name=$flohmarkt_filename
|
||||
ynh_script_progression "Restoring flohmarkt.service and integrating service into YunoHost..."
|
||||
ynh_restore "/etc/systemd/system/$flohmarkt_filename.service"
|
||||
ynh_systemctl --action=enable --service=$flohmarkt_filename
|
||||
yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
|
||||
flohmarkt_ynh_start_service
|
||||
|
||||
# RELOAD NGINX
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
ynh_script_progression "Reloading NGINX web server..."
|
||||
ynh_systemctl --service=nginx --action=reload
|
||||
|
||||
# create symlinks
|
||||
ynh_script_progression --message="Creating symlinks..." --weight=1
|
||||
ynh_script_progression "Creating symlinks..."
|
||||
flohmarkt_ynh_create_symlinks
|
||||
|
||||
# restore cronjob file for urlwatch
|
||||
ynh_script_progression --message="Restoring cronjob for urlwatch..." --weight=1
|
||||
ynh_restore_file --origin_path="${flohmarkt_cron_job}"
|
||||
ynh_script_progression "Restoring cronjob for urlwatch..."
|
||||
ynh_restore "${flohmarkt_cron_job}"
|
||||
|
||||
ynh_script_progression --message="Restoration completed for $app" --last
|
||||
ynh_script_progression "Restoration completed for $app"
|
||||
|
|
|
@ -7,9 +7,8 @@ source /usr/share/yunohost/helpers
|
|||
# UPGRADE_APP if the upstream app version has changed
|
||||
# DOWNGRADE
|
||||
# UPGRADE_SAME
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
|
||||
ynh_script_progression "Stopping flohmarkt and CouchDB..."
|
||||
# stop flohmarkt
|
||||
flohmarkt_ynh_stop_service
|
||||
# stop couchdb
|
||||
|
@ -18,76 +17,76 @@ flohmarkt_ynh_stop_couchdb
|
|||
# Upgrade ynh4 → ynh5, change of paths and filenames
|
||||
# https://matrix.to/#/!PauySEslPVuJCJCwlZ:matrix.org/$auU_rSL6MACt9wkyFGlCQbO8ivFlU0ztYW74TimZdcM?via=matrix.org&via=aria-net.org&via=sans-nuage.fr
|
||||
# and follow-ups
|
||||
if ynh_compare_current_package_version --comparison lt --version 0.0~ynh5 &&
|
||||
if ynh_app_upgrading_from_version_before 0.0~ynh5 &&
|
||||
( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
|
||||
then
|
||||
flohmarkt_ynh_upgrade_path_ynh5
|
||||
fi
|
||||
|
||||
# upgrade couchdb
|
||||
ynh_script_progression --message="Upgrading CouchDB..." --weight=50
|
||||
ynh_script_progression "Upgrading CouchDB..."
|
||||
flohmarkt_ynh_up_inst_couchdb
|
||||
|
||||
# stop couchdb
|
||||
ynh_script_progression --message="Stop couchdb before updating configuration file..." --weight=1
|
||||
ynh_script_progression "Stop couchdb before updating configuration file..."
|
||||
flohmarkt_ynh_stop_couchdb
|
||||
|
||||
# upgrade couchdb config
|
||||
ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
|
||||
ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
ynh_script_progression "Updating couchdb configuration file..."
|
||||
ynh_config_add --template="05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
|
||||
chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
|
||||
chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
|
||||
|
||||
# start couchdb
|
||||
ynh_script_progression --message="Starting couchdb..." --weight=1
|
||||
ynh_script_progression "Starting couchdb..."
|
||||
flohmarkt_ynh_start_couchdb
|
||||
|
||||
# install upgrade for flohmarkt
|
||||
ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
|
||||
ynh_script_progression "Upgrading flohmarkt..."
|
||||
ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
|
||||
|
||||
ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=6
|
||||
ynh_script_progression "Upgrading flohmarkt python dependencies..."
|
||||
# upgrade python environment / install new dependencies
|
||||
flohmarkt_ynh_venv_upgrade
|
||||
flohmarkt_ynh_venv_requirements
|
||||
|
||||
# upgrade flohmarkt.conf
|
||||
ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
|
||||
ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
|
||||
ynh_script_progression "Upgrading flohmarkt configuration..."
|
||||
ynh_config_add --template="flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf"
|
||||
|
||||
ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
|
||||
ynh_script_progression "Upgrading flohmarkt couchdb..."
|
||||
flohmarkt_ynh_initialize_couchdb
|
||||
|
||||
# set file permissions for install dir
|
||||
flohmarkt_ynh_set_permission
|
||||
|
||||
# systemd service upgrade
|
||||
ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
|
||||
ynh_add_systemd_config --service=$flohmarkt_filename
|
||||
ynh_script_progression "Upgrading flohmarkt systemd service..."
|
||||
ynh_config_add_systemd --service=$flohmarkt_filename
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
|
||||
ynh_script_progression "Integrating service in YunoHost..."
|
||||
yunohost service add $flohmarkt_filename --description="A decentral federated small advertisement platform" --log="$flohmarkt_logfile"
|
||||
|
||||
# upgrade logrotate
|
||||
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
||||
ynh_script_progression "Upgrading logrotate configuration..."
|
||||
# Use logrotate to manage app-specific logfile(s)
|
||||
ynh_use_logrotate --non-append
|
||||
ynh_config_add_logrotate
|
||||
|
||||
# upgrade nginx configuration
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
||||
ynh_add_nginx_config
|
||||
ynh_script_progression "Upgrading NGINX web server configuration..."
|
||||
ynh_config_add_nginx
|
||||
|
||||
# UPGRADE FAIL2BAN
|
||||
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
|
||||
ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden' --max_retry=5
|
||||
ynh_script_progression "Reconfiguring Fail2Ban..."
|
||||
ynh_config_add_fail2ban --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST>:\d+ - "POST /token HTTP/\d+\.\d+" 403 Forbidden'
|
||||
|
||||
# start flohmarkt
|
||||
ynh_script_progression --message="Starting flohmarkt..." --weight=3
|
||||
ynh_script_progression "Starting flohmarkt..."
|
||||
flohmarkt_ynh_start_service
|
||||
|
||||
# check if admin_mail is already set and if not use a default
|
||||
if ! [[ -v admin_mail ]] || [[ -z "${admin_mail}" ]]; then
|
||||
ynh_print_warn --message="new setting admin_mail - trying to set a default"
|
||||
ynh_print_warn "new setting admin_mail - trying to set a default"
|
||||
# try to read admin email address from flohmarkt installation
|
||||
admin_mail=$( flohmarkt_ynh_local_curl -n -m POST -u admin -p "$password_couchdb_admin" \
|
||||
-H "Accept: application/json" -H "Content-Type: application/json" -s none \
|
||||
|
@ -99,12 +98,12 @@ if ! [[ -v admin_mail ]] || [[ -z "${admin_mail}" ]]; then
|
|||
# use yunohost admin group
|
||||
admin_mail="admin@$(yunohost domain main-domain | cut -d' ' -f2)"
|
||||
fi
|
||||
ynh_print_warn --message="using ${admin_mail} for new setting admin_mail"
|
||||
ynh_app_setting_set --app=$app --key=admin_mail --value="${admin_mail}"
|
||||
ynh_print_warn "using ${admin_mail} for new setting admin_mail"
|
||||
ynh_app_setting_set --key=admin_mail --value="${admin_mail}"
|
||||
fi
|
||||
|
||||
# upgrade urlwatch configuration
|
||||
ynh_script_progression --message="Upgrade urlwatch configuration..." --weight=1
|
||||
ynh_script_progression "Upgrade urlwatch configuration..."
|
||||
flohmarkt_ynh_urlwatch_cron
|
||||
|
||||
ynh_script_progression --message="Upgrade of $app completed" --last
|
||||
ynh_script_progression "Upgrade of $app completed"
|
||||
|
|
Loading…
Reference in a new issue