[a0867b37] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file opengnsys_update.sh |
---|
| 4 | #@brief Script actualización de OpenGnSys |
---|
| 5 | #@warning No se actualiza BD, ni ficheros de configuración. |
---|
| 6 | #@version 0.9 - basado en opengnsys_installer.sh |
---|
| 7 | #@author Ramón Gómez - ETSII Univ. Sevilla |
---|
| 8 | #@date 2010/01/27 |
---|
[c1e00e4] | 9 | #@version 1.0 - adaptación a OpenGnSys 1.0 |
---|
| 10 | #@author Ramón Gómez - ETSII Univ. Sevilla |
---|
| 11 | #@date 2011/03/02 |
---|
[64dd765] | 12 | #@version 1.0.1 - control de auto actualización del script |
---|
| 13 | #@author Ramón Gómez - ETSII Univ. Sevilla |
---|
| 14 | #@date 2011/05/17 |
---|
[a0867b37] | 15 | #*/ |
---|
| 16 | |
---|
| 17 | |
---|
[295b4ab] | 18 | #### AVISO: Editar configuración de acceso por defecto a la Base de Datos. |
---|
| 19 | OPENGNSYS_DATABASE="ogAdmBD" # Nombre de la base datos |
---|
| 20 | OPENGNSYS_DBUSER="usuog" # Usuario de acceso |
---|
| 21 | OPENGNSYS_DBPASSWORD="passusuog" # Clave del usuario |
---|
| 22 | |
---|
| 23 | #### AVISO: NO Editar variables de acceso desde el cliente |
---|
| 24 | OPENGNSYS_CLIENTUSER="opengnsys" # Usuario Samba |
---|
| 25 | |
---|
| 26 | |
---|
[a0867b37] | 27 | # Sólo ejecutable por usuario root |
---|
| 28 | if [ "$(whoami)" != 'root' ] |
---|
| 29 | then |
---|
| 30 | echo "ERROR: this program must run under root privileges!!" |
---|
| 31 | exit 1 |
---|
| 32 | fi |
---|
[4e51cb0] | 33 | # Error si OpenGnSys no está instalado (no existe el directorio del proyecto) |
---|
| 34 | INSTALL_TARGET=/opt/opengnsys |
---|
| 35 | if [ ! -d $INSTALL_TARGET ]; then |
---|
| 36 | echo "ERROR: OpenGnSys is not installed, cannot update!!" |
---|
| 37 | exit 1 |
---|
| 38 | fi |
---|
[a0867b37] | 39 | |
---|
| 40 | # Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). |
---|
| 41 | PROGRAMDIR=$(readlink -e $(dirname "$0")) |
---|
[64dd765] | 42 | PROGRAMNAME=$(basename "$0") |
---|
[c1e00e4] | 43 | DEPS="build-essential g++-multilib rsync ctorrent samba unzip netpipes debootstrap schroot squashfs-tools" |
---|
[07c3a59] | 44 | OPENGNSYS_SERVER="www.opengnsys.es" |
---|
[a0867b37] | 45 | if [ -d "$PROGRAMDIR/../installer" ]; then |
---|
| 46 | USESVN=0 |
---|
| 47 | else |
---|
| 48 | USESVN=1 |
---|
| 49 | DEPS="$DEPS subversion" |
---|
| 50 | fi |
---|
[eb9424f] | 51 | SVN_URL="http://$OPENGNSYS_SERVER/svn/branches/version1.0/" |
---|
[a0867b37] | 52 | |
---|
| 53 | WORKDIR=/tmp/opengnsys_update |
---|
| 54 | mkdir -p $WORKDIR |
---|
| 55 | |
---|
| 56 | LOG_FILE=/tmp/opengnsys_update.log |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | ##################################################################### |
---|
| 61 | ####### Algunas funciones útiles de propósito general: |
---|
| 62 | ##################################################################### |
---|
[295b4ab] | 63 | |
---|
[64dd765] | 64 | # Comprobar auto-actualización. |
---|
| 65 | function checkAutoUpdate() |
---|
| 66 | { |
---|
| 67 | local update=0 |
---|
| 68 | |
---|
| 69 | # Actaulizar el script si ha cambiado o no existe el original. |
---|
| 70 | if [ $USESVN -eq 1 ]; then |
---|
[7b0c6ff] | 71 | svn export $SVN_URL/installer/$PROGRAMNAME |
---|
[64dd765] | 72 | if ! diff --brief $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME &>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then |
---|
| 73 | mv $PROGRAMNAME $INSTALL_TARGET/lib |
---|
| 74 | update=1 |
---|
| 75 | else |
---|
| 76 | rm -f $PROGRAMNAME |
---|
| 77 | fi |
---|
| 78 | else |
---|
| 79 | if ! diff --brief $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME &>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then |
---|
| 80 | cp -a $PROGRAMDIR/$PROGRAMNAME $INSTALL_TARGET/lib |
---|
| 81 | update=1 |
---|
| 82 | fi |
---|
| 83 | fi |
---|
| 84 | |
---|
| 85 | return $update |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
[a0867b37] | 89 | function getDateTime() |
---|
| 90 | { |
---|
[295b4ab] | 91 | date "+%Y%m%d-%H%M%S" |
---|
[a0867b37] | 92 | } |
---|
| 93 | |
---|
| 94 | # Escribe a fichero y muestra por pantalla |
---|
| 95 | function echoAndLog() |
---|
| 96 | { |
---|
| 97 | echo $1 |
---|
| 98 | FECHAHORA=`getDateTime` |
---|
| 99 | echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | function errorAndLog() |
---|
| 103 | { |
---|
| 104 | echo "ERROR: $1" |
---|
| 105 | FECHAHORA=`getDateTime` |
---|
| 106 | echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | ##################################################################### |
---|
| 111 | ####### Funciones de copia de seguridad y restauración de ficheros |
---|
| 112 | ##################################################################### |
---|
| 113 | |
---|
| 114 | # Hace un backup del fichero pasado por parámetro |
---|
| 115 | # deja un -last y uno para el día |
---|
| 116 | function backupFile() |
---|
| 117 | { |
---|
| 118 | if [ $# -ne 1 ]; then |
---|
| 119 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 120 | exit 1 |
---|
| 121 | fi |
---|
| 122 | |
---|
| 123 | local fichero=$1 |
---|
| 124 | local fecha=`date +%Y%m%d` |
---|
| 125 | |
---|
| 126 | if [ ! -f $fichero ]; then |
---|
| 127 | errorAndLog "${FUNCNAME}(): file $fichero doesn't exists" |
---|
| 128 | return 1 |
---|
| 129 | fi |
---|
| 130 | |
---|
[ebbbfc01] | 131 | echoAndLog "${FUNCNAME}(): Making $fichero back-up" |
---|
[a0867b37] | 132 | |
---|
| 133 | # realiza una copia de la última configuración como last |
---|
| 134 | cp -p $fichero "${fichero}-LAST" |
---|
| 135 | |
---|
| 136 | # si para el día no hay backup lo hace, sino no |
---|
| 137 | if [ ! -f "${fichero}-${fecha}" ]; then |
---|
| 138 | cp -p $fichero "${fichero}-${fecha}" |
---|
| 139 | fi |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | # Restaura un fichero desde su copia de seguridad |
---|
| 143 | function restoreFile() |
---|
| 144 | { |
---|
| 145 | if [ $# -ne 1 ]; then |
---|
| 146 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 147 | exit 1 |
---|
| 148 | fi |
---|
| 149 | |
---|
| 150 | local fichero=$1 |
---|
| 151 | |
---|
[ebbbfc01] | 152 | echoAndLog "${FUNCNAME}(): restoring file $fichero" |
---|
[a0867b37] | 153 | if [ -f "${fichero}-LAST" ]; then |
---|
| 154 | cp -p "$fichero-LAST" "$fichero" |
---|
| 155 | fi |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | ##################################################################### |
---|
[295b4ab] | 160 | ####### Funciones de acceso a base de datos |
---|
| 161 | ##################################################################### |
---|
| 162 | |
---|
| 163 | # Actualizar la base datos |
---|
| 164 | function importSqlFile() |
---|
| 165 | { |
---|
| 166 | if [ $# -ne 4 ]; then |
---|
| 167 | errorAndLog "${FNCNAME}(): invalid number of parameters" |
---|
| 168 | exit 1 |
---|
| 169 | fi |
---|
| 170 | |
---|
| 171 | local dbuser="$1" |
---|
| 172 | local dbpassword="$2" |
---|
| 173 | local database="$3" |
---|
| 174 | local sqlfile="$4" |
---|
| 175 | local tmpfile=$(mktemp) |
---|
| 176 | local status |
---|
| 177 | |
---|
| 178 | if [ ! -r $sqlfile ]; then |
---|
| 179 | errorAndLog "${FUNCNAME}(): Unable to read $sqlfile!!" |
---|
| 180 | return 1 |
---|
| 181 | fi |
---|
| 182 | |
---|
| 183 | echoAndLog "${FUNCNAME}(): importing SQL file to ${database}..." |
---|
| 184 | chmod 600 $tmpfile |
---|
| 185 | sed -e "s/SERVERIP/$SERVERIP/g" -e "s/DBUSER/$OPENGNSYS_DB_USER/g" \ |
---|
| 186 | -e "s/DBPASSWORD/$OPENGNSYS_DB_PASSWD/g" $sqlfile > $tmpfile |
---|
| 187 | mysql -u$dbuser -p"$dbpassword" --default-character-set=utf8 "$database" < $tmpfile |
---|
| 188 | status=$? |
---|
| 189 | rm -f $tmpfile |
---|
| 190 | if [ $status -ne 0 ]; then |
---|
| 191 | errorAndLog "${FUNCNAME}(): error importing $sqlfile in database $database" |
---|
| 192 | return 1 |
---|
| 193 | fi |
---|
| 194 | echoAndLog "${FUNCNAME}(): file imported to database $database" |
---|
| 195 | return 0 |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | ##################################################################### |
---|
[a0867b37] | 200 | ####### Funciones de instalación de paquetes |
---|
| 201 | ##################################################################### |
---|
| 202 | |
---|
| 203 | # Instalar las deependencias necesarias para el actualizador. |
---|
[64dd765] | 204 | function installDependencies() |
---|
[a0867b37] | 205 | { |
---|
| 206 | if [ $# = 0 ]; then |
---|
| 207 | echoAndLog "${FUNCNAME}(): no deps needed." |
---|
[c1e00e4] | 208 | else |
---|
| 209 | while [ $# -gt 0 ]; do |
---|
[ebbbfc01] | 210 | dpkg -s $1 2>/dev/null | grep -q "Status: install ok" |
---|
[c1e00e4] | 211 | if [ $? -ne 0 ]; then |
---|
| 212 | INSTALLDEPS="$INSTALLDEPS $1" |
---|
| 213 | fi |
---|
| 214 | shift |
---|
| 215 | done |
---|
| 216 | if [ -n "$INSTALLDEPS" ]; then |
---|
[ebbbfc01] | 217 | apt-get update && apt-get -y install --force-yes $INSTALLDEPS |
---|
[c1e00e4] | 218 | if [ $? -ne 0 ]; then |
---|
| 219 | errorAndLog "${FUNCNAME}(): cannot install some dependencies: $INSTALLDEPS." |
---|
| 220 | return 1 |
---|
| 221 | fi |
---|
| 222 | fi |
---|
| 223 | fi |
---|
[a0867b37] | 224 | } |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | ##################################################################### |
---|
| 228 | ####### Funciones para el manejo de Subversion |
---|
| 229 | ##################################################################### |
---|
| 230 | |
---|
| 231 | function svnExportCode() |
---|
| 232 | { |
---|
| 233 | if [ $# -ne 1 ]; then |
---|
| 234 | errorAndLog "${FUNCNAME}(): invalid number of parameters" |
---|
| 235 | exit 1 |
---|
| 236 | fi |
---|
| 237 | |
---|
[27dc5ff] | 238 | local url="$1" |
---|
[a0867b37] | 239 | |
---|
| 240 | echoAndLog "${FUNCNAME}(): downloading subversion code..." |
---|
| 241 | |
---|
[7ad4465] | 242 | svn checkout "${url}" opengnsys |
---|
[a0867b37] | 243 | if [ $? -ne 0 ]; then |
---|
| 244 | errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password" |
---|
| 245 | return 1 |
---|
| 246 | fi |
---|
| 247 | echoAndLog "${FUNCNAME}(): subversion code downloaded" |
---|
| 248 | return 0 |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | ############################################################ |
---|
| 253 | ### Detectar red |
---|
| 254 | ############################################################ |
---|
| 255 | |
---|
[07c3a59] | 256 | # Comprobar si existe conexión. |
---|
| 257 | function checkNetworkConnection() |
---|
| 258 | { |
---|
| 259 | OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"www.opengnsys.es"} |
---|
| 260 | wget --spider -q $OPENGNSYS_SERVER |
---|
| 261 | } |
---|
| 262 | |
---|
[a0867b37] | 263 | |
---|
| 264 | ##################################################################### |
---|
| 265 | ####### Funciones específicas de la instalación de Opengnsys |
---|
| 266 | ##################################################################### |
---|
| 267 | |
---|
[cf2142ea] | 268 | # Copiar ficheros de arranque de los servicios del sistema de OpenGnSys |
---|
[64dd765] | 269 | function updateServicesStart() |
---|
| 270 | { |
---|
[51b179a] | 271 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys init file ..." |
---|
[6b65dfd] | 272 | cp -p $WORKDIR/opengnsys/admin/Sources/Services/opengnsys.init /etc/init.d/opengnsys |
---|
[cf2142ea] | 273 | if [ $? != 0 ]; then |
---|
| 274 | errorAndLog "${FUNCNAME}(): Error updating /etc/init.d/opengnsys" |
---|
| 275 | exit 1 |
---|
| 276 | fi |
---|
[51b179a] | 277 | echoAndLog "${FUNCNAME}(): init file updated successfully." |
---|
[cf2142ea] | 278 | } |
---|
| 279 | |
---|
[45f1fe8] | 280 | # Actualizar cliente OpenGnSys |
---|
[295b4ab] | 281 | function updateClientFiles() |
---|
[45f1fe8] | 282 | { |
---|
| 283 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys Client files." |
---|
| 284 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client |
---|
| 285 | if [ $? -ne 0 ]; then |
---|
| 286 | errorAndLog "${FUNCNAME}(): error while updating client structure" |
---|
[51b179a] | 287 | exit 1 |
---|
[45f1fe8] | 288 | fi |
---|
| 289 | find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null |
---|
| 290 | |
---|
| 291 | echoAndLog "${FUNCNAME}(): Updating OpenGnSys Cloning Engine files." |
---|
[51b179a] | 292 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin |
---|
[45f1fe8] | 293 | if [ $? -ne 0 ]; then |
---|
| 294 | errorAndLog "${FUNCNAME}(): error while updating engine files" |
---|
[51b179a] | 295 | exit 1 |
---|
[45f1fe8] | 296 | fi |
---|
| 297 | |
---|
[51b179a] | 298 | echoAndLog "${FUNCNAME}(): client files update success." |
---|
[45f1fe8] | 299 | } |
---|
[4e51cb0] | 300 | |
---|
| 301 | # Exportar nombre de usuario y grupo del servicio Apache. |
---|
| 302 | function getApacheUser() |
---|
| 303 | { |
---|
| 304 | # Variables de ejecución de Apache |
---|
| 305 | # - APACHE_RUN_USER |
---|
| 306 | # - APACHE_RUN_GROUP |
---|
| 307 | if [ -f /etc/apache2/envvars ]; then |
---|
| 308 | source /etc/apache2/envvars |
---|
| 309 | fi |
---|
| 310 | APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"} |
---|
| 311 | APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"} |
---|
| 312 | } |
---|
| 313 | |
---|
[a0867b37] | 314 | # Copiar ficheros del OpenGnSys Web Console. |
---|
| 315 | function updateWebFiles() |
---|
| 316 | { |
---|
[d655cc4] | 317 | local ERRCODE |
---|
[a0867b37] | 318 | echoAndLog "${FUNCNAME}(): Updating web files..." |
---|
[d655cc4] | 319 | backupFile $INSTALL_TARGET/www/controlacceso.php |
---|
| 320 | mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole |
---|
[1db2ed8] | 321 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET |
---|
[d655cc4] | 322 | ERRCODE=$? |
---|
| 323 | mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www |
---|
[c1e00e4] | 324 | unzip -o $WORKDIR/opengnsys/admin/xajax_0.5_standard.zip -d $INSTALL_TARGET/www/xajax |
---|
[d655cc4] | 325 | if [ $ERRCODE != 0 ]; then |
---|
[a0867b37] | 326 | errorAndLog "${FUNCNAME}(): Error updating web files." |
---|
| 327 | exit 1 |
---|
| 328 | fi |
---|
[d655cc4] | 329 | restoreFile $INSTALL_TARGET/www/controlacceso.php |
---|
[a0867b37] | 330 | # Cambiar permisos para ficheros especiales. |
---|
[ebbbfc01] | 331 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/includes $INSTALL_TARGET/www/images/iconos |
---|
[a0867b37] | 332 | echoAndLog "${FUNCNAME}(): Web files updated successfully." |
---|
| 333 | } |
---|
| 334 | |
---|
[72134d5] | 335 | # Copiar carpeta de Interface |
---|
[64dd765] | 336 | function updateInterfaceAdm() |
---|
[72134d5] | 337 | { |
---|
[27dc5ff] | 338 | local errcode=0 |
---|
[72134d5] | 339 | |
---|
| 340 | # Crear carpeta y copiar Interface |
---|
| 341 | echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" |
---|
| 342 | mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface |
---|
| 343 | rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client |
---|
[27dc5ff] | 344 | errcoce=$? |
---|
[72134d5] | 345 | mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm |
---|
[27dc5ff] | 346 | if [ $errcode -ne 0 ]; then |
---|
[72134d5] | 347 | echoAndLog "${FUNCNAME}(): error while updating admin interface" |
---|
| 348 | exit 1 |
---|
| 349 | fi |
---|
| 350 | chmod -R +x $INSTALL_TARGET/client/interfaceAdm |
---|
[b6f1726] | 351 | chown $OPENGNSYS_CLIENTUSER:$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
[f6c1d2b] | 352 | chmod 700 $INSTALL_TARGET/client/interfaceAdm/CambiarAcceso |
---|
[72134d5] | 353 | echoAndLog "${FUNCNAME}(): Admin interface updated successfully." |
---|
| 354 | } |
---|
[a0867b37] | 355 | |
---|
[5d6bf97] | 356 | # Crear documentación Doxygen para la consola web. |
---|
| 357 | function makeDoxygenFiles() |
---|
| 358 | { |
---|
| 359 | echoAndLog "${FUNCNAME}(): Making Doxygen web files..." |
---|
| 360 | $WORKDIR/opengnsys/installer/ogGenerateDoc.sh \ |
---|
| 361 | $WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www |
---|
| 362 | if [ ! -d "$INSTALL_TARGET/www/html" ]; then |
---|
| 363 | errorAndLog "${FUNCNAME}(): unable to create Doxygen web files." |
---|
| 364 | return 1 |
---|
| 365 | fi |
---|
[45f1fe8] | 366 | rm -fr "$INSTALL_TARGET/www/api" |
---|
[15b2a4e] | 367 | mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api" |
---|
| 368 | rm -fr $INSTALL_TARGET/www/{man,perlmod,rtf} |
---|
[5d6bf97] | 369 | chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api |
---|
| 370 | echoAndLog "${FUNCNAME}(): Doxygen web files created successfully." |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
[a0867b37] | 374 | # Crea la estructura base de la instalación de opengnsys |
---|
| 375 | function createDirs() |
---|
| 376 | { |
---|
[eb9424f] | 377 | # Crear estructura de directorios. |
---|
[a0867b37] | 378 | echoAndLog "${FUNCNAME}(): creating directory paths in ${INSTALL_TARGET}" |
---|
| 379 | mkdir -p ${INSTALL_TARGET} |
---|
| 380 | mkdir -p ${INSTALL_TARGET}/bin |
---|
| 381 | mkdir -p ${INSTALL_TARGET}/client |
---|
| 382 | mkdir -p ${INSTALL_TARGET}/doc |
---|
| 383 | mkdir -p ${INSTALL_TARGET}/etc |
---|
| 384 | mkdir -p ${INSTALL_TARGET}/lib |
---|
| 385 | mkdir -p ${INSTALL_TARGET}/log/clients |
---|
[eb9424f] | 386 | ln -fs ${INSTALL_TARGET}/log /var/log/opengnsys |
---|
[a0867b37] | 387 | mkdir -p ${INSTALL_TARGET}/sbin |
---|
| 388 | mkdir -p ${INSTALL_TARGET}/www |
---|
| 389 | mkdir -p ${INSTALL_TARGET}/images |
---|
| 390 | ln -fs /var/lib/tftpboot ${INSTALL_TARGET} |
---|
[eb9424f] | 391 | mkdir -p ${INSTALL_TARGET}/tftpboot/pxelinux.cfg |
---|
[a0867b37] | 392 | if [ $? -ne 0 ]; then |
---|
| 393 | errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" |
---|
| 394 | return 1 |
---|
| 395 | fi |
---|
| 396 | |
---|
[eb9424f] | 397 | # Crear usuario ficticio. |
---|
| 398 | if id -u $OPENGNSYS_CLIENTUSER &>/dev/null; then |
---|
| 399 | echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENTUSER\" is already created" |
---|
| 400 | else |
---|
| 401 | echoAndLog "${FUNCNAME}(): creating OpenGnSys user" |
---|
| 402 | useradd $OPENGNSYS_CLIENTUSER 2>/dev/null |
---|
| 403 | if [ $? -ne 0 ]; then |
---|
| 404 | errorAndLog "${FUNCNAME}(): error creating OpenGnSys user" |
---|
| 405 | return 1 |
---|
| 406 | fi |
---|
| 407 | fi |
---|
| 408 | |
---|
| 409 | # Establecer los permisos básicos. |
---|
| 410 | echoAndLog "${FUNCNAME}(): setting directory permissions" |
---|
| 411 | chmod -R 775 $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg} |
---|
| 412 | chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/{log/clients,images,tftpboot/pxelinux.cfg} |
---|
| 413 | if [ $? -ne 0 ]; then |
---|
| 414 | errorAndLog "${FUNCNAME}(): error while setting permissions" |
---|
| 415 | return 1 |
---|
| 416 | fi |
---|
| 417 | |
---|
[a0867b37] | 418 | echoAndLog "${FUNCNAME}(): directory paths created" |
---|
| 419 | return 0 |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | # Copia ficheros de configuración y ejecutables genéricos del servidor. |
---|
[64dd765] | 423 | function updateServerFiles() |
---|
[bb30a50] | 424 | { |
---|
[c1e00e4] | 425 | # No copiar ficheros del antiguo cliente Initrd |
---|
[873cf1e] | 426 | local SOURCES=( repoman/bin \ |
---|
[c1e00e4] | 427 | server/bin \ |
---|
[873cf1e] | 428 | server/tftpboot \ |
---|
[bb30a50] | 429 | installer/opengnsys_uninstall.sh \ |
---|
[873cf1e] | 430 | doc ) |
---|
| 431 | local TARGETS=( bin \ |
---|
| 432 | bin \ |
---|
| 433 | tftpboot \ |
---|
[4057c5d] | 434 | lib/opengnsys_uninstall.sh \ |
---|
[873cf1e] | 435 | doc ) |
---|
[a0867b37] | 436 | |
---|
| 437 | if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then |
---|
| 438 | errorAndLog "${FUNCNAME}(): inconsistent number of array items" |
---|
| 439 | exit 1 |
---|
| 440 | fi |
---|
| 441 | |
---|
| 442 | echoAndLog "${FUNCNAME}(): updating files in server directories" |
---|
| 443 | pushd $WORKDIR/opengnsys >/dev/null |
---|
| 444 | local i |
---|
| 445 | for (( i = 0; i < ${#SOURCES[@]}; i++ )); do |
---|
[27dc5ff] | 446 | if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then |
---|
[4057c5d] | 447 | rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}")) |
---|
[aa36857] | 448 | else |
---|
[4057c5d] | 449 | rsync --exclude .svn -irplt "${SOURCES[i]}" $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}") |
---|
[aa36857] | 450 | fi |
---|
[a0867b37] | 451 | done |
---|
| 452 | popd >/dev/null |
---|
[9ee62ad] | 453 | echoAndLog "${FUNCNAME}(): updating cron files" |
---|
| 454 | echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator |
---|
[da8db11] | 455 | echoAndLog "${FUNCNAME}(): server files updated successfully." |
---|
[a0867b37] | 456 | } |
---|
| 457 | |
---|
| 458 | #################################################################### |
---|
| 459 | ### Funciones de compilación de código fuente de servicios |
---|
| 460 | #################################################################### |
---|
| 461 | |
---|
[bb30a50] | 462 | # Recompilar y actualiza los serivicios y clientes. |
---|
[64dd765] | 463 | function compileServices() |
---|
[a0867b37] | 464 | { |
---|
[bb30a50] | 465 | local hayErrores=0 |
---|
| 466 | |
---|
| 467 | # Compilar OpenGnSys Server |
---|
| 468 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Admin Server" |
---|
| 469 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmServer |
---|
| 470 | make && mv ogAdmServer $INSTALL_TARGET/sbin |
---|
| 471 | if [ $? -ne 0 ]; then |
---|
| 472 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server" |
---|
| 473 | hayErrores=1 |
---|
| 474 | fi |
---|
| 475 | popd |
---|
| 476 | # Compilar OpenGnSys Repository Manager |
---|
| 477 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Repository Manager" |
---|
| 478 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmRepo |
---|
| 479 | make && mv ogAdmRepo $INSTALL_TARGET/sbin |
---|
| 480 | if [ $? -ne 0 ]; then |
---|
| 481 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager" |
---|
| 482 | hayErrores=1 |
---|
| 483 | fi |
---|
| 484 | popd |
---|
| 485 | # Compilar OpenGnSys Agent |
---|
| 486 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Agent" |
---|
| 487 | pushd $WORKDIR/opengnsys/admin/Sources/Services/ogAdmAgent |
---|
| 488 | make && mv ogAdmAgent $INSTALL_TARGET/sbin |
---|
| 489 | if [ $? -ne 0 ]; then |
---|
| 490 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Agent" |
---|
| 491 | hayErrores=1 |
---|
| 492 | fi |
---|
| 493 | popd |
---|
| 494 | |
---|
[a0867b37] | 495 | # Compilar OpenGnSys Client |
---|
[bb30a50] | 496 | echoAndLog "${FUNCNAME}(): Recompiling OpenGnSys Client" |
---|
[72134d5] | 497 | pushd $WORKDIR/opengnsys/admin/Sources/Clients/ogAdmClient |
---|
[e473667] | 498 | make && mv ogAdmClient $INSTALL_TARGET/client/bin |
---|
[a0867b37] | 499 | if [ $? -ne 0 ]; then |
---|
| 500 | echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Client" |
---|
| 501 | hayErrores=1 |
---|
| 502 | fi |
---|
| 503 | popd |
---|
| 504 | |
---|
| 505 | return $hayErrores |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | |
---|
| 509 | #################################################################### |
---|
[4e51cb0] | 510 | ### Funciones instalacion cliente OpenGnSys |
---|
[a0867b37] | 511 | #################################################################### |
---|
| 512 | |
---|
[c1e00e4] | 513 | # Actualizar nuevo cliente para OpenGnSys 1.0 |
---|
| 514 | function updateClient() |
---|
| 515 | { |
---|
| 516 | local DOWNLOADURL=http://www.opengnsys.es/downloads |
---|
[e9722d2] | 517 | local FILENAME=ogclient-1.0.1-lucid-32bit.tar.gz |
---|
[6ef9f23] | 518 | local TMPFILE=/tmp/$FILENAME |
---|
[c1e00e4] | 519 | |
---|
| 520 | echoAndLog "${FUNCNAME}(): Loading Client" |
---|
| 521 | # Descargar y descomprimir cliente ogclient |
---|
[03882ae] | 522 | wget $DOWNLOADURL/$FILENAME -O $TMPFILE |
---|
[6ef9f23] | 523 | if [ ! -s $TMPFILE ]; then |
---|
| 524 | errorAndLog "${FUNCNAME}(): Error loading OpenGnSys Client" |
---|
[c1e00e4] | 525 | return 1 |
---|
| 526 | fi |
---|
[03882ae] | 527 | echoAndLog "${FUNCNAME}(): Extracting Client files" |
---|
[6ef9f23] | 528 | tar xzvf $TMPFILE -C $INSTALL_TARGET/tftpboot |
---|
| 529 | rm -f $TMPFILE |
---|
[c1e00e4] | 530 | # Usar la versión más reciente del Kernel y del Initrd para el cliente. |
---|
[295b4ab] | 531 | ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/vmlinuz-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/ogvmlinuz |
---|
| 532 | ln -f $(ls $INSTALL_TARGET/tftpboot/ogclient/initrd.img-*|tail -1) $INSTALL_TARGET/tftpboot/ogclient/oginitrd.img |
---|
[c1e00e4] | 533 | # Establecer los permisos. |
---|
| 534 | chmod -R 755 $INSTALL_TARGET/tftpboot/ogclient |
---|
[295b4ab] | 535 | chown -R :$OPENGNSYS_CLIENTUSER $INSTALL_TARGET/tftpboot/ogclient |
---|
[c1e00e4] | 536 | echoAndLog "${FUNCNAME}(): Client update successfully" |
---|
| 537 | } |
---|
[a0867b37] | 538 | |
---|
[eb9424f] | 539 | # Resumen de actualización. |
---|
| 540 | function updateSummary() |
---|
| 541 | { |
---|
| 542 | # Actualizar fichero de versión y revisión. |
---|
| 543 | local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt" |
---|
| 544 | local REVISION=$(LANG=C svn info $SVN_URL|awk '/Revision:/ {print "r"$2}') |
---|
| 545 | |
---|
| 546 | [ -f $VERSIONFILE ] || echo "OpenGnSys" >$VERSIONFILE |
---|
| 547 | perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE |
---|
| 548 | |
---|
| 549 | echo |
---|
| 550 | echoAndLog "OpenGnSys Update Summary" |
---|
| 551 | echo "========================" |
---|
| 552 | echoAndLog "Project version: $(cat $VERSIONFILE)" |
---|
| 553 | echo |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | |
---|
[a0867b37] | 557 | |
---|
| 558 | ##################################################################### |
---|
[3320409] | 559 | ####### Proceso de actualización de OpenGnSys |
---|
[a0867b37] | 560 | ##################################################################### |
---|
| 561 | |
---|
| 562 | |
---|
| 563 | echoAndLog "OpenGnSys update begins at $(date)" |
---|
| 564 | |
---|
[bb30a50] | 565 | pushd $WORKDIR |
---|
| 566 | |
---|
[27dc5ff] | 567 | # Comprobar si hay conexión y detectar parámetros de red por defecto. |
---|
| 568 | checkNetworkConnection |
---|
| 569 | if [ $? -ne 0 ]; then |
---|
| 570 | errorAndLog "Error connecting to server. Causes:" |
---|
| 571 | errorAndLog " - Network is unreachable, review devices parameters." |
---|
| 572 | errorAndLog " - You are inside a private network, configure the proxy service." |
---|
| 573 | errorAndLog " - Server is temporally down, try agian later." |
---|
| 574 | exit 1 |
---|
| 575 | fi |
---|
| 576 | |
---|
[64dd765] | 577 | # Comprobar auto-actualización del programa. |
---|
| 578 | if [ "$PROGRAMDIR" != "$INSTALL_TARGET/bin" ]; then |
---|
| 579 | checkAutoUpdate |
---|
| 580 | if [ $? -ne 0 ]; then |
---|
[f580c51] | 581 | echoAndLog "OpenGnSys updater has been overwritten." |
---|
| 582 | echoAndLog "Please, re-execute this script." |
---|
[64dd765] | 583 | exit |
---|
| 584 | fi |
---|
| 585 | fi |
---|
| 586 | |
---|
[bb30a50] | 587 | # Instalar dependencias. |
---|
[a0867b37] | 588 | installDependencies $DEPS |
---|
| 589 | if [ $? -ne 0 ]; then |
---|
| 590 | errorAndLog "Error: you may install all needed dependencies." |
---|
| 591 | exit 1 |
---|
| 592 | fi |
---|
| 593 | |
---|
| 594 | # Arbol de directorios de OpenGnSys. |
---|
| 595 | createDirs ${INSTALL_TARGET} |
---|
| 596 | if [ $? -ne 0 ]; then |
---|
| 597 | errorAndLog "Error while creating directory paths!" |
---|
| 598 | exit 1 |
---|
| 599 | fi |
---|
| 600 | |
---|
| 601 | # Si es necesario, descarga el repositorio de código en directorio temporal |
---|
| 602 | if [ $USESVN -eq 1 ]; then |
---|
| 603 | svnExportCode $SVN_URL |
---|
| 604 | if [ $? -ne 0 ]; then |
---|
| 605 | errorAndLog "Error while getting code from svn" |
---|
| 606 | exit 1 |
---|
| 607 | fi |
---|
| 608 | else |
---|
| 609 | ln -fs "$(dirname $PROGRAMDIR)" opengnsys |
---|
| 610 | fi |
---|
| 611 | |
---|
[295b4ab] | 612 | # Si existe fichero de actualización de la base de datos; aplicar cambios. |
---|
| 613 | INSTVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt) |
---|
| 614 | REPOVERSION=$(awk '{print $2}' $WORKDIR/opengnsys/doc/VERSION.txt) |
---|
| 615 | OPENGNSYS_DBUPDATEFILE="$WORKDIR/opengnsys/admin/Database/$OPENGNSYS_DATABASE-$INSTVERSION-$REPOVERSION.sql" |
---|
| 616 | if [ -f $OPENGNSYS_DBUPDATEFILE ]; then |
---|
| 617 | echoAndLog "Updating tables from version $INSTVERSION to $REPOVERSION" |
---|
| 618 | importSqlFile $OPENGNSYS_DBUSER $OPENGNSYS_DBPASSWORD $OPENGNSYS_DATABASE $OPENGNSYS_DBUPDATEFILE |
---|
| 619 | else |
---|
| 620 | echoAndLog "Database unchanged." |
---|
| 621 | fi |
---|
| 622 | |
---|
| 623 | # Actualizar ficheros complementarios del servidor |
---|
[a0867b37] | 624 | updateServerFiles |
---|
| 625 | if [ $? -ne 0 ]; then |
---|
[da8db11] | 626 | errorAndLog "Error updating OpenGnSys Server files" |
---|
[a0867b37] | 627 | exit 1 |
---|
| 628 | fi |
---|
| 629 | |
---|
[295b4ab] | 630 | # Actualizar ficheros del cliente |
---|
| 631 | updateClientFiles |
---|
| 632 | updateInterfaceAdm |
---|
[45f1fe8] | 633 | |
---|
[295b4ab] | 634 | # Actualizar páqinas web |
---|
[4e51cb0] | 635 | getApacheUser |
---|
[a0867b37] | 636 | updateWebFiles |
---|
| 637 | if [ $? -ne 0 ]; then |
---|
[da8db11] | 638 | errorAndLog "Error updating OpenGnSys Web Admin files" |
---|
[a0867b37] | 639 | exit 1 |
---|
| 640 | fi |
---|
[5d6bf97] | 641 | # Generar páginas Doxygen para instalar en el web |
---|
| 642 | makeDoxygenFiles |
---|
[a0867b37] | 643 | |
---|
[bb30a50] | 644 | # Recompilar y actualizar los servicios del sistema |
---|
| 645 | compileServices |
---|
| 646 | |
---|
| 647 | # Actaulizar ficheros auxiliares del cliente |
---|
[a0867b37] | 648 | updateClient |
---|
| 649 | if [ $? -ne 0 ]; then |
---|
| 650 | errorAndLog "Error updating clients" |
---|
| 651 | exit 1 |
---|
| 652 | fi |
---|
| 653 | |
---|
[95f1f68] | 654 | # Actualizamos el fichero que arranca los servicios de OpenGnSys |
---|
| 655 | updateServicesStart |
---|
| 656 | |
---|
[3320409] | 657 | # Eliminamos el fichero de estado del tracker porque es incompatible entre los distintos paquetes |
---|
[ebbbfc01] | 658 | if [ -f /tmp/dstate ]; then |
---|
| 659 | rm -f /tmp/dstate |
---|
[3320409] | 660 | fi |
---|
| 661 | |
---|
[eb9424f] | 662 | # Mostrar resumen de actualización. |
---|
| 663 | updateSummary |
---|
| 664 | |
---|
[a0867b37] | 665 | #rm -rf $WORKDIR |
---|
| 666 | echoAndLog "OpenGnSys update finished at $(date)" |
---|
| 667 | |
---|
| 668 | popd |
---|
| 669 | |
---|