diff --git a/lib/core/update.py b/lib/core/update.py index c2f38ecfb..f41b9cdf3 100644 --- a/lib/core/update.py +++ b/lib/core/update.py @@ -5,6 +5,7 @@ Copyright (c) 2006-2012 sqlmap developers (http://www.sqlmap.org/) See the file 'doc/COPYING' for copying permission """ +import os import re import time @@ -25,31 +26,39 @@ def update(): if not conf.updateAll: return + success = False rootDir = paths.SQLMAP_ROOT_PATH - infoMsg = "updating sqlmap to the latest development version from the " - infoMsg += "GitHub repository" - logger.info(infoMsg) - - debugMsg = "sqlmap will try to update itself using 'git' command" - logger.debug(debugMsg) - - dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X")) - process = execute("git pull %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE) - pollProcess(process, True) - stdout, stderr = process.communicate() - - if not process.returncode: - logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", REVISION)) + if not os.path.exists(os.path.join(rootDir, ".git")): + errMsg = "not a git repository. Please checkout the 'sqlmapproject/sqlmap' repository " + errMsg += "from GitHub (e.g. git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev)" + logger.error(errMsg) else: - logger.error("update could not be completed (%s)" % repr(stderr)) + infoMsg = "updating sqlmap to the latest development version from the " + infoMsg += "GitHub repository" + logger.info(infoMsg) + debugMsg = "sqlmap will try to update itself using 'git' command" + logger.debug(debugMsg) + + dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X")) + process = execute("git pull %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE) + pollProcess(process, True) + stdout, stderr = process.communicate() + success = not process.returncode + + if success: + logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", REVISION)) + else: + logger.error("update could not be completed ('%s')" % re.sub(r"\W+", " ", stderr).strip()) + + if not success: if IS_WIN: infoMsg = "for Windows platform it's recommended " infoMsg += "to use a GitHub for Windows client for updating " infoMsg += "purposes (http://windows.github.com/)" else: - infoMsg = "for Linux platform it's recommended " - infoMsg += "to use a standard 'git' package (e.g.: 'sudo apt-get install git')" + infoMsg = "for Linux platform it's required " + infoMsg += "to install a standard 'git' package (e.g.: 'sudo apt-get install git')" logger.info(infoMsg)