Magellan Linux

Annotation of /trunk/mage-buildroot/mage-buildroot.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 383 - (hide annotations) (download) (as text)
Tue Jun 13 16:47:54 2006 UTC (17 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 6104 byte(s)
nicer messages and moving now builded packages in a seperate build directory

1 niro 309 #!/bin/bash
2 niro 383 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage-buildroot/mage-buildroot.sh,v 1.3 2006-06-13 16:47:54 niro Exp $
3 niro 309 #
4     # mage buildroot
5 niro 322 # creates a buildroot to compile programms
6 niro 309 # may get later into mage
7     #
8 niro 322 # Niels Rogalla <niro@magellan-linux.de>
9     #
10 niro 309
11     # default die function
12     die()
13     {
14     echo -e ${COLRED}"$@"${COLDEFAULT}
15     exit 1
16     }
17    
18     [[ $(id -u ) != 0 ]] && die "you must be root"
19    
20     # i need some settings and functions from mage
21     [ -f /etc/rc.d/init.d/functions ] && \
22     source /etc/rc.d/init.d/functions || \
23     die "Your /etc/mage.rc is missing. Aborting."
24    
25     [ -f /etc/mage.rc.global ] && \
26     source /etc/mage.rc.global || \
27     die "/etc/mage.rc.global missing"
28    
29     [ -f /etc/mage.rc ] && source /etc/mage.rc || \
30     die "Your /etc/mage.rc is missing. Aborting."
31    
32     [ -f ${MLIBDIR}/mage4.functions.sh ] && \
33     source ${MLIBDIR}/mage4.functions.sh || \
34     die "mage functions missing"
35    
36     installrc()
37     {
38     local var="$1"
39    
40     # sanity checks
41     [ -z "${MROOT}" ] && die "\$MROOT not given."
42     echo "${var}" >> ${MROOT}/.installrc || die "add_initrc() adding \$var"
43     }
44    
45     enter_chroot()
46     {
47     [ ! -d ${MROOT}/proc ] && install -d ${MROOT}/proc
48     [ ! -d ${MROOT}/dev ] && install -d ${MROOT}/dev
49     [ ! -d ${MROOT}/sys ] && install -d ${MROOT}/sys
50    
51     mount -t proc proc ${MROOT}/proc
52     mount -t sysfs sysfs ${MROOT}/sys
53     mount -o bind /dev ${MROOT}/dev
54    
55     # chroot ${MROOT} /bin/bash -i /.installrc
56     chroot ${MROOT} /usr/bin/env -i \
57     HOME=/root \
58     TERM="${TERM}" \
59     PS1='\u:\w\$ ' \
60     PATH=/bin:/usr/bin:/sbin:/usr/sbin \
61     /bin/bash -i /.installrc #|| die "chr00ting"
62    
63     umount ${MROOT}/dev
64     umount ${MROOT}/proc
65     umount ${MROOT}/sys
66    
67     #[ -f ${MROOT}/.installrc ] && rm ${MROOT}/.installrc
68     }
69    
70     # some sane defaults
71     MROOT="$1"
72     TARGET_PKG="$2"
73     #MAGERC="/etc/mage.rc"
74     MAGERC="/home/tjoke/mage.rc-buildroot"
75     MAGE_PROFILE="$(basename $(readlink /etc/mage-profile))"
76     TOOLCHAIN=toolchain
77     BASESYSTEM=common-devutils
78    
79     # first install a toolchain and some common dev-utils using bootstrap2
80     # only if not already builded
81     if [ ! -f ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} ]
82     then
83     #mage-bootstrap \
84     /home/tjoke/alx-cvs/magellan-src/bootstrap/scripts/mage-bootstrap.sh \
85     --root "${MROOT}" \
86     --magerc "${MAGERC}" \
87     --profile "${MAGE_PROFILE}" \
88     --toolchain "${TOOLCHAIN}" \
89     --basesystem "${BASESYSTEM}" \
90     || die "bootstrapping toolchain"
91    
92     # mark this as builded
93     touch ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} || die "touch ok"
94     fi
95    
96     #####################################################
97     # setup a chroot environment #
98     #####################################################
99     echo > ${MROOT}/.installrc || die
100    
101     # some needed env-vars and functions
102     installrc 'unset MROOT'
103     installrc 'env-rebuild'
104     installrc 'source /etc/profile'
105     installrc 'die() { echo -e ${COLRED}"$@"${COLDEFAULT}; exit 1; }'
106     installrc '[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions' # || die "Your /etc/mage.rc is missing. Aborting."'
107     installrc '[ -f /etc/mage.rc.global ] && . /etc/mage.rc.global' # || die "/etc/mage.rc.global missing"'
108     installrc '[ -f /etc/mage.rc ] && . /etc/mage.rc' # || die "Your /etc/mage.rc is missing. Aborting."'
109     installrc '[ -f ${MLIBDIR}/mage4.functions.sh ] && . ${MLIBDIR}/mage4.functions.sh' # || die "mage functions missing"'
110     installrc "export FAKE_MROOT=\"${MROOT}\""
111     installrc "export TARGET_PKG=\"${TARGET_PKG}\""
112    
113     # update mage only if buildroot already exists
114     [ -f ${MROOT}/.buildroot_build_ok-${TOOLCHAIN}-${BASESYSTEM} ] && installrc 'mage update'
115     installrc 'smage2 update'
116    
117     # run part
118     cat >> ${MROOT}/.installrc << "EOF"
119    
120     #####################################################
121     # now calculate the src-dependencies for TARGET_PKG #
122     #####################################################
123    
124     # before anything run mage_setup
125     mage_setup || die "error in mage_setup()"
126    
127     # first of all get the right pkg which going to be installed
128     PCAT="$(pname2pcat ${TARGET_PKG})"
129    
130     # package does not exists
131     [ -z "${PCAT}" ] && die "Package '${TARGET_PKG}' does not exist."
132    
133     # source the highest magefile of this pkg
134     PKGNAME=$(get_value_from_magefile PKGNAME $(get_highest_magefile ${PCAT} ${TARGET_PKG}))
135    
136     # convert PKGNAME to PNAME/PVER/PBUILD
137     # we're working *only* with these three vars from here on
138     PNAME="$(pkgname2pname ${PKGNAME})"
139     PVER="$(pkgname2pver ${PKGNAME})"
140     PBUILD="$(pkgname2pbuild ${PKGNAME})"
141    
142     if is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
143     then
144     echo -en "Package "
145     echo -en "${COLRED}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
146     echo -e " already installed."
147     exit 3
148     fi
149    
150     # get all dependencies of this package
151 niro 383 echo
152     echo -n "Calculating dependencies ... "
153 niro 309 ALLDEPS="$(${MLIBDIR}/depwalker.sh \
154     --method srcinstall \
155     --pcat ${PCAT} \
156     --pname ${PNAME} \
157     --pver ${PVER} \
158     --pbuild ${PBUILD})"
159 niro 383 echo "done"
160 niro 309
161     # remove TARGET_PKG from list
162     SRC_INSTALL_DEPS="$(get_highest_magefile ${PCAT} ${TARGET_PKG})"
163     INSTALL_DEPS="${ALLDEPS/${SRC_INSTALL_DEPS}/}"
164    
165     echo
166     echo "---- environment -----"
167     echo "MROOT: ${FAKE_MROOT}"
168     echo "PKGDIR: ${PKGDIR}"
169     echo "BUILDDIR: ${BUILDDIR}"
170     echo "BINDIR: ${BINDIR}"
171     echo "----------------------"
172     echo
173     echo "---- dependencies ----"
174 niro 383 echo "SRC_INSTALL_DEPS:"
175     for i in ${SRC_INSTALL_DEPS}
176     do
177     echo " * ${i}"
178     done
179     echo "INSTALL_DEPS:"
180     for i in ${INSTALL_DEPS}
181     do
182     echo " * ${i}"
183     done
184 niro 309 echo "----------------------"
185    
186     #read
187    
188     # now install the packages (no srcinstall, when the user not explcitly want this)
189     fetch_packages ${INSTALL_DEPS} || die "fetching packages"
190     md5sum_packages ${INSTALL_DEPS} || die "md5 sum packages"
191     unpack_packages ${INSTALL_DEPS} || die "unpacking packages"
192     install_packages ${INSTALL_DEPS} || die "installing packages"
193    
194     # whipe out all packages
195     mage clean
196    
197     # now src-install TARGET_PKG
198     install_packages --src-install ${SRC_INSTALL_DEPS} || die "src-installing packages"
199    
200     # done
201 niro 383 [[ ! -d /BUILDED ]] && install -d /BUILDED
202     mv ${PKGDIR}/${PNAME}-${PVER}-${ARCH}-${PBUILD}.mpk /BUILDED || die "pkg move"
203 niro 309 echo -e "Package ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT} successfully builded."
204 niro 383 echo "You will find this in ${FAKE_MROOT}/BUILDED."
205 niro 309 EOF
206    
207     # run this stuff
208     enter_chroot

Properties

Name Value
svn:executable *