diff options
author | Ramón M. Gómez <ramongomez@us.es> | 2018-06-14 10:48:39 +0200 |
---|---|---|
committer | Ramón M. Gómez <ramongomez@us.es> | 2018-06-14 10:59:34 +0200 |
commit | b60d6b807c580e58f06a337def9a1a83b1f3bcfc (patch) | |
tree | 7ee39403eb4f70a9f7120eb8168d6317b339bf1e /installer/opengnsys_update.sh | |
parent | 5367fb5e61f2e89797bfe7df0e4811a1ff890f08 (diff) | |
parent | e0e4c021382f2c8a66402c545229aa8e528750f9 (diff) |
#794: Applying new commits from {{{devel}}} branch to {{{pjlink}}} branch.
Diffstat (limited to 'installer/opengnsys_update.sh')
-rwxr-xr-x | installer/opengnsys_update.sh | 90 |
1 files changed, 53 insertions, 37 deletions
diff --git a/installer/opengnsys_update.sh b/installer/opengnsys_update.sh index 99eac4a9..0a6631f7 100755 --- a/installer/opengnsys_update.sh +++ b/installer/opengnsys_update.sh @@ -64,16 +64,19 @@ if [ -z "$OPENGNSYS_DATABASE" -o -z "$OPENGNSYS_DBUSER" -o -z "$OPENGNSYS_DBPASS exit 1 fi -# Comprobar si se ha descargado el paquete comprimido (USESVN=0) o sólo el instalador (USESVN=1). +# Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1). PROGRAMDIR=$(readlink -e $(dirname "$0")) PROGRAMNAME=$(basename "$0") OPENGNSYS_SERVER="opengnsys.es" if [ -d "$PROGRAMDIR/../installer" ]; then - USESVN=0 + REMOTE=0 else - USESVN=1 + REMOTE=1 fi -SVN_URL="https://$OPENGNSYS_SERVER/svn/branches/version1.1/" +BRANCH="devel" +CODE_URL="https://codeload.github.com/opengnsys/OpenGnsys/zip/$BRANCH" +API_URL="https://api.github.com/repos/opengnsys/OpenGnsys/branches/$BRANCH" +RAW_URL="https://raw.githubusercontent.com/opengnsys/OpenGnsys/$BRANCH" WORKDIR=/tmp/opengnsys_update mkdir -p $WORKDIR @@ -113,7 +116,7 @@ function autoConfigure() # Configuración según la distribución de Linux. if [ -f /etc/debian_version ]; then - # Distribución basada en paquetes Deb. + # Distribución basada en paquetes Deb. DEPENDENCIES=( curl rsync btrfs-tools procps arp-scan realpath php-curl gettext moreutils jq wakeonlan udpcast python-pip ) UPDATEPKGLIST="add-apt-repository -y ppa:ondrej/php; apt-get update" INSTALLPKGS="apt-get -y install" @@ -133,7 +136,7 @@ function autoConfigure() APACHEGROUP="www-data" INETDCFGDIR=/etc/xinetd.d elif [ -f /etc/redhat-release ]; then - # Distribución basada en paquetes rpm. + # Distribución basada en paquetes rpm. DEPENDENCIES=( curl rsync btrfs-progs procps-ng arp-scan gettext moreutils jq net-tools python-pip ) # En CentOS 7 instalar arp-scan de CentOS 6. [ "$OSDISTRIB$OSVERSION" == "centos7" ] && DEPENDENCIES=( ${DEPENDENCIES[*]/arp-scan/http://dag.wieers.com/redhat/el6/en/$(arch)/dag/RPMS/arp-scan-1.9-1.el6.rf.$(arch).rpm} ) @@ -174,8 +177,9 @@ function checkAutoUpdate() local update=0 # Actaulizar el script si ha cambiado o no existe el original. - if [ $USESVN -eq 1 ]; then - svn export $SVN_URL/installer/$PROGRAMNAME + if [ $REMOTE -eq 1 ]; then + curl -s $RAW_URL/installer/$PROGRAMNAME -o $PROGRAMNAME + chmod +x $PROGRAMNAME if ! diff -q $PROGRAMNAME $INSTALL_TARGET/lib/$PROGRAMNAME 2>/dev/null || ! test -f $INSTALL_TARGET/lib/$PROGRAMNAME; then mv $PROGRAMNAME $INSTALL_TARGET/lib update=1 @@ -201,7 +205,7 @@ function getDateTime() # Escribe a fichero y muestra por pantalla function echoAndLog() { - echo $1 + echo "$1" DATETIME=`getDateTime` echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE } @@ -396,10 +400,10 @@ function installDependencies() ##################################################################### -####### Funciones para el manejo de Subversion +####### Funciones para descargar código ##################################################################### -function svnExportCode() +function downloadCode() { if [ $# -ne 1 ]; then errorAndLog "${FUNCNAME}(): invalid number of parameters" @@ -408,14 +412,15 @@ function svnExportCode() local url="$1" - echoAndLog "${FUNCNAME}(): downloading subversion code..." + echoAndLog "${FUNCNAME}(): downloading code..." - svn checkout "${url}" opengnsys + curl "${url}" -o opengnsys.zip && unzip opengnsys.zip && mv "OpenGnsys-$BRANCH" opengnsys if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password" return 1 fi - echoAndLog "${FUNCNAME}(): subversion code downloaded" + rm -f opengnsys.zip + echoAndLog "${FUNCNAME}(): code was downloaded" return 0 } @@ -428,7 +433,14 @@ function svnExportCode() function checkNetworkConnection() { OPENGNSYS_SERVER=${OPENGNSYS_SERVER:-"opengnsys.es"} - wget --spider -q $OPENGNSYS_SERVER + if which curl &>/dev/null; then + curl --connect-timeout 10 -s $OPENGNSYS_SERVER -o /dev/null + elif which wget &>/dev/null; then + wget --spider -q $OPENGNSYS_SERVER + else + echoAndLog "${FUNCNAME}(): Cannot execute \"wget\" nor \"curl\"." + return 1 + fi } # Comprobar si la versión es anterior a la actual. @@ -437,11 +449,12 @@ function checkVersion() local PRE # Obtener versión actual y versión a actualizar. - OLDVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null) - if [ $USESVN -eq 1 ]; then - NEWVERSION=$(curl -s $SVN_URL/doc/VERSION.txt 2>/dev/null | awk '{print $2}') + [ -f $INSTALL_TARGET/doc/VERSION.txt ] && OLDVERSION=$(awk '{print $2}' $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null) + [ -f $INSTALL_TARGET/doc/VERSION.json ] && OLDVERSION=$(jq -r '.version' $INSTALL_TARGET/doc/VERSION.json 2>/dev/null) + if [ $REMOTE -eq 1 ]; then + NEWVERSION=$(curl -s $RAW_URL/doc/VERSION.json 2>/dev/null | jq -r '.version') else - NEWVERSION=$(awk '{print $2}' $PROGRAMDIR/doc/VERSION.txt 2>/dev/null) + NEWVERSION=$(jq -r '.version' $PROGRAMDIR/doc/VERSION.json 2>/dev/null) fi [[ "$NEWVERSION" =~ pre ]] && PRE=1 @@ -482,16 +495,15 @@ function updateClientFiles() # Actualizar ficheros del cliente. backupFile $ENGINECFG echoAndLog "${FUNCNAME}(): Updating OpenGnsys Client files" - rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client + rsync -irplt $WORKDIR/opengnsys/client/shared/* $INSTALL_TARGET/client if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while updating client structure" exit 1 fi - find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null # Actualizar librerías del motor de clonación. echoAndLog "${FUNCNAME}(): Updating OpenGnsys Cloning Engine files" - rsync --exclude .svn -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin + rsync -irplt $WORKDIR/opengnsys/client/engine/*.lib* $INSTALL_TARGET/client/lib/engine/bin if [ $? -ne 0 ]; then errorAndLog "${FUNCNAME}(): error while updating engine files" exit 1 @@ -606,7 +618,7 @@ function updateWebFiles() # Copiar los ficheros nuevos conservando el archivo de configuración de acceso. backupFile $INSTALL_TARGET/www/controlacceso.php mv $INSTALL_TARGET/www $INSTALL_TARGET/WebConsole - rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET + rsync -irplt $WORKDIR/opengnsys/admin/WebConsole $INSTALL_TARGET ERRCODE=$? mv $INSTALL_TARGET/WebConsole $INSTALL_TARGET/www rm -fr $INSTALL_TARGET/www/xajax @@ -651,7 +663,7 @@ function updateDownloadableFiles() mv $PROGRAMDIR/$FILENAME $TARGETFILE else echoAndLog "${FUNCNAME}(): Downloading $FILENAME" - wget $DOWNLOADURL/$FILENAME -O $TARGETFILE + curl $DOWNLOADURL/$FILENAME -o $TARGETFILE fi if [ ! -s $TARGETFILE ]; then errorAndLog "${FUNCNAME}(): Cannot download $FILENAME" @@ -662,7 +674,7 @@ function updateDownloadableFiles() tar xvzf $TARGETFILE -C $INSTALL_TARGET/www/descargas if [ $? != 0 ]; then errorAndLog "${FUNCNAME}(): Error uncompressing archive $FILENAME" - exit 1 + return 1 fi } @@ -674,7 +686,7 @@ function updateInterfaceAdm() # Crear carpeta y copiar Interface echoAndLog "${FUNCNAME}(): Copying Administration Interface Folder" mv $INSTALL_TARGET/client/interfaceAdm $INSTALL_TARGET/client/Interface - rsync --exclude .svn -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client + rsync -irplt $WORKDIR/opengnsys/admin/Interface $INSTALL_TARGET/client errcoce=$? mv $INSTALL_TARGET/client/Interface $INSTALL_TARGET/client/interfaceAdm if [ $errcode -ne 0 ]; then @@ -831,7 +843,7 @@ function updateServerFiles() local i for (( i = 0; i < ${#SOURCES[@]}; i++ )); do if [ -d "$INSTALL_TARGET/${TARGETS[i]}" ]; then - rsync --exclude .svn -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}")) + rsync -irplt "${SOURCES[i]}" $(dirname $(readlink -e "$INSTALL_TARGET/${TARGETS[i]}")) else rsync -irplt "${SOURCES[i]}" $(readlink -m "$INSTALL_TARGET/${TARGETS[i]}") fi @@ -964,7 +976,7 @@ function updateClient() oglivecli convert fi # Comprobar si debe actualizarse el cliente. - SOURCELENGTH=$(LANG=C wget --spider $SOURCEFILE 2>&1 | awk '/Length:/ {print $2}') + SOURCELENGTH=$(curl -sI $SOURCEFILE 2>&1 | awk '/Content-Length:/ {print $2}') TARGETLENGTH=$(stat -c "%s" $TARGETFILE 2>/dev/null) [ -z $TARGETLENGTH ] && TARGETLENGTH=0 if [ "$SOURCELENGTH" != "$TARGETLENGTH" ]; then @@ -1019,16 +1031,20 @@ function checkFiles() function updateSummary() { # Actualizar fichero de versión y revisión. - local VERSIONFILE="$INSTALL_TARGET/doc/VERSION.txt" - local REVISION=$(LANG=C svn info $SVN_URL|awk '/Rev:/ {print "r"$4}') - - [ -f $VERSIONFILE ] || echo "OpenGnsys" >$VERSIONFILE - perl -pi -e "s/($| r[0-9]*)/ $REVISION/" $VERSIONFILE + local VERSIONFILE REVISION + VERSIONFILE="$INSTALL_TARGET/doc/VERSION.json" + # Revisión: rAñoMesDía.Gitcommit (8 caracteres de fecha y 7 primeros de commit). + REVISION=$(curl -s "$API_URL" | jq '"r" + (.commit.commit.committer.date | gsub("-"; "")[:8]) + "." + (.commit.sha[:7])') + [ -f $VERSIONFILE ] || echo '{ "project": "OpenGnsys" }' > $VERSIONFILE + jq ".release=$REVISION" $VERSIONFILE | sponge $VERSIONFILE + VERSION="$(jq -r '[.project, .version, .codename, .release] | join(" ")' $VERSIONFILE 2>/dev/null)" + # Borrar antiguo fichero de versión. + rm -f "${VERSIONFILE/json/txt}" echo echoAndLog "OpenGnsys Update Summary" echo "========================" - echoAndLog "Project version: $(cat $VERSIONFILE)" + echoAndLog "Project version: $VERSION" echoAndLog "Update log file: $LOG_FILE" if [ -n "$NEWFILES" ]; then echoAndLog "Check new config files: $(echo $NEWFILES)" @@ -1114,10 +1130,10 @@ if [ $? -ne 0 ]; then fi # Si es necesario, descarga el repositorio de código en directorio temporal -if [ $USESVN -eq 1 ]; then - svnExportCode $SVN_URL +if [ $REMOTE -eq 1 ]; then + downloadCode $CODE_URL if [ $? -ne 0 ]; then - errorAndLog "Error while getting code from svn server" + errorAndLog "Error while getting code from repository" exit 1 fi else |