From 8df35680ed8f3369cbbe6c11a7efde7c28f1c276 Mon Sep 17 00:00:00 2001 From: rishwanth1995 Date: Wed, 9 May 2018 10:28:46 -0400 Subject: [PATCH 1/3] added python script to setup sleuthkit branch in appveyor and travis --- .travis.yml | 9 ++++--- appveyor.yml | 29 ++++++++++----------- setupSleuthkitBranch.py | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 setupSleuthkitBranch.py diff --git a/.travis.yml b/.travis.yml index 8cde465f7d..9200839ce7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,17 +6,20 @@ os: env: global: - TSK_HOME=$TRAVIS_BUILD_DIR/sleuthkit/sleuthkit +python: + - "2.7" jdk: - oraclejdk8 before_install: - - git clone https://github.com/sleuthkit/sleuthkit.git sleuthkit/sleuthkit + - git clone https://github.com/sleuthkit/sleuthkit.git sleuthkit/sleuthkit + - python setupSleuthkitBranch.py install: - sudo apt-get install testdisk - - cd sleuthkit/sleuthkit + - cd sleuthkit/sleuthkit - sh travis_build.sh script: - set -e - - echo "building autopsy..." && echo -en 'travis_fold:start:script.build\\r' + - echo "building autopsy..." && echo -en 'travis_fold:start:script.build\\r' - cd $TRAVIS_BUILD_DIR/ - ant -q build - echo -en 'travis_fold:end:script.build\\r' diff --git a/appveyor.yml b/appveyor.yml index 8500f65855..03eaf5a4ae 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,21 +1,18 @@ version: 4.6.0.{build} cache: - - C:\Users\appveyor\.ant -> appveyor.yml - - C:\Users\appveyor\.ivy2 -> appveyor.yml - - C:\ProgramData\chocolatey\bin -> appveyor.yml - - C:\ProgramData\chocolatey\lib -> appveyor.yml + - C:\Users\appveyor\.ant + - C:\ProgramData\chocolatey\bin + - C:\ProgramData\chocolatey\lib + - C:\libewf_64bit + - C:\libvhdi_64bit + - C:\libvmdk_64bit + - C:\zlib + - '%APPVEYOR_BUILD_FOLDER%\Core\test\qa-functional\data' -branches: - only: - - develop image: Visual Studio 2015 platform: x64 -init: - - ps: choco install ant --ignore-dependencies - - ps: $env:Path="C:\Program Files\Java\jdk1.8.0\bin;$($env:Path);C:\ProgramData\chocolatey\lib\ant" - - set PATH=C:\Python36-x64\';%PATH% environment: global: TSK_HOME: "C:\\sleuthkit" @@ -27,10 +24,14 @@ environment: PYTHON: "C:\\Python36-x64" install: - - ps: pushd C:\ + - ps: choco install ant --ignore-dependencies - git clone https://github.com/sleuthkit/sleuthkit - - ps: popd - + - ps: $env:Path="C:\Program Files\Java\jdk1.8.0\bin;$($env:Path);C:\ProgramData\chocolatey\lib\ant" + - set PATH=C:\Python36-x64\';%PATH% + - cd C:\ + - git clone https://github.com/sleuthkit/sleuthkit + - cd %APPVEYOR_BUILD_FOLDER% + - python setupSleuthkitBranch.py services: - postgresql95 diff --git a/setupSleuthkitBranch.py b/setupSleuthkitBranch.py new file mode 100644 index 0000000000..eb6a4f43ed --- /dev/null +++ b/setupSleuthkitBranch.py @@ -0,0 +1,56 @@ +# This python script sets the sleuthkit branch based on the autopsy build branch +# in appveyor and travis + +import os +import sys +import subprocess +import xml.etree.ElementTree as ET + +TSK_HOME=os.getenv("TSK_HOME",False) +passed = 1 + +def gitSleuthkitCheckout(branch): + global passed + cmd = ['git','checkout',branch] + passed = subprocess.call(cmd,stdout=sys.stdout,cwd=TSK_HOME) + +def parseXML(xmlFile): + tree = ET.parse('TSKVersion.xml') + root = tree.getroot() + for child in root: + if child.attrib['name']=='TSK_VERSION': + return child.attrib['value'] + return None + +def main(): + global passed + + if not TSK_HOME: + sys.exit(1) + print('Please set TSK_HOME env variable') + + TRAVIS=os.getenv("TRAVIS",False) + APPVEYOR=os.getenv("APPVEYOR",False) + if TRAVIS == "true": + CURRENT_BRANCH=os.getenv("TRAVIS_BRANCH",False) + elif APPVEYOR: + CURRENT_BRANCH=os.getenv("APPVEYOR_REPO_BRANCH",False) + else: + cmd=['git','rev-parse','--abbrev-ref','HEAD'] + output = subprocess.check_output(cmd) + CURRENT_BRANCH=output.strip() + + if CURRENT_BRANCH.startswith('custom-'): + gitSleuthkitCheckout(CURRENT_BRANCH) + else: + version = parseXML('TSKVersion.xml') + RELEASE_BRANCH = "release-"+version + gitSleuthkitCheckout(RELEASE_BRANCH) + + if passed != 0: + gitSleuthkitCheckout('develop') + if passed != 0: + print('Something gone wrong') + sys.exit(1) +if __name__ == '__main__': + main() From 496875b8d5875e35dc7168b801422aef7657d179 Mon Sep 17 00:00:00 2001 From: rishwanth1995 Date: Fri, 11 May 2018 10:12:41 -0400 Subject: [PATCH 2/3] changed algorithm for sleuthkit branches --- setupSleuthkitBranch.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/setupSleuthkitBranch.py b/setupSleuthkitBranch.py index eb6a4f43ed..9bed177677 100644 --- a/setupSleuthkitBranch.py +++ b/setupSleuthkitBranch.py @@ -9,13 +9,38 @@ import xml.etree.ElementTree as ET TSK_HOME=os.getenv("TSK_HOME",False) passed = 1 +def getSleuthkitBranchList(): + # Returns the list of sleuthkit branches + cmd = ['git','branch','-a'] + retdir = os.getcwd() + os.chdir(TSK_HOME) + output = subprocess.check_output(cmd) + branches = [] + for branch in output.strip().split(): + if branch.startswith('remotes/origin'): + branches.append(branch.split('/')[2]) + os.chdir(retdir) + return branches + def gitSleuthkitCheckout(branch): + ''' + Checksout sleuthkit branch + Args: + branch: String, which branch to checkout + ''' + # passed is a global variable that gets set to non-zero integer + # When an error occurs global passed cmd = ['git','checkout',branch] passed = subprocess.call(cmd,stdout=sys.stdout,cwd=TSK_HOME) def parseXML(xmlFile): - tree = ET.parse('TSKVersion.xml') + ''' + parses the TSKVersion.xml file for sleuthkit version + Args: + xmlFile: String, xml file to parse + ''' + tree = ET.parse(xmlFile) root = tree.getroot() for child in root: if child.attrib['name']=='TSK_VERSION': @@ -39,13 +64,13 @@ def main(): cmd=['git','rev-parse','--abbrev-ref','HEAD'] output = subprocess.check_output(cmd) CURRENT_BRANCH=output.strip() - - if CURRENT_BRANCH.startswith('custom-'): - gitSleuthkitCheckout(CURRENT_BRANCH) - else: + #check if sleuthkit has release branch + if CURRENT_BRANCH.startswith('release'): version = parseXML('TSKVersion.xml') RELEASE_BRANCH = "release-"+version gitSleuthkitCheckout(RELEASE_BRANCH) + elif CURRENT_BRANCH in getSleuthkitBranchList(): # check sleuthkit has same branch as autopsy + gitSleuthkitCheckout(CURRENT_BRANCH) if passed != 0: gitSleuthkitCheckout('develop') From 5dbe8469b44f6677224812f3a80e76b2f40706d1 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 11 May 2018 11:22:24 -0400 Subject: [PATCH 3/3] Updated comments. --- setupSleuthkitBranch.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/setupSleuthkitBranch.py b/setupSleuthkitBranch.py index 9bed177677..9164cfaaaa 100644 --- a/setupSleuthkitBranch.py +++ b/setupSleuthkitBranch.py @@ -1,5 +1,10 @@ -# This python script sets the sleuthkit branch based on the autopsy build branch -# in appveyor and travis +# This python script is used to automatically set the branch in The Sleuth Kit repository +# for use in automated build environments. +# +# Basic idea is that it determines what Autopsy branch is being used and then checksout +# a corresponding TSK branch. +# +# TSK_HOME environment variable must be set for this to work. import os import sys @@ -54,6 +59,8 @@ def main(): sys.exit(1) print('Please set TSK_HOME env variable') + # Get the Autopsy branch being used. Travis and Appveyor + # will tell us where a pull request is directed TRAVIS=os.getenv("TRAVIS",False) APPVEYOR=os.getenv("APPVEYOR",False) if TRAVIS == "true": @@ -64,18 +71,26 @@ def main(): cmd=['git','rev-parse','--abbrev-ref','HEAD'] output = subprocess.check_output(cmd) CURRENT_BRANCH=output.strip() - #check if sleuthkit has release branch + + # If we are in an Autopsy release branch, then use the + # info in TSKVersion.xml to find the corresponding TSK + # release branch. For other branches, we don't always + # trust that TSKVersion has been updated. if CURRENT_BRANCH.startswith('release'): version = parseXML('TSKVersion.xml') RELEASE_BRANCH = "release-"+version gitSleuthkitCheckout(RELEASE_BRANCH) - elif CURRENT_BRANCH in getSleuthkitBranchList(): # check sleuthkit has same branch as autopsy + # Check if the same branch exists in TSK (develop->develop, custom1->custom1, etc.) + elif CURRENT_BRANCH in getSleuthkitBranchList(): gitSleuthkitCheckout(CURRENT_BRANCH) + # Otherwise, default to develop if passed != 0: gitSleuthkitCheckout('develop') + if passed != 0: - print('Something gone wrong') - sys.exit(1) + print('Error checking out a Sleuth Kit branch') + sys.exit(1) + if __name__ == '__main__': main()