Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 440 - (show annotations) (download) (as text)
Mon Mar 19 19:10:07 2007 UTC (17 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 4507 byte(s)
added  some nice colors

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.14 2007-03-19 19:10:07 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 COLRED="\033[1;6m\033[31m"
18 COLGREEN="\033[1;6m\033[32m"
19 COLDEFAULT="\033[0m"
20
21 # export default C locale
22 export LC_ALL=C
23
24 [[ -z $1 ]] && echo "No package name given. Aborting." && exit 1
25 [[ -z $2 ]] && echo "No source dir given. Aborting." && exit 1
26
27 source /etc/mage.rc.global
28 if [ -f ${MAGERC} ]
29 then
30 source ${MAGERC}
31 else
32 echo "Your ${MAGERC} is missing. Aborting."
33 exit 1
34 fi
35 source ${MLIBDIR}/mage4.functions.sh
36
37 # set PKGDIR and BUILDDIR and BINDIR to MROOT
38 if [[ -n ${MROOT} ]]
39 then
40 export PKGDIR=${MROOT}/${PKGDIR}
41 export BUILDDIR=${MROOT}/${BUILDDIR}
42 export BINDIR=${MROOT}/${BINDIR}
43 fi
44
45 build_preinstall()
46 {
47 if [ -d ${BUILDDIR}/${PKGNAME} ]
48 then
49 rm -rf ${BUILDDIR}/${PKGNAME}
50 fi
51
52 install -d ${BUILDDIR}/${PKGNAME}/binfiles
53 touch ${BUILDDIR}/${PKGNAME}/.dirs
54 touch ${BUILDDIR}/${PKGNAME}/.symlinks
55 touch ${BUILDDIR}/${PKGNAME}/.files
56 touch ${BUILDDIR}/${PKGNAME}/.pipes
57 touch ${BUILDDIR}/${PKGNAME}/.char
58 }
59
60 build_postinstall()
61 {
62 echo -e "${COLBLUE}===${COLGREEN} fetching files for package '${PKGNAME}' ...${COLDEFAULT}"
63
64 # 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 M_MTIME=$(stat -c %Y ${BINDIR})
69
70 # install mtime to package (needed for later checks)
71 echo "${M_MTIME}" > ${BUILDDIR}/${PKGNAME}/.mtime
72
73 # !! we use § as field seperator !!
74 # doing so prevent us to get errors by filenames with spaces
75 BUILD_TODELFILES=$(find ${SEARCHDIRS} -printf %p§)
76
77 # sets fieldseperator to "§" instead of " "
78 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 [[ ${FILEOWNER} = UNKNOWN ]] && FILEOWNER="root"
92 [[ ${FILEGROUP} = UNKNOWN ]] && FILEGROUP="root"
93
94 case "${FILETYPE}" in
95 "directory")
96 if [[ $I != ${SEARCHDIRS} ]]
97 then
98 echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}" >> ${BUILDDIR}/${PKGNAME}/.dirs
99 fi
100 ;;
101
102 "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
126 "block special file")
127 echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}" >> ${BUILDDIR}/${PKGNAME}/.pipes
128 ;;
129
130 "character special file")
131 # 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 echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${CHAR_MAJOR}§${CHAR_MINOR}" >> ${BUILDDIR}/${PKGNAME}/.char
136 ;;
137
138 *)
139 echo "What I am ? -- $I"
140 echo "$0 paused ... Press Enter"
141 read
142 ;;
143 esac
144 fi
145 done
146
147 # very important: unsetting the '§' fieldseperator
148 unset IFS
149
150 # forcing mtime to same value
151 echo -e "${COLBLUE}===${COLGREEN} forcing mtime to the same value ...${COLDEFAULT}"
152 find ${BUILDDIR}/${PKGNAME}/binfiles -exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';'
153 }
154
155 build_rmtimestamp()
156 {
157 rm /var/tmp/timestamp
158 }
159
160 build_package()
161 {
162 echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}"
163 cd ${BUILDDIR}
164 tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME}
165 install -d ${PKGDIR}
166 mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX}
167 }
168
169 build_preinstall
170 build_postinstall
171 build_package

Properties

Name Value
svn:executable *