slitaz-tools view tinyutils/frugal @ rev 839

frugal: create root dir
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 19 19:27:02 2014 +0100 (2014-03-19)
parents 3da34f57cbb3
children 5d80f6fdbdb7
line source
1 #!/bin/sh
2 #
3 # Frugal is a tiny tool to handle SliTaz frugal installation.
4 #
5 # Copyright (C) 2013 SliTaz GNU/Linux - BSD License
6 #
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
11 [ "$root" ] || root="/boot/frugal"
13 # NOTES:
14 # Have a --web option to dl ISO ?
15 # Auto configure GRUB ?
16 #
18 # Internationalization
19 . /usr/bin/gettext.sh
20 TEXTDOMAIN='slitaz-tools'
21 export TEXTDOMAIN
23 #
24 # Functions
25 #
27 # Small help and usage.
28 usage() {
29 name=$(basename $0)
30 cat << EOT
32 $(boldify $(gettext "Usage:")) $name [iso|command] [--options]
34 $(gettext "SliTaz frugal installation")
36 $(boldify $(gettext "Commands:"))
37 info $(gettext "Display install path and size stats")
38 clean $(gettext "Remove all frugal files")
39 grub-ex $(gettext "Show GRUB configuration example")
41 $(boldify $(gettext "Options:"))
42 --root= $(gettext "Set root installation path")
43 --debug $(gettext "Display some useful debug information")
45 $(boldify $(gettext "Examples:"))
46 $name slitaz-rolling.iso
47 $name slitaz-5.0.iso --root=/boot/frugal
49 EOT
50 }
52 # GRUB config example.
53 grub_example() {
54 cat << EOT
55 title SliTaz GNU/Linux (frugal)
56 root (hd0,0)
57 kernel /boot/frugal/bzImage root=/dev/null lang=en kmap=us
58 initrd /boot/frugal/rootfs.gz
59 EOT
60 }
62 #
63 # Commands
64 #
66 case "$1" in
67 "") usage ;;
68 info)
69 newline
70 boldify "Frugal info"
71 separator
72 # First check if we are running in frugal mode
73 if fgrep -q 'root=/dev/null' /proc/cmdline; then
74 gettext "Frugal system running detected"; newline
75 separator && newline && exit 0
76 fi
77 gettext "Installation directory:"; indent 30 $(colorize 36 "$root")
78 gettext "Kernel size:"
79 if [ -f "${root}/bzImage" ]; then
80 indent 30 $(du -sh ${root}/bzImage | awk '{print $1}')
81 else
82 indent 30 $(boldify "N/A")
83 fi
84 gettext "Rootfs size:"
85 if [ -f "${root}/rootfs.gz" ]; then
86 indent 30 $(du -sh ${root}/rootfs.gz | awk '{print $1}')
87 else
88 indent 30 $(boldify "N/A")
89 fi
90 separator && newline ;;
91 clean)
92 check_root
93 gettext "Cleaning:"; echo " $root"
94 rm -rf ${root}/* ;;
95 grub-ex)
96 newline
97 boldify "GRUB config example"
98 separator
99 grub_example
100 separator && newline ;;
101 *)
102 iso="$1"
103 loop="/tmp/frugal-$$"
104 check_root
105 newline
106 boldify "SliTaz Frugal"
107 separator
108 if [ ! -f "$iso" ]; then
109 gettext "Unable to find ISO image:"; colorize 31 " $iso"
110 newline && return 1
111 fi
112 mkdir -p ${root}
113 debug "$iso $root"
114 gettext "Mounting ISO image..."
115 mkdir -p ${loop}
116 mount -o loop "$iso" ${loop} 2>/dev/null
117 status
118 gettext "Installing the Kernel..."
119 cp -a ${loop}/boot/bzImage ${root}
120 status
121 gettext "Installing the root filesystem..."
122 if [ -f ${loop}/boot/rootfs1.gz ]; then
123 cd ${loop}/boot
124 cat $(ls -r rootfs*.gz) > ${root}/rootfs.gz
125 cd - >/dev/null
126 else
127 cp -a ${loop}/boot/rootfs.gz ${root}
128 fi
129 status
130 # Umount the loop device
131 gettext "Unmounting ISO image..."
132 sleep 1
133 umount ${loop} && rm -rf ${loop}
134 status
135 separator && newline ;;
136 esac
138 exit 0