insert_data.sh 2.45 KB
Newer Older
1
# This script will call every script needed to insert data.
2 3 4 5 6 7 8
# Parameters are the year and month from the data that will be inserted, and an elasticsearch username and password.
# Also, scripts called by insert_data.sh use a config file, located in every subfolder and called 'config.sh'.
# Those config files have some variables that have to be set:
# - Index: The index prefix to be saved on ElasticSearch.
# - Host: The hostname of the machine runnning ElasticSearch.
# - Filter: An array of n values, that will create n indexes in ElasticSearch, each one filtering data from Portal Transparencia using its corresponding string. Ex: "UNIVERSIDADE FEDERAL DO PARANA"
# - University: An array of n values, with n being the same n as Filter's array. This array should contain the initials from Universities declared in Filter array, in the same order.
9

10
if [[ "$#" -ne 5 || "$year" == "-help" || "$year" == "--help" ]]; then
11 12 13
    echo "  Usage: $0 <year> <month> <user> <password> <insertions>"
    echo "    Insertions must be one between: expenses, travel_allowances, workers, ministry_of_health, all"
    echo "    Example: $0 2016 12 myuser mypass all"
14 15 16
    exit
fi

17 18 19 20 21 22
year=$1
month=$2
user=$3
passwd=$4
insertions=$5

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# Treating the cases where the year input is invalid
if [[ "${#year}" != "4" ]]; then
    echo "  Year is invalid. Please enter a 4 digit year."
    echo "    Example: $0 2016 12 myuser mypass all"
    exit
fi

# Treating the case where month is too big
if [[ "${#month}" -gt "2" ]]; then
    echo "  Month is invalid. Please enter a 2 digit month."
    echo "    Example: $0 2016 12 myuser mypass all"
    exit
fi

# Treating the case where the user uses only 1 digit to the month value
if [[ "${#month}" -eq "1" ]]; then
    month="0$month"
fi

42
if [[ "$insertions" == "all" || "$insertions" == "expenses" ]]; then
43
    # First, insert Expenses data.
44 45
    echo "Inserting Expenses from ${year}-${month}..."
    (cd expenses && ./insert_expenses.sh $year $month $user $passwd)
46
fi
47

48
if [[ "$insertions" == "all" || "$insertions" == "travel_allowances" ]]; then
49
    # We should now insert Travel allowance data.
50 51
    echo "Inserting Travel Allowances from ${year}-${month}..."
    (cd travel_allowances && ./insert_travel_allowances.sh $year $month $user $passwd)
52
fi
53

54
if [[ "$insertions" == "all" || "$insertions" == "workers" ]]; then
55
    # Now, insert Workers data.
56 57
    echo "Inserting Workers from ${year}-${month}..."
    (cd workers && ./insert_register_payment.sh $year $month $user $passwd)
58
fi