Magellan Linux

Annotation of /trunk/mage/usr/lib/mage/pkgbuild_dir.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1292 - (hide annotations) (download) (as text)
Fri May 27 12:55:43 2011 UTC (12 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 5491 byte(s)
-fixed coding style and fixed packaging of block special devices
1 niro 24 #!/bin/bash
2    
3     #
4     # builds packages from given dir
5     #
6    
7 niro 443 # $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 niro 24
9 niro 419 # set default user mage.rc
10     : ${MAGERC="/etc/mage.rc"}
11    
12 niro 24 PKGSUFFIX="mpk"
13     PKGNAME="$1"
14     SEARCHDIRS="$2"
15     MLIBDIR=/usr/lib/mage
16    
17 niro 443 ## only for tests -> normally in /etc/rc.d/init.d/functions
18 niro 24 COLRED="\033[1;6m\033[31m"
19     COLGREEN="\033[1;6m\033[32m"
20 niro 443 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 niro 24 COLDEFAULT="\033[0m"
27    
28 niro 443 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 niro 169 # export default C locale
42     export LC_ALL=C
43    
44 niro 272 [[ -z $1 ]] && echo "No package name given. Aborting." && exit 1
45     [[ -z $2 ]] && echo "No source dir given. Aborting." && exit 1
46 niro 24
47 niro 440 source /etc/mage.rc.global
48 niro 443 [[ -f ${MAGERC} ]] && source ${MAGERC}
49 niro 272 source ${MLIBDIR}/mage4.functions.sh
50 niro 24
51 niro 312 # set PKGDIR and BUILDDIR and BINDIR to MROOT
52 niro 347 if [[ -n ${MROOT} ]]
53     then
54     export PKGDIR=${MROOT}/${PKGDIR}
55     export BUILDDIR=${MROOT}/${BUILDDIR}
56     export BINDIR=${MROOT}/${BINDIR}
57     fi
58 niro 312
59 niro 272 build_preinstall()
60     {
61 niro 24 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 niro 1215 touch ${BUILDDIR}/${PKGNAME}/.fifo
73 niro 24 }
74    
75 niro 272 build_postinstall()
76     {
77 niro 1292 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 niro 440 echo -e "${COLBLUE}===${COLGREEN} fetching files for package '${PKGNAME}' ...${COLDEFAULT}"
92 niro 24
93 niro 1292 # md5sums will only be generated for files: $m_md5sum
94 niro 272
95 niro 1292 # sets mtime to same value of the $BINDIR: $m_mtime
96 niro 272 # only needed for files and symlinks
97 niro 1292 m_mtime=$(stat -c %Y ${BINDIR})
98 niro 272
99     # install mtime to package (needed for later checks)
100 niro 1292 echo "${m_mtime}" > ${BUILDDIR}/${PKGNAME}/.mtime
101 niro 24
102 niro 272 # !! we use § as field seperator !!
103 niro 24 # doing so prevent us to get errors by filenames with spaces
104 niro 1292 filelist=$(find ${SEARCHDIRS} -printf %p§)
105 niro 272
106     # sets fieldseperator to "§" instead of " "
107 niro 24 IFS=§
108    
109 niro 1292 for item in ${filelist}
110 niro 24 do
111 niro 1292 check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})"
112 niro 24
113 niro 1292 if [[ -z ${check_srcdir} ]]
114 niro 24 then
115 niro 1292 filetype="$(stat -c %F ${item})"
116     fileposix="$(stat -c %a ${item})"
117     fileowner="$(stat -c %U ${item})"
118     filegroup="$(stat -c %G ${item})"
119 niro 24
120 niro 1292 [[ ${fileowner} = UNKNOWN ]] && fileowner="root"
121     [[ ${filegroup} = UNKNOWN ]] && filegroup="root"
122 niro 24
123 niro 1292 case "${filetype}" in
124 niro 24 "directory")
125 niro 1292 if [[ ${item} != ${SEARCHDIRS} ]]
126 niro 24 then
127 niro 1292 echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs
128 niro 24 fi
129     ;;
130 niro 272
131 niro 24 "symbolic link")
132 niro 1292 lnkdest="$(readlink ${item})"
133     echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks
134 niro 24 ;;
135    
136     "regular empty file")
137 niro 1292 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 niro 24 ;;
144    
145     "regular file" )
146 niro 1292 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 niro 24 ;;
153 niro 272
154 niro 24 "block special file")
155 niro 1271 # convert hex2dec
156     # printf '%d' 0x12 -> 18
157 niro 1292 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 niro 24 ;;
161    
162     "character special file")
163 niro 315 # convert hex2dec
164     # printf '%d' 0x12 -> 18
165 niro 1292 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 niro 24 ;;
169 niro 272
170 niro 1208 "fifo")
171 niro 1292 echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.fifo
172 niro 1208 ;;
173    
174 niro 24 *)
175     echo "What I am ? -- $I"
176     echo "$0 paused ... Press Enter"
177     read
178     ;;
179     esac
180     fi
181     done
182 niro 272
183     # very important: unsetting the '§' fieldseperator
184 niro 24 unset IFS
185 niro 272
186     # forcing mtime to same value
187 niro 440 echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}"
188     find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';'
189 niro 24 }
190    
191 niro 272 build_rmtimestamp()
192     {
193 niro 24 rm /var/tmp/timestamp
194     }
195    
196 niro 272 build_package()
197     {
198 niro 440 echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}"
199 niro 24 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 *