Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 309 - (hide annotations) (download) (as text)
Sun Jan 1 17:20:46 2006 UTC (18 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 5811 byte(s)
initial version

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

Properties

Name Value
svn:executable *