All references to MySQL and WebConsole have been removed.

ogboot_installer
Antonio Guerrero 2024-04-11 00:39:39 -06:00
parent 3f5fac71ea
commit bb440428de
1 changed files with 10 additions and 634 deletions

View File

@ -10,39 +10,6 @@
####### Funciones de configuración
#####################################################################
# Devuelve en la variable PASSWORD la clave introducida por el usuario (o la indicada por defecto)
function enterPassword ()
{
local PASSWORD2
local DEFAULT_PASSWORD="$1"
while : ; do
stty -echo
read -r PASSWORD
stty echo
if [ -z "$PASSWORD" ]; then
# Si esta vacio ponemos el valor por defecto
PASSWORD="${PASSWORD:-$DEFAULT_PASSWORD}"
break
else
if [ -n "${PASSWORD//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico
echo -e "\\aERROR: Password must be alphanumeric, try again..."
else
echo -n -e "\\nConfirm password: "
stty -echo
read -r PASSWORD2
stty echo
if [ "$PASSWORD" == "$PASSWORD2" ]; then
break
else
echo -e "\\aERROR: Passwords don't match, try again."
fi
fi
fi
echo -n -e "Please, enter a new password (${DEFAULT_PASSWORD}): "
done
}
# Si la distribución no es la recomendada mostramos mensaje informativo.
function checkDistribution()
{
@ -66,8 +33,6 @@ function userData ()
{
#### AVISO: Puede editar configuración de acceso por defecto.
#### WARNING: Edit default access configuration if you wish.
DEFAULT_MYSQLHOST="172.17.8.71" # IP por defecto de la base de datos
DEFAULT_MYSQL_ROOT_PASSWORD="passwordroot" # Clave por defecto root de MySQL
DEFAULT_OPENGNSYS_DB_USER="usuog" # Usuario por defecto de acceso a la base de datos
DEFAULT_OPENGNSYS_DB_PASSWD="passusuog" # Clave por defecto de acceso a la base de datos
DEFAULT_OPENGNSYS_CLIENT_PASSWD="og" # Clave por defecto de acceso del cliente
@ -78,51 +43,11 @@ function userData ()
if [[ $- =~ s ]]; then
echo -e "\\nNot interactive mode: setting default configuration values.\\n"
MYSQLHOST="$DEFAULT_MYSQLHOST"
MYSQL_ROOT_PASSWORD="$DEFAULT_MYSQL_ROOT_PASSWORD"
OPENGNSYS_DB_USER="$DEFAULT_OPENGNSYS_DB_USER"
OPENGNSYS_DB_PASSWD="$DEFAULT_OPENGNSYS_DB_PASSWD"
OPENGNSYS_CLIENT_PASSWD="$DEFAULT_OPENGNSYS_CLIENT_PASSWD"
OGLIVE="$DEFAULT_OGLIVE"
return
fi
# IP de Servidor MySQL
echo -n -e "\\nEnter IP or HOSTNAME for MySQL (${DEFAULT_MYSQLHOST}): "
enterPassword "$DEFAULT_MYSQL_HOST"
MYSQLHOST="$PASSWORD"
# Clave root de MySQL
echo -n -e "\\nEnter root password for MySQL (${DEFAULT_MYSQL_ROOT_PASSWORD}): "
enterPassword "$DEFAULT_MYSQL_ROOT_PASSWORD"
MYSQL_ROOT_PASSWORD="$PASSWORD"
# Usuario de acceso a la base de datos
while : ; do
echo -n -e "\\n\\nEnter username for OpenGnsys console (${DEFAULT_OPENGNSYS_DB_USER}): "
read -r OPENGNSYS_DB_USER
if [ -n "${OPENGNSYS_DB_USER//[a-zA-Z0-9]/}" ]; then # Comprobamos que sea un valor alfanumerico
echo -e "\\aERROR: Must be alphanumeric, try again..."
else
# Si esta vacio ponemos el valor por defecto
OPENGNSYS_DB_USER="${OPENGNSYS_DB_USER:-$DEFAULT_OPENGNSYS_DB_USER}"
break
fi
done
# Clave de acceso a la base de datos
echo -n -e "\\nEnter password for OpenGnsys console (${DEFAULT_OPENGNSYS_DB_PASSWD}): "
enterPassword "$DEFAULT_OPENGNSYS_DB_PASSWD"
OPENGNSYS_DB_PASSWD="$PASSWORD"
# Clave de acceso del cliente
echo -n -e "\\n\\nEnter root password for OpenGnsys client (${DEFAULT_OPENGNSYS_CLIENT_PASSWD}): "
enterPassword "$DEFAULT_OPENGNSYS_CLIENT_PASSWD"
OPENGNSYS_CLIENT_PASSWD="$PASSWORD"
unset PASSWORD
# El ogclient sólo es compatible con ogLive de kernel 5.x. Se comenta la elección de ogLive.
# Selección de clientes ogLive para descargar.
#while : ; do
# echo -e "\\n\\nChoose ogLive client to install."
# echo -e "1) Kernel 5.4, 64-bit, EFI-compatible"
@ -142,7 +67,6 @@ function userData ()
#done
OGLIVE="$DEFAULT_OGLIVE"
echo -e "\\n=============================="
}
# Asigna valores globales de configuración para el script.
@ -164,7 +88,7 @@ function globalSetup ()
API_URL="https://api.github.com/repos/opengnsys/OpenGnsys"
# Directorios de instalación y destino de OpenGnsys.
WORKDIR=/tmp/opengnsys_installer
WORKDIR=/tmp/ogboot_installer
INSTALL_TARGET=/opt/opengnsys
INSTALL_OGBOOT_TARGET=/opt/ogboot
PATH=$PATH:$INSTALL_OGBOOT_TARGET/bin
@ -175,9 +99,6 @@ function globalSetup ()
# Usuario del cliente para acceso remoto.
OPENGNSYS_CLIENT_USER="opengnsys"
# Nombre de la base datos y fichero SQL para su creación.
OPENGNSYS_DATABASE="ogAdmBD"
OPENGNSYS_DB_CREATION_FILE=ogboot/admin/Database/${OPENGNSYS_DATABASE}.sql
}
# Generar variables de configuración del instalador
@ -194,8 +115,6 @@ function globalSetup ()
# - PHPFPMSERV - servicio PHP FastCGI Process Manager para Apache
# - INETDSERV - servicio Inetd
# - DHCPSERV, DHCPCFGDIR - servicio y configuración de DHCP
# - MYSQLSERV, TMPMYCNF - servicio MySQL y fichero temporal con credenciales de acceso
# - MARIADBSERV - servicio MariaDB (sustituto de MySQL en algunas distribuciones)
# - RSYNCSERV, RSYNCCFGDIR - servicio y configuración de Rsync
# - SAMBASERV, SAMBACFGDIR - servicio y configuración de Samba
# - TFTPSERV, TFTPCFGDIR - servicio y configuración de TFTP/PXE
@ -217,7 +136,7 @@ OSVERSION="${OSVERSION%%.*}"
# Configuración según la distribución GNU/Linux (usar minúsculas).
case "$OSDISTRIB" in
ubuntu|debian|linuxmint)
DEPENDENCIES=( subversion apache2 php php-ldap php-fpm mysql-client php-mysql isc-dhcp-server bittorrent tftp-hpa tftpd-hpa xinetd build-essential g++-multilib libmysqlclient-dev wget curl graphviz bittornado ctorrent samba rsync unzip netpipes debootstrap schroot squashfs-tools btrfs-tools procps arp-scan realpath php-curl gettext moreutils jq wakeonlan udpcast libev-dev libjansson-dev libssl-dev shim-signed grub-efi-amd64-signed gawk libdbi-dev libdbi1 libdbd-mysql automake liblz4-tool )
DEPENDENCIES=( subversion apache2 php php-ldap php-fpm isc-dhcp-server bittorrent tftp-hpa tftpd-hpa xinetd build-essential g++-multilib wget curl graphviz bittornado ctorrent samba rsync unzip netpipes debootstrap schroot squashfs-tools btrfs-tools procps arp-scan realpath php-curl gettext moreutils jq wakeonlan udpcast libev-dev libjansson-dev libssl-dev shim-signed grub-efi-amd64-signed gawk libdbi-dev libdbi1 automake liblz4-tool )
UPDATEPKGLIST="apt-get update"
INSTALLPKG="apt-get -y install --force-yes"
CHECKPKG="dpkg -s \$package 2>/dev/null | grep Status | grep -qw install"
@ -244,11 +163,6 @@ case "$OSDISTRIB" in
DHCPCFGDIR=/etc/dhcp
INETDSERV=xinetd
INETDCFGDIR=/etc/xinetd.d
MYSQLSERV=mysql
MYSQLHOST=172.17.8.74
MYSQLPORT=3301
MYSQLCFGDIR=/etc/mysql/mysql.conf.d
MARIADBSERV=mariadb
PHPFPMSERV=php-fpm
RSYNCSERV=rsync
RSYNCCFGDIR=/etc
@ -257,7 +171,7 @@ case "$OSDISTRIB" in
TFTPCFGDIR=/var/lib/tftpboot
;;
fedora|centos)
DEPENDENCIES=( subversion httpd mod_ssl php-ldap php-fpm mysql mysql-devel mysql-devel.i686 php-mysql dhcp tftp-server tftp xinetd binutils gcc gcc-c++ glibc-devel glibc-devel.i686 glibc-static glibc-static.i686 libstdc++-devel.i686 make wget curl doxygen graphviz ctorrent samba samba-client rsync unzip debootstrap schroot squashfs-tools python-crypto arp-scan procps-ng gettext moreutils jq net-tools udpcast libev-devel jansson-devel openssl-devel shim-x64 grub2-efi-x64 grub2-efi-x64-modules gawk libdbi-devel libdbi libdbi-dbd-mysql automake http://ftp.altlinux.org/pub/distributions/ALTLinux/5.1/branch/$(arch)/RPMS.classic/netpipes-4.2-alt1.$(arch).rpm )
DEPENDENCIES=( subversion httpd mod_ssl php-ldap php-fpm dhcp tftp-server tftp xinetd binutils gcc gcc-c++ glibc-devel glibc-devel.i686 glibc-static glibc-static.i686 libstdc++-devel.i686 make wget curl doxygen graphviz ctorrent samba samba-client rsync unzip debootstrap schroot squashfs-tools python-crypto arp-scan procps-ng gettext moreutils jq net-tools udpcast libev-devel jansson-devel openssl-devel shim-x64 grub2-efi-x64 grub2-efi-x64-modules gawk libdbi-devel libdbi automake http://ftp.altlinux.org/pub/distributions/ALTLinux/5.1/branch/$(arch)/RPMS.classic/netpipes-4.2-alt1.$(arch).rpm )
[ "$OSDISTRIB" == "centos" ] && UPDATEPKGLIST="yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$OSVERSION.noarch.rpm http://rpms.remirepo.net/enterprise/remi-release-$OSVERSION.rpm"
INSTALLEXTRADEPS=( 'pushd /tmp; wget -t3 http://ftp.acc.umu.se/mirror/bittornado/BitTornado-0.3.18.tar.gz && tar xvzf BitTornado-0.3.18.tar.gz && cd BitTornado-CVS && python setup.py install && ln -fs btlaunchmany.py /usr/bin/btlaunchmany && ln -fs bttrack.py /usr/bin/bttrack; popd' )
INSTALLPKG="yum install -y libstdc++ libstdc++.i686"
@ -284,11 +198,6 @@ case "$OSDISTRIB" in
DHCPCFGDIR=/etc/dhcp
INETDSERV=xinetd
INETDCFGDIR=/etc/xinetd.d
MYSQLSERV=mysqld
MYSQLHOST=172.17.8.74
MYSQLPORT=3301
MYSQLCFGDIR=/etc/my.cnf.d
MARIADBSERV=mariadb
PHPFPMSERV=php-fpm
RSYNCSERV=rsync
RSYNCCFGDIR=/etc
@ -302,12 +211,7 @@ case "$OSDISTRIB" in
*) echo "ERROR: Distribution not supported by OpenGnsys."
exit 1 ;;
esac
# Fichero de credenciales de acceso a MySQL.
TMPMYCNF=/tmp/.my.cnf.$$
}
# Modificar variables de configuración tras instalar paquetes del sistema.
function autoConfigurePost()
{
@ -355,8 +259,6 @@ case "$OSDISTRIB" in
PHPFPMSERV="${PHP7VERSION}-fpm"
DEPENDENCIES=( ${DEPENDENCIES[@]//php/$PHP7VERSION} )
fi
# Adaptar dependencias para libmysqlclient.
[ -z "$(apt-cache pkgnames libmysqlclient-dev)" ] && [ -n "$(apt-cache pkgnames libmysqlclient15)" ] && DEPENDENCIES=( ${DEPENDENCIES[@]//libmysqlclient-dev/libmysqlclient15} )
# Paquete correcto para realpath.
[ -z "$(apt-cache pkgnames realpath)" ] && DEPENDENCIES=( ${DEPENDENCIES[@]//realpath/coreutils} )
;;
@ -367,8 +269,6 @@ case "$OSDISTRIB" in
DEPENDENCIES=( ${PHP7VERSION} ${DEPENDENCIES[@]//php/$PHP7VERSION-php} )
# Cambios a aplicar a partir de CentOS 7.
if [ $OSVERSION -ge 7 ]; then
# Sustituir MySQL por MariaDB.
DEPENDENCIES=( ${DEPENDENCIES[*]/mysql-/mariadb-} )
# Instalar ctorrent de EPEL para CentOS 6 (no disponible en CentOS 7).
DEPENDENCIES=( ${DEPENDENCIES[*]/ctorrent/http://dl.fedoraproject.org/pub/epel/6/$(arch)/Packages/c/ctorrent-1.3.4-14.dnh3.3.2.el6.$(arch).rpm} )
fi
@ -376,8 +276,6 @@ case "$OSDISTRIB" in
fedora) # Postconfiguación personalizada para Fedora.
# Incluir paquetes específicos.
DEPENDENCIES=( ${DEPENDENCIES[@]} btrfs-progs )
# Sustituir MySQL por MariaDB a partir de Fedora 20.
[ $OSVERSION -ge 20 ] && DEPENDENCIES=( ${DEPENDENCIES[*]/mysql-/mariadb-} )
;;
esac
}
@ -578,264 +476,6 @@ function backupFile()
echoAndLog "${FUNCNAME}(): $file backup success"
}
#####################################################################
####### Funciones para el manejo de bases de datos
#####################################################################
# This function set password to root
function mysqlSetRootPassword()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local root_mysql="$1"
echoAndLog "${FUNCNAME}(): setting root password in MySQL server"
mysqladmin -h $MYSQLHOST -u root password "$root_mysql"
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while setting root password in MySQL server"
return 1
fi
echoAndLog "${FUNCNAME}(): root password saved!"
return 0
}
# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
function mysqlGetRootPassword()
{
local pass_mysql
local pass_mysql2
# Comprobar si MySQL está instalado con la clave de root por defecto.
if mysql -h $MYSQLHOST -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then
echoAndLog "${FUNCNAME}(): Using default mysql root password."
else
stty -echo
echo "There is a MySQL service already installed."
read -p "Enter MySQL root password: " pass_mysql
echo ""
read -p "Confrim password:" pass_mysql2
echo ""
stty echo
if [ "$pass_mysql" == "$pass_mysql2" ] ;then
MYSQL_ROOT_PASSWORD="$pass_mysql"
return 0
else
echo "The keys don't match. Do not configure the server's key,"
echo "transactions in the database will give error."
return 1
fi
fi
}
# comprueba si puede conectar con mysql con el usuario root
function mysqlTestConnection()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local root_password="$1"
echoAndLog "${FUNCNAME}(): checking connection to mysql..."
# Componer fichero con credenciales de conexión a MySQL.
touch $TMPMYCNF
chmod 600 $TMPMYCNF
cat << EOT > $TMPMYCNF
[client]
user=root
password=$root_password
EOT
echo "------------------------"
cat $TMPMYCNF
echo "------------------------"
# Comprobar conexión a MySQL.
echo "" | mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): connection to mysql failed, check root password and if daemon is running!"
return 1
else
echoAndLog "${FUNCNAME}(): connection success"
return 0
fi
# Borrar el fichero temporal si termina el proceso de instalación.
trap "rm -f $TMPMYCNF" 0 1 2 3 6 9 15
}
# comprueba si la base de datos existe
function mysqlDbExists()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local database="$1"
echoAndLog "${FUNCNAME}(): checking if $database exists..."
echo "show databases" | mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST | grep "^${database}$"
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}():database $database doesn't exists"
return 1
else
echoAndLog "${FUNCNAME}():database $database exists"
return 0
fi
}
# Comprueba si la base de datos está vacía.
function mysqlCheckDbIsEmpty()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local database="$1"
echoAndLog "${FUNCNAME}(): checking if $database is empty..."
num_tablas=`echo "show tables" | mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST "${database}" | wc -l`
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error executing query, check database and root password"
exit 1
fi
if [ $num_tablas -eq 0 ]; then
echoAndLog "${FUNCNAME}():database $database is empty"
return 0
else
echoAndLog "${FUNCNAME}():database $database has tables"
return 1
fi
}
# Importa un fichero SQL en la base de datos.
# Parámetros:
# - 1: nombre de la BD.
# - 2: fichero a importar.
# Nota: el fichero SQL puede contener las siguientes palabras reservadas:
# - SERVERIP: se sustituye por la dirección IP del servidor.
# - DBUSER: se sustituye por usuario de conexión a la BD definido en este script.
# - DBPASSWD: se sustituye por la clave de conexión a la BD definida en este script.
function mysqlImportSqlFileToDb()
{
if [ $# -ne 2 ]; then
errorAndLog "${FNCNAME}(): invalid number of parameters"
exit 1
fi
local database="$1"
local sqlfile="$2"
local tmpfile=$(mktemp)
local i=0
local dev=""
local status
if [ ! -f $sqlfile ]; then
errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
return 1
fi
echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..."
chmod 600 $tmpfile
for dev in ${DEVICE[*]}; do
if [ "${DEVICE[i]}" == "$DEFAULTDEV" ]; then
sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
-e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
-e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
$sqlfile > $tmpfile
fi
let i++
done
echo "----------------------"
mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST --default-character-set=utf8 "${database}" < $tmpfile
status=$?
rm -f $tmpfile
if [ $status -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
return 1
fi
echoAndLog "${FUNCNAME}(): file imported to database $database"
return 0
}
# Crea la base de datos
function mysqlCreateDb()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local database="$1"
echoAndLog "${FUNCNAME}(): creating database..."
mysqladmin --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST create $database
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while creating database $database"
return 1
fi
# Quitar modo ONLY_FULL_GROUP_BY de MySQL (ticket #730).
mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST -e "SET GLOBAL sql_mode=(SELECT TRIM(BOTH ',' FROM REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')));"
echoAndLog "${FUNCNAME}(): database $database created"
return 0
}
# Comprueba si ya está definido el usuario de acceso a la BD.
function mysqlCheckUserExists()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local userdb="$1"
echoAndLog "${FUNCNAME}(): checking if $userdb exists..."
echo "select user from user where user='${userdb}'\\G" |mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST mysql | grep user
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}(): user doesn't exists"
return 1
else
echoAndLog "${FUNCNAME}(): user already exists"
return 0
fi
}
# Crea un usuario administrativo para la base de datos
function mysqlCreateAdminUserToDb()
{
if [ $# -ne 3 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local database="$1"
local userdb="$2"
local passdb="$3"
echoAndLog "${FUNCNAME}(): creating admin user ${userdb} to database ${database}"
cat > $WORKDIR/create_${database}.sql <<EOF
GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
FLUSH PRIVILEGES ;
EOF
mysql --defaults-extra-file=$TMPMYCNF -h $MYSQLHOST < $WORKDIR/create_${database}.sql
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while creating user in mysql"
rm -f $WORKDIR/create_${database}.sql
return 1
else
echoAndLog "${FUNCNAME}(): user created ok"
rm -f $WORKDIR/create_${database}.sql
return 0
fi
}
#####################################################################
####### Funciones para la descarga de código
#####################################################################
@ -996,10 +636,10 @@ function smbConfigure()
backupFile $SAMBACFGDIR/smb.conf
# Copiar plantailla de recursos para OpenGnsys
sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \
sed -e "s/OPENGNSYSDIR/${INSTALL_OGBOOT_TARGET//\//\\/}/g" \
$WORKDIR/ogboot/server/etc/smb-og.conf.tmpl > $SAMBACFGDIR/smb-og.conf
# Configurar y recargar Samba"
perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= OpenGnsys Samba Server/" $SAMBACFGDIR/smb.conf
perl -pi -e "s/WORKGROUP/OPENGNSYS/; s/server string \=.*/server string \= ogBoot Samba Server/" $SAMBACFGDIR/smb.conf
if ! grep -q "smb-og" $SAMBACFGDIR/smb.conf; then
echo "include = $SAMBACFGDIR/smb-og.conf" >> $SAMBACFGDIR/smb.conf
fi
@ -1108,72 +748,6 @@ function dhcpConfigure()
####### Funciones específicas de la instalación de Opengnsys
#####################################################################
# Copiar ficheros del OpenGnsys Web Console.
function installWebFiles()
{
local COMPATDIR f
local SLIMFILE="slim-2.6.1.zip"
local SWAGGERFILE="swagger-ui-2.2.5.zip"
echoAndLog "${FUNCNAME}(): Installing web files..."
# Copiar ficheros.
cp -a $WORKDIR/ogboot/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para Doxygen.
if [ $? != 0 ]; then
errorAndLog "${FUNCNAME}(): Error copying web files."
exit 1
fi
# Descomprimir librerías: Slim y Swagger-UI.
unzip -o $WORKDIR/ogboot/admin/$SLIMFILE -d $INSTALL_TARGET/www/rest
unzip -o $WORKDIR/ogboot/admin/$SWAGGERFILE -d $INSTALL_TARGET/www/rest
# Compatibilidad con dispositivos móviles.
COMPATDIR="$INSTALL_TARGET/www/principal"
for f in acciones administracion aula aulas hardwares imagenes menus repositorios softwares; do
sed 's/clickcontextualnodo/clicksupnodo/g' $COMPATDIR/$f.php > $COMPATDIR/$f.device.php
done
cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php
# Acceso al manual de usuario
ln -fs ../doc/userManual $INSTALL_TARGET/www/userManual
# Ficheros de log de la API REST.
touch $INSTALL_TARGET/log/{ogagent,remotepc,rest}.log
echoAndLog "${FUNCNAME}(): Web files installed successfully."
}
# Copiar ficheros en la zona de descargas de OpenGnsys Web Console.
function installDownloadableFiles()
{
local VERSIONFILE OGVERSION FILENAME TARGETFILE
# Obtener versión a descargar.
VERSIONFILE="$INSTALL_TARGET/doc/VERSION.json"
OGVERSION="$(jq -r ".ogagent // \"$INSTVERSION\"" $VERSIONFILE 2>/dev/null || echo "$INSTVERSION")"
FILENAME="ogagentpkgs-$OGVERSION.tar.gz"
TARGETFILE=$WORKDIR/$FILENAME
# Descargar archivo comprimido, si es necesario.
if [ -s $PROGRAMDIR/$FILENAME ]; then
echoAndLog "${FUNCNAME}(): Moving $PROGRAMDIR/$FILENAME file to $(dirname $TARGETFILE)"
mv $PROGRAMDIR/$FILENAME $TARGETFILE
else
echoAndLog "${FUNCNAME}(): Downloading $FILENAME"
curl $DOWNLOADURL/$FILENAME -o $TARGETFILE
fi
if [ ! -s $TARGETFILE ]; then
errorAndLog "${FUNCNAME}(): Cannot download $FILENAME"
return 1
fi
# Descomprimir fichero en zona de descargas.
tar xvzf $TARGETFILE -C $INSTALL_TARGET/www/descargas
if [ $? != 0 ]; then
errorAndLog "${FUNCNAME}(): Error uncompressing archive."
exit 1
fi
}
# Configuración específica de Apache.
function installWebConsoleApacheConf()
{
if [ $# -ne 2 ]; then
@ -1233,22 +807,6 @@ function installWebConsoleApacheConf()
return 0
}
# Crear documentación Doxygen para la consola web.
function makeDoxygenFiles()
{
echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
$WORKDIR/ogboot/installer/ogGenerateDoc.sh \
$WORKDIR/ogboot/client/engine $INSTALL_TARGET/www
if [ ! -d "$INSTALL_TARGET/www/html" ]; then
errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
return 1
fi
mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
}
# Crea la estructura base de la instalación de ogBoot
function createDirs()
{
@ -1386,7 +944,7 @@ function ogServerCompilation ()
echoAndLog "${FUNCNAME}(): Compiling OpenGnsys Server"
pushd "$WORKDIR/ogServer-${BRANCH#v}"
autoreconf -fi && ./configure && make && mv ogserver $INSTALL_TARGET/sbin
autoreconf -fi && ./configure && make && mv ogserver $INSTALL_OGBOOT_TARGET/sbin
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}(): error while compiling OpenGnsys Server"
error=1
@ -1396,27 +954,6 @@ function ogServerCompilation ()
return $error
}
####################################################################
### Funciones de copia de la Interface de administración
####################################################################
# Copiar carpeta de Interface
function copyInterfaceAdm ()
{
local hayErrores=0
# Crear carpeta y copiar Interface
echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder"
cp -ar $WORKDIR/ogboot/admin/Interface $INSTALL_TARGET/client/interfaceAdm
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}(): error while copying Administration Interface Folder"
hayErrores=1
fi
return $hayErrores
}
####################################################################
### Funciones instalacion cliente opengnsys
####################################################################
@ -1488,7 +1025,7 @@ function clientCreate()
echo "-----------------------------3"
local FILENAME="$1"
local TARGETFILE=$INSTALL_OGBOOT_TARGET/lib/$FILENAME
local TARGETFILE=$INSTALL_TARGET/lib/$FILENAME
# Descargar cliente, si es necesario.
echo "PROGRAMDIR/FILENAME: $PROGRAMDIR/$FILENAME"
@ -1515,122 +1052,6 @@ function clientCreate()
echoAndLog "${FUNCNAME}(): Client generation success"
}
# Configuración básica de servicios de OpenGnsys
function openGnsysConfigure()
{
local i=0
local dev=""
local CONSOLEURL
echoAndLog "${FUNCNAME}(): Copying init files."
cp -a $WORKDIR/ogboot/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys
cp -a $WORKDIR/ogboot/admin/Sources/Services/opengnsys.service \
/lib/systemd/system/opengnsys.service
cp -a $WORKDIR/ogServer-${BRANCH#v}/cfg/ogserver.service \
/lib/systemd/system/ogserver.service
cp -a $WORKDIR/ogboot/admin/Sources/Services/opengnsys.default /etc/default/opengnsys
# Deshabilitar servicios de BitTorrent si no están instalados.
if [ ! -e /usr/bin/bttrack ]; then
sed -i 's/RUN_BTTRACKER="yes"/RUN_BTTRACKER="no"/; s/RUN_BTSEEDER="yes"/RUN_BTSEEDER="no"/' \
/etc/default/opengnsys
fi
echoAndLog "${FUNCNAME}(): Creating cron files."
echo "* * * * * root [ -x $INSTALL_OGBOOT_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator
echo "5 * * * * root [ -x $INSTALL_OGBOOT_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker
echo "* * * * * root [ -x $INSTALL_OGBOOT_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete
echo "* * * * * root [ -x $INSTALL_OGBOOT_TARGET/bin/ogagentqueue.cron ] && $INSTALL_TARGET/bin/ogagentqueue.cron" > /etc/cron.d/ogagentqueue
echoAndLog "${FUNCNAME}(): Creating logrotate configuration files."
sed -e "s/$OPENGNSYSDIR/${INSTALL_OGBOOT_TARGET//\//\\/}/g" \
$WORKDIR/ogboot/server/etc/logrotate.tmpl > /etc/logrotate.d/opengnsysServer
sed -e "s/$OPENGNSYSDIR/${INSTALL_OGBOOT_TARGET//\//\\/}/g" \
$WORKDIR/ogboot/repoman/etc/logrotate.tmpl > /etc/logrotate.d/opengnsysRepo
echoAndLog "${FUNCNAME}(): Creating OpenGnsys config files."
for dev in ${DEVICE[*]}; do
if [ -n "${SERVERIP[i]}" ]; then
echo "{
\"rest\" : {
\"ip\" : \"${SERVERIP[i]}\",
\"port\" : \"8888\",
\"api_token\": \"5a5ca1172136299640a9f47469237e0a\"
},
\"database\" : {
\"ip\": \"$OPENGNSYS_SERVER\",
\"port\": \"3306\",
\"name\" : \"$OPENGNSYS_DATABASE\",
\"user\" : \"$OPENGNSYS_DB_USER\",
\"pass\" : \"$OPENGNSYS_DB_PASSWD\"
},
\"wol\" : {
\"interface\" : \"$dev\"
}
}" | jq '.' > "$INSTALL_OGBOOT_TARGET"/etc/ogserver-"$dev".json
sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
$WORKDIR/ogboot/repoman/etc/ogAdmRepo.cfg.tmpl > $INSTALL_TARGET/etc/ogAdmRepo-$dev.cfg
CONSOLEURL="https://${SERVERIP[i]}/opengnsys"
sed -e "s/SERVERIP/${SERVERIP[i]}/g" \
-e "s/DBUSER/$OPENGNSYS_DB_USER/g" \
-e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" \
-e "s/DATABASE/$OPENGNSYS_DATABASE/g" \
-e "s/OPENGNSYSURL/${CONSOLEURL//\//\\/}/g" \
$INSTALL_OGBOOT_TARGET/www/controlacceso.php > $INSTALL_OGBOOT_TARGET/www/controlacceso-$dev.php
if [ "$dev" == "$DEFAULTDEV" ]; then
OPENGNSYS_CONSOLEURL="$CONSOLEURL"
OPENGNSYS_SERVERIP="${SERVERIP[i]}"
fi
fi
let i++
done
ln -f $INSTALL_OGBOOT_TARGET/etc/ogserver-$DEFAULTDEV.json $INSTALL_OGBOOT_TARGET/etc/ogserver.json
ln -f $INSTALL_OGBOOT_TARGET/etc/ogAdmRepo-$DEFAULTDEV.cfg $INSTALL_OGBOOT_TARGET/etc/ogAdmRepo.cfg
ln -f $INSTALL_OGBOOT_TARGET/www/controlacceso-$DEFAULTDEV.php $INSTALL_OGBOOT_TARGET/www/controlacceso.php
# Configuración del motor de clonación.
# - Zona horaria del servidor.
TZ=$(timedatectl status|awk -F"[:()]" '/Time.*zone/ {print $2}')
cat << EOT >> $INSTALL_OGBOOT_TARGET/client/etc/engine.cfg
# OpenGnsys Server timezone.
TZ="${TZ// /}"
EOT
# Revisar permisos generales.
if [ -x $INSTALL_OGBOOT_TARGET/bin/checkperms ]; then
echoAndLog "${FUNCNAME}(): Checking permissions."
OPENGNSYS_DIR="$INSTALL_OGBOOT_TARGET" OPENGNSYS_USER="$OPENGNSYS_CLIENT_USER" APACHE_USER="$APACHE_RUN_USER" APACHE_GROUP="$APACHE_RUN_GROUP" checkperms
fi
# Evitar inicio de duplicado en Ubuntu 14.04 (Upstart y SysV Init).
if [ -f /etc/init/${MYSQLSERV}.conf -a -n "$(which initctl 2>/dev/null)" ]; then
service=$MYSQLSERV
$DISABLESERVICE
fi
# Actualizar tokens de autenticación e iniciar los servicios.
service="opengnsys"
$ENABLESERVICE
if [ -x $INSTALL_OGBOOT_TARGET/bin/settoken ]; then
echoAndLog "${FUNCNAME}(): Setting authentication tokens and starting OpenGnsys services."
$INSTALL_OGBOOT_TARGET/bin/settoken "$OPENGNSYS_DB_USER"
$INSTALL_OGBOOT_TARGET/bin/settoken -f
else
echoAndLog "${FUNCNAME}(): Starting OpenGnsys services."
$STARTSERVICE
fi
# Enable and start ogServer systemd service
service="ogserver"
$ENABLESERVICE; $STARTSERVICE
echoAndLog "${FUNCNAME}(): Creating ogClient config files."
sed -i -e 's/127.0.0.1/'$OPENGNSYS_SERVERIP'/' \
-e 's/pass'.*$'/pass\": \"'$OPENGNSYS_CLIENT_PASSWD'\"/' \
$INSTALL_OGBOOT_TARGET/client/ogClient/cfg/ogclient.json
}
#####################################################################
####### Función de resumen informativo de la instalación
#####################################################################
@ -1679,22 +1100,13 @@ function installationSummary()
echoAndLog "Review or edit all configuration files."
echoAndLog "Insert DHCP configuration data and restart service."
echoAndLog "Review syslog configuration and logrotate by syslog,"
echo
}
#####################################################################
#####################################################################
#####################################################################
#####################################################################
#####################################################################
#####################################################################
#####################################################################
####### Proceso de instalación de ogBoot
#####################################################################
#####################################################################
#####################################################################
#####################################################################
#####################################################################
# Sólo ejecutable por usuario root
@ -1706,14 +1118,14 @@ fi
globalSetup
# Comprobar instalación previa.
if cat $INSTALL_OGBOOT_TARGET/doc/VERSION.* &>/dev/null; then
echo "ERROR: OpenGnsys is already installed. Run \"$INSTALL_OGBOOT_TARGET/lib/ogboot-update.sh\" as root to update."
echo "ERROR: ogBoot is already installed. Run \"$INSTALL_OGBOOT_TARGET/lib/ogboot-update.sh\" as root to update."
exit 2
fi
# Si la distribución no es la recomendada mostramos mensaje informativo.
checkDistribution
echoAndLog "OpenGnsys installation begins at $(date)"
echoAndLog "ogBoot installation begins at $(date)"
# Introducir datos de configuración y establecer variables globales.
userData
@ -1783,7 +1195,6 @@ if [ $REMOTE -eq 1 ]; then
else
ln -fs "$(dirname $PROGRAMDIR)" ogboot
fi
echo "*****************************************"
# Configuración de TFTP.
tftpConfigure
@ -1812,38 +1223,6 @@ if [ $? -ne 0 ]; then
fi
INSTVERSION=$(jq -r '.version' $INSTALL_OGBOOT_TARGET/doc/VERSION.json)
mysqlTestConnection "${MYSQL_ROOT_PASSWORD}"
if [ $? -ne 0 ]; then
errorAndLog "Error while connection to mysql"
exit 1
fi
mysqlDbExists ${OPENGNSYS_DATABASE}
if [ $? -ne 0 ]; then
echoAndLog "Creating Web Console database"
mysqlCreateDb ${OPENGNSYS_DATABASE}
if [ $? -ne 0 ]; then
errorAndLog "Error while creating Web Console database"
exit 1
fi
else
echoAndLog "Web Console database exists, ommiting creation"
fi
mysqlCheckUserExists ${OPENGNSYS_DB_USER}
if [ $? -ne 0 ]; then
echoAndLog "Creating user in database"
mysqlCreateAdminUserToDb ${OPENGNSYS_DATABASE} ${OPENGNSYS_DB_USER} "${OPENGNSYS_DB_PASSWD}"
if [ $? -ne 0 ]; then
errorAndLog "Error while creating database user"
exit 1
fi
fi
rm -f $TMPMYCNF
# Creando configuración de Apache.
installWebConsoleApacheConf $INSTALL_OGBOOT_TARGET $APACHECFGDIR
if [ $? -ne 0 ]; then
errorAndLog "Error configuring Apache for OpenGnsys Admin"
exit 1
@ -1868,12 +1247,9 @@ for i in $OGLIVE; do
fi
done
# Configuración de servicios de OpenGnsys
openGnsysConfigure
# Mostrar sumario de la instalación e instrucciones de post-instalación.
installationSummary
rm -rf $WORKDIR
echoAndLog "OpenGnsys installation finished at $(date)"
echoAndLog "ogBoot installation finished at $(date)"
exit 0