Contents of /branches/mage-next/src/pkgbuild_dir.in
Parent Directory | Revision Log
Revision 2573 -
(show annotations)
(download)
Wed Jan 29 12:27:04 2014 UTC (10 years, 8 months ago) by niro
File size: 4799 byte(s)
Wed Jan 29 12:27:04 2014 UTC (10 years, 8 months ago) by niro
File size: 4799 byte(s)
-removed executable property
1 | #!/bin/bash |
2 | # $Id$ |
3 | |
4 | # |
5 | # builds packages from given dir |
6 | # |
7 | |
8 | # export default C locale |
9 | export LC_ALL=C |
10 | |
11 | PKGNAME="$1" |
12 | SEARCHDIRS="$2" |
13 | |
14 | [[ -z ${PKGNAME} ]] && echo "No package name given. Aborting." && exit 1 |
15 | [[ -z ${SEARCHDIRS} ]] && echo "No source dir given. Aborting." && exit 1 |
16 | |
17 | source /etc/mage.rc.global |
18 | [[ -f ${MAGERC} ]] && source ${MAGERC} |
19 | source ${MLIBDIR}/mage4.functions.sh |
20 | |
21 | # set PKGDIR and BUILDDIR and BINDIR to MROOT |
22 | if [[ -n ${MROOT} ]] |
23 | then |
24 | export PKGDIR=${MROOT}/${PKGDIR} |
25 | export BUILDDIR=${MROOT}/${BUILDDIR} |
26 | export BINDIR=${MROOT}/${BINDIR} |
27 | fi |
28 | |
29 | build_preinstall() |
30 | { |
31 | 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 | touch ${BUILDDIR}/${PKGNAME}/.fifo |
43 | } |
44 | |
45 | build_postinstall() |
46 | { |
47 | 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 | echo -e "${COLBLUE}===${COLGREEN} fetching files for package '${PKGNAME}' ...${COLDEFAULT}" |
62 | |
63 | # md5sums will only be generated for files: $m_md5sum |
64 | |
65 | # sets mtime to same value of the $BINDIR: $m_mtime |
66 | # only needed for files and symlinks |
67 | m_mtime=$(stat -c %Y ${BINDIR}) |
68 | |
69 | # install mtime to package (needed for later checks) |
70 | echo "${m_mtime}" > ${BUILDDIR}/${PKGNAME}/.mtime |
71 | |
72 | # !! we use § as field seperator !! |
73 | # doing so prevent us to get errors by filenames with spaces |
74 | filelist=$(find ${SEARCHDIRS} -printf %p§) |
75 | |
76 | # sets fieldseperator to "§" instead of " " |
77 | IFS=§ |
78 | |
79 | for item in ${filelist} |
80 | do |
81 | check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})" |
82 | |
83 | if [[ -z ${check_srcdir} ]] |
84 | then |
85 | filetype="$(stat -c %F ${item})" |
86 | fileposix="$(stat -c %a ${item})" |
87 | fileowner="$(stat -c %U ${item})" |
88 | filegroup="$(stat -c %G ${item})" |
89 | |
90 | [[ ${fileowner} = UNKNOWN ]] && fileowner="root" |
91 | [[ ${filegroup} = UNKNOWN ]] && filegroup="root" |
92 | |
93 | case "${filetype}" in |
94 | "directory") |
95 | if [[ ${item} != ${SEARCHDIRS} ]] |
96 | then |
97 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
98 | fi |
99 | ;; |
100 | |
101 | "symbolic link") |
102 | lnkdest="$(readlink ${item})" |
103 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks |
104 | ;; |
105 | |
106 | "regular empty file") |
107 | 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 | ;; |
114 | |
115 | "regular file" ) |
116 | 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 | ;; |
123 | |
124 | "block special file") |
125 | # convert hex2dec |
126 | # printf '%d' 0x12 -> 18 |
127 | 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 | ;; |
131 | |
132 | "character special file") |
133 | # convert hex2dec |
134 | # printf '%d' 0x12 -> 18 |
135 | 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 | ;; |
139 | |
140 | "fifo") |
141 | echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.fifo |
142 | ;; |
143 | |
144 | *) |
145 | echo "What I am ? -- $I" |
146 | echo "$0 paused ... Press Enter" |
147 | read |
148 | ;; |
149 | esac |
150 | fi |
151 | done |
152 | |
153 | # very important: unsetting the '§' fieldseperator |
154 | unset IFS |
155 | |
156 | # forcing mtime to same value |
157 | echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}" |
158 | find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' |
159 | } |
160 | |
161 | build_package() |
162 | { |
163 | echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}" |
164 | 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 |