Annotation of /branches/mage-next/usr/lib/mage/pkgbuild_dir.sh
Parent Directory | Revision Log
Revision 1545 -
(hide annotations)
(download)
(as text)
Tue Dec 27 09:10:36 2011 UTC (12 years, 9 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/pkgbuild_dir.sh
File MIME type: application/x-sh
File size: 4799 byte(s)
Tue Dec 27 09:10:36 2011 UTC (12 years, 9 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/pkgbuild_dir.sh
File MIME type: application/x-sh
File size: 4799 byte(s)
-fixed header -removed all locallay defined varibales/functions which have proper includes -use variable names not arguments -removed deprecated build_rmtimestamp function
1 | niro | 24 | #!/bin/bash |
2 | niro | 1545 | # $Id$ |
3 | niro | 24 | |
4 | # | ||
5 | # builds packages from given dir | ||
6 | # | ||
7 | |||
8 | niro | 1545 | # export default C locale |
9 | export LC_ALL=C | ||
10 | niro | 24 | |
11 | PKGNAME="$1" | ||
12 | SEARCHDIRS="$2" | ||
13 | |||
14 | niro | 1545 | [[ -z ${PKGNAME} ]] && echo "No package name given. Aborting." && exit 1 |
15 | [[ -z ${SEARCHDIRS} ]] && echo "No source dir given. Aborting." && exit 1 | ||
16 | niro | 24 | |
17 | niro | 440 | source /etc/mage.rc.global |
18 | niro | 443 | [[ -f ${MAGERC} ]] && source ${MAGERC} |
19 | niro | 272 | source ${MLIBDIR}/mage4.functions.sh |
20 | niro | 24 | |
21 | niro | 312 | # set PKGDIR and BUILDDIR and BINDIR to MROOT |
22 | niro | 347 | if [[ -n ${MROOT} ]] |
23 | then | ||
24 | export PKGDIR=${MROOT}/${PKGDIR} | ||
25 | export BUILDDIR=${MROOT}/${BUILDDIR} | ||
26 | export BINDIR=${MROOT}/${BINDIR} | ||
27 | fi | ||
28 | niro | 312 | |
29 | niro | 272 | build_preinstall() |
30 | { | ||
31 | niro | 24 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
32 | then | ||
33 | rm -rf ${BUILDDIR}/${PKGNAME} | ||
34 | fi | ||
35 | |||
36 | install -d ${BUILDDIR}/${PKGNAME}/binfiles | ||
37 | touch ${BUILDDIR}/${PKGNAME}/.dirs | ||
38 | touch ${BUILDDIR}/${PKGNAME}/.symlinks | ||
39 | touch ${BUILDDIR}/${PKGNAME}/.files | ||
40 | touch ${BUILDDIR}/${PKGNAME}/.pipes | ||
41 | touch ${BUILDDIR}/${PKGNAME}/.char | ||
42 | niro | 1215 | touch ${BUILDDIR}/${PKGNAME}/.fifo |
43 | niro | 24 | } |
44 | |||
45 | niro | 272 | build_postinstall() |
46 | { | ||
47 | niro | 1292 | local m_mtime |
48 | local m_md5sum | ||
49 | local filelist | ||
50 | local item | ||
51 | local check_srcdir | ||
52 | local filetype | ||
53 | local fileposix | ||
54 | local fileowner | ||
55 | local filegroup | ||
56 | local lnkdest | ||
57 | local filedir | ||
58 | local char_major | ||
59 | local char_minor | ||
60 | |||
61 | niro | 440 | echo -e "${COLBLUE}===${COLGREEN} fetching files for package '${PKGNAME}' ...${COLDEFAULT}" |
62 | niro | 24 | |
63 | niro | 1292 | # md5sums will only be generated for files: $m_md5sum |
64 | niro | 272 | |
65 | niro | 1292 | # sets mtime to same value of the $BINDIR: $m_mtime |
66 | niro | 272 | # only needed for files and symlinks |
67 | niro | 1292 | m_mtime=$(stat -c %Y ${BINDIR}) |
68 | niro | 272 | |
69 | # install mtime to package (needed for later checks) | ||
70 | niro | 1292 | echo "${m_mtime}" > ${BUILDDIR}/${PKGNAME}/.mtime |
71 | niro | 24 | |
72 | niro | 272 | # !! we use § as field seperator !! |
73 | niro | 24 | # doing so prevent us to get errors by filenames with spaces |
74 | niro | 1292 | filelist=$(find ${SEARCHDIRS} -printf %p§) |
75 | niro | 272 | |
76 | # sets fieldseperator to "§" instead of " " | ||
77 | niro | 24 | IFS=§ |
78 | |||
79 | niro | 1292 | for item in ${filelist} |
80 | niro | 24 | do |
81 | niro | 1292 | check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})" |
82 | niro | 24 | |
83 | niro | 1292 | if [[ -z ${check_srcdir} ]] |
84 | niro | 24 | then |
85 | niro | 1292 | filetype="$(stat -c %F ${item})" |
86 | fileposix="$(stat -c %a ${item})" | ||
87 | fileowner="$(stat -c %U ${item})" | ||
88 | filegroup="$(stat -c %G ${item})" | ||
89 | niro | 24 | |
90 | niro | 1292 | [[ ${fileowner} = UNKNOWN ]] && fileowner="root" |
91 | [[ ${filegroup} = UNKNOWN ]] && filegroup="root" | ||
92 | niro | 24 | |
93 | niro | 1292 | case "${filetype}" in |
94 | niro | 24 | "directory") |
95 | niro | 1292 | if [[ ${item} != ${SEARCHDIRS} ]] |
96 | niro | 24 | then |
97 | niro | 1292 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
98 | niro | 24 | fi |
99 | ;; | ||
100 | niro | 272 | |
101 | niro | 24 | "symbolic link") |
102 | niro | 1292 | lnkdest="$(readlink ${item})" |
103 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks | ||
104 | niro | 24 | ;; |
105 | |||
106 | "regular empty file") | ||
107 | niro | 1292 | filedir="$(dirname ${item})" |
108 | filedir="${filedir#${SEARCHDIRS}*}" | ||
109 | m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" | ||
110 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_mtime}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files | ||
111 | install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} | ||
112 | cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} | ||
113 | niro | 24 | ;; |
114 | |||
115 | "regular file" ) | ||
116 | niro | 1292 | filedir="$(dirname ${item})" |
117 | filedir="${filedir#${SEARCHDIRS}*}" | ||
118 | m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" | ||
119 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_time}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files | ||
120 | install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} | ||
121 | cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} | ||
122 | niro | 24 | ;; |
123 | niro | 272 | |
124 | niro | 24 | "block special file") |
125 | niro | 1271 | # convert hex2dec |
126 | # printf '%d' 0x12 -> 18 | ||
127 | niro | 1292 | char_major="$(printf 0x$(stat -c %t ${item}))" |
128 | char_minor="$(printf 0x$(stat -c %T ${item}))" | ||
129 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${char_major}§${char_minor}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.pipes | ||
130 | niro | 24 | ;; |
131 | |||
132 | "character special file") | ||
133 | niro | 315 | # convert hex2dec |
134 | # printf '%d' 0x12 -> 18 | ||
135 | niro | 1292 | char_major="$(printf 0x$(stat -c %t ${item}))" |
136 | char_minor="$(printf 0x$(stat -c %T ${item}))" | ||
137 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${char_major}§${char_minor}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.char | ||
138 | niro | 24 | ;; |
139 | niro | 272 | |
140 | niro | 1208 | "fifo") |
141 | niro | 1292 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.fifo |
142 | niro | 1208 | ;; |
143 | |||
144 | niro | 24 | *) |
145 | echo "What I am ? -- $I" | ||
146 | echo "$0 paused ... Press Enter" | ||
147 | read | ||
148 | ;; | ||
149 | esac | ||
150 | fi | ||
151 | done | ||
152 | niro | 272 | |
153 | # very important: unsetting the '§' fieldseperator | ||
154 | niro | 24 | unset IFS |
155 | niro | 272 | |
156 | # forcing mtime to same value | ||
157 | niro | 440 | echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}" |
158 | find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' | ||
159 | niro | 24 | } |
160 | |||
161 | niro | 272 | build_package() |
162 | { | ||
163 | niro | 440 | echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}" |
164 | niro | 24 | cd ${BUILDDIR} |
165 | tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} | ||
166 | install -d ${PKGDIR} | ||
167 | mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} | ||
168 | } | ||
169 | |||
170 | build_preinstall | ||
171 | build_postinstall | ||
172 | build_package |
Properties
Name | Value |
---|---|
svn:executable | * |