summaryrefslogtreecommitdiff
path: root/extra/coadde/xbslibre
blob: 90d36e0d345a30898e6838104b4e81d6bfc2d1c9 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

set -e

# Steps
# * Sync bs derivation (abs)
# * Download blacklist.txt
# * Sync bs (abslibre) from bs derivation (abs) excluding from blacklist
# * Create repo.abs.tar.gz tarballs

source "$(dirname "$(readlink -e "$0")")/config_platforms"

for 'platform' in "${DD_PLATFORMS[@]}"; do

	source "$(dirname "$(readlink -e "$0")")/config_${platform}"

	function sync_bs_derivation() {
		for 'ARCH' in 'any' "${ARCHES[@]}"; do
			rsync "${SYNC_ARGS}" "${SYNC_DD_SERVER}::${BS_DD_NAME}/${ARCH}" "${BS_DD_DIR}/${ARCH}" || return $?
		done

		# fix some permissions
		find "${BS_DD_DIR}" -type d -print0 | xargs -0 chmod 755
		find "${BS_DD_DIR}" -type f -print0 | xargs -0 chmod 644
	}

	function get_blacklist() {
		printf ":: Updating blacklist...\t"
		cat "${BLACKLIST_FILE}" | cut -d':' -f1 | sort -u | \
			sed "s/^/**\//" > "${BLACKLIST_TMP}" || {
			printf "[FAILED]\n"
			return 1
		}

		# Prevent using an empty blacklist
		[ $(wc -l "${BLACKLIST_TMP}" | cut -d " " -f1) -eq 0 ] && return 1

		printf "[OK]\n"
	}

	function sync_bs() {

		# Clone BS git repo
		if [ -d "${BS_GIT_TMP}"/.git ]; then
			pushd "${BS_GIT_TMP}" >/dev/null 2>&1
			git pull
			popd  >/dev/null 2>&1
		else
			git clone "${BS_GIT}" "${BS_GIT_TMP}"
		fi

		# Sync from BS_DD and then sync from BS
		printf ":: Syncing ${BS_MAIN_NAME}...\t"
		(rsync "${SYNC_ARGS}" --delete-excluded \
			--exclude-from="${BLACKLIST_TMP}" \
			"${BS_DD_DIR}" \
			"${BS_MAIN_DIR}" \
			&&
			for 'ARCH' in "${ARCHES[@]}"; do rsync -v -mrtq --no-motd --no-p --no-o --no-g --quiet --exclude=.git/ "${BS_GIT_TMP}" "${BS_MAIN_DIR}/${ARCH}/"; done) || {
			printf "[FAILED]\n"
			return 1
		}

		# fix some permissions
		find "${BS_MAIN_DIR}" -type d -print0 | xargs -0 chmod 755
		find "${BS_MAIN_DIR}" -type f -print0 | xargs -0 chmod 644

		printf "[OK]\n"
	}

	# Create .abs.tar.gz tarballs
	create_tarballs() {
		for 'repo' in "${BS_MAIN_DIR}/${ARCHES[@]}/"*; do
			baserepo="${repo##*/}"
			arch="$(basename $(dirname ${repo}))"

			# Remove the old one
			mkdir -p "${REPO_DIR}/${baserepo}/os/${arch}"
			rm -fv "${REPO_DIR}/${baserepo}/os/${arch}/${baserepo}.abs.tar.gz"
			# Create a new one joining arch and any
			# Remove the first part of the path (it could be $repo but any isn't hit)
			bsdtar -czf "${REPO_DIR}/${baserepo}/os/${arch}/${baserepo}.abs.tar.gz" \
				-s ":${BS_MAIN_DIR}/[a-z0-9_]\+/[a-z]\+::" \
				"${repo}"/* "${BS_MAIN_DIR}/any/${baserepo}"/*

		done
	}

	sync_bs_derivation
	get_blacklist
	sync_bs
	create_tarballs
done