-
Notifications
You must be signed in to change notification settings - Fork 3
/
sark-localbuild
executable file
·155 lines (121 loc) · 5.58 KB
/
sark-localbuild
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
set -e
export REPOSITORY_NAME="${REPOSITORY_NAME:-$(basename $(pwd))}"
export LC_ALL=en_US.UTF-8
# Speed up test runs by disabling slow syncs and mirror sorts
export SKIP_PORTAGE_SYNC="${SKIP_PORTAGE_SYNC:-0}"
export SKIP_CLEAN_PACKAGESDIR="${SKIP_CLEAN_PACKAGESDIR:-0}"
export EQUO_MIRRORSORT="${EQUO_MIRRORSORT:-0}"
# Enable/Disable create repository phase
export CREATEREPO_PHASE=${CREATEREPO_PHASE:-true}
# Enable/Disable builder phase. In general this is always true.
# It is set to false for testing injection of packages or move binhost files
# under a new repository.
export BUILDER_PHASE=${BUILDER_PHASE:-true}
export SAB_WORKSPACE="${SAB_WORKSPACE:-$PWD}"
export SAB_ARCH="${SAB_ARCH:-intel}"
export MAKE_CONF="${MAKE_CONF:-}"
export LOCAL_OVERLAY="${LOCAL_OVERLAY:-$SAB_WORKSPACE/local_overlay}"
# Add skip env print if there are env vars with credentials.
export SKIP_PRINTENV="${SKIP_PRINTENV:-0}"
export SAB_BUILDFILE=${SAB_BUILDFILE:-build.yaml}
export SAB_BUILDER=${SAB_BUILDER:-/usr/sbin/builder}
export SAB_PORTDIR=${SAB_PORTDIR:-/opt/sabayon-build/conf/${SAB_ARCH}/portage}
export EDITOR=cat
if [ -e "$SAB_WORKSPACE/specs/make.conf" ]; then
echo "You specified a make.conf. I hope you know what are you doing"
export MAKE_CONF="${MAKE_CONF:-$SAB_WORKSPACE/specs/make.conf}"
fi
. /sbin/sark-functions.sh
if [ ! -e ${SAB_BUILDFILE} ]; then
echo "Must be run from a repository directory containing a ${SAB_BUILDFILE}"
exit 1
fi
load_env_from_yaml ${SAB_BUILDFILE}
export OUTPUT_DIR="${SAB_WORKSPACE}/artifacts/${REPOSITORY_NAME}-binhost"
export CHECK_BUILD_DIFFS=${CHECK_BUILD_DIFFS:-1}
NEW_BINHOST_MD5=$(mktemp -t "$(basename $0).XXXXXXXXXX")
OLD_BINHOST_MD5=$(mktemp -t "$(basename $0).XXXXXXXXXX")
[ "${SKIP_CLEAN_PACKAGESDIR}" = 0 ] && rm -rfv /usr/portage/packages/* || true
[ -d ${OUTPUT_DIR} ] || mkdir -p "${OUTPUT_DIR}"
[ "$CHECK_BUILD_DIFFS" -eq 1 ] && packages_hash ${SAB_WORKSPACE} $REPOSITORY_NAME $OLD_BINHOST_MD5
[ -z "$PORTAGE_CACHE" ] || [ -d "$PORTAGE_CACHE" ] && cp -rfv $PORTAGE_CACHE /usr/portage
[ -z "$DISTFILES" ] || [ -d "$DISTFILES" ] && cp -rfv $DISTFILES /usr/portage/
[ -z "$ENTROPY_DOWNLOADED_PACKAGES" ] || [ -d "$ENTROPY_DOWNLOADED_PACKAGES" ] && cp -rfv $ENTROPY_DOWNLOADED_PACKAGES /var/lib/entropy/client/packages
[ -d "$LOCAL_OVERLAY" ] && cp -rfv $LOCAL_OVERLAY /usr/local/local_portage
PRE_SCRIPT_FILE=$(mktemp -t "$(basename $0).XXXXXXXXXX")
POST_SCRIPT_FILE=$(mktemp -t "$(basename $0).XXXXXXXXXX")
# Prepare and post script
[ -n "${PRE_SCRIPT_COMMANDS}" ] && \
printf '%s\n' "${PRE_SCRIPT_COMMANDS[@]}" > $PRE_SCRIPT_FILE && \
cp -rfv $PRE_SCRIPT_FILE /pre-script
[ -n "${POST_SCRIPT_COMMANDS}" ] && \
printf '%s\n' "${POST_SCRIPT_COMMANDS[@]}" > $POST_SCRIPT_FILE && \
cp -rfv $POST_SCRIPT_FILE /post-script
if [ -d "$SAB_WORKSPACE"/specs ]; then
echo "Specs found"
if [ -e "$SAB_WORKSPACE"/specs/custom.mask ] ; then
mkdir -p "${SAB_PORTDIR}/package.mask" || true
cp -rfv "$SAB_WORKSPACE/specs/custom.mask" "${SAB_PORTDIR}/package.mask/99-custom.mask"
fi
if [ -e "$SAB_WORKSPACE"/specs/custom.unmask ] ; then
mkdir -p "${SAB_PORTDIR}/package.unmask" || true
cp -rfv "$SAB_WORKSPACE/specs/custom.unmask" "${SAB_PORTDIR}/package.unmask/99-custom.unmask"
fi
if [ -e "$SAB_WORKSPACE"/specs/custom.use ] ; then
mkdir -p "${SAB_PORTDIR}/package.use" || true
cp -rfv "$SAB_WORKSPACE/specs/custom.use" "${SAB_PORTDIR}/package.use/99-custom.use"
fi
if [ -e "$SAB_WORKSPACE"/specs/custom.keywords ] ; then
mkdir -p "${SAB_PORTDIR}/package.keywords" || true
cp -rfv "$SAB_WORKSPACE/specs/custom.keywords" "${SAB_PORTDIR}/package.keywords/99-custom.keywords"
fi
[ -d "$SAB_WORKSPACE"/specs/env ] && cp -rfv "$SAB_WORKSPACE/specs/env/" "${SAB_PORTDIR}/env/"
[ -e "$SAB_WORKSPACE"/specs/custom.env ] && cp -rfv "$SAB_WORKSPACE/specs/custom.env" "${SAB_PORTDIR}/package.env"
fi
# Debug what env vars are being passed to the builder
if [ "${SKIP_PRINTENV}" != 1 ] ; then
printenv | sort
fi
if [ "$BUILDER_PHASE" = true ] ; then
pushd /
/usr/bin/tini -s -- ${SAB_BUILDER} $BUILD_ARGS
popd
fi
BUILD_STATUS=$?
rm -rf $PRE_SCRIPT_FILE || true
rm -rf $POST_SCRIPT_FILE || true
cp -R /usr/portage/packages/* ${OUTPUT_DIR} || true
[ "$CREATEREPO_PHASE" = false ] && exit $BUILD_STATUS
TEMPDIR=$(mktemp -d)
# Checking diffs
if [ "$CHECK_BUILD_DIFFS" -eq 1 ]; then
echo "*** Checking tbz2 diffs ***"
# let's do the hash of the tbz2 without xpak data
packages_hash ${SAB_WORKSPACE} $REPOSITORY_NAME $NEW_BINHOST_MD5
TO_INJECT=($(diff -ru $OLD_BINHOST_MD5 $NEW_BINHOST_MD5 | grep -v -e '^\+[\+]' | grep -e '^\+' | awk '{print $2}'))
echo "INJECT RESULT = ${TO_INJECT[@]}"
#if diffs are detected, regenerate the repository
if diff -q $OLD_BINHOST_MD5 $NEW_BINHOST_MD5 >/dev/null ; then
echo "No changes where detected, repository generation prevented"
rm -rf $OLD_BINHOST_MD5 $NEW_BINHOST_MD5
exit 0
else
TBZ2_DIR=${SAB_WORKSPACE}/artifacts/${REPOSITORY_NAME}-binhost
echo "${TO_INJECT[@]} packages needs to be injected"
for ((i=0; i<${#TO_INJECT[@]}; i++)) ; do
# We need maintains category directory because
# if there are two package with different category but with same
# name and version, last win.
dir=$(dirname ${TO_INJECT[$i]})
echo "Copying ${TO_INJECT[$i]} to ${TEMPDIR}/${dir}..."
mkdir -p ${TEMPDIR}/${dir} || true
cp -rf "${TBZ2_DIR}"/${TO_INJECT[$i]} ${TEMPDIR}/${dir}/
done
fi
else
# Inject all packages available under /usr/portage/packages
cp -R /usr/portage/packages/* ${TEMPDIR} || true
fi
export PKGS_CACHE_DIR=$TEMPDIR
sark-localcreaterepo