#!/bin/bash
## Generates the bundle

function copy_dir {
    rm -rf dwarf-compilation
    cp -r dwarf-compilation.base dwarf-compilation
}

function download_repo {
    echo -n "Downloading $1… "
    wget -q "https://git.tobast.fr/m2-internship/$1/archive/master.tar.gz"
    tar xzf master.tar.gz
    rm -f master.tar.gz
    echo "OK"
}

function download_tgz {
    echo -n "Downloading $3… "
    wget -q "$1" -O archive.tar.gz
    tar xzf archive.tar.gz
    mv "$2" "$3"
    rm archive.tar.gz
    echo "OK"
}

function download {
    cd dwarf-compilation
    download_repo "dwarf-assembly"
    download_repo "libunwind-eh_elf"
    cd contrib
    download_tgz "http://www.mr511.de/software/libelf-0.8.13.tar.gz" \
        'libelf-0.8.13' 'libelf'
    cd ../..
}

function package {
    echo -n "Packaging… "
    tar czf dwarf-compilation.tar.gz dwarf-compilation
    echo "OK"
}

copy_dir
download
package
