Magellan Linux

Annotation of /tags/mage-0_4_23/usr/lib/mage/pkgbuild_dir.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 419 - (hide annotations) (download) (as text)
Mon Jan 22 00:24:14 2007 UTC (17 years, 3 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/pkgbuild_dir.sh
File MIME type: application/x-sh
File size: 4393 byte(s)
variable mage.rc

1 niro 24 #!/bin/bash
2    
3     #
4     # builds packages from given dir
5     #
6    
7 niro 419 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/pkgbuild_dir.sh,v 1.13 2007-01-22 00:24:14 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     COLRED="\033[1;6m\033[31m"
18     COLGREEN="\033[1;6m\033[32m"
19     COLDEFAULT="\033[0m"
20    
21 niro 169 # export default C locale
22     export LC_ALL=C
23    
24 niro 272 [[ -z $1 ]] && echo "No package name given. Aborting." && exit 1
25     [[ -z $2 ]] && echo "No source dir given. Aborting." && exit 1
26 niro 24
27 niro 419 if [ -f ${MAGERC} ]
28 niro 24 then
29 niro 419 source ${MAGERC}
30 niro 24 else
31 niro 419 echo "Your ${MAGERC} is missing. Aborting."
32 niro 24 exit 1
33     fi
34 niro 272 source ${MLIBDIR}/mage4.functions.sh
35 niro 24
36 niro 312 # set PKGDIR and BUILDDIR and BINDIR to MROOT
37 niro 347 if [[ -n ${MROOT} ]]
38     then
39     export PKGDIR=${MROOT}/${PKGDIR}
40     export BUILDDIR=${MROOT}/${BUILDDIR}
41     export BINDIR=${MROOT}/${BINDIR}
42     fi
43 niro 312
44 niro 272 build_preinstall()
45     {
46 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
47     then
48     rm -rf ${BUILDDIR}/${PKGNAME}
49     fi
50    
51     install -d ${BUILDDIR}/${PKGNAME}/binfiles
52     touch ${BUILDDIR}/${PKGNAME}/.dirs
53     touch ${BUILDDIR}/${PKGNAME}/.symlinks
54     touch ${BUILDDIR}/${PKGNAME}/.files
55     touch ${BUILDDIR}/${PKGNAME}/.pipes
56     touch ${BUILDDIR}/${PKGNAME}/.char
57     }
58    
59 niro 272 build_postinstall()
60     {
61 niro 24 echo
62     echo "Fetching files for package '${PKGNAME}' ..."
63    
64 niro 272 # md5sums will only be generated for files: $M_MD5SUM
65    
66     # sets mtime to same value of the $BINDIR: $M_MTIME
67     # only needed for files and symlinks
68 niro 24 M_MTIME=$(stat -c %Y ${BINDIR})
69 niro 272
70     # install mtime to package (needed for later checks)
71 niro 24 echo "${M_MTIME}" > ${BUILDDIR}/${PKGNAME}/.mtime
72    
73 niro 272 # !! we use § as field seperator !!
74 niro 24 # doing so prevent us to get errors by filenames with spaces
75     BUILD_TODELFILES=$(find ${SEARCHDIRS} -printf %p§)
76 niro 272
77     # sets fieldseperator to "§" instead of " "
78 niro 24 IFS=§
79    
80     for I in $BUILD_TODELFILES
81     do
82     CHECK_SRCDIR="$(echo ${I#${SEARCHDIRS}*}|grep $BUILDDIR)"
83    
84     if [ -z "$CHECK_SRCDIR" ]
85     then
86     FILETYPE="$(stat -c %F $I)"
87     FILEPOSIX="$(stat -c %a $I)"
88     FILEOWNER="$(stat -c %U $I)"
89     FILEGROUP="$(stat -c %G $I)"
90    
91 niro 272 [[ ${FILEOWNER} = UNKNOWN ]] && FILEOWNER="root"
92     [[ ${FILEGROUP} = UNKNOWN ]] && FILEGROUP="root"
93 niro 24
94     case "${FILETYPE}" in
95     "directory")
96 niro 272 if [[ $I != ${SEARCHDIRS} ]]
97 niro 24 then
98     echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}" >> ${BUILDDIR}/${PKGNAME}/.dirs
99     fi
100     ;;
101 niro 272
102 niro 24 "symbolic link")
103     LNKDEST="$(readlink $I)"
104     echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${LNKDEST#${SEARCHDIRS}*}§${M_MTIME}" >> ${BUILDDIR}/${PKGNAME}/.symlinks
105     ;;
106    
107    
108     "regular empty file")
109     FILEDIR="$(dirname $I)"
110     FILEDIR="${FILEDIR#${SEARCHDIRS}*}"
111     M_MD5SUM="$(md5sum ${I}|cut -d' ' -f1)"
112     echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}§${M_MTIME}§${M_MD5SUM}" >> ${BUILDDIR}/${PKGNAME}/.files
113     install -d ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR}
114     cp ${I} ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR}
115     ;;
116    
117     "regular file" )
118     FILEDIR="$(dirname $I)"
119     FILEDIR="${FILEDIR#${SEARCHDIRS}*}"
120     M_MD5SUM="$(md5sum ${I}|cut -d' ' -f1)"
121     echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}§${M_MTIME}§${M_MD5SUM}" >> ${BUILDDIR}/${PKGNAME}/.files
122     install -d ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR}
123     cp ${I} ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR}
124     ;;
125 niro 272
126 niro 24 "block special file")
127     echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}" >> ${BUILDDIR}/${PKGNAME}/.pipes
128     ;;
129    
130     "character special file")
131 niro 315 # convert hex2dec
132     # printf '%d' 0x12 -> 18
133     local CHAR_MAJOR="$(printf 0x$(stat -c %t $I))"
134     local CHAR_MINOR="$(printf 0x$(stat -c %T $I))"
135 niro 312 echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${CHAR_MAJOR}§${CHAR_MINOR}" >> ${BUILDDIR}/${PKGNAME}/.char
136 niro 24 ;;
137 niro 272
138 niro 24 *)
139     echo "What I am ? -- $I"
140     echo "$0 paused ... Press Enter"
141     read
142     ;;
143     esac
144     fi
145     done
146 niro 272
147     # very important: unsetting the '§' fieldseperator
148 niro 24 unset IFS
149 niro 272
150     # forcing mtime to same value
151 niro 24 echo -n "Forcing mtime to the same value ..."
152     find ${BUILDDIR}/${PKGNAME}/binfiles \
153     -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' \
154     && echo done || echo false
155     }
156    
157 niro 272 build_rmtimestamp()
158     {
159 niro 24 rm /var/tmp/timestamp
160     }
161    
162 niro 272 build_package()
163     {
164 niro 24 echo "Building Package ..."
165     cd ${BUILDDIR}
166     tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME}
167     install -d ${PKGDIR}
168     mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX}
169     }
170    
171     build_preinstall
172     build_postinstall
173     build_package

Properties

Name Value
svn:executable *