seb view seb @ rev 12

Improve README/manual
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 06 20:08:52 2017 +0100 (2017-03-06)
parents d28b86ae0e45
children 212ea6d3ec20
line source
1 #!/bin/sh
2 #
3 # SEB - SliTaz Embedded Builder - Back to the roots with SliTaz in
4 # only a few MB. Please read the README file for more information.
5 #
6 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
10 unset status get_cols separator colorize boldify
12 # --iso --work --linux can be set in config file or from cmdline
13 [ -f "build.conf" ] && . build.conf
15 [ "$work" ] || work="$(pwd)"
16 [ "$iso" ] || iso="seb-os-$(date '+%Y%m%d').iso"
17 [ "$linux" ] || linux="/boot/vmlinuz-$(uname -r)"
19 rootfs="$work/rootfs"
20 rootiso="$work/rootiso"
21 sebfs="$work/sebfs"
22 sebpkgs="$work/sebpkgs"
23 cache="$work/cache"
24 vdisk="$work/sebhome.img"
25 qemu_opts="-m 512"
27 tools="/usr/share/seb/tools"
28 initfs="/usr/share/seb/initfs"
29 packages="/usr/share/seb/packages"
31 # Working from source tree
32 [ -d "tools" ] && tools="$(pwd)/tools"
33 [ -d "initfs" ] && initfs="$(pwd)/initfs"
34 [ -d "packages" ] && packages="$(pwd)/packages"
36 # Source libseb.sh (overwrite libtaz.sh function)
37 if [ -f "$PWD/libseb.sh" ]; then
38 libseb="$PWD/libseb.sh"
39 . ${libseb}
40 else
41 if ! . /lib/libseb.sh; then
42 echo "Can't source any: libseb.sh"; exit 1
43 fi
44 libseb="/lib/libseb.sh"
45 fi
46 debug "work=$work"
48 #
49 # Functions
50 #
52 help() {
53 cat << EOT
55 $(colorize 35 "SliTaz Embedded Builder")
57 $(boldify "Usage:") $(basename $0) [command] [--opts]
58 $(boldify "Manuel:") man seb
60 $(boldify "Commands:")
61 -h help Display this short built-in help
62 -i init Creat base files to customize
63 -b build Generate a distribution (initramfs & iso)
64 -p packages Handle packages: --list --add
65 -g geniso Re-generate the ISO image
66 -c clean Remove all SEB generated files
67 -l lsfs List all files in rootfs (-type f)
68 -v vdisk Create, mount or unmount a virtual disk
69 -e emu Emulate ISO image with Qemu
70 env Print current seb environment
72 $(boldify "Options:")
73 --work= Path to build directory
74 --iso= Specify SliTaz Embedded ISO image name
75 --linux= Path to a custom Linux kernel
76 --all Clean all files including sebfs
77 --emu Emulate ISO image after build
78 --check Check a virtual disk image
80 EOT
81 }
83 # Initial files who can be modified via sebfs/
84 init() {
85 mkdir -p ${sebfs} ${sebpkgs}
86 cp -rf ${initfs}/* ${sebfs}
87 }
89 geniso() {
90 echo -n "Generating ISO image: ${iso}"
91 cd ${work}
92 genisoimage -R -o ${iso} \
93 -b boot/isolinux/isolinux.bin \
94 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
95 -V "SliTaz Embedded" -input-charset iso8859-1 \
96 -boot-info-table rootiso 2> /dev/null; check
97 echo -n "Checking ISO image size..."
98 info 035 $(du -mhs $iso | awk '{print $1}')
99 }
101 emulate() {
102 if [ -x "/usr/bin/qemu" ]; then
103 echo "qemu $qemu_opts -cdrom $1"
104 if [ -f "$vdisk" ]; then
105 hda="-hda $vdisk"
106 umount ${vdisk} 2>/dev/null
107 fi
108 qemu ${qemu_opts} ${hda} -cdrom ${1}
109 else
110 echo $(echo "Please install:") $(boldify qemu); exit 0
111 fi
112 }
114 # Install files in the rootfs with same path than on the build host
115 # Usage: install_files "/file/1" "/lib/lib.so*" "/file/N"
116 install_files() {
117 for file in ${@} ; do
118 path=$(dirname $file)
119 echo -n "Installing: $file"
120 cp -a ${file} ${rootfs}${path} && check
121 done
122 }
124 # Populate /dev + 'mdev -s' on boot
125 create_dev_files() {
126 echo -n "Populating: /dev"
127 mkdir -p ${rootfs}/dev/pts ${rootfs}/dev/shm
128 cd ${rootfs}/dev
129 mknod -m 0666 null c 1 3
130 mknod -m 0622 console c 5 1
131 mknod -m 0666 tty c 5 0
132 for i in 0 1 2; do
133 mknod -m 0666 tty$i c 4 $i
134 done; check
135 }
137 # Configuration files for /etc not generate by init to keep initfs/sebfs
138 # filesytems minimals
139 create_etc_files() {
140 echo -n "Creating config files in: /etc"
141 (echo "127.0.0.1 localhost seb" > ${rootfs}/etc/hosts
142 echo "localnet 127.0.0.1" > ${rootfs}/etc/networks
143 echo "order hosts,bind" > ${rootfs}/etc/host.conf
144 echo "multi on" >> ${rootfs}/etc/host.conf
145 # Users & passwd
146 echo "root:x:0:0:root:/root:/bin/sh" > ${rootfs}/etc/passwd
147 echo "root::13525:0:99999:7:::" > ${rootfs}/etc/shadow
148 cat > ${rootfs}/etc/group << EOT
149 root:x:0:
150 www:x:80:
151 EOT
152 cat > ${rootfs}/etc/gshadow << EOT
153 root:*::
154 www:!::
155 EOT
156 chmod 640 ${rootfs}/etc/*shadow)
157 cat > ${rootfs}/etc/nsswitch.conf << EOT
158 # /etc/nsswitch.conf: GNU Name Service Switch config.
159 #
161 passwd: files
162 group: files
163 shadow: files
165 hosts: files dns
166 networks: files
167 EOT
168 check
169 }
171 build() {
172 title "Starting SliTaz Embedded builder"
174 # Build environment
175 rm -rf ${rootfs} ${rootiso}
176 mkdir -p ${rootfs} ${rootiso}/boot/isolinux
178 # FSH Tree
179 echo -n "Populating: filesystem"
180 for d in bin dev etc lib root run home proc media sbin sys \
181 usr/bin usr/sbin usr/share var/log var/cache var/lib var/run
182 do
183 mkdir -p ${rootfs}/${d}
184 done
185 install -d -m 1777 ${rootfs}/tmp; check
187 # /etc + /dev
188 create_etc_files
189 create_dev_files
191 # Initial sebfs from initfs: files can be modified
192 [ ! -d "$sebfs" ] && init
194 # GNU libc before chroot /bin/busybox --install + name resolution
195 for lib in /lib/libm[-.]* /lib/libc[-.]* /lib/ld-* /lib/libpthread*; do
196 echo -n "Installing: $lib"
197 cp -a ${lib} ${rootfs}/lib && check
198 done
199 install_files "/lib/libnss_dns*" "/lib/libnss_file*" "/lib/libresolv*"
201 # Busybox applets
202 action "Installing: busybox"
203 cp -a /bin/busybox ${rootfs}/bin
204 chroot ${rootfs} /bin/busybox --install -s; check
206 # Busybox configs
207 echo -n "Installing: busybox configs"
208 cp -r /usr/share/udhcpc ${rootfs}/usr/share
209 cp -f /etc/udhcpd.conf ${rootfs}/etc
210 cp -f /etc/httpd.conf ${rootfs}/etc
211 check
213 # Busybox keymap
214 echo -n "Dumping : keymap"
215 mkdir -p ${rootfs}/usr/share/kmap
216 dumpkmap > ${rootfs}/usr/share/kmap/default; check
218 # Kilo editor (20K) with syntax highlight and search (Thanks Paul :-)
219 action "Installing: kilo text editor"
220 cp -a ${tools}/kilo ${rootfs}/usr/bin; check
222 # Ncursesw && dialog for sebos and additional tools
223 install_files "/lib/libncursesw.so*" "/lib/libtinfo.so*"
224 mkdir -p ${rootfs}/usr/share/terminfo/l
225 cp /usr/share/terminfo/l/linux ${rootfs}/usr/share/terminfo/l
226 install_files "/usr/bin/dialog" "/etc/dialogrc"
228 # /lib/libseb.sh & sebos config tool
229 echo -n "Installing: /lib/libseb.sh"
230 cp ${libseb} ${rootfs}/lib; check
231 action "Installing: sebos config tool"
232 cp ${tools}/sebos ${rootfs}/usr/bin; check
234 # httphelper.sh for amazing CGI/Shell functions
235 mkdir -p ${rootfs}/usr/lib/slitaz
236 cp /usr/lib/slitaz/httphelper.sh ${rootfs}/usr/lib/slitaz
238 # Packages TODO: handle deps
239 touch ${rootfs}/var/lib/packages
240 for pkg in $(ls $sebpkgs); do
241 echo -n $(colorize 035 "Installing package:"); info 036 "$pkg"
242 . ${sebpkgs}/${pkg}
243 seb_install; echo "$pkg|$desc" >> ${rootfs}/var/lib/packages
244 done
246 # Custom files NOW
247 if [ -d "$sebfs" ]; then
248 echo -n "Copying custom files from sebfs..."
249 cp -rf ${sebfs}/* ${rootfs}; check
250 fi
252 # COPYING
253 mkdir -p ${rootfs}/usr/share/licenses
254 cat > ${rootfs}/usr/share/licenses/COPYING << EOT
255 Copyright (c) 2007-$(date '+%Y') SliTaz GNU/Linux
257 SliTaz is free software; you can redistribute it and/or modify it under
258 the terms of the GNU General Public License as published by the Free
259 Software Foundation; either version 3 of the License, or (at your option)
260 any later version.
262 SliTaz is distributed in the hope that it will be useful, but WITHOUT ANY
263 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
264 FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
266 EOT
268 # Build date
269 cat >> ${rootfs}/etc/seb.conf << EOT
271 # Seb-OS Build date
272 build_date="$(date '+%Y%m%d')"
274 # Seb-OS/SliTaz release string
275 seb_os_release="$(cat /etc/slitaz-release)"
277 EOT
279 # Security check
280 chown -R 0.0 ${rootfs}
281 chmod 0600 ${rootfs}/etc/busybox.conf
283 # Rootfs archive
284 action "Creating the initramfs..."
285 cd ${rootfs}
286 find . -print | cpio -o -H newc | lzma e -si -so \
287 > ${rootiso}/boot/rootfs.gz 2>/dev/null
288 check
290 # Linux Kernel
291 echo -n "Copying the Linux kernel..."
292 cp ${linux} ${rootiso}/boot/bzImage; check
294 # Bootloader
295 echo -n "Copying the bootloader (isolinux)..."
296 cp ${tools}/isolinux.bin ${rootiso}/boot/isolinux; check
298 echo -n "Creating bootloader configs..."
299 cat > ${rootiso}/boot/isolinux/isolinux.cfg << EOF
300 display display.txt
301 default seb
302 label seb
303 kernel /boot/bzImage
304 append initrd=/boot/rootfs.gz rw root=/dev/null rdinit=/sbin/init loglevel=5
305 implicit 0
306 prompt 1
307 timeout 40
308 EOF
309 cat > ${rootiso}/boot/isolinux/display.txt << EOF
311 ____ _ _ _ _ ___ _
312 / ___| \ | | | | | / / | (_)_ __ _ ___ __
313 | | _| \| | | | |/ /| | | | '_ \| | | \ \/ /
314 | |_| | |\ | |_| / / | |___| | | | | |_| |> <
315 \____|_| \_|\___/_/ |_____|_|_| |_|\__,_/_/\_\
317 SliTaz Embedded OS - Press <ENTER> to boot
318 www.slitaz.org
321 EOF
322 check
324 echo -n "Checking rootfs size..."
325 info 035 $(du -mhs $rootfs | awk '{print $1}')
326 echo -n "Installed files in rootfs..."
327 info 036 $(find ${rootfs} -type f | wc -l)
329 # ISO image
330 geniso; footer
331 }
333 # Handle seb packages
334 packages_handler() {
336 # List avalaible packages
337 if [ ! "$1" ]; then
338 title "Seb packages"
339 for pkg in $(ls ${packages}); do
340 . ${packages}/${pkg}
341 echo -n "$(colorize 036 $pkg)"; indent 20 "$desc"
342 unset desc deps
343 done
344 footer && exit 0
345 fi
347 # Add package(s)
348 if [ "$add" ]; then
349 for pkg in ${@}; do
350 case "$pkg" in
351 --*) continue ;;
352 *)
353 if [ -f "$packages/$pkg" ]; then
354 echo -n "Addind package: $pkg"
355 mkdir -p ${sebpkgs}
356 cp -f ${packages}/${pkg} ${sebpkgs}; check
357 else
358 echo "Can't find package: $package/$pkg"
359 fi ;;
360 esac
361 done
362 fi
363 }
365 # Handle vdisk: create, check, mount, umount
366 vdisk_hanler() {
367 title "SEB Virtual disk"
368 vsize=40960
369 root=${vdisk%.img}
371 # Info or create
372 if [ -f "$vdisk" ]; then
373 echo -n "Virtual disk: $vdisk"
374 info 035 "$(du -mhs $vdisk | awk '{print $1}')"
375 else
376 echo "Creating virtual disk image..."
377 dd if=/dev/zero of=${vdisk} bs=1k count=${vsize}
378 action "Creating ext3 filesystem..."; echo
379 mkfs.ext3 -L "SebOShome" ${vdisk}
380 fi
382 # Check
383 if [ "$check" ]; then
384 echo "Umounting vdisk before: e2fsck -p"
385 umount ${vdisk} >/dev/null
386 e2fsck -p ${vdisk}
387 fi
389 # Action: mount/unmount
390 if ! mount | grep -q "^$vdisk"; then
391 echo -n "Mounting virtual disk..."; mkdir -p ${root}
392 mount -o loop -t ext3 ${vdisk} ${root}; status
393 else
394 echo -n "Unmounting virtual disk..."
395 umount ${vdisk}; status; sleep 1
396 fi; footer
397 }
399 #
400 # Commands
401 #
403 case "$1" in
405 -i|init)
406 rootfs="$sebfs"
407 echo -n "Creating files in: ${rootfs}"
408 init; check ;;
410 -b|build)
411 check_root
412 build
413 [ "$emu" ] && emulate ${work}/${iso} ;;
415 -g|geniso)
416 check_root
417 geniso ;;
419 -c|clean)
420 check_root
421 echo -n "Cleaning: ${work}"
422 [ "$all" ] && rm -rf ${sebfs} ${cache}
423 rm -rf ${rootfs}* ${rootiso} ${work}/*.iso
424 check ;;
426 -p|package*)
427 shift
428 packages_handler "$@" ;;
430 -v|vdisk)
431 vdisk_hanler ;;
433 -l|lsfs)
434 title "Listing: $rootfs"
435 cd ${rootfs}; find . -type f | sed s'/^.//'g
436 footer "Rootfs files: $(find . -type f | wc -l)" ;;
438 -e|emu)
439 title "Emulating: $iso"
440 emulate ${work}/${iso}
441 footer ;;
443 env)
444 title "SEB environment"
445 cat << EOT
446 work=$work
447 rootfs=$rootfs
448 rootiso=$rootiso
449 sebfs=$sebfs
450 sebpkgs=$sebpkgs
451 cache=$cache
452 vdisk=$vdisk
453 tools=$tools
454 initfs=$initfs
455 packages=$packages
456 iso=$iso
457 linux=$linux
458 EOT
459 footer ;;
461 -t|testsuite)
462 # Development purpose
463 ${tools}/libseb.sh ;;
465 *) help ;;
467 esac && exit 0