diff --git a/start.sh b/start.sh index 858bd1e..7019e32 100644 --- a/start.sh +++ b/start.sh @@ -11,22 +11,46 @@ echo -e " COUNTRIES="af es" - - for country in $COUNTRIES; do url="https://www.ipdeny.com/ipblocks/data/countries/${country}.zone" - echo "Baixando lista de IPs para o país: $country" - - # Baixar o arquivo - curl -s -O "$url" - - # Criar ipset para o país, ignorar se já existir - ipset create "$country" hash:net -exist - + echo "Tentando baixar lista de IPs para o país: $country" + + tmp_file="zone/${country}.zone.tmp" + target_file="zone/${country}.zone" + + if curl -sSf -o "$tmp_file" "$url"; then + echo "Download concluído para $country." + + if [ -f "$target_file" ]; then + if cmp -s "$tmp_file" "$target_file"; then + echo "Arquivo para $country não mudou. Mantendo versão atual." + rm "$tmp_file" + else + echo "Arquivo para $country mudou. Atualizando..." + mv "$tmp_file" "$target_file" + fi + else + echo "Arquivo para $country não existia. Salvando novo arquivo." + mv "$tmp_file" "$target_file" + fi + else + echo "Falha no download do arquivo para $country. Mantendo versão antiga (se existir)." + [ -f "$tmp_file" ] && rm "$tmp_file" + continue + fi + + # Verifica se ipset existe + if ipset list "$country" > /dev/null 2>&1; then + echo "IpSet '$country' já existe." + else + echo "Criando IpSet '$country'." + ipset create "$country" hash:net + fi + # Adicionar cada rede ao ipset while read -r subnet; do ipset add "$country" "$subnet" -exist - done < "${country}.zone" - + done < "$target_file" + echo "Concluído para o país $country." done