1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Id$ |
3 |
|
|
4 |
# |
# |
5 |
# builds packages from given dir |
# builds packages from given dir |
6 |
# |
# |
7 |
|
|
8 |
# version: 0.3.6-r10 |
# export default C locale |
9 |
|
export LC_ALL=C |
10 |
|
|
|
PKGSUFFIX="mpk" |
|
11 |
PKGNAME="$1" |
PKGNAME="$1" |
12 |
SEARCHDIRS="$2" |
SEARCHDIRS="$2" |
|
MLIBDIR=/usr/lib/mage |
|
13 |
|
|
14 |
COLRED="\033[1;6m\033[31m" |
[[ -z ${PKGNAME} ]] && echo "No package name given. Aborting." && exit 1 |
15 |
COLGREEN="\033[1;6m\033[32m" |
[[ -z ${SEARCHDIRS} ]] && echo "No source dir given. Aborting." && exit 1 |
|
COLDEFAULT="\033[0m" |
|
16 |
|
|
17 |
if [ -z "$1" ] |
source /etc/mage.rc.global |
18 |
then |
[[ -f ${MAGERC} ]] && source ${MAGERC} |
19 |
echo "No package name given. Aborting." |
source ${MLIBDIR}/mage4.functions.sh |
|
fi |
|
|
|
|
|
if [ -z "$2" ] |
|
|
then |
|
|
echo "No source dir given. Aborting." |
|
|
fi |
|
20 |
|
|
21 |
if [ -f /etc/mage.rc ] |
# set PKGDIR and BUILDDIR and BINDIR to MROOT |
22 |
|
if [[ -n ${MROOT} ]] |
23 |
then |
then |
24 |
source /etc/mage.rc |
export PKGDIR=${MROOT}/${PKGDIR} |
25 |
else |
export BUILDDIR=${MROOT}/${BUILDDIR} |
26 |
echo "Your /etc/mage.rc is missing. Aborting." |
export BINDIR=${MROOT}/${BINDIR} |
|
exit 1 |
|
27 |
fi |
fi |
|
source ${MLIBDIR}/mage3.functions.sh |
|
28 |
|
|
29 |
build_preinstall() { |
build_preinstall() |
30 |
|
{ |
31 |
if [ -d ${BUILDDIR}/${PKGNAME} ] |
if [ -d ${BUILDDIR}/${PKGNAME} ] |
32 |
then |
then |
33 |
rm -rf ${BUILDDIR}/${PKGNAME} |
rm -rf ${BUILDDIR}/${PKGNAME} |
39 |
touch ${BUILDDIR}/${PKGNAME}/.files |
touch ${BUILDDIR}/${PKGNAME}/.files |
40 |
touch ${BUILDDIR}/${PKGNAME}/.pipes |
touch ${BUILDDIR}/${PKGNAME}/.pipes |
41 |
touch ${BUILDDIR}/${PKGNAME}/.char |
touch ${BUILDDIR}/${PKGNAME}/.char |
42 |
|
touch ${BUILDDIR}/${PKGNAME}/.fifo |
43 |
} |
} |
44 |
|
|
45 |
build_postinstall() { |
build_postinstall() |
46 |
|
{ |
47 |
echo |
local m_mtime |
48 |
echo "Fetching files for package '${PKGNAME}' ..." |
local m_md5sum |
49 |
|
local filelist |
50 |
#md5sums will only be generated for files: $M_MD5SUM |
local item |
51 |
|
local check_srcdir |
52 |
#sets mtime to same value of the $BINDIR: $M_MTIME |
local filetype |
53 |
#only needed for files and symlinks |
local fileposix |
54 |
M_MTIME=$(stat -c %Y ${BINDIR}) |
local fileowner |
55 |
|
local filegroup |
56 |
#install mtime to package (needed for later checks) |
local lnkdest |
57 |
echo "${M_MTIME}" > ${BUILDDIR}/${PKGNAME}/.mtime |
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 |
#!! we use § as field seperator !! |
# 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 |
# doing so prevent us to get errors by filenames with spaces |
74 |
BUILD_TODELFILES=$(find ${SEARCHDIRS} -printf %p§) |
filelist=$(find ${SEARCHDIRS} -printf %p§) |
75 |
|
|
76 |
#sets fieldseperator to "§" instead of " " |
# sets fieldseperator to "§" instead of " " |
77 |
IFS=§ |
IFS=§ |
78 |
|
|
79 |
for I in $BUILD_TODELFILES |
for item in ${filelist} |
80 |
do |
do |
81 |
CHECK_SRCDIR="$(echo ${I#${SEARCHDIRS}*}|grep $BUILDDIR)" |
check_srcdir="$(echo ${item#${SEARCHDIRS}*}|grep ${BUILDDIR})" |
82 |
|
|
83 |
if [ -z "$CHECK_SRCDIR" ] |
if [[ -z ${check_srcdir} ]] |
84 |
then |
then |
85 |
FILETYPE="$(stat -c %F $I)" |
filetype="$(stat -c %F ${item})" |
86 |
FILEPOSIX="$(stat -c %a $I)" |
fileposix="$(stat -c %a ${item})" |
87 |
FILEOWNER="$(stat -c %U $I)" |
fileowner="$(stat -c %U ${item})" |
88 |
FILEGROUP="$(stat -c %G $I)" |
filegroup="$(stat -c %G ${item})" |
|
|
|
|
if [ "${FILEOWNER}" == "UNKNOWN" ] |
|
|
then |
|
|
FILEOWNER="root" |
|
|
fi |
|
|
|
|
|
if [ "${FILEGROUP}" == "UNKNOWN" ] |
|
|
then |
|
|
FILEGROUP="root" |
|
|
fi |
|
89 |
|
|
90 |
case "${FILETYPE}" in |
[[ ${fileowner} = UNKNOWN ]] && fileowner="root" |
91 |
|
[[ ${filegroup} = UNKNOWN ]] && filegroup="root" |
92 |
|
|
93 |
|
case "${filetype}" in |
94 |
"directory") |
"directory") |
95 |
if [ "$I" != "${SEARCHDIRS}" ] |
if [[ ${item} != ${SEARCHDIRS} ]] |
96 |
then |
then |
97 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}" >> ${BUILDDIR}/${PKGNAME}/.dirs |
98 |
fi |
fi |
99 |
;; |
;; |
100 |
|
|
101 |
"symbolic link") |
"symbolic link") |
102 |
LNKDEST="$(readlink $I)" |
lnkdest="$(readlink ${item})" |
103 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${LNKDEST#${SEARCHDIRS}*}§${M_MTIME}" >> ${BUILDDIR}/${PKGNAME}/.symlinks |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${lnkdest#${SEARCHDIRS}*}§${m_mtime}" >> ${BUILDDIR}/${PKGNAME}/.symlinks |
104 |
;; |
;; |
|
|
|
105 |
|
|
106 |
"regular empty file") |
"regular empty file") |
107 |
FILEDIR="$(dirname $I)" |
filedir="$(dirname ${item})" |
108 |
FILEDIR="${FILEDIR#${SEARCHDIRS}*}" |
filedir="${filedir#${SEARCHDIRS}*}" |
109 |
M_MD5SUM="$(md5sum ${I}|cut -d' ' -f1)" |
m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" |
110 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}§${M_MTIME}§${M_MD5SUM}" >> ${BUILDDIR}/${PKGNAME}/.files |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_mtime}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files |
111 |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
112 |
cp ${I} ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
113 |
;; |
;; |
114 |
|
|
115 |
"regular file" ) |
"regular file" ) |
116 |
FILEDIR="$(dirname $I)" |
filedir="$(dirname ${item})" |
117 |
FILEDIR="${FILEDIR#${SEARCHDIRS}*}" |
filedir="${filedir#${SEARCHDIRS}*}" |
118 |
M_MD5SUM="$(md5sum ${I}|cut -d' ' -f1)" |
m_md5sum="$(md5sum ${item}|cut -d' ' -f1)" |
119 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}§${FILEOWNER}§${FILEGROUP}§${M_MTIME}§${M_MD5SUM}" >> ${BUILDDIR}/${PKGNAME}/.files |
echo "${item#${SEARCHDIRS}*}§${fileposix}§${fileowner}§${filegroup}§${m_time}§${m_md5sum}" >> ${BUILDDIR}/${PKGNAME}/.files |
120 |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
install -d ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
121 |
cp ${I} ${BUILDDIR}/${PKGNAME}/binfiles/${FILEDIR} |
cp ${item} ${BUILDDIR}/${PKGNAME}/binfiles/${filedir} |
122 |
;; |
;; |
123 |
|
|
124 |
"block special file") |
"block special file") |
125 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}" >> ${BUILDDIR}/${PKGNAME}/.pipes |
# 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") |
"character special file") |
133 |
echo "${I#${SEARCHDIRS}*}§${FILEPOSIX}" >> ${BUILDDIR}/${PKGNAME}/.char |
# 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" |
echo "What I am ? -- $I" |
146 |
echo "$0 paused ... Press Enter" |
echo "$0 paused ... Press Enter" |
149 |
esac |
esac |
150 |
fi |
fi |
151 |
done |
done |
152 |
|
|
153 |
#very important: unsetting the '§' fieldseperator |
# very important: unsetting the '§' fieldseperator |
154 |
unset IFS |
unset IFS |
|
|
|
|
#forcing mtime to same value |
|
|
echo -n "Forcing mtime to the same value ..." |
|
|
find ${BUILDDIR}/${PKGNAME}/binfiles \ |
|
|
-exec touch -m -r ${BUILDDIR}/${PKGNAME}/.mtime '{}' ';' \ |
|
|
&& echo done || echo false |
|
|
|
|
|
} |
|
155 |
|
|
156 |
build_rmtimestamp() { |
# forcing mtime to same value |
157 |
rm /var/tmp/timestamp |
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 |
build_package() { |
{ |
163 |
echo "Building Package ..." |
echo -e "${COLBLUE}===${COLGREEN} building package tarball ...${COLDEFAULT}" |
164 |
cd ${BUILDDIR} |
cd ${BUILDDIR} |
165 |
tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} |
tar cvjf ${PKGNAME}.tar.bz2 ./${PKGNAME} |
166 |
install -d ${PKGDIR} |
install -d ${PKGDIR} |
167 |
mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} |
mv ${PKGNAME}.tar.bz2 ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} |
168 |
} |
} |
169 |
|
|
|
|
|
170 |
build_preinstall |
build_preinstall |
171 |
build_postinstall |
build_postinstall |
172 |
build_package |
build_package |