forked from th3architect/MariaDB-Manager-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateAPIkey.sh
executable file
·52 lines (47 loc) · 1.64 KB
/
generateAPIkey.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#
# Part of MariaDB Manager package
#
# This file is distributed as part of the MariaDB Manager package.
# It is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright 2013-2014 (c) SkySQL Corporation Ab
#
# Author : Massimo Siani
# Version : 1.1
# Date : December 2013
# Description : Generates a new API ID/key pair
#
# parameters : $1 API ID
# The code below also checks whether a key with the same ID exists
# and, if it does, does not overwrite it.
if [ $# -lt 1 ]; then
echo "Component ID not provided. Please provide the component ID. Key not created."
exit 1
fi
componentID=$1
componentFile=/etc/mariadbmanager/manager.ini
# Generating API key
touch $componentFile
grep "\[apikeys\]" ${componentFile} &>/dev/null
if [ "$?" != "0" ] ; then
echo "[apikeys]" >> $componentFile
fi
newKey=$(echo $RANDOM$(date)$RANDOM | md5sum | cut -f1 -d" ")
keyString="${componentID} = \"${newKey}\""
# Registering key
grep "^${componentID} = \"" ${componentFile} &>/dev/null
if [ "$?" != "0" ] ; then
sed -i "/^\[apikeys\]/a $keyString" $componentFile
fi