-
Notifications
You must be signed in to change notification settings - Fork 3
/
sark-localcreaterepo
executable file
·158 lines (127 loc) · 5.26 KB
/
sark-localcreaterepo
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
156
#!/bin/bash
export REPOSITORY_NAME="${REPOSITORY_NAME:-$(basename $(pwd))}"
export LC_ALL=en_US.UTF-8
export SKIP_PULL="${SKIP_PULL:-0}"
export SKIP_PUSH="${SKIP_PUSH:-0}"
export SKIP_COMMIT="${SKIP_COMMIT:-0}"
export SKIP_INJECT="${SKIP_INJECT:-0}"
export SAB_WORKSPACE="${SAB_WORKSPACE:-$PWD}"
# Add additional option for eit inject command.
export EIT_INJECT_OPTS="${EIT_INJECT_OPTS:---quick}"
export REPO_RESET="${REPO_RESET:-0}"
# Enable additional options for eit remove command. Additional option possible --nodeps
export EIT_REMOVE_OPTS="${EIT_REMOVE_OPTS:---quick}"
# Add skip env print if there are env vars with credentials.
export SKIP_PRINTENV="${SKIP_PRINTENV:-0}"
export REPO_CLEAN_EXPIRE="${REPO_CLEAN_EXPIRE:-0}"
export REPO_CLEAN_EXPIRE_DAYS="${REPO_CLEAN_EXPIRE_DAYS:-1}"
# Clean obsolete packages .tgz under binhost directory
export REPO_BINHOST_CLEAN="${REPO_BINHOST_CLEAN:-0}"
export SAB_BUILDFILE=${SAB_BUILDFILE:-build.yaml}
export REPOSITORY_DESCRIPTION="${REPOSITORY_DESCRIPTION:-Autogenerated repository}"
export ENTROPY_DIR="${ENTROPY_DIR:-/${SAB_WORKSPACE}/artifacts/${REPOSITORY_NAME}}"
export PACKAGES_DIR="${PACKAGES_DIR:-/${SAB_WORKSPACE}/artifacts/${REPOSITORY_NAME}-binhost}"
export ENTROPY_RSS_BASEURL="${ENTROPY_RSS_BASEURL:-http://packages.sabayon.org/?quicksearch=}"
export ENTROPY_RSS_WEBURL="${ENTROPY_RSS_WEBURL:-http://www.sabayon.org/}"
# When PKGS_CACHE_DIR is defined then use directly packages
# directory without the use of a temporary directory.
export PKGS_CACHE_DIR="${PKGS_CACHE_DIR:-}"
set -e
. /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}
cat >/etc/entropy/server.conf <<EOF
# expiration-days = <internal value>
community-mode = enable
weak-package-files = disable
database-format = bz2
# sync-speed-limit =
# server-basic-languages = en_US C
# disabled-eapis = 1,2
# expiration-based-scope = disable
# nonfree-packages-directory-support = disable
rss-feed = enable
changelog = enable
rss-name = packages.rss
rss-base-url = ${ENTROPY_RSS_BASEURL}
rss-website-url = ${ENTROPY_RSS_WEBURL}
max-rss-entries = 10000
# max-rss-light-entries = 100
rss-light-name = updates.rss
managing-editor =
broken-reverse-deps = disable
default-repository = $REPOSITORY_NAME
repository=$REPOSITORY_NAME|$REPOSITORY_DESCRIPTION|file:///${ENTROPY_DIR}
EOF
mkdir -p ${ENTROPY_DIR} || true
if [[ ${SKIP_INJECT} = 0 ]] ; then
if [ -z "${PKGS_CACHE_DIR}" ] ; then
TEMPDIR=$(mktemp -d)
cp -rf $(find $PACKAGES_DIR -name "*.tbz2" | xargs) $TEMPDIR
else
TEMPDIR="${PKGS_CACHE_DIR}"
fi
built_pkgs=$(find $TEMPDIR -name "*.tbz2" | xargs)
[[ -z "${built_pkgs}" ]] && echo "ERROR: no tbz2s found" && exit 2
fi
if [ -d "${ENTROPY_DIR}/standard" ]; then
if [[ $SKIP_PULL = 0 ]] ; then
echo "=== Repository already exists, syncronizing ==="
eit unlock $REPOSITORY_NAME || true
eit pull --quick $REPOSITORY_NAME || true
fi
# #eit sync \$repo
else
echo "=== Repository is empty, intializing ==="
echo "Yes" | eit init --quick $REPOSITORY_NAME
eit push --quick --force ${REPOSITORY_NAME}
fi
echo "=== Update config files ==="
echo -9 | equo conf update
if [[ ${REPO_RESET} = 1 ]] ; then
# This is needed
echo "=== Reset Repository Revision ==="
eit reset --quick --local ${REPOSITORY_NAME}
echo "=== Reset COMPLETED ==="
fi
[ -f "${SAB_WORKSPACE}/confs/${REPOSITORY_NAME}.pub" ] && [ -f "${SAB_WORKSPACE}/confs/${REPOSITORY_NAME}.key" ] && { ! eit key status ${REPOSITORY_NAME}; } && \
eit key import ${REPOSITORY_NAME} ${SAB_WORKSPACE}/confs/${REPOSITORY_NAME}.key ${SAB_WORKSPACE}/confs/${REPOSITORY_NAME}.pub && { eit key sign ${REPOSITORY_NAME} || true; } && { echo "=== Repository key imported successfully ==="; }
if [ -n "${TOREMOVE_BEFORE}" ] ; then
echo "=== Removing packages before inject ==="
# NOTE: Require pull of the repository for retrieve list of packages.
eit rm ${EIT_REMOVE_OPTS} --from $REPOSITORY_NAME $TOREMOVE_BEFORE || {
echo "ouch unable to remove" && exit 3;
}
echo "=== Removing packages before inject COMPLETED ==="
fi
if [[ ${SKIP_INJECT} = 0 ]] ; then
echo "=== Injecting packages ==="
echo "INJECT = ${built_pkgs}"
eit inject ${EIT_INJECT_OPTS} --to ${REPOSITORY_NAME} --quick ${built_pkgs} || { echo "ouch unable to inject" && exit 3; }
echo "=== Inject COMPLETED ====="
fi
echo "=== Removing packages ==="
if [ -n "${TOREMOVE}" ]; then
eit rm ${EIT_REMOVE_OPTS} --from $REPOSITORY_NAME $TOREMOVE || { echo "ouch unable to remove" && exit 3; }
fi
echo "=== Removing packages completed ==="
if [[ ${SKIP_COMMIT} = 0 ]] ; then
echo "=== Commit packages ====="
eit commit --quick
echo "=== Commit COMPLETED ====="
fi
echo "=== Pushing built packages locally ==="
eit push --quick --force ${REPOSITORY_NAME}
[ -f "${SAB_WORKSPACE}/confs/${REPOSITORY_NAME}.pub" ] && [ -f "${SAB_WORKSPACE}/confs/${REPOSITORY_NAME}.key" ] && rm -rf /etc/entropy/gpg-keys
if [[ ${REPO_CLEAN_EXPIRE} = 1 ]] ; then
echo "=== Clean expire packages ==="
eit vacuum --quick --days ${REPO_CLEAN_EXPIRE_DAYS} ${REPOSITORY_NAME}
fi
if [[ ${REPO_BINHOST_CLEAN} = 1 ]] ; then
purge_binhost_packages ${PACKAGES_DIR}
fi
VAGRANT_DIR=$SAB_WORKSPACE generate_repository_metadata
echo "=== ALL DONE. bye ==="