Contents of /branches/mage-next/src/pkgbuild_dir.in
Parent Directory | Revision Log
Revision 1292 -
(show annotations)
(download)
(as text)
Fri May 27 12:55:43 2011 UTC (13 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/pkgbuild_dir.sh
File MIME type: application/x-sh
File size: 5491 byte(s)
Fri May 27 12:55:43 2011 UTC (13 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/pkgbuild_dir.sh
File MIME type: application/x-sh
File size: 5491 byte(s)
-fixed coding style and fixed packaging of block special devices
1 | #!/bin/bash |
2 | |
3 | # |
4 | # builds packages from given dir |
5 | # |
6 | |
7 | # $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" |
13 | PKGNAME="$1" |
14 | SEARCHDIRS="$2" |
15 | MLIBDIR=/usr/lib/mage |
16 | |
17 | ## only for tests -> normally in /etc/rc.d/init.d/functions |
18 | COLRED="\033[1;6m\033[31m" |
19 | 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" |
27 | |
28 | if [[ ${NOCOLORS} = true ]] |
29 | then |
30 | COLRED="" |
31 | COLGREEN="" |
32 | COLYELLOW="" |
33 | COLBLUE="" |
34 | COLMAGENTA="" |
35 | COLWHITE="" |
36 | COLGRAY="" |
37 | COLBOLD="" |
38 | COLDEFAULT="" |
39 | fi |
40 | |
41 | # export default C locale |
42 | export LC_ALL=C |
43 | |
44 | [[ -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 | # set PKGDIR and BUILDDIR and BINDIR to MROOT |
52 | if [[ -n ${MROOT} ]] |
53 | then |
54 | export PKGDIR=${MROOT}/${PKGDIR} |
55 | export BUILDDIR=${MROOT}/${BUILDDIR} |
56 | export BINDIR=${MROOT}/${BINDIR} |
57 | fi |
58 | |
59 | build_preinstall() |
60 | { |
61 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
62 | then |
63 | rm -rf ${BUILDDIR}/${PKGNAME} |
64 | fi |
65 | |
66 | install -d ${BUILDDIR}/${PKGNAME}/binfiles |
67 | touch ${BUILDDIR}/${PKGNAME}/.dirs |
68 | touch ${BUILDDIR}/${PKGNAME}/.symlinks |
69 | touch ${BUILDDIR}/${PKGNAME}/.files |
70 | touch ${BUILDDIR}/${PKGNAME}/.pipes |
71 | touch ${BUILDDIR}/${PKGNAME}/.char |
72 | touch ${BUILDDIR}/${PKGNAME}/.fifo |
73 | } |
74 | |
75 | build_postinstall() |
76 | { |
77 | local m_mtime |
78 | local m_md5sum |
79 | local filelist |
80 | local item |
81 | local check_srcdir |
82 | local filetype |
83 | local fileposix |
84 | local fileowner |
85 | local filegroup |
86 | local lnkdest |
87 | 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 | # 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 |
104 | filelist=$(find ${SEARCHDIRS} -printf %p§) |
105 | |
106 | # sets fieldseperator to "§" instead of " " |
107 | IFS=§ |
108 | |
109 | for item in ${filelist} |
110 | do |
111 | check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})" |
112 | |
113 | if [[ -z ${check_srcdir} ]] |
114 | then |
115 | filetype="$(stat -c %F ${item})" |
116 | fileposix="$(stat -c %a ${item})" |
117 | fileowner="$(stat -c %U ${item})" |
118 | filegroup="$(stat -c %G ${item})" |
119 | |
120 | [[ ${fileowner} = UNKNOWN ]] && fileowner="root" |
121 | [[ ${filegroup} = UNKNOWN ]] && filegroup="root" |
122 | |
123 | case "${filetype}" in |
124 | "directory") |
125 | if [[ ${item} != ${SEARCHDIRS} ]] |
126 | then |
127 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
128 | fi |
129 | ;; |
130 | |
131 | "symbolic link") |
132 | lnkdest="$(readlink ${item})" |
133 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks |
134 | ;; |
135 | |
136 | "regular empty file") |
137 | filedir="$(dirname ${item})" |
138 | filedir="${filedir#${SEARCHDIRS}*}" |
139 | m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" |
140 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_mtime}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files |
141 | install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
142 | cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
143 | ;; |
144 | |
145 | "regular file" ) |
146 | filedir="$(dirname ${item})" |
147 | filedir="${filedir#${SEARCHDIRS}*}" |
148 | m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" |
149 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_time}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files |
150 | install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
151 | cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
152 | ;; |
153 | |
154 | "block special file") |
155 | # 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") |
163 | # 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" |
176 | echo "$0 paused ... Press Enter" |
177 | read |
178 | ;; |
179 | esac |
180 | fi |
181 | done |
182 | |
183 | # very important: unsetting the '§' fieldseperator |
184 | unset IFS |
185 | |
186 | # forcing mtime to same value |
187 | echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}" |
188 | find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' |
189 | } |
190 | |
191 | build_rmtimestamp() |
192 | { |
193 | rm /var/tmp/timestamp |
194 | } |
195 | |
196 | build_package() |
197 | { |
198 | echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}" |
199 | cd ${BUILDDIR} |
200 | tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} |
201 | install -d ${PKGDIR} |
202 | mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} |
203 | } |
204 | |
205 | build_preinstall |
206 | build_postinstall |
207 | build_package |
Properties
Name | Value |
---|---|
svn:executable | * |