Skip to content

Commit

Permalink
build.sh improvements
Browse files Browse the repository at this point in the history
Upgrade Gradle to 6.8.2.
Upgrade Corretto to 15.
Use variables to deduplicate things.
Replace mkdir before tar with --one-top-level.
Shorten unzip -q -d to -qd.
Always run tests with CI.
Add popd.
  • Loading branch information
Margen67 authored and mborgerson committed Feb 14, 2021
1 parent 50061c7 commit 4fac5ab
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
#!/bin/bash -e

export CORRETTO_ARCHIVE=amazon-corretto-15-x64-linux-jdk.tar.gz
export CORRETTO_URL=https://corretto.aws/downloads/latest/${CORRETTO_ARCHIVE}
export GHIDRA_VER=9.2.2_PUBLIC
export GHIDRA_DATE=20201229
export GHIDRA_ARCHIVE=ghidra_${GHIDRA_VER}_${GHIDRA_DATE}.zip
export GHIDRA_URL=https://ghidra-sre.org/${GHIDRA_ARCHIVE}
export GRADLE_ARCHIVE=gradle-6.8.2-bin.zip
export GRADLE_URL=https://services.gradle.org/distributions/${GRADLE_ARCHIVE}
export XBSYMBOLDATABASE_ARCHIVE=XbSymbolDatabase.zip
export XBSYMBOLDATABASE_URL=https://github.com/Cxbx-Reloaded/XbSymbolDatabase/releases/latest/download/${XBSYMBOLDATABASE_ARCHIVE}
declare -a URLS=(
$CORRETTO_URL
$GHIDRA_URL
$GRADLE_URL
$XBSYMBOLDATABASE_URL
)

pushd /tmp

echo "[*] Downloading files..."
cat <<EOF > urls.txt
https://corretto.aws/downloads/latest/amazon-corretto-11-x64-linux-jdk.tar.gz
https://services.gradle.org/distributions/gradle-5.0-bin.zip
https://ghidra-sre.org/ghidra_9.2.2_PUBLIC_20201229.zip
https://github.com/Cxbx-Reloaded/XbSymbolDatabase/releases/latest/download/XbSymbolDatabase.zip
EOF
cat urls.txt | xargs -n 1 -P 10 wget --no-verbose
echo ${URLS[@]} | xargs -n 1 -P ${#URLS[@]} wget -nv

echo "[*] Extracting JDK..."
mkdir -p jdk
tar --strip-components=1 -C jdk --extract -f amazon-corretto-11-x64-linux-jdk.tar.gz
tar --strip-components=1 --one-top-level=jdk -xf ${CORRETTO_ARCHIVE}
export JAVA_HOME=$PWD/jdk
export PATH=$JAVA_HOME/bin:$PATH

echo "[*] Extracting Gradle..."
unzip -q gradle-5.0-bin.zip
export PATH=$PWD/gradle-5.0/bin:$PATH
unzip -q ${GRADLE_ARCHIVE}
export PATH=$PWD/gradle-${GRADLE_VER}/bin:$PATH

echo "[*] Extracting Ghidra..."
unzip -q ghidra_9.2.2_PUBLIC_20201229.zip
export GHIDRA_INSTALL_DIR=$PWD/ghidra_9.2.2_PUBLIC
unzip -q ${GHIDRA_ARCHIVE}
export GHIDRA_INSTALL_DIR=$PWD/ghidra_${GHIDRA_VER}

echo "[*] Extracting XbSymbolDatabase..."
unzip -q -d XbSymbolDatabase XbSymbolDatabase.zip
unzip -qd XbSymbolDatabase ${XBSYMBOLDATABASE_ARCHIVE}
export XBSYMBOLDATABASE=$PWD/XbSymbolDatabase

popd # Back to source root

# Copy XbSymbolDatabase into this source tree for redist
cp $XBSYMBOLDATABASE/linux_x64/bin/XbSymbolDatabaseCLI os/linux64/XbSymbolDatabaseTool
cp $XBSYMBOLDATABASE/LICENSE os/linux64/XbSymbolDatabaseTool.LICENSE
cp $XBSYMBOLDATABASE/macos_x64/bin/XbSymbolDatabaseCLI os/osx64/XbSymbolDatabaseTool
cp $XBSYMBOLDATABASE/LICENSE os/osx64/XbSymbolDatabaseTool.LICENSE
cp $XBSYMBOLDATABASE/win_x64/bin/XbSymbolDatabaseCLI.exe os/win64/XbSymbolDatabaseTool.exe
cp $XBSYMBOLDATABASE/LICENSE os/win64/XbSymbolDatabaseTool.LICENSE
cp $XBSYMBOLDATABASE/linux_x64/bin/XbSymbolDatabaseCLI os/linux64/XbSymbolDatabaseTool
cp $XBSYMBOLDATABASE/LICENSE os/linux64/XbSymbolDatabaseTool.LICENSE
cp $XBSYMBOLDATABASE/macos_x64/bin/XbSymbolDatabaseCLI os/osx64/XbSymbolDatabaseTool
cp $XBSYMBOLDATABASE/LICENSE os/osx64/XbSymbolDatabaseTool.LICENSE
cp $XBSYMBOLDATABASE/win_x64/bin/XbSymbolDatabaseCLI.exe os/win64/XbSymbolDatabaseTool.exe
cp $XBSYMBOLDATABASE/LICENSE os/win64/XbSymbolDatabaseTool.LICENSE

echo "[*] Building..."
gradle -b build.gradle

if [[ "$RUNTESTS" == "1" ]]; then
if [[ "$RUNTESTS" == "1" || "$CI" == "true" ]]; then
echo "[*] Installing Extension..."
cp ./dist/*ghidra-xbe.zip $GHIDRA_INSTALL_DIR/Ghidra/Extensions
cp dist/*ghidra-xbe.zip $GHIDRA_INSTALL_DIR/Ghidra/Extensions
pushd $GHIDRA_INSTALL_DIR/Ghidra/Extensions
unzip *ghidra-xbe.zip
popd
Expand All @@ -57,6 +68,20 @@ if [[ "$RUNTESTS" == "1" ]]; then
echo "[-] Test FAILED"
exit 1
fi
popd
fi

if [[ "$CI" == "true" ]]; then
export BUILD_TAG=build-$(date -u +'%Y%m%d%H%M')
mkdir -p dist
echo -n $BUILD_TAG > dist/tag
fi

if [[ "$GITHUB_ACTIONS" == "true" ]]; then
echo "::set-output name=BUILD_TAG::$BUILD_TAG"
echo "::set-output name=GHIDRA_VER::$GHIDRA_VER"
echo "::set-output name=GHIDRA_ARCHIVE::$GHIDRA_ARCHIVE"
echo "::set-output name=GHIDRA_URL::$GHIDRA_URL"
fi

echo "[*] Done!"

0 comments on commit 4fac5ab

Please sign in to comment.