Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Sobota, 20. apríl 2024

Súbor: [Platon] / scripts / php / sk-nic / download.sh (stiahnutie)

Revízia 1.16, Mon Aug 8 11:14:28 2022 UTC (20 months, 1 week ago) by nepto


Zmeny od 1.15: +2 -2 [lines]

Do not output one error to stderr

#!/bin/sh

#
# download.sh
#
# Developed by Ondrej Jombik <jombik@platon.org>
# Copyright (c) 2006-2017 Platon Group, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2006-08-13 - created
# 2017-09-12 - implemented new SK-NIC-EPP/CentralNic export
# 2017-09-23 - added support for multiple imports: domains, registrars
# 2017-10-07 - added import of expired domains (droplist)
#

# $Platon: scripts/php/sk-nic/download.sh,v 1.15 2017/10/07 09:33:42 nepto Exp $

#
# Put this into your crontab, it will run this script every morning at 6:15 am:
#
#    15 6 * * * /home/ondrej/prog/scripts/php/sk-nic/download.sh
#
# NOTE: you will probably need to alter the script path
#

PREFIX="SK-NIC";
PREFIX_ERR="$PREFIX-ERROR";
PREFIX_INFO="$PREFIX-INFO";
PHP="`which php`";
WGET="`which wget`";

if [ -z "$1" ]; then
    echo "Usage: `basename \"$0\"` <type_or_file1> [ <type_or_file2> ]";
    exit 1;
fi

work_dir="`dirname $0`";
if [ "X$work_dir" = "X" ]; then
    echo "$PREFIX_ERR: empty work directory variable";
    exit 2;
fi;

cd "$work_dir";
if [ "$?" -ne 0 ]; then
    echo "$PREFIX_ERR: unable to change directory";
    exit 3;
fi;

if [ -z "$PHP" ]; then
    echo "$PREFIX_ERR: php binary not found, no import was done";
    exit 4;
fi;


for PROCESS_FILE in "$@"; do

    # if file type is provided, download one from www.sk-nic.sk
    if [ "$PROCESS_FILE" = "domains" -o "$PROCESS_FILE" = "registrars" ]; then
        INPUT_FILE="https://sk-nic.sk/subory/$PROCESS_FILE"".txt";
        OUTPUT_FILE="data-new/$PROCESS_FILE"".`date '+%F'`.txt";

        if [ -z "$WGET" ]; then
            echo "$PREFIX_ERR: wget binary not found";
            exit 5;
        fi;
        if [ -s "$OUTPUT_FILE" ]; then
            echo "$PREFIX_ERR: file already exists: $OUTPUT_FILE";
            exit 6;
        fi;

        echo "$PREFIX_INFO: fetching $INPUT_FILE";
        echo "$PREFIX_INFO: into destination file $OUTPUT_FILE";

        $WGET --quiet -O "$OUTPUT_FILE" --no-check-certificate "$INPUT_FILE";
        rc="$?";

        if [ "$rc" -eq 8 ]; then
            echo "$PREFIX_ERR: error 404 Not Found - repeat download";
            exit "$rc";
        elif [ "$rc" -ne 0 ]; then
            echo "$PREFIX_ERR: fetch error (wget_exit:$rc; wget_bin:$WGET)";
            exit "$rc";
        fi;

        PROCESS_FILE="$OUTPUT_FILE";
    else
        echo "$PREFIX_INFO: using provided file: $PROCESS_FILE";
    fi

    if [ \! -r "$PROCESS_FILE" ]; then
            echo "$PREFIX_ERR: file $PROCESS_FILE not found or not readable";
            exit 7;
    fi

    if [ \! -s "$PROCESS_FILE" ]; then
        echo "$PREFIX_ERR: file $PROCESS_FILE is empty";
        exit 8;
    fi

    # and now real import
    $PHP sk-nic.php "$PROCESS_FILE"
    rc="$?";
    if [ "$rc" -ne 0 ]; then
        echo "ERROR: return code from sk-nic.php: $rc";
        exit $rc;
    fi

done

#echo "THESE FILES WAS DELETED BY AUTOMATED PROCESS:";
#echo "---------------------------------------------";
#find data/ -maxdepth 1 -type f -name 'sk-nic.*.csv' -mtime +10
#find data/ -maxdepth 1 -type f -name 'sk-nic.*.csv' -mtime +10 -exec rm -f {} \;


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok