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