4 |
# builds packages from given dir |
# builds packages from given dir |
5 |
# |
# |
6 |
|
|
7 |
# version: 0.3.6-r8 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/pkgbuild_dir.sh,v 1.15 2007-03-19 19:24:46 niro Exp $ |
8 |
|
|
9 |
|
# set default user mage.rc |
10 |
|
: ${MAGERC="/etc/mage.rc"} |
11 |
|
|
12 |
PKGSUFFIX="mpk" |
PKGSUFFIX="mpk" |
13 |
PKGNAME="$1" |
PKGNAME="$1" |
14 |
SEARCHDIRS="$2" |
SEARCHDIRS="$2" |
15 |
MLIBDIR=/usr/lib/mage |
MLIBDIR=/usr/lib/mage |
16 |
|
|
17 |
|
## only for tests -> normally in /etc/rc.d/init.d/functions |
18 |
COLRED="\033[1;6m\033[31m" |
COLRED="\033[1;6m\033[31m" |
19 |
COLGREEN="\033[1;6m\033[32m" |
COLGREEN="\033[1;6m\033[32m" |
20 |
|
COLYELLOW="\033[1;6m\033[33m" |
21 |
|
COLBLUE="\033[1;6m\033[34m" |
22 |
|
COLMAGENTA="\033[1;6m\033[35m" |
23 |
|
COLWHITE="\033[1;6m\033[37m" |
24 |
|
COLGRAY="\033[0;6m\033[37m" |
25 |
|
COLBOLD="\033[1m" |
26 |
COLDEFAULT="\033[0m" |
COLDEFAULT="\033[0m" |
27 |
|
|
28 |
if [ -z "$1" ] |
if [[ ${NOCOLORS} = true ]] |
29 |
then |
then |
30 |
echo "No package name given. Aborting." |
COLRED="" |
31 |
|
COLGREEN="" |
32 |
|
COLYELLOW="" |
33 |
|
COLBLUE="" |
34 |
|
COLMAGENTA="" |
35 |
|
COLWHITE="" |
36 |
|
COLGRAY="" |
37 |
|
COLBOLD="" |
38 |
|
COLDEFAULT="" |
39 |
fi |
fi |
40 |
|
|
41 |
if [ -z "$2" ] |
# export default C locale |
42 |
then |
export LC_ALL=C |
43 |
echo "No source dir given. Aborting." |
|
44 |
fi |
[[ -z $1 ]] && echo "No package name given. Aborting." && exit 1 |
45 |
|
[[ -z $2 ]] && echo "No source dir given. Aborting." && exit 1 |
46 |
|
|
47 |
|
source /etc/mage.rc.global |
48 |
|
[[ -f ${MAGERC} ]] && source ${MAGERC} |
49 |
|
source ${MLIBDIR}/mage4.functions.sh |
50 |
|
|
51 |
if [ -f /etc/mage.rc ] |
# set PKGDIR and BUILDDIR and BINDIR to MROOT |
52 |
|
if [[ -n ${MROOT} ]] |
53 |
then |
then |
54 |
source /etc/mage.rc |
export PKGDIR=${MROOT}/${PKGDIR} |
55 |
else |
export BUILDDIR=${MROOT}/${BUILDDIR} |
56 |
echo "Your /etc/mage.rc is missing. Aborting." |
export BINDIR=${MROOT}/${BINDIR} |
|
exit 1 |
|
57 |
fi |
fi |
|
source ${MLIBDIR}/mage3.functions.sh |
|
58 |
|
|
59 |
build_preinstall() { |
build_preinstall() |
60 |
|
{ |
61 |
if [ -d ${BUILDDIR}/${PKGNAME} ] |
if [ -d ${BUILDDIR}/${PKGNAME} ] |
62 |
then |
then |
63 |
rm -rf ${BUILDDIR}/${PKGNAME} |
rm -rf ${BUILDDIR}/${PKGNAME} |
69 |
touch ${BUILDDIR}/${PKGNAME}/.files |
touch ${BUILDDIR}/${PKGNAME}/.files |
70 |
touch ${BUILDDIR}/${PKGNAME}/.pipes |
touch ${BUILDDIR}/${PKGNAME}/.pipes |
71 |
touch ${BUILDDIR}/${PKGNAME}/.char |
touch ${BUILDDIR}/${PKGNAME}/.char |
72 |
|
touch ${BUILDDIR}/${PKGNAME}/.fifo |
73 |
} |
} |
74 |
|
|
75 |
build_postinstall() { |
build_postinstall() |
76 |
|
{ |
77 |
echo |
local m_mtime |
78 |
echo "Fetching files for package '${PKGNAME}' ..." |
local m_md5sum |
79 |
|
local filelist |
80 |
#md5sums will only be generated for files: $M_MD5SUM |
local item |
81 |
|
local check_srcdir |
82 |
#sets mtime to same value of the $BINDIR: $M_MTIME |
local filetype |
83 |
#only needed for files and symlinks |
local fileposix |
84 |
M_MTIME=$(stat -c %Y ${BINDIR}) |
local fileowner |
85 |
|
local filegroup |
86 |
#install mtime to package (needed for later checks) |
local lnkdest |
87 |
echo "${M_MTIME}" > ${BUILDDIR}/${PKGNAME}/.mtime |
local filedir |
88 |
|
local char_major |
89 |
|
local char_minor |
90 |
|
|
91 |
|
echo -e "${COLBLUE}===${COLGREEN} fetching files for package '${PKGNAME}' ...${COLDEFAULT}" |
92 |
|
|
93 |
|
# md5sums will only be generated for files: $m_md5sum |
94 |
|
|
95 |
|
# sets mtime to same value of the $BINDIR: $m_mtime |
96 |
|
# only needed for files and symlinks |
97 |
|
m_mtime=$(stat -c %Y ${BINDIR}) |
98 |
|
|
99 |
#!! we use § as field seperator !! |
# install mtime to package (needed for later checks) |
100 |
|
echo "${m_mtime}" > ${BUILDDIR}/${PKGNAME}/.mtime |
101 |
|
|
102 |
|
# !! we use § as field seperator !! |
103 |
# doing so prevent us to get errors by filenames with spaces |
# doing so prevent us to get errors by filenames with spaces |
104 |
BUILD_TODELFILES=$(find ${SEARCHDIRS} -printf %p§) |
filelist=$(find ${SEARCHDIRS} -printf %p§) |
105 |
|
|
106 |
#sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
107 |
IFS=§ |
IFS=§ |
108 |
|
|
109 |
for I in $BUILD_TODELFILES |
for item in ${filelist} |
110 |
do |
do |
111 |
CHECK_SRCDIR="$(echo ${I#${SEARCHDIRS}*}|grep $BUILDDIR)" |
check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})" |
112 |
|
|
113 |
if [ -z "$CHECK_SRCDIR" ] |
if [[ -z ${check_srcdir} ]] |
114 |
then |
then |
115 |
FILETYPE="$(stat -c %F $I)" |
filetype="$(stat -c %F ${item})" |
116 |
FILEPOSIX="$(stat -c %a $I)" |
fileposix="$(stat -c %a ${item})" |
117 |
FILEOWNER="$(stat -c %U $I)" |
fileowner="$(stat -c %U ${item})" |
118 |
FILEGROUP="$(stat -c %G $I)" |
filegroup="$(stat -c %G ${item})" |
|
|
|
|
if [ "${FILEOWNER}" == "UNKNOWN" ] |
|
|
then |
|
|
FILEOWNER="root" |
|
|
fi |
|
|
|
|
|
if [ "${FILEGROUP}" == "UNKNOWN" ] |
|
|
then |
|
|
FILEGROUP="root" |
|
|
fi |
|
119 |
|
|
120 |
case "${FILETYPE}" in |
[[ ${fileowner} = UNKNOWN ]] && fileowner="root" |
121 |
|
[[ ${filegroup} = UNKNOWN ]] && filegroup="root" |
122 |
|
|
123 |
|
case "${filetype}" in |
124 |
"directory") |
"directory") |
125 |
if [ "$I" != "${SEARCHDIRS}" ] |
if [[ ${item} != ${SEARCHDIRS} ]] |
126 |
then |
then |
127 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
128 |
fi |
fi |
129 |
;; |
;; |
130 |
|
|
131 |
"symbolic link") |
"symbolic link") |
132 |
LNKDEST="$(readlink $I)" |
lnkdest="$(readlink ${item})" |
133 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${LNKDEST#${SEARCHDIRS}*}§${M_MTIME}" >> ${BUILDDIR}/${PKGNAME}/.symlinks |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks |
134 |
;; |
;; |
|
|
|
135 |
|
|
136 |
"regular empty file") |
"regular empty file") |
137 |
FILEDIR="$(dirname $I)" |
filedir="$(dirname ${item})" |
138 |
FILEDIR="${FILEDIR#${SEARCHDIRS}*}" |
filedir="${filedir#${SEARCHDIRS}*}" |
139 |
M_MD5SUM="$(md5sum ${I}|cut -d' ' -f1)" |
m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" |
140 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}§${M_MTIME}§${M_MD5SUM}" >> ${BUILDDIR}/${PKGNAME}/.files |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_mtime}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files |
141 |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
142 |
cp ${I} ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
143 |
;; |
;; |
144 |
|
|
145 |
"regular file" ) |
"regular file" ) |
146 |
FILEDIR="$(dirname $I)" |
filedir="$(dirname ${item})" |
147 |
FILEDIR="${FILEDIR#${SEARCHDIRS}*}" |
filedir="${filedir#${SEARCHDIRS}*}" |
148 |
M_MD5SUM="$(md5sum ${I}|cut -d' ' -f1)" |
m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" |
149 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}§${M_MTIME}§${M_MD5SUM}" >> ${BUILDDIR}/${PKGNAME}/.files |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_time}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files |
150 |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
151 |
cp ${I} ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
152 |
;; |
;; |
153 |
|
|
154 |
"block special file") |
"block special file") |
155 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}" >> ${BUILDDIR}/${PKGNAME}/.pipes |
# convert hex2dec |
156 |
|
# printf '%d' 0x12 -> 18 |
157 |
|
char_major="$(printf 0x$(stat -c %t ${item}))" |
158 |
|
char_minor="$(printf 0x$(stat -c %T ${item}))" |
159 |
|
echo "${item#${SEARCHDIRS}*}§${fileposix}§${char_major}§${char_minor}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.pipes |
160 |
;; |
;; |
161 |
|
|
162 |
"character special file") |
"character special file") |
163 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}" >> ${BUILDDIR}/${PKGNAME}/.char |
# convert hex2dec |
164 |
|
# printf '%d' 0x12 -> 18 |
165 |
|
char_major="$(printf 0x$(stat -c %t ${item}))" |
166 |
|
char_minor="$(printf 0x$(stat -c %T ${item}))" |
167 |
|
echo "${item#${SEARCHDIRS}*}§${fileposix}§${char_major}§${char_minor}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.char |
168 |
|
;; |
169 |
|
|
170 |
|
"fifo") |
171 |
|
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.fifo |
172 |
;; |
;; |
173 |
|
|
174 |
*) |
*) |
175 |
echo "What I am ? -- $I" |
echo "What I am ? -- $I" |
176 |
echo "$0 paused ... Press Enter" |
echo "$0 paused ... Press Enter" |
179 |
esac |
esac |
180 |
fi |
fi |
181 |
done |
done |
182 |
|
|
183 |
#very important: unsetting the '§' fieldseperator |
# very important: unsetting the '§' fieldseperator |
184 |
unset IFS |
unset IFS |
185 |
|
|
186 |
#forcing mtime to same value |
# forcing mtime to same value |
187 |
echo -n "Forcing mtime to the same value ..." |
echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}" |
188 |
find ${BUILDDIR}/${PKGNAME}/binfiles \ |
find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' |
|
-exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' \ |
|
|
&& echo done || echo false |
|
|
|
|
189 |
} |
} |
190 |
|
|
191 |
build_rmtimestamp() { |
build_rmtimestamp() |
192 |
|
{ |
193 |
rm /var/tmp/timestamp |
rm /var/tmp/timestamp |
194 |
} |
} |
195 |
|
|
196 |
|
build_package() |
197 |
build_package() { |
{ |
198 |
echo "Building Package ..." |
echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}" |
199 |
cd ${BUILDDIR} |
cd ${BUILDDIR} |
200 |
tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} |
tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} |
201 |
install -d ${PKGDIR} |
install -d ${PKGDIR} |
202 |
mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} |
mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} |
203 |
} |
} |
204 |
|
|
|
|
|
205 |
build_preinstall |
build_preinstall |
206 |
build_postinstall |
build_postinstall |
207 |
build_package |
build_package |