also conditionally run hub upgrade

This commit is contained in:
Sebastien Blot 2024-04-19 10:49:25 +02:00
parent a895b16fc7
commit 3ce82cb400
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A

View file

@ -60,24 +60,44 @@ run_hub_update() {
fi fi
} }
run_hub_update_if_from_volume() { is_mounted() {
path=$(readlink -f "/etc/crowdsec/hub/.index.json") # even though it's unlikely, resolve symlink path=$(readlink -f "$1")
mounts=$(awk '{print $2}' /proc/mounts) mounts=$(awk '{print $2}' /proc/mounts)
while true; do while true; do
if grep -qE ^"$path"$ <<< "$mounts"; then if grep -qE ^"$path"$ <<< "$mounts"; then
echo "$path was found in a volume, running hub update" echo "$path was found in a volume"
run_hub_update
return 0 return 0
fi fi
path=$(dirname "$path") path=$(dirname "$path")
if [ "$path" = "/" ]; then if [ "$path" = "/" ]; then
echo "It looks like the hub index is not in a volume, skipping update"
return 1 return 1
fi fi
done done
return 1 #unreachable return 1 #unreachable
} }
run_hub_update_if_from_volume() {
is_mounted "/etc/crowdsec/hub/.index.json"
if [ $? -eq 0 ]; then
echo "Running hub update"
run_hub_update
else
echo "Skipping hub update, index file is not in a volume"
fi
}
run_hub_upgrade_if_from_volume() {
isfalse "$NO_HUB_UPGRADE" || return 0
is_mounted "/var/lib/crowdsec/data"
if [ $? -eq 0 ]; then
echo "Running hub upgrade"
cscli hub upgrade
else
echo "Skipping hub upgrade, data directory is not in a volume"
fi
}
# conf_get <key> [file_path] # conf_get <key> [file_path]
# retrieve a value from a file (by default $CONFIG_FILE) # retrieve a value from a file (by default $CONFIG_FILE)
conf_get() { conf_get() {
@ -339,10 +359,7 @@ conf_set_if "$PLUGIN_DIR" '.config_paths.plugin_dir = strenv(PLUGIN_DIR)'
## Install hub items ## Install hub items
run_hub_update_if_from_volume || true run_hub_update_if_from_volume || true
run_hub_upgrade_if_from_volume || true
if isfalse "$NO_HUB_UPGRADE"; then
cscli hub upgrade || true
fi
cscli_if_clean parsers install crowdsecurity/docker-logs cscli_if_clean parsers install crowdsecurity/docker-logs
cscli_if_clean parsers install crowdsecurity/cri-logs cscli_if_clean parsers install crowdsecurity/cri-logs