Merge pull request #534 from NebulousLabs/improve-skylink-block-script

add option to pass a list of skylinks for blocklist
This commit is contained in:
Karol Wypchło 2020-11-24 16:25:20 +01:00 committed by GitHub
commit 2968571a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 5 deletions

View File

@ -3,14 +3,51 @@
set -e # exit on first error set -e # exit on first error
if [ -z "$1" ]; then 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 new lines" && exit 1
fi 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=','
line_number=1
while read line
do
if [[ $line =~ ([a-zA-Z0-9_-]{46}) ]]; then
skylinks+=("$BASH_REMATCH")
else
echo "Incorrect skylink at line ${line_number}: $line" && exit 1
fi
let line_number+=1
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"; 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 do
echo "⌁ Blocking skylink on ${server}" #############################################################
ssh -q -t user@${server} 'docker exec sia siac skynet blocklist add '$1'' # iterate throught all skylinks and add each one to blocklist
ssh -q -t user@${server} 'rm -rf /home/user/skynet_webportal/docker/data/nginx/cache' # prune nginx cache #############################################################
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 done
echo "✓ All portals succesfully blocklisted $1" ######################################################
# purge nginx cache after all the skylinks are blocked
######################################################
ssh -q -t user@${server} 'docker exec nginx sh -c "rm -rf /data/nginx/cache/*"'
echo ".... 🗑️ Pruned nginx cache on ${server}"
done
echo "✓ All done !"