Magellan Linux

Annotation of /trunk/bootstrap/scripts/bootstrap2.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 263 - (hide annotations) (download) (as text)
Tue Oct 4 21:01:27 2005 UTC (18 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 5538 byte(s)
new version of bootstrap-magellan

1 niro 263 #!/bin/bash
2     # bootstrap2.sh
3    
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     # set some proper traps
111     trap "trap_exit" SIGINT SIGQUIT
112    
113     # very basic getops
114     for i in $*
115     do
116     case $1 in
117     --toolchain|-t) shift; TOOLCHAIN="$1" ;;
118     --basesystem|-b) shift; BASESYSTEM="$1" ;;
119     --profile|-p) shift; PROFILE="$1" ;;
120     --root|-r) shift; MROOT="$1" ;;
121     --stage1|-s1) ABORT_AFTER_STAGE1=true ;;
122     --magerc|-m) shift; MAGERC="$1" ;;
123     esac
124     shift
125     done
126    
127     # sanity checks; abort if not given
128     [ -z "${MROOT}" ] && die "\$MROOT not given."
129     [ -z "${MAGERC}" ] && die "\$MAGERC not given."
130     [ -z "${PROFILE}" ] && die "\$PROFILE not given."
131    
132     # they may be empty, they are included in the profile
133     [ -z "${TOOLCHAIN}" ] && echo "\$TOOLCHAIN not given, using toolchain from profile."
134     [[ ${ABORT_AFTER_STAGE1} = false ]] && [ -z "${BASESYSTEM}" ] \
135     && echo "\$BASESYSTEM not given, using basesystem from profile."
136    
137     # check needed global commands, dirs and files
138     [ ! -d /usr/mage ] && die "/usr/mage does not exists"
139     [ ! -x /sbin/mage ] && die "'/sbin/mage' not found. Please install '>= app-mage/mage-0.4' first."
140     [ ! -x /bin/mount ] && die "'/bin/mount' not found. Please install '>= sys-apps/util-linux' first."
141     [ ! -f ${MAGERC} ] && die "Please setup your mage.rc first."
142     [ ! -f /etc/resolv.conf ] && die "/etc/resolv.conf missing. Please setup your networking first."
143    
144     # install fake-root if not exist
145     [ ! -d ${MROOT} ] && { install -d ${MROOT} || die "create fakedir"; }
146    
147     # create a fake dirs and mount them to / of the host system
148     MY_MAGEDIR="$(read_magerc MAGEDIR ${MAGERC})"
149     MY_PKGDIR="$(read_magerc PKGDIR ${MAGERC})"
150    
151     install -d ${MROOT}/${MY_MAGEDIR} || die "create magedir"
152     install -d ${MROOT}/${MY_PKGDIR} || die "create pkgdir"
153    
154     mount -o bind ${MROOT}/${MY_MAGEDIR} ${MY_MAGEDIR} || die "mount magedir"
155     mount -o bind ${MROOT}/${MY_PKGDIR} ${MY_PKGDIR} || die "mount pkgdir"
156    
157     # link to the right profile
158     ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile || die "link profile"
159    
160     # update mage tree
161     mage update || die "update mage-tree"
162    
163     # now get the toolchain and the basesystem layout file
164     [ -z "${TOOLCHAIN}" ] && TOOLCHAIN="toolchain.defaults"
165     [ -z "${BASESYSTEM}" ] && BASESYSTEM="basesystem.defaults"
166     # read them
167     TOOLCHAIN="$(< /etc/mage-profile/${TOOLCHAIN})"
168     BASESYSTEM="$(< /etc/mage-profile/${BASESYSTEM})"
169    
170     # install toolchain
171     CONFIG_PROTECT="-*" MROOT="${MROOT}" mage install ${TOOLCHAIN} || die "toolchain install"
172    
173     # umount dirs, they are not needed anymore
174     umount ${MY_MAGEDIR} ${MY_PKGDIR} || die "umount mage/pkgdir"
175    
176     # copy some needed files to the fake-root
177     install -m 0644 ${MAGERC} ${MROOT}/etc/mage.rc || die "install mage.rc"
178     install -m 0644 /etc/resolv.conf ${MROOT}/etc/resolv.conf || die "install resolv.conf"
179    
180     # now create an initrc for the installation of the basesystem
181     :> ${MROOT}/.installrc
182     add_initrc "export HOME=/root"
183     add_initrc "export PATH=/bin:/usr/bin:/sbin:/usr/sbin"
184     add_initrc "export BASESYSTEM=${BASESYSTEM}"
185     add_initrc "export PROFILE=${PROFILE}"
186     add_initrc "export CONFIG_PROTECT=-*"
187     add_initrc "export MY_MAGEDIR=${MY_MAGEDIR}"
188    
189     # add proxies if defined
190     [[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}"
191     [[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}"
192     [[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}"
193     [[ -n ${RSYNC_PROXY} ]] && add_initrc "export RSYNC_PROXY=${RSYNC_PROXY}"
194    
195     # install comands
196     add_initrc "ln -snf ${MY_MAGEDIR}/profiles/${PROFILE} /etc/mage-profile"
197     add_initrc "mage install ${BASESYSTEM}"
198     add_initrc "mage clean"
199    
200     # chroot the toolchain
201     enter_chroot
202    
203     echo "System bootstrap to '${MROOT}' finished."
204