From 311162020b25bfa7bb27a90e9dd28384aac260db Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 24 Nov 2020 12:39:44 +0100 Subject: [PATCH 1/4] add option to pass a list of skylinks for blocklist --- scripts/blocklist-skylink.sh | 45 ++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/scripts/blocklist-skylink.sh b/scripts/blocklist-skylink.sh index 296354ac..6a3c7d42 100755 --- a/scripts/blocklist-skylink.sh +++ b/scripts/blocklist-skylink.sh @@ -3,14 +3,49 @@ set -e # exit on first error if [ -z "$1" ]; then - echo "Please provide a skylink to blocklist" && exit 1 + echo "Please provide either a skylink or file with skylinks separated by blank lines" && exit 1 fi +######################################################### +# read either a file containing skylinks separated by new +# lines or a single skylink and put them in an array +######################################################### +skylinks=() +if test -f "$1"; then + OLDIFS=$IFS + IFS=',' + while read line + do + if [[ $line =~ ([a-zA-Z0-9_-]{46}) ]]; then + skylinks+=("$BASH_REMATCH") + else + echo "Incorrect skylink: $line" && exit 1 + fi + done < $1; + IFS=$OLDIFS +else + skylinks=("$1") # just single skylink passed as input argument +fi + +#################################################### +# iterate through all servers and block the skylinks +#################################################### for server in "germany.siasky.net" "helsinki.siasky.net" "us-west.siasky.net" "us-va-1.siasky.net" "us-pa-1.siasky.net" "us-pa-2.siasky.net" "siasky.xyz"; do - echo "⌁ Blocking skylink on ${server}" - ssh -q -t user@${server} 'docker exec sia siac skynet blocklist add '$1'' - ssh -q -t user@${server} 'rm -rf /home/user/skynet_webportal/docker/data/nginx/cache' # prune nginx cache + ############################################################# + # iterate throught all skylinks and add each one to blocklist + ############################################################# + for skylink in "${skylinks[@]}"; + do + echo ".. ⌁ Blocking skylink ${skylink} on ${server}" + ssh -q -t user@${server} 'docker exec sia siac skynet blocklist add '$skylink'' + done + + ###################################################### + # purge nginx cache after all the skylinks are blocked + ###################################################### + ssh -q -t user@${server} 'rm -rf /home/user/skynet_webportal/docker/data/nginx/cache' + echo ".... 🗑️ Pruned nginx cache on ${server}" done -echo "✓ All portals succesfully blocklisted $1" +echo "✓ All done !" From 24ab5063e0b4092e3db9627cd16c1bc5d948d5c6 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 24 Nov 2020 14:40:39 +0100 Subject: [PATCH 2/4] fix cache prune docker command --- scripts/blocklist-skylink.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/blocklist-skylink.sh b/scripts/blocklist-skylink.sh index 6a3c7d42..8cc19eda 100755 --- a/scripts/blocklist-skylink.sh +++ b/scripts/blocklist-skylink.sh @@ -44,7 +44,7 @@ do ###################################################### # purge nginx cache after all the skylinks are blocked ###################################################### - ssh -q -t user@${server} 'rm -rf /home/user/skynet_webportal/docker/data/nginx/cache' + ssh -q -t user@${server} 'docker exec nginx sh -c "rm -rf /data/nginx/cache/*"' echo ".... 🗑️ Pruned nginx cache on ${server}" done From fd404fa2ea55b13505b8327df0a6311dede8061b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Tue, 24 Nov 2020 14:51:20 +0100 Subject: [PATCH 3/4] wording: blank line -> new line --- scripts/blocklist-skylink.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/blocklist-skylink.sh b/scripts/blocklist-skylink.sh index 8cc19eda..f61f9816 100755 --- a/scripts/blocklist-skylink.sh +++ b/scripts/blocklist-skylink.sh @@ -3,7 +3,7 @@ set -e # exit on first error if [ -z "$1" ]; then - echo "Please provide either a skylink or file with skylinks separated by blank lines" && exit 1 + echo "Please provide either a skylink or file with skylinks separated by new lines" && exit 1 fi ######################################################### From 5a203a95834935414ea710b464c274318a24995c Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 24 Nov 2020 15:14:22 +0100 Subject: [PATCH 4/4] show line number if bad skylink is found --- scripts/blocklist-skylink.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/blocklist-skylink.sh b/scripts/blocklist-skylink.sh index f61f9816..097cf069 100755 --- a/scripts/blocklist-skylink.sh +++ b/scripts/blocklist-skylink.sh @@ -14,13 +14,15 @@ skylinks=() if test -f "$1"; then OLDIFS=$IFS IFS=',' + line_number=1 while read line do if [[ $line =~ ([a-zA-Z0-9_-]{46}) ]]; then skylinks+=("$BASH_REMATCH") else - echo "Incorrect skylink: $line" && exit 1 + echo "Incorrect skylink at line ${line_number}: $line" && exit 1 fi + let line_number+=1 done < $1; IFS=$OLDIFS else