#!/usr/bin/bash
#  +----------------------------------------------------------------------+
#  | Issabel version 4                                                    |
#  | http://www.issabel.org                                               |
#  +----------------------------------------------------------------------+
#  | Copyright (c) 2020 Issabel Foundation                                |
#  +----------------------------------------------------------------------+
#  | The contents of this file are subject to the General Public License  |
#  | (GPL) Version 2 (the "License"); you may not use this file except in |
#  | compliance with the License. You may obtain a copy of the License at |
#  | http://www.opensource.org/licenses/gpl-license.php                   |
#  |                                                                      |
#  | Software distributed under the License is distributed on an "AS IS"  |
#  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
#  | the License for the specific language governing rights and           |
#  | limitations under the License.                                       |
#  +----------------------------------------------------------------------+
#  | The Initial Developer of the Original Code is German Venturino       |
#  +----------------------------------------------------------------------+

# $1=save/get $2 key

function save_key {
#$1 key
  echo "LICENSE_KEY=$1" | tr -d " " > /etc/geoip_key.conf
  exit 0
}

function get_key {
  THE_KEY=$(cat /etc/geoip_key.conf | grep LICENSE_KEY | cut -d"=" -f2)
  echo $THE_KEY
}

case $1 in
     save)
        save_key $2
     ;;
     get)
        get_key
     ;;
     *)
        echo "USAGE: $(basename $0) save your_key_here or $(basename $0) get"
        exit 1
     ;;
  esac
