From patchwork Tue Jul 28 20:02:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3282 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BGSJz43VZz3xVB for ; Tue, 28 Jul 2020 20:02:59 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BGSJx3T2vz1k7; Tue, 28 Jul 2020 20:02:57 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BGSJx29Lwz306l; Tue, 28 Jul 2020 20:02:57 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BGSJv5MMZz2xVW for ; Tue, 28 Jul 2020 20:02:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BGSJt5bw8z1h4; Tue, 28 Jul 2020 20:02:54 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1595966575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=gQmhDjN3Jzykm63dndgyYzHDdY7ShH/K0rzBb8jxoR8=; b=mwLQkMqcAfslmXSXb62k1yi9Lh9SMyBfn4JsHti9WF2cbN76LairbIoECc1xMPS22Ys2oh IQ/wlQs6huPxQ1BA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1595966575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=gQmhDjN3Jzykm63dndgyYzHDdY7ShH/K0rzBb8jxoR8=; b=N3dIMfRh9eHFLDffexc34CjzhFb+P74ihTVdF4bjleohdhKnyDIe3qwMG3QK0LBqbC7JkI sFg2FsV/cOz3ENOWUgjP0cWVQ0A/KULgcKHOe35t4lQvLw+NcV1DLhcXfDPMws0hkMI26i 8BZEq/3nhij636HYtbd48NzVwit+gtzUeV81arCxwTdaAJN3/vEilIymqUv3N5F1bjG4HA a1jT4DtNVmnY54q49Ce6bT4ivahftRg1kZnEKemukmjUeYUD3e0OCe4yOyIwEsfjtdfg43 z6WrL4olRozUlCPNrEDP56EdWgivI4UWSJ4TBD0OJGgevUJuGxTsiozdFifO2A== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] update-location-database: Only update database once a week. Date: Tue, 28 Jul 2020 22:02:46 +0200 Message-Id: <20200728200246.3834-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Ensure to download and update the database only once a week, even the script will be called by cron each hour. Also detect of the database has been changed and only in this case re-export the database. Fixes #12462. Signed-off-by: Stefan Schantl --- src/scripts/update-location-database | 32 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/scripts/update-location-database b/src/scripts/update-location-database index d830286ce..b3eb27c92 100644 --- a/src/scripts/update-location-database +++ b/src/scripts/update-location-database @@ -21,6 +21,19 @@ eval $(/usr/local/bin/readhash /var/ipfire/proxy/settings) +DB_FILE="/var/lib/location/database.db" +UPDATE_INTERVAL="weekly" + +# Tiny function to get the current timestamp of the database file. +function get_db_timestamp { + local timestamp=`stat -c "%Y" $DB_FILE` + + echo $timestamp +} + +# Get database timestamp. +database_timestamp=$(get_db_timestamp) + # Proxy settings. # Check if a proxy should be used. if [[ $UPSTREAM_PROXY ]]; then @@ -39,11 +52,20 @@ if [[ $UPSTREAM_PROXY ]]; then fi # Get the latest location database from server. -if /usr/bin/location update; then - # Call location and export all countries in xt_geoip compatible format. - if /usr/bin/location export --directory=/usr/share/xt_geoip --family=ipv4 --format=xt_geoip; then +if /usr/bin/location update --cron=$UPDATE_INTERVAL; then + # Grab timestamp of the database again. + new_database_timestamp=$(get_db_timestamp) - # Call initscript to reload the firewall. - /etc/init.d/firewall reload + # Check if the timestamps are different. + # In this case it needs to be exported again. + if [ ! $database_timestamp eq $new_database_timestamp ]; then + # Call location and export all countries in xt_geoip compatible format. + if /usr/bin/location export --directory=/usr/share/xt_geoip --family=ipv4 --format=xt_geoip; then + + # Call initscript to reload the firewall. + /etc/init.d/firewall reload + fi fi fi + +