Skip to content
Snippets Groups Projects
Select Git revision
  • d797725c889de15766ec1f4cb4728b32dbf861e5
  • master default protected
  • 133-fail2ban-page
  • reorganisation
  • 16-maintenace-service
  • 11-fail2ban
  • 6-monit-update
  • 7-dolibarr-fail2ban
  • 6-surveillance-interne-des-serveur
  • test-glpi
  • 2-migrate-to-phpfpm
  • jessie
  • github
13 results

upgradeDolibarr.sh

Blame
  • upgradeDolibarr.sh 3.23 KiB
    #!/bin/bash
    
    # Copyright (C) 2017  Tetras Libre <admin@tetras-libre.fr>
    # Author: Beniamine, David <David.Beniamine@tetras-libre.fr>
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    DIR=`dirname $0`
    . $DIR/main.env
    DOLIBARR_DB=${DOLIBARR_DB:-"dolibarr"}
    if [ -z "`dpkg -l | grep dolibarr`" ]
    then
        echo "Dolibarr not installed, aborting"
        exit 1
    fi
    
    current_version=`apt-cache policy dolibarr | grep Installed \
        | awk '{print $2}' | sed 's/-[^-*]$//'`
    echo "Current version of Dolibarr: $current_version"
    current_major=`echo $current_version | cut -d . -f 1`
    
    echo "Retrieving list of Dolibarr versions"
    if [ "$1" == "force" ]
    then
        update_type="major"
        num=''
    else
        update_type="minor"
        num=$current_major
    fi
    
    
    url=`$DIR/getLastDolibarrDeb.sh $num`
    
    last_ver=`echo $url | cut -d ' ' -f 2`
    url=`echo $url | cut -d ' ' -f 1`
    if [ "$current_major" != "`echo $last_ver | cut -d . -f 1`" ]
    then
        if [ "`echo $last_ver | cut -d . -f 2-3`" == "0.0" ]
        then
            echo "Not installing version $last_ver, waiting for .1 release"
            exit
        fi
        # Force interaction on major version upgrade
        read -p "Are you sure you want to upgrade from $current_version to $last_ver [y/N]" answer
        if [ "$answer" != "y" ]
        then
            echo "Aborting"
            exit
        fi
    fi
    
    echo "Last $update_type version is $last_ver"
    
    if [ "$current_version" == "$last_ver" ]
    then
    echo "This server is running $update_type version of Dolibarr, nothing to do"
        exit
    fi
    
    # Get sources
    OLDDIR=$PWD
    if [ ! -e "/opt/dolibarr" ]
    then
        cd /opt
        git clone https://github.com/Dolibarr/dolibarr/
    fi
    cd /opt/dolibarr
    git reset --hard HEAD
    git checkout -b $current_version $current_version
    git branch -v
    
    # Get local changes
    cp -r /usr/share/dolibarr/htdocs/* htdocs/
    cd $OLDDIR
    
    echo "Backing up database"
    mysqldump --databases $DOLIBARR_DB > /root/$DOLIBARR_DB.sql
    mysqldump --all-databases > /root/dbs.sql
    
    echo "Downloading Dolibarr $last_ver"
    package=dolibarr-$last_ver.deb
    wget -O  $package $url
    
    echo "Installing $package"
    dpkg -i $package
    rm $package
    
    echo "Fixing dependencies"
    apt-get -f install
    
    rm /usr/share/dolibarr/documents/install.lock
    echo "One final step is required to upgrade to Dolibarr $last_ver:"
    echo "Please go to your Dolibarr page and run the manual upgrade step"
    
    echo "There might be local changes to Dolibarr previous to upgrade, see below:"
    cd /opt/dolibarr
    git diff > patch
    cat patch
    git status
    cd $OLDDIR
    read -p "Hit enter when you are done with the manual upgrade step"
    echo "En cas d'erreur de type The maximum column sze is 767 bytes, please adapt the following query:"
    echo "ALTER TABLE llx_my_table ROW_FORMAT=DYNAMIC ;"
    echo "After running it, restart the manual upgrade"