1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nodebb_ynh.git synced 2024-09-03 19:46:29 +02:00
nodebb_ynh/scripts/_common.sh

61 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
2021-03-25 17:00:29 +01:00
#=================================================
# COMMON VARIABLES
#=================================================
2021-03-25 17:00:29 +01:00
# dependencies used by the app
2021-08-31 21:26:01 +02:00
pkg_dependencies="postgresql redis-server"
2021-08-09 17:18:49 +02:00
nodejs_version=14
2021-03-25 20:22:23 +01:00
#=================================================
2021-03-25 17:00:29 +01:00
# PERSONAL HELPERS
#=================================================
#=================================================
2017-12-27 13:08:59 +01:00
# EXPERIMENTAL HELPERS
#=================================================
2021-08-31 16:30:08 +02:00
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
2021-07-01 23:26:53 +02:00
2021-08-31 16:30:08 +02:00
# get the first available redis database
2021-07-01 23:26:53 +02:00
#
2021-08-31 16:30:08 +02:00
# 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)
2021-07-01 23:26:53 +02:00
2021-08-31 16:30:08 +02:00
# get the num
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
2021-07-01 23:26:53 +02:00
2021-08-31 16:30:08 +02:00
db=0
# default Debian setting is 15 databases
for i in $(seq 0 "$max")
do
if ! echo "$result" | grep -q "db$i"
2021-07-01 23:26:53 +02:00
then
2021-08-31 16:30:08 +02:00
db=$i
break 1
2021-07-01 23:26:53 +02:00
fi
2021-08-31 16:30:08 +02:00
db=-1
done
2021-07-01 23:26:53 +02:00
2021-08-31 16:30:08 +02:00
test "$db" -eq -1 && ynh_die --message="No available Redis databases..."
2021-07-01 23:26:53 +02:00
2021-08-31 16:30:08 +02:00
echo "$db"
2021-07-01 23:26:53 +02:00
}
2021-08-31 16:30:08 +02:00
# Create a master password and set up global settings
# Please always call this script in install and restore scripts
2021-07-01 23:26:53 +02:00
#
2021-08-31 16:30:08 +02:00
# usage: ynh_redis_remove_db database
# | arg: database - the database to erase
ynh_redis_remove_db() {
local db=$1
redis-cli -n "$db" flushall
2021-07-01 23:26:53 +02:00
}