download-via-git.sh 1.04 KB
Newer Older
Aaditya Bagga's avatar
Aaditya Bagga committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/bin/bash
# download-via-git.sh: downloads openrc scripts from gentoo sources

# for safety and robustness
set -e

# get source list
. "$(pwd)/source_list.sh"

# Test
if [ "$1" = -t ]; then
	# Searching in the indices of CATEGORIES
	for i in ${!CATEGORIES[*]}; do
		# Now we get the actual category
		k=${CATEGORIES[$i]}
		# Now we need to evaluate the array pointed by CATEGORY index
		eval "j=\${$i[*]}"
		# Print programs in each category
		for l in $j; do
			echo "$k: $l"
		done
	done
	exit 0
fi

REMOTE_REPO="gentoo"
REMOTE_REPO_URL="https://github.com/gentoo/gentoo.git"

# checking out selective directories via git
# https://askubuntu.com/a/645276/183206
mkdir -p "${REMOTE_REPO}"
cd "$REMOTE_REPO"
if [ ! -d .git ]; then
	git init
	git remote add origin "$REMOTE_REPO_URL"
	git config core.sparseCheckout true
fi

cd -
sparse_checkout_file="${REMOTE_REPO}/.git/info/sparse-checkout"
[ -f "$sparse_checkout_file" ] && rm "$sparse_checkout_file"
./generate-sparse-checkout-list.sh >> "$sparse_checkout_file"

cd "$REMOTE_REPO"
git pull origin master

exit $?