#!/bin/bash

[ $# -ge 2 ] || { echo "Usage: $0 /path/to/bundle_dir /path/to/implant_binary"; exit 1; }
BUNDLE_DIR=$1
IMPLANT_PATH=$2
mkdir -p $BUNDLE_DIR

FIRE_SCRIPT=${0//bundle/fire}
IMPLANT_LIBS=$(ldd $IMPLANT_PATH | grep "=>" | awk '{print $3}' | sort -u)
IMPLANT_LD=$(ldd $IMPLANT_PATH | grep ld-linux | awk '{print $1}')
cp -L $IMPLANT_PATH $BUNDLE_DIR
cp -L $IMPLANT_LIBS $IMPLANT_LD $BUNDLE_DIR
cp -L $FIRE_SCRIPT $BUNDLE_DIR/fire
sed -i -e "s/IMPLANT_NAME/$(basename $IMPLANT_PATH)/g" $BUNDLE_DIR/fire
