Snippets

Zen LIU LinOTP configure Maria DB RDS

Updated by Zen LIU

File linotp-create-mariadb-rds Modified

  • Ignore whitespace
  • Hide word diff
 DB_USERNAME=$2
 DB_PASSWORD=$3
 
-echo "DB_HOST=$DB_HOST DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD"
-exit 0
-
 function print_support_information {
     echo -e "Please contact ${BOLD}support@keyidentity.com${DEFAULT} or ${BOLD}+49615186086115${DEFAULT} for assistance."
         }
 echo -e "${BOLD}Creating database and database users...${DEFAULT}"
 echo "Connect will be done with MariaDB account: $DB_USERNAME"
 
-mysql -u $DB_USERNAME -p$DB_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $DB_NAME; grant all privileges on $DB_NAME.* to $DB_USER@'%' identified by '$DB_PASS'; flush privileges"
+mysql -h $DB_HOST -u $DB_USERNAME -p$DB_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $DB_NAME; grant all privileges on $DB_NAME.* to $DB_USER@'%' identified by '$DB_PASS'; flush privileges"
 
 if [ $? -ne 0 ]
 then
Created by Zen LIU

File linotp-create-mariadb-rds Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/bash
+#    version 3
+#
+#    LinOTP - the open source solution for two factor authentication
+#    Copyright (C) 2010 - 2018 KeyIdentity GmbH
+#
+#    This file is part of LinOTP server.
+#
+#    This program is free software: you can redistribute it and/or
+#    modify it under the terms of the GNU Affero General Public
+#    License, version 3, as published by the Free Software Foundation.
+#
+#    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 Affero General Public License for more details.
+#
+#    You should have received a copy of the
+#               GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#
+#    E-mail: support@keyidentity.com
+#    Website: http://www.keyidentity.com
+#
+
+LANG=C
+ENCKEY=encKey
+LINOTP_CONF_DIR=/etc/linotp2
+LINOTP_INI=$LINOTP_CONF_DIR/linotp.ini
+#DB_HOST=localhost
+DB_NAME=LINOTP
+DB_USER=linotp
+SERVICE=mariadb.service
+#Colors
+#DEFAULT='\e[39m'
+DEFAULT='\e[0m'
+RED='\e[91m'
+#YELLOW='\e[93m'
+#BLUE='\e[34m'
+GREEN='\e[32m'
+BOLD='\e[1m'
+
+#handle parameters
+if [ $# -lt 3 ]; then
+    echo "Missing parameters! Usage: $0 <rds hostname> <db usernmae> <db password>"
+    exit 2
+fi
+
+DB_HOST=$1
+DB_USERNAME=$2
+DB_PASSWORD=$3
+
+echo "DB_HOST=$DB_HOST DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD"
+exit 0
+
+function print_support_information {
+    echo -e "Please contact ${BOLD}support@keyidentity.com${DEFAULT} or ${BOLD}+49615186086115${DEFAULT} for assistance."
+        }
+validate_reply () {
+    ret=0
+    if [ -z "$1" ]; then
+        reply=y
+        return $ret
+    fi
+    case $1 in
+        y|Y|yes|Yes|YES) reply=y ;;
+        n|N|no|No|NO)    reply=n ;;
+        *) ret=1 ;;
+    esac
+    return $ret
+}
+
+clear
+echo -e "${BOLD}Welcome to the database setup script for LinOTP!${DEFAULT}"
+echo "Please be aware that you have to install LinOTP before you start this script."
+echo "------------------------------------------------------------------------------------------"
+
+if [ $UID -ne 0 ]
+  then
+	echo "This script has to be executed as root user." 1>&2
+	echo "Exiting script....." 1>&2
+	exit 1
+fi
+
+echo -e "${GREEN}Starting MariaDB setup...${DEFAULT}"
+echo ""
+
+#Check if the database key exists as a nonempty file and create one in case it is not present.
+if ! [ -s /etc/linotp2/encKey ]
+then
+	#echo "Generiere Datenbankschlüssel - dies kann eine Weile dauern, bitte haben Sie Geduld."
+    echo "Create database key - this may take a while. Please be patient."
+	echo "--------------------------------------------------"
+    if ! ( dd if=/dev/urandom of="$LINOTP_CONF_DIR/$ENCKEY" bs=1 count=128 && chown linotp "$LINOTP_CONF_DIR/$ENCKEY" && chmod 640 "$LINOTP_CONF_DIR/$ENCKEY" )
+    then
+		echo -e "${RED}Creating of database key failed. Exiting script...${DEFAULT}" 1>&2
+        exit 6
+	  else
+		 echo -e "Database key was ${GREEN}successfully generated.${DEFAULT}"
+    fi
+fi
+
+unset DB_PASS
+DB_PASS=$(pwgen -cnsB 32 1)
+if [ -z "$DB_PASS" ]
+then
+    echo -e "${RED}Password could not be generated" 1>&2
+    echo -e "Exiting program${DEFAULT}" 1>&2
+    exit 10
+fi
+echo "Generated password is $DB_PASS" 
+
+echo ""
+echo "--------------------------------------------------"
+echo ""
+
+echo -e "${BOLD}Creating database and database users...${DEFAULT}"
+echo "Connect will be done with MariaDB account: $DB_USERNAME"
+
+mysql -u $DB_USERNAME -p$DB_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $DB_NAME; grant all privileges on $DB_NAME.* to $DB_USER@'%' identified by '$DB_PASS'; flush privileges"
+
+if [ $? -ne 0 ]
+then
+	echo -e "${RED}Database initialization failed. Exiting script...${DEFAULT}" 1>&2
+	exit 8
+fi
+
+echo "--------------------------------------------------"
+echo ""
+echo "Preparing linotp.ini for initial setup...."
+DATE=$(date +%Y%m%d-%H%M%S)
+
+if [ -e /etc/linotp2/linotp.ini ]
+then
+	echo "$LINOTP_INI already exists. A backup is created..."
+	cp -a "$LINOTP_INI" "$LINOTP_INI.backup.$DATE"
+fi
+
+echo "Creating $LINOTP_INI from $LINOTP_CONF_DIR/linotp.ini.example for initial setup..."
+
+cp -a $LINOTP_CONF_DIR/linotp.ini.example $LINOTP_INI
+sed -i -re "s%^sqlalchemy.url =.*%sqlalchemy.url = mysql://$DB_USER:$DB_PASS@$DB_HOST/$DB_NAME%" $LINOTP_INI
+echo "--------------------------------------------------"
+echo ""
+
+echo -e "${BOLD}Setup for LinOTP ${GREEN}succeeded.${DEFAULT}"
+echo "Please proceed with the web server setup"
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.