Magellan Linux

Annotation of /tags/bootstrap-1_12/mage-bootstrap.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (hide annotations) (download) (as text)
Thu Feb 23 16:36:21 2006 UTC (18 years, 2 months ago) by niro
Original Path: trunk/bootstrap/scripts/mage-bootstrap.sh
File MIME type: application/x-sh
File size: 6830 byte(s)
fixed header

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

Properties

Name Value
svn:executable *