Skip to content

Commit 0d2c2da

Browse files
authored
Migration script from debian/ubuntu package 1.4.6 (#3420)
1 parent 0106c40 commit 0d2c2da

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

debian/migrate-hub.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env sh
2+
3+
# This script is provided (only in the source distribution) as an ad-hoc solution
4+
# to migrate an installation from the crowdsec package maintained in the debian repositories
5+
# to the official crowdsec repository.
6+
7+
set -eu
8+
9+
if [ ! -d /var/lib/crowdsec/hub/ ]; then
10+
echo "You don't have a hub directory to migrate."
11+
echo
12+
echo "Use this script only if you upgrade from the crowdsec package included in the debian repositories."
13+
exit 1
14+
fi
15+
16+
# Download everything on the new hub but don't install anything yet
17+
18+
echo "Downloading Hub content..."
19+
20+
for itemtype in $(cscli hub types -o raw); do
21+
ALL_ITEMS=$(cscli "$itemtype" list -a -o raw | tail +2 | cut -d, -f1)
22+
if [ -n "${ALL_ITEMS}" ]; then
23+
# shellcheck disable=SC2086
24+
cscli "$itemtype" install \
25+
$ALL_ITEMS \
26+
--download-only -y
27+
fi
28+
done
29+
30+
# Fix links
31+
32+
BASEDIR=/etc/crowdsec/
33+
OLD_PATH=/var/lib/crowdsec/hub/
34+
NEW_PATH=/etc/crowdsec/hub/
35+
36+
find "$BASEDIR" -type l 2>/dev/null | while IFS= read -r link
37+
do
38+
target="$(readlink "$link")" || continue
39+
40+
case "$target" in
41+
"$OLD_PATH"*)
42+
suffix="${target#"$OLD_PATH"}"
43+
new_target="${NEW_PATH}${suffix}"
44+
45+
if [ -e "$target" ]; then
46+
continue
47+
fi
48+
49+
if [ ! -e "$new_target" ]; then
50+
continue
51+
fi
52+
53+
echo "Update symlink: $link"
54+
ln -sf "$new_target" "$link"
55+
;;
56+
*)
57+
;;
58+
esac
59+
done
60+
61+
# upgrade tainted collections
62+
63+
cscli hub upgrade --force

0 commit comments

Comments
 (0)