Last active
September 26, 2024 10:59
-
-
Save LaurenceJJones/6960107296145e8e365009973b9d7f6d to your computer and use it in GitHub Desktop.
crowdsec debian symlinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TMP_DIR=$(mktemp -d) | |
dump_tree() { | |
cscli "$1" list --output raw | cut -d, -f1 | grep -v ^name$ > "$TMP_DIR/$1.txt" | |
} | |
check_root() { | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
} | |
load_tree() { | |
## We always remove the folder and recreate | |
rm -rf "/etc/crowdsec/$1" && mkdir -p "/etc/crowdsec/$1" | |
## Check if the temporary file has contents to avoid fatal in cscli | |
if [ -s "$TMP_DIR/$1.txt" ]; then | |
#shellcheck disable=SC2046 | |
cscli "$1" install --force --ignore $(cat "$TMP_DIR/$1.txt") | |
fi; | |
} | |
check_root | |
for i in parsers scenarios postoverflows collections; do | |
dump_tree "$i" | |
load_tree "$i" | |
done | |
rm -rf "$TMP_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment