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