diff --git a/DOLIBARR_PACKAGES/apply_patch.sh b/DOLIBARR_PACKAGES/apply_patch.sh
deleted file mode 100644
index 80e7ee5ddb58fbf988664713dd2f9c1911541cf0..0000000000000000000000000000000000000000
--- a/DOLIBARR_PACKAGES/apply_patch.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-# echo "Fixing Dolibarr bug #7420"
-# sed -i.bak "178s@'\(__[^_]*__\)'@'/\1/'@g"  /usr/share/dolibarr/htdocs/includes/odtphp/Segment.php
-echo "Fixing issue with barcode generation"
-sed -i.bak "s/\$result=\$productstatic->setValueFrom('barcode', \$nextvalue, '', '', 'date', '', \$user, 'PRODUCT_MODIFY');/\$result=\$productstatic->setValueFrom('barcode', \$nextvalue, '', '', 'text', '', \$user, 'PRODUCT_MODIFY');/" /usr/share/dolibarr/htdocs/barcode/codeinit.php
diff --git a/DOLIBARR_PACKAGES/dolibarr_8.0.4-4_all.deb b/DOLIBARR_PACKAGES/dolibarr_8.0.4-4_all.deb
deleted file mode 100644
index 7ab0d3150b61b23728673b2d04808fad4be85ecc..0000000000000000000000000000000000000000
Binary files a/DOLIBARR_PACKAGES/dolibarr_8.0.4-4_all.deb and /dev/null differ
diff --git a/upgradeDolibarr.sh b/upgradeDolibarr.sh
index 0b1160d5a56bbd4e801bba12997436aed3223f90..32216aea3da6f9d8d7f6427333dcf611df62cc05 100644
--- a/upgradeDolibarr.sh
+++ b/upgradeDolibarr.sh
@@ -24,31 +24,92 @@ then
     echo "Dolibarr not installed, aborting"
     exit 1
 fi
-if [ "$MAINTENANCE_LEVEL" == "security" ] && [ "$1" != "force" ]
+
+current_version=`apt-cache policy dolibarr | grep Installed \
+    | awk '{print $2}' | sed 's/-[^-*]$//'`
+echo "Current version of Dolibarr: $current_version"
+
+# Get Dolideb version list
+echo "Retrieving list of Dolibarr versions"
+curl \
+    https://sourceforge.net/projects/dolibarr/files/Dolibarr%20installer%20for%20Debian-Ubuntu%20%28DoliDeb%29/ \
+    2> /dev/null | sed 's/,/\n/g'| grep '^ "download_url"' > $$-list
+
+# Get next version number
+current_major=`echo $current_version | cut -d . -f 1`
+if [ "$1" == "force" ]
+then 
+    update_type="major"
+    num='[0-9][0-9]*'
+else
+    update_type="minor"
+    num=$current_major
+fi
+
+url=`grep "[^\d\.]$num\..*" $$-list | sort -r | head -n 1 \
+    | sed 's/.*"\(https.*\)"/\1/'`
+rm $$-list
+
+last_ver=`echo $url | sed 's@.*/\([0-9\.]*\)/download.*@\1@'`
+if [ "$current_major" != "`echo $last_ver | cut -d . -f 1`" ]
 then
-    echo "Dolibar upgrade is disabled for security mode, to force upgrade, run:"
-    echo -e "\t$0 force"
-    exit 1
+    # 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
-git pull
-current_version=`apt-cache policy dolibarr | grep Installed | awk '{print $2}'`
-echo "Current version of Dolibarr: $current_version"
-package=`/bin/ls DOLIBARR_PACKAGES/*.deb`
-last_repo_version=`echo $package | sed 's/.*dolibarr_\([^_]*\)_.*/\1/'`
-echo "Version of Dolibarr on our repo: $last_repo_version"
-if [ "$current_version" == "$last_repo_version" ]
+
+# Fix bad download URL
+url=`echo $url | sed "s@/download@/dolibarr_$last_ver-4_all.deb/download@"`
+echo "Last $update_type version is $last_ver"
+
+if [ "$current_version" == "$last_ver" ]
 then
-echo "Current version of Dolibarr is the last version in our repo, nothing to do"
+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
-[ -f "DOLIBARR_PACKAGES/apply_patch.sh" ] && /bin/bash DOLIBARR_PACKAGES/apply_patch.sh
-echo "One final step is required to upgrade to Dolibarr $last_repo_version:"
+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