1
0
Fork 0

Aggiunta 'modalità interattiva'

This commit is contained in:
pezcurrel 2019-12-18 16:24:55 +01:00
parent 3a019ffe09
commit c83b4e2978

View file

@ -14,6 +14,7 @@
MASTHOME='/var/lib/mastodon'
MASTENVFP="$MASTHOME/live/.env.production"
SISTERSFP="istanzesorelle"
INTERACTIVE=0
HELP="SINTASSI
mastblocksmerge.sh [opzioni]
@ -45,6 +46,10 @@ OPZIONI
-s, --sistersfp
Definisce il percorso del file da cui leggere la lista delle istanze
sorelle.
-i, --interactive
Modalità interattiva: se vengono nelle blocklist vengono trovate
istanze ancora non presenti nel database di mastodon, viene chiesto
per ciascuna se aggiungerla o meno.
-h, --help
Mostra questo aiuto ed esce."
@ -81,6 +86,9 @@ while [ $i -lt ${#args[@]} ]; do
SISTERSFP="${args[$i]}"
fi
;;
"-i" | "--interactive" )
INTERACTIVE=1
;;
"-h" | "--help" )
echo "$HELP"
exit 0
@ -114,12 +122,15 @@ DB_PASS=`grep 'DB_PASS' "$MASTENVFP"|sed -e 's/[^=]*=//'`
IFS=$'\n'
for sisdom in $(grep -P '^[^#]+[^\s]+' "$SISTERSFP"); do
blocks="$(curl -s "https://$sisdom/domain_blocks.txt" | grep -P '^[^#]+[^\s]+')"
# blocks=$(cat "$sisdom" | grep -P '^[^#]+[^\s]+')
# blocks="$(curl -s "https://$sisdom/domain_blocks.txt" | grep -P '^[^#]+[^\s]+')"
blocks=$(cat "$sisdom" | grep -P '^[^#]+[^\s]+')
for line in $blocks; do
dom=$(echo "$line" | sed -e 's/\t.*//' -e 's/\./\\./g')
echo "$allblocks" | grep -P "^$dom\t" &>/dev/null
[ $? -ne 0 ] && allblocks+="$line$IFS"
echo "$allblocks"|grep -F "$line" &>/dev/null
if [ $? -ne 0 ]; then
dom=$(echo "$line" | sed -e 's/\t.*//' -e 's/\./\\./g')
echo "$allblocks" | grep -P "^$dom\t" &>/dev/null
[ $? -ne 0 ] && allblocks+="$line$IFS"
fi
done
done
allblocks=$(echo "$allblocks" | head -n -1 | sort)
@ -138,4 +149,20 @@ newblocks=$(echo "$newblocks" | head -n -1 | sort)
echo "Ho trovato $i istanza/e bloccata da aggiungere."
if [ $INTERACTIVE -eq 1 ]; then
for line in $newblocks; do
echo "$line"
ask=1
while [ $ask -eq 1 ]; do
read -p "Vuoi aggiungere questa istanza alla tabella delle istanze bloccate? [S/n] " inp
echo "$inp" | grep -P '^[sSnN]{0,1}$' &>/dev/null
[ $? -eq 0 ] && ask=0
done
if [ "$inp" == "" ] || [ "$inp" == "s" ] || [ "$inp" == "S" ]; then
buf+="$line"
fi
done
newblocks="$buf"
fi
echo "$newblocks" | PGPASSWORD="$DB_PASS" psql -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -U "$DB_USER" -A -t -c "COPY domain_blocks ( domain, created_at, updated_at, severity, reject_media, reject_reports, public_comment ) FROM STDIN WITH ( FORMAT text, DELIMITER ' ' )"