From 5160a5ac3eff3124212a6fcdd8272177bb5a7246 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 10 Jul 2021 18:50:02 +0200 Subject: [PATCH 1/3] Add redis helper --- conf/.env.example | 2 +- scripts/_common.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ scripts/install | 6 +++++- scripts/remove | 8 ++++++++ scripts/upgrade | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/conf/.env.example b/conf/.env.example index d3a70b1..6ccd22f 100644 --- a/conf/.env.example +++ b/conf/.env.example @@ -34,4 +34,4 @@ cache.handler="redis" cache.redis.host="127.0.0.1" cache.redis.password=null cache.redis.port=6379 -cache.redis.database=__REDIS_NUMBER__ +cache.redis.database=__REDIS_DB__ diff --git a/scripts/_common.sh b/scripts/_common.sh index dba399b..ed4ae6b 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -21,3 +21,45 @@ pkg_dependencies="redis-server redis-tools" #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +#================================================= +# REDIS HELPERS +#================================================= + +# get the first available redis database +# +# usage: ynh_redis_get_free_db +# | returns: the database number to use +ynh_redis_get_free_db() { + local result max db + result="$(redis-cli INFO keyspace)" + + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max") + do + if ! echo "$result" | grep -q "db$i" + then + db=$i + break 1 + fi + db=-1 + done + + test "$db" -eq -1 && ynh_die --message="No available Redis databases..." + + echo "$db" +} + +# Create a master password and set up global settings +# Please always call this script in install and restore scripts +# +# usage: ynh_redis_remove_db database +# | arg: database - the database to erase +ynh_redis_remove_db() { + local db=$1 + redis-cli -n "$db" flushall +} diff --git a/scripts/install b/scripts/install index ea993d1..c240925 100755 --- a/scripts/install +++ b/scripts/install @@ -111,7 +111,11 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= ynh_script_progression --message="Configuring Castopod..." --weight=1 -redis_number=$(( $YNH_APP_INSTANCE_NUMBER - 1 )) +# Configure redis +redis_db=$(ynh_redis_get_free_db) +ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" + +#redis_number=$(( $YNH_APP_INSTANCE_NUMBER - 1 )) ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env" chmod 600 $final_path/.env chown $app:www-data "$final_path/.env" diff --git a/scripts/remove b/scripts/remove index 884ea16..8b467da 100755 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) #================================================= # REMOVE THE MYSQL DATABASE @@ -29,6 +30,13 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +#================================================= +# REMOVE THE REDIS DATABASE +#================================================= +ynh_script_progression --message="Removing the Redis database..." --weight=1 + +ynh_redis_remove_db "$redis_db" + #================================================= # REMOVE DEPENDENCIES #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 91f8f16..a54125c 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) phpversion=$YNH_PHP_VERSION #================================================= @@ -121,7 +122,6 @@ ynh_add_fpm_config --package="$extra_php_dependencies" #================================================= ynh_script_progression --message="Configuring Castopod..." --weight=1 -redis_number=$(( $YNH_APP_INSTANCE_NUMBER - 1 )) ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env" chmod 600 $final_path/.env chown $app:www-data "$final_path/.env" From 7f446307b39cebaab8f1ecf8a09f4fbee24fb7ba Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Mon, 19 Jul 2021 12:16:31 +0200 Subject: [PATCH 2/3] 64 --- conf/app.src | 4 ++-- manifest.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conf/app.src b/conf/app.src index 15a8a25..7c1b5ab 100755 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://code.podlibre.org/podlibre/castopod-host/uploads/94954ec7cb77783cc9354d51a57e91b7/castopod-host-1.0.0-alpha.62.zip -SOURCE_SUM=8959db163b049a1e937da19fe7174402b8c7d8c1f8fbf74dd90dd50d2f3edda4 +SOURCE_URL=https://code.podlibre.org/podlibre/castopod-host/uploads/142d6a7830b73f74c03962c9c209ac87/castopod-host-1.0.0-alpha.64.zip +SOURCE_SUM=ca0151e8b52734f20a94a85c4981bcfe8895aa507d430c05276273af34c9ee37 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true diff --git a/manifest.json b/manifest.json index a2dc089..5d435a8 100755 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Hosting platform made for podcasters", "fr": "Plateforme d'hébergement conçue pour les podcasteurs" }, - "version": "1.0.0-62~ynh1", + "version": "1.0.0-64~ynh1", "url": "https://podlibre.org/", "upstream": { "license": "GPL-3.0-only", From 4eb6a48d5fe09a379573fcd1b9a1f4aaaf6d158f Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Mon, 19 Jul 2021 10:16:38 +0000 Subject: [PATCH 3/3] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 790423f..ea7629e 100755 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Hosting platform made for podcasters -**Shipped version:** 1.0.0-62~ynh1 +**Shipped version:** 1.0.0-64~ynh1 **Demo:** https://podcast.podlibre.org/@podlibre_fr diff --git a/README_fr.md b/README_fr.md index 50ef9a1..860cd45 100755 --- a/README_fr.md +++ b/README_fr.md @@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour Plateforme d'hébergement conçue pour les podcasteurs -**Version incluse :** 1.0.0-62~ynh1 +**Version incluse :** 1.0.0-64~ynh1 **Démo :** https://podcast.podlibre.org/@podlibre_fr