Magellan Linux

Annotation of /trunk/bootstrap/mage-bootstrap.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1075 - (hide annotations) (download) (as text)
Mon Jun 28 17:22:52 2010 UTC (13 years, 10 months ago) by niro
Original Path: trunk/bootstrap/mage-bootstrap.sh
File MIME type: application/x-sh
File size: 7566 byte(s)
-added update-tarball support
1 niro 324 #!/bin/bash
2 niro 744 # $Header: /home/cvsd/magellan-cvs/magellan-src/bootstrap/scripts/mage-bootstrap.sh,v 1.8 2008-06-23 19:26:40 niro Exp $
3 niro 324
4     TOOLCHAIN=""
5     BASESYSTEM=""
6     PROFILE=""
7     MROOT=""
8     ABORT_AFTER_STAGE1=false
9     MY_MAGEDIR=""
10     MY_PKGDIR=""
11 niro 977 MAGEUPDATE=true
12 niro 1075 MAGEUPDATETARBALL=false
13 niro 324
14     die()
15     {
16     echo "ERROR: $@"
17     trap_exit
18     exit 1
19     }
20    
21     read_magerc()
22     {
23     local var="$1"
24     local magerc="$2"
25     local value
26    
27     # local all possible vars of a magerc file
28     # to prevent bad issues
29     local PKGDIR
30     local BUILDDIR
31     local INSTALLDB
32     local MAGEDIR
33     local MLIBDIR
34     local VIRTUALDB_DEFAULTS
35     local VIRTUALDB_FILE
36     local SOURCEDIR
37     local BINDIR
38     local SMAGESCRIPTSDIR
39     local MROOT
40     local PKGSUFFIX
41     local VERBOSE
42     local MAGEDEBUG
43     local ARCH
44     local MAGE_UNINSTALL_TIMEOUT
45     local CHOST
46     local CFLAGS
47     local CXXFLAGS
48     local SMAGE_USE_CCACHE
49     local SMAGE_USE_DISTCC
50     local MAKEOPTS
51     local DISTCC_HOSTS
52     local DISTCC_DIR
53     local DISTCC_VERBOSE
54     local DISTCC_LOG
55     local MIRRORS
56     local RSYNC
57     local SMAGE2RSYNC
58    
59     # sanity checks
60 niro 683 [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global || \
61     die "get_value_from_magefile: /etc/mage.rc.global not found."
62 niro 324 [ -f ${magerc} ] && source ${magerc} || \
63     die "get_value_from_magefile: ${magerc} not found."
64     [ -z "${var}" ] && die "get_value_from_magefile: \$var not given."
65    
66     source ${magerc}
67     eval value=\$$(echo ${var})
68     echo "${value}"
69     }
70    
71     add_initrc()
72     {
73     local var="$1"
74    
75     # sanity checks
76     [ -z "${MROOT}" ] && die "\$MROOT not given."
77     echo "${var}" >> ${MROOT}/.installrc || die "add_initrc() adding \$var"
78     }
79    
80     enter_chroot()
81     {
82     mount -t proc proc ${MROOT}/proc || die "mount proc"
83     mount -o bind /dev ${MROOT}/dev || die "mount dev"
84    
85     chroot ${MROOT} /bin/bash -i /.installrc || die "chr00ting"
86    
87     umount ${MROOT}/dev ${MROOT}/proc || die "mount proc/dev"
88    
89     [ -f ${MROOT}/.installrc ] && rm ${MROOT}/.installrc
90     }
91    
92     is_loc_mounted()
93     {
94     local filesys
95     local i
96     filesys=$1
97    
98     i="$(cat /proc/mounts | grep " ${filesys} " | cut -d ' ' -f2)"
99     [[ ${i} != ${filesys} ]] && return 1
100    
101     return 0
102     }
103    
104     trap_exit()
105     {
106     is_loc_mounted "${MROOT}/dev" && umount ${MROOT}/dev
107     is_loc_mounted "${MROOT}/proc" && umount ${MROOT}/proc
108     is_loc_mounted "${MY_MAGEDIR}" && umount ${MY_MAGEDIR}
109     is_loc_mounted "${MY_PKGDIR}" && umount ${MY_PKGDIR}
110     echo "bootstrap aborted"
111     exit 1
112     }
113    
114     print_usage()
115     {
116 niro 340 echo "mage-bootstrap, version @VERSION@"
117 niro 324 echo "Usage: $(basename $0) --opt arg ..."
118     echo
119     echo "Options:"
120 niro 1075 echo " --profile, -p -- select a profile (needed)"
121     echo " --root, -r -- location to new root (needed)"
122     echo " --magerc, -m -- location of mage.rc (needed)"
123 niro 324 echo
124 niro 1075 echo " --toolchain, -t -- select other toolchain than from profile"
125     echo " --basesystem, -b -- select other basesystem than from profile"
126     echo " --stage1, -s1 -- if set, abort after stage1 (toolchain)"
127     echo " --update-tarball, -ut -- update via tarball not rsync"
128     echo " --no-update, -u -- do not update the mage tree"
129     echo " --help, -h -- prints this help"
130 niro 324 echo
131    
132     exit 1
133     }
134    
135     # set some proper traps
136     trap "trap_exit" SIGINT SIGQUIT
137    
138     # show usage if no opts given
139     [[ -z $* ]] && print_usage
140    
141     # very basic getops
142     for i in $*
143     do
144     case $1 in
145     --toolchain|-t) shift; TOOLCHAIN="$1" ;;
146     --basesystem|-b) shift; BASESYSTEM="$1" ;;
147     --profile|-p) shift; PROFILE="$1" ;;
148     --root|-r) shift; MROOT="$1" ;;
149     --stage1|-s1) ABORT_AFTER_STAGE1=true ;;
150     --magerc|-m) shift; MAGERC="$1" ;;
151 niro 1075 --update-tarball|-ut) shift; MAGEUPDATETARBALL=true ;;
152 niro 977 --no-update|-u) shift; MAGEUPDATE=false ;;
153 niro 324 --help|-h) print_usage ;;
154     '') shift;;
155     *) echo "Unkown option '$1', use --help or -h to get more info."; exit 1 ;;
156     esac
157     shift
158     done
159    
160     # sanity checks; abort if not given
161     [ -z "${MROOT}" ] && die "\$MROOT not given."
162     [ -z "${MAGERC}" ] && die "\$MAGERC not given."
163     [ -z "${PROFILE}" ] && die "\$PROFILE not given."
164    
165     # they may be empty, they are included in the profile
166     [ -z "${TOOLCHAIN}" ] && echo "\$TOOLCHAIN not given, using toolchain from profile."
167     [[ ${ABORT_AFTER_STAGE1} = false ]] && [ -z "${BASESYSTEM}" ] \
168     && echo "\$BASESYSTEM not given, using basesystem from profile."
169    
170     # check needed global commands, dirs and files
171     [ ! -d /usr/mage ] && die "/usr/mage does not exists"
172     [ ! -x /sbin/mage ] && die "'/sbin/mage' not found. Please install '>= app-mage/mage-0.4' first."
173     [ ! -x /bin/mount ] && die "'/bin/mount' not found. Please install '>= sys-apps/util-linux' first."
174     [ ! -f ${MAGERC} ] && die "Please setup your mage.rc first."
175     [ ! -f /etc/resolv.conf ] && die "/etc/resolv.conf missing. Please setup your networking first."
176    
177     # install fake-root if not exist
178     [ ! -d ${MROOT} ] && { install -d ${MROOT} || die "create fakedir"; }
179    
180     # create a fake dirs and mount them to / of the host system
181     MY_MAGEDIR="$(read_magerc MAGEDIR ${MAGERC})"
182     MY_PKGDIR="$(read_magerc PKGDIR ${MAGERC})"
183    
184     install -d ${MROOT}/${MY_MAGEDIR} || die "create magedir"
185     install -d ${MROOT}/${MY_PKGDIR} || die "create pkgdir"
186    
187     mount -o bind ${MROOT}/${MY_MAGEDIR} ${MY_MAGEDIR} || die "mount magedir"
188     mount -o bind ${MROOT}/${MY_PKGDIR} ${MY_PKGDIR} || die "mount pkgdir"
189    
190     # link to the right profile
191     ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile || die "link profile"
192    
193     # update mage tree
194 niro 977 if [[ ${MAGEUPDATE} = true ]]
195     then
196 niro 1075 if [[ ${MAGEUPDATETARBALL} = true ]]
197     then
198     MAGERC="${MAGERC}" mage update-tarball || die "update mage-tree"
199     else
200     MAGERC="${MAGERC}" mage update || die "update mage-tree"
201     fi
202 niro 977 fi
203 niro 324
204     # now get the toolchain and the basesystem layout file
205     # [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="toolchain.defaults"
206     # [ -z "${BASESYSTEM}" ] && BASESYSTEM="basesystem.defaults"
207     # # read them
208     # TOOLCHAIN="$(< /etc/mage-profile/${TOOLCHAIN})"
209     # BASESYSTEM="$(< /etc/mage-profile/${BASESYSTEM})"
210    
211 niro 422 # this way toolchain and basesystem can be packages;
212 niro 324 # only if nothing set the layout files from the profile will be taken
213 niro 683 [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="$(< ${MY_MAGEDIR}/profiles/${PROFILE}/toolchain.defaults)"
214     [ -z "${BASESYSTEM}" ] && BASESYSTEM="$(< ${MY_MAGEDIR}/profiles/${PROFILE}/basesystem.defaults)"
215 niro 324
216     # install toolchain
217 niro 422 CONFIG_PROTECT="-*" MROOT="${MROOT}" MAGERC="${MAGERC}" mage install ${TOOLCHAIN} || die "toolchain install"
218 niro 324
219     # umount dirs, they are not needed anymore
220     umount ${MY_MAGEDIR} ${MY_PKGDIR} || die "umount mage/pkgdir"
221    
222     # copy some needed files to the fake-root
223     install -m 0644 ${MAGERC} ${MROOT}/etc/mage.rc || die "install mage.rc"
224     install -m 0644 /etc/resolv.conf ${MROOT}/etc/resolv.conf || die "install resolv.conf"
225    
226     # abort if wanted
227     if [[ ${ABORT_AFTER_STAGE1} = true ]]
228     then
229     echo "Stage1 complete; user requested to abort after this step."
230     echo "Exiting ..."
231     exit 0
232     fi
233    
234     # now create an initrc for the installation of the basesystem
235     :> ${MROOT}/.installrc
236 niro 422 add_initrc "export MAGE_BOOTSTRAP=true"
237 niro 324 add_initrc "export HOME=/root"
238     add_initrc "export PATH=/bin:/usr/bin:/sbin:/usr/sbin"
239     add_initrc "export BASESYSTEM=${BASESYSTEM}"
240     add_initrc "export PROFILE=${PROFILE}"
241     add_initrc "export CONFIG_PROTECT=-*"
242     add_initrc "export MY_MAGEDIR=${MY_MAGEDIR}"
243    
244     # add proxies if defined
245     [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}"
246     [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}"
247     [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}"
248     [[ -n ${RSYNC_PROXY} ]] && add_initrc "export RSYNC_PROXY=${RSYNC_PROXY}"
249    
250     # install comands
251     add_initrc "ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile"
252     add_initrc "mage install ${BASESYSTEM}"
253     add_initrc "mage clean"
254    
255     # chroot the toolchain
256     enter_chroot
257    
258     echo "System bootstrap to '${MROOT}' finished."
259     exit 0

Properties

Name Value
svn:executable *