-
Notifications
You must be signed in to change notification settings - Fork 0
/
setsource
executable file
·167 lines (142 loc) · 4.82 KB
/
setsource
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
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
UPDATE_CURRENT=${UPDATE_CURRENT:-false};
. ./packaging.sh
branch=
curpkg=
pkgname=$1;
stripped="${pkgname%#*}"
if [ "${stripped}" != "${pkgname}" ]; then
branch="${pkgname#*#}";
pkgname=${stripped}
fi;
if [ ! -d "${CONFIG_ROOT}/${pkgname}" ]; then
echo "setsource: ${pkgname} is not a known package name";
exit;
fi;
if [ -f ${STATE_ROOT}/PKGNAME ]; then
curpkg=$(cat ${STATE_ROOT}/PKGNAME);
else
curpkg=;
fi
if ! ([ -n "${curpkg}" ] && [ -d "src/${curpkg}" ] && [ -f "work/${curpkg}.tar" ]); then
UPDATE_CURRENT=yes
fi;
if [ "${curpkg}" = "${pkgname}" ] && [ ! -n "${UPDATE_CURRENT}" ]; then
exit;
fi;
if [ -n "${curpkg}" ]; then echo "Switching from ${curpkg} to ${pkgname}"; fi;
PKGNAME=${pkgname};
rm -f ${STATE_ROOT}/*;
echo "${pkgname}" > ${STATE_ROOT}/PKGNAME;
if [ -n "${branch}" ]; then echo "${branch}" > ${STATE_ROOT}/BRANCH; fi;
cp ${PACKAGING_ROOT}/defaults/* ${STATE_ROOT} 2> /dev/null;
if [ -d ${PACKAGING_ROOT}/defaults/${pkgname} ]; then
cp ${PACKAGING_ROOT}/defaults/${pkgname}/* ${STATE_ROOT} 2> /dev/null;
fi;
if [ -z "${branch}" ]; then
if [ -f defaults/${pkgname}/BRANCH ]; then
BRANCH=$(cat defaults/${pkgname}/BRANCH);
branch=${BRANCH};
elif [ -f defaults/BRANCH ]; then
BRANCH=$(cat defaults/BRANCH);
branch=${BRANCH};
fi;
fi
if [ -n "${branch}" ]; then echo ${branch} > state/BRANCH; fi;
if [ -n "${DEBUG}" ]; then
echo setsource PKGNAME=${PKGNAME} BRANCH=${BRANCH} VERSION=${VERSION};
fi;
# Getting repo information
if [ -n "${REPO}" ]; then
:;
elif [ -f "${CONFIG_ROOT}/${PKGNAME}/repo" ]; then
REPO=$(cat "${CONFIG_ROOT}/${PKGNAME}/repo");
echo "${REPO}" > state/REPO;
fi;
if [ -n "${REPOMAN}" ]; then
:;
elif [ -f "${CONFIG_ROOT}/${PKGNAME}/repoman" ]; then
REPOMAN=$(cat "${CONFIG_ROOT}/${PKGNAME}/repoman");
echo "${REPOMAN}" > state/REPOMAN;
else
REPOMAN="Repository Manager <[email protected]>";
fi;
if [ -n "${REPO}" ]; then
echo ${REPO} > state/REPO;
fi;
if [ -n "${REPOMAN}" ]; then
echo ${REPOMAN} > state/REPOMAN;
fi;
# Getting sources
tarfile=${PKGNAME}.tar
srcurl=$(cat ${CONFIG_ROOT}/${PKGNAME}/srcloc)
srcdir=src/${PKGNAME}
if [ "${GIT_PROTOCOL}" = "ssh" ] && [ "${srcurl#https:}" != "${srcurl}" ]; then
newurl=$(echo ${srcurl} | sed -e 's|^https://|git@|' | sed 's|/|:|')
if [ "${newurl}" != "${srcurl}" ]; then
echo "Rewrote ${srcurl} as ${newurl}";
srcurl="${newurl}";
fi;
elif [ "${GIT_PROTOCOL}" = "https" ] && [ "${srcurl#git@github.}" != "${srcurl}" ]; then
newurl=$(echo ${srcurl} | sed 's|:|/|' | sed -e 's|^git@|https://|')
if [ "${newurl}" != "${srcurl}" ]; then
echo "Rewrote ${srcurl} as ${newurl}";
srcurl="${newurl}";
fi;
fi
if [ ! -d "${srcdir}" ]; then
git clone ${srcurl} ${srcdir};
("cd" ${srcdir};
if [ -n "${BRANCH}" ]; then git checkout ${BRANCH}; fi;
git submodule init;
git submodule update;
if [ -z "${GIT_NO_LFS}" ]; then git lfs install; git lfs checkout; fi;);
else ("cd" ${srcdir};
if [ -n "${BRANCH}" ]; then git checkout ${BRANCH}; fi;
git pull;
git submodule init;
git submodule update;
if [ -z "${GIT_NO_LFS}" ]; then
git lfs fetch;
git lfs pull;
fi;);
fi
# This should be consistent with branch
if [ -d ${srcdir}/.git ]; then
BRANCH=$("cd" ${srcdir}; u8_gitbranch);
echo ${BRANCH} > ${STATE_ROOT}/BRANCH;
fi;
if [ -f ${srcdir}/etc/base_version ]; then
(cd "${srcdir}";
echo $(u8_gitversion etc/base_version) > ${STATE_ROOT}/VERSION;
echo $(u8_gitversion etc/base_version -full) > ${STATE_ROOT}/FULL_VERSION;
cp etc/base_version ${STATE_ROOT}/BASE_VERSION);
elif [ -f ${srcdir}/etc/knomod_version ]; then
("cd" ${srcdir};
MOD_VERSION=$(u8_gitversion etc/knomod_version);
echo ${KNO_MAJOR}.${KNO_MINOR}.${MOD_VERSION} > ${STATE_ROOT}/VERSION;
echo $(u8_gitversion etc/knomod_version -full) > ${STATE_ROOT}/FULL_VERSION;
cp etc/knomod_version ${STATE_ROOT}/BASE_VERSION);
fi;
if [ -f ${srcdir}/dist/libname ]; then
LIBNAME=$(cat ${srcdir}/dist/libname);
echo ${LIBNAME} > ${STATE_ROOT}/LIBNAME;
elif [ "${pkgname#kno-}" != "${pkgname}" ]; then
LIBNAME=${pkgname#kno-};
echo ${LIBNAME} > ${STATE_ROOT}/LIBNAME;
fi;
import_state;
logmsg "Creating source tarball ${tarfile} with version info";
if [ -x ${srcdir}/make_source_tar ]; then
("cd" ${srcdir}; ./make_source_tar ../../work/${tarfile});
else
("cd" ${srcdir}; git archive -o ../../work/${tarfile} HEAD );
("cd" state; tar -rf ../work/${tarfile} \
VERSION BASE_VERSION FULL_VERSION VERSION);
fi;
if [ ! -d output/${PKGNAME} ]; then
mkdir ${PACKAGING_ROOT}/output/${PKGNAME};
fi;
rm -f ${PACKAGING_ROOT}/output/${PKGNAME}/_.* run/INSTALLED.${PKGNAME};
touch ${PACKAGING_ROOT}/output/${PKGNAME}/_.STARTED;
echo "Package ${PKGNAME}(${BRANCH}) version ${VERSION}"