1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
|
3 |
# some default settings - gets overidden with the profile config |
# some default settings - gets overidden with the profile config |
4 |
CDPROFILE="$1" |
CDPROFILE="$2" |
5 |
[[ -z ${CDPROFILE} ]] && CDPROFILE="default" |
[[ -z ${CDPROFILE} ]] && CDPROFILE="default" |
6 |
LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}" |
LIVECDROOT="/mnt/MLIVECDBUILD/${CDPROFILE}" |
7 |
CDCHROOTDIR="${LIVECDROOT}/chroot" |
CDCHROOTDIR="${LIVECDROOT}/chroot" |
46 |
|| die "bootstrapping toolchain" |
|| die "bootstrapping toolchain" |
47 |
} |
} |
48 |
|
|
49 |
|
custom_services() |
50 |
|
{ |
51 |
|
local cmd="$1" |
52 |
|
local services="$2" |
53 |
|
|
54 |
|
case ${cmd} in |
55 |
|
add|del|default) |
56 |
|
# add given services from profile |
57 |
|
if [[ -n ${services} ]] |
58 |
|
then |
59 |
|
local i |
60 |
|
for i in ${services} |
61 |
|
do |
62 |
|
MROOT="${CDCHROOTDIR}" rc-config ${cmd} ${i} || die "rc ${cmd} ${i}" |
63 |
|
done |
64 |
|
fi |
65 |
|
;; |
66 |
|
*) die "custom_services: unkown command ${cmd}";; |
67 |
|
esac |
68 |
|
} |
69 |
|
|
70 |
|
add_initrc() |
71 |
|
{ |
72 |
|
local var="$1" |
73 |
|
|
74 |
|
# sanity checks |
75 |
|
[[ -z ${CDCHROOTDIR} ]] && die "\$CDCHROOTDIR not given." |
76 |
|
echo "${var}" >> ${CDCHROOTDIR}/.installrc || die "add_initrc() adding \$var" |
77 |
|
} |
78 |
|
|
79 |
|
custom_packages() |
80 |
|
{ |
81 |
|
local cmd="$1" |
82 |
|
local packages="$2" |
83 |
|
|
84 |
|
case ${cmd} in |
85 |
|
install|uninstall) |
86 |
|
if [[ -n ${packages} ]] |
87 |
|
then |
88 |
|
:> ${CDCHROOTDIR}/.installrc |
89 |
|
|
90 |
|
# respect proxies |
91 |
|
[[ -n ${http_proxy} ]] && add_initrc "export http_proxy=${http_proxy}" |
92 |
|
[[ -n ${ftp_proxy} ]] && add_initrc "export ftp_proxy=${ftp_proxy}" |
93 |
|
[[ -n ${no_proxy} ]] && add_initrc "export no_proxy=${no_proxy}" |
94 |
|
|
95 |
|
# do not auto-start any services! |
96 |
|
add_initrc "export MAGE_BOOTSTRAP=true" |
97 |
|
|
98 |
|
local i |
99 |
|
for i in ${packages} |
100 |
|
do |
101 |
|
add_initrc "mage ${cmd} ${i}" |
102 |
|
done |
103 |
|
add_initrc "mage clean" |
104 |
|
|
105 |
|
# now run the .installrc script |
106 |
|
mount -t proc proc ${CDCHROOTDIR}/proc || die "mount proc" |
107 |
|
mount -t sysfs sysfs ${CDCHROOTDIR}/sys || die "mount sys" |
108 |
|
mount -o bind /dev ${CDCHROOTDIR}/dev || die "mount dev" |
109 |
|
chroot ${CDCHROOTDIR} /bin/bash -i /.installrc || die "chr00ting" |
110 |
|
umount ${CDCHROOTDIR}/dev || die "umount dev" |
111 |
|
umount ${CDCHROOTDIR}/proc || die "umount proc" |
112 |
|
umount ${CDCHROOTDIR}/sys || die "umount sys" |
113 |
|
[ -f ${CDCHROOTDIR}/.installrc ] && rm ${CDCHROOTDIR}/.installrc |
114 |
|
fi |
115 |
|
;; |
116 |
|
*) die "custom_packages: unkown command ${cmd}";; |
117 |
|
esac |
118 |
|
} |
119 |
|
|
120 |
|
read_config() |
121 |
|
{ |
122 |
|
local file="$1" |
123 |
|
local pkg |
124 |
|
|
125 |
|
( cat ${file}; echo ) | while read pkg |
126 |
|
do |
127 |
|
case "${pkg}" in |
128 |
|
\#*|"") continue ;; |
129 |
|
esac |
130 |
|
echo "${pkg}" |
131 |
|
done |
132 |
|
} |
133 |
|
|
134 |
prepare_iso() |
prepare_iso() |
135 |
{ |
{ |
136 |
echo Preparing LiveCD ISO Image ... |
echo Preparing LiveCD ISO Image ... |
137 |
|
|
138 |
# fixes some issues with xfree/xorg xkb |
# fixes some issues with xfree/xorg xkb |
139 |
if [ -L "${CDCHROOTDIR}/etc/X11/xkb" -a -d "/usr/X11R6/lib/X11/xkb" ] |
if [[ -L ${CDCHROOTDIR}/etc/X11/xkb ]] && [[ -d /usr/X11R6/lib/X11/xkb ]] |
140 |
then |
then |
141 |
rm ${CDCHROOTDIR}/etc/X11/xkb || die |
rm ${CDCHROOTDIR}/etc/X11/xkb || die |
142 |
mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die |
mv ${CDCHROOTDIR}/usr/X11R6/lib/X11/xkb ${CDCHROOTDIR}/etc/X11 || die |
147 |
install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die |
install -m 0644 $(get_profile fstab) ${CDCHROOTDIR}/etc/fstab || die |
148 |
install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die |
install -m 0644 $(get_profile motd) ${CDCHROOTDIR}/etc/motd || die |
149 |
install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die |
install -m 0644 $(get_profile issue) ${CDCHROOTDIR}/etc/issue || die |
150 |
|
install -m 0644 $(get_profile net.eth0) ${CDCHROOTDIR}/etc/conf.d/net.eth0 || die |
151 |
echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
echo "${CDHOSTNAME}" > ${CDCHROOTDIR}/etc/hostname || die |
152 |
|
|
153 |
echo Setting up services ... |
echo Setting up services ... |
154 |
|
|
|
# change mountfs with mountfslivecd |
|
|
MROOT="${CDCHROOTDIR}" rc-config del mountfs || die "rc del mountfs" |
|
|
MROOT="${CDCHROOTDIR}" rc-config add mountfslivecd || die "rc add mountfslivecd" |
|
|
|
|
155 |
# add hardware detection |
# add hardware detection |
156 |
MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" |
MROOT="${CDCHROOTDIR}" rc-config add hwdetect || die "rc add hwdetect" |
157 |
|
|
158 |
# del checkfs |
# del checkfs |
159 |
MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" |
MROOT="${CDCHROOTDIR}" rc-config del checkfs || die "rc del checkfs" |
160 |
|
|
161 |
|
# add custom packages |
162 |
|
[[ -n ${ADD_PACKAGES} ]] && custom_packages install "${ADD_PACKAGES}" |
163 |
|
[ -f $(get_profile add_packages) ] && custom_packages install "$(read_config $(get_profile add_packages))" |
164 |
|
|
165 |
|
# del custom packages |
166 |
|
[[ -n ${DEL_PACKAGES} ]] && custom_packages uninstall "${DEL_PACKAGES}" |
167 |
|
[ -f $(get_profile del_packages) ] && custom_packages uninstall "$(read_config $(get_profile del_packages))" |
168 |
|
|
169 |
|
# add given services from profile |
170 |
|
[[ -n ${ADD_SERVICES} ]] && custom_services add "${ADD_SERVICES}" |
171 |
|
[ -f $(get_profile add_services) ] && custom_services add "$(read_config $(get_profile add_services))" |
172 |
|
|
173 |
|
# del given services from profile |
174 |
|
[[ -n ${DEL_SERVICES} ]] && custom_services del "${DEL_SERVICES}" |
175 |
|
[ -f $(get_profile del_services) ] && custom_services del "$(read_config $(get_profile del_services))" |
176 |
|
|
177 |
|
# setup default runlevel |
178 |
|
[[ -n ${DEFAULT_RUNLEVEL} ]] && custom_services default "${DEFAULT_RUNLEVEL}" |
179 |
|
|
180 |
|
if [ -f $(get_profile prepare_custom) ] |
181 |
|
then |
182 |
|
echo Running custom user script ... |
183 |
|
source $(get_profile prepare_custom) || die "running custom user script" |
184 |
|
fi |
185 |
|
|
186 |
echo Cleaning unwanted files ... |
echo Cleaning unwanted files ... |
187 |
:> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" |
:> ${CDCHROOTDIR}/etc/mtab || die "whiping /etc/mtab" |
188 |
|
[ -f ${CDCHROOTDIR}/root/.bash_history ] && rm ${CDCHROOTDIR}/root/.bash_history |
189 |
} |
} |
190 |
|
|
191 |
generate_rootfs() |
generate_rootfs() |
204 |
|
|
205 |
# iso linux binary |
# iso linux binary |
206 |
install -d ${CDISOROOT}/isolinux |
install -d ${CDISOROOT}/isolinux |
207 |
install /usr/lib/mlivecdbuild/isolinux.bin ${CDISOROOT}/isolinux || die |
install /usr/lib/mkinitrd/isolinux.bin ${CDISOROOT}/isolinux || die |
208 |
|
|
209 |
# kernel |
# kernel |
210 |
local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" |
local kimg="$(basename $(readlink ${CDCHROOTDIR}/boot/vmlinuz))" |
221 |
generate_initrd() |
generate_initrd() |
222 |
{ |
{ |
223 |
local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" |
local CHROOTSH="$(mktemp -p ${CDCHROOTDIR})" |
|
echo "DEBUG: ${CHROOTSH}" |
|
224 |
|
|
225 |
echo Generating initrd image ... |
echo Generating initrd image ... |
226 |
echo '#!/bin/bash' > ${CHROOTSH} || die |
echo '#!/bin/bash' > ${CHROOTSH} || die |
258 |
|
|
259 |
enter_livecd() |
enter_livecd() |
260 |
{ |
{ |
261 |
mount -t sysfs sysfs ${CDCHROOTDIR}/proc |
mount -t sysfs sysfs ${CDCHROOTDIR}/sys |
262 |
mount -t proc proc ${CDCHROOTDIR}/proc |
mount -t proc proc ${CDCHROOTDIR}/proc |
263 |
mount -o bind /dev ${CDCHROOTDIR}/dev |
mount -o bind /dev ${CDCHROOTDIR}/dev |
264 |
|
|
267 |
HOME=/root \ |
HOME=/root \ |
268 |
TERM=$TERM PS1='\u:\w\$ ' \ |
TERM=$TERM PS1='\u:\w\$ ' \ |
269 |
PATH=/bin:/usr/bin:/sbin:/usr/sbin \ |
PATH=/bin:/usr/bin:/sbin:/usr/sbin \ |
270 |
|
http_proxy=${http_proxy} \ |
271 |
|
ftp_proxy=${ftp_proxy} \ |
272 |
|
no_proxy=${no_proxy} \ |
273 |
/bin/bash -i |
/bin/bash -i |
274 |
|
|
275 |
|
umount ${CDCHROOTDIR}/dev |
276 |
|
umount ${CDCHROOTDIR}/proc |
277 |
|
umount ${CDCHROOTDIR}/sys |
278 |
|
} |
279 |
|
|
280 |
|
usage() |
281 |
|
{ |
282 |
|
echo "Usage: $(basename $0) [command] [profile] ..." |
283 |
|
echo |
284 |
|
echo "Commands:" |
285 |
|
echo " bootstrap - bootstraps the rootfs for the livecd" |
286 |
|
echo " prepare - prepare the rootfs to run from a livecd" |
287 |
|
echo " rootfs - generates the squashfs rootfs image" |
288 |
|
echo " initrd - generates a livecd suitable initrd" |
289 |
|
echo " bootloader - installs the bootloader" |
290 |
|
echo " isogen - generate the final livecd iso image" |
291 |
|
echo " all - runs all tasks to get a livecd from zero" |
292 |
|
echo " enter - enters the rootfs of a livecd" |
293 |
|
echo |
294 |
|
echo " for example '$(basename $0) all default'" |
295 |
|
echo " creates a livecd using the default profile." |
296 |
|
echo |
297 |
} |
} |
298 |
|
|
299 |
# source profile config - overrides all other vars |
# source profile config - overrides all other vars |
300 |
[ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config |
[ -f ${PROFILES_DIR}/${CDPROFILE}/config ] && . ${PROFILES_DIR}/${CDPROFILE}/config |
301 |
|
|
302 |
bootstrap_system |
case $1 in |
303 |
prepare_iso |
bootstrap) bootstrap_system;; |
304 |
generate_rootfs |
prepare) prepare_iso;; |
305 |
generate_initrd |
rootfs) generate_rootfs;; |
306 |
install_bootloader |
initrd) generate_initrd;; |
307 |
generate_iso |
bootloader) install_bootloader;; |
308 |
|
isogen) generate_iso;; |
309 |
|
all) |
310 |
|
bootstrap_system |
311 |
|
prepare_iso |
312 |
|
generate_rootfs |
313 |
|
generate_initrd |
314 |
|
install_bootloader |
315 |
|
generate_iso |
316 |
|
;; |
317 |
|
enter) enter_livecd ;; |
318 |
|
*|'') usage;; |
319 |
|
esac |