2020-06-01 09:17:44 +00:00
#! /usr/bin/env bash
2021-07-26 20:03:49 +00:00
# This script is meant to be used when manually adding a skylink to the
# blocklist on all the skynet web portals. The automatic script that is used to
# continuously sync a google sheets list with the blocklist on the web portals
# is /setup-scripts/blocklist-airtable.py
2020-06-01 09:17:44 +00:00
set -e # exit on first error
if [ -z " $1 " ] ; then
2020-11-24 13:51:20 +00:00
echo "Please provide either a skylink or file with skylinks separated by new lines" && exit 1
2020-06-01 09:17:44 +00:00
fi
2020-11-24 11:39:44 +00:00
#########################################################
2021-04-27 09:13:41 +00:00
# read either a file containing skylinks separated by new
2020-11-24 11:39:44 +00:00
# lines or a single skylink and put them in an array
#########################################################
skylinks = ( )
if test -f " $1 " ; then
OLDIFS = $IFS
IFS = ','
2020-11-24 14:14:22 +00:00
line_number = 1
2020-11-24 11:39:44 +00:00
while read line
do
if [ [ $line = ~ ( [ a-zA-Z0-9_-] { 46} ) ] ] ; then
skylinks += ( " $BASH_REMATCH " )
else
2020-11-24 14:14:22 +00:00
echo " Incorrect skylink at line ${ line_number } : $line " && exit 1
2020-11-24 11:39:44 +00:00
fi
2020-11-24 14:14:22 +00:00
let line_number += 1
2020-11-24 11:39:44 +00:00
done < $1 ;
IFS = $OLDIFS
else
skylinks = ( " $1 " ) # just single skylink passed as input argument
fi
2020-12-03 11:59:50 +00:00
#########################################################################
# iterate through all servers, block the skylinks and purge it from cache
#########################################################################
2021-07-26 20:03:49 +00:00
declare -a servers = ( "eu-ger-1.siasky.net" "eu-ger-2.siasky.net" "eu-ger-3.siasky.net" "eu-ger-4.siasky.net" "eu-ger-5.siasky.net" "eu-ger-6.siasky.net" "eu-ger-7.siasky.net" "eu-ger-8.siasky.net"
2021-10-21 18:41:24 +00:00
"eu-ger-9.siasky.net" "eu-ger-10.siasky.net" "eu-ger-11.siasky.net" "eu-ger-12.siasky.net"
"eu-fin-1.siasky.net" "eu-fin-2.siasky.net" "eu-fin-3.siasky.net" "eu-fin-4.siasky.net" "eu-fin-5.siasky.net" "eu-fin-6.siasky.net" "eu-fin-7-siasky.net" "eu-fin-8.siasky.net"
"eu-fin-9.siasky.net" "eu-fin-10.siasky.net" "eu-fin-11.siasky.net" "eu-fin-12.siasky.net" "eu-fin-13.siasky.net" "eu-fin-14.siasky.net" "eu-fin-15.siasky.net"
"eu-pol-1.siasky.net" "eu-pol-2.siasky.net" "eu-pol-3.siasky.net" "eu-pol-4.siasky.net" "eu-pol-5.siasky.net"
"us-ny-1.siasky.net" "us-ny-2.siasky.net"
2021-04-27 09:13:41 +00:00
"us-or-1.siasky.net" "us-or-2.siasky.net"
2021-10-21 18:41:24 +00:00
"us-la-1.siasky.net" "us-la-2.siasky.net" "us-la-3.siasky.net"
2021-04-27 09:13:41 +00:00
"us-pa-1.siasky.net" "us-pa-2.siasky.net"
2021-10-21 18:41:24 +00:00
"us-va-1.siasky.net" "us-va-2.siasky.net" "us-va-3.siasky.net" "us-va-4.siasky.net" "us-va-5.siasky.net" "us-va-6.siasky.net"
"as-hk-1.siasky.net" "as-sp-1.siasky.net" "as-sp-2.siasky.net"
2021-07-26 20:03:49 +00:00
"siasky.xyz" "dev1.siasky.dev" "dev2.siasky.dev" "dev3.siasky.dev" )
2021-04-27 09:13:41 +00:00
for server in " ${ servers [@] } " ;
2020-06-01 09:17:44 +00:00
do
2020-11-24 11:39:44 +00:00
for skylink in " ${ skylinks [@] } " ;
do
echo " .. ⌁ Blocking skylink ${ skylink } on ${ server } "
2021-10-21 18:41:24 +00:00
# Add to blocklist
ssh -q -t user@${ server } " docker exec sia siac skynet blocklist add ${ skylink } "
# Remove from NGINX cache
2021-07-27 14:33:20 +00:00
cached_files_command = " find /data/nginx/cache/ -type f | xargs -r grep -Elsq '^Skynet-Skylink: ${ skylink } ' "
2021-07-26 20:03:49 +00:00
ssh -q -t user@${ server } " docker exec -it nginx bash -c ${ cached_files_command } | xargs -r rm "
2021-10-21 18:41:24 +00:00
2021-07-26 20:03:49 +00:00
echo " .. ⌁ Skylink ${ skylink } Blocked on ${ server } "
echo "--------------------------------------------"
2020-12-03 11:59:50 +00:00
done
2020-06-01 09:17:44 +00:00
done
2020-11-24 11:39:44 +00:00
echo "✓ All done !"