slitaz-tools diff tinyutils/frugal @ rev 817

Add: frugal (small to to handle SliTaz frugal install from cmdline)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Jan 02 18:52:54 2014 +0100 (2014-01-02)
parents
children a4f64dd9b359
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tinyutils/frugal	Thu Jan 02 18:52:54 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Frugal is a tiny tool to handle SliTaz frugal installation.
     1.7 +#
     1.8 +# Copyright (C) 2013 SliTaz GNU/Linux - BSD License
     1.9 +#
    1.10 +# Author: Christophe Lincoln <pankso@slitaz.org>
    1.11 +#
    1.12 +. /lib/libtaz.sh
    1.13 +
    1.14 +[ "$root" ] || root="/boot/frugal"
    1.15 +
    1.16 +# NOTES:
    1.17 +#	Have a --web option to dl ISO ?
    1.18 +#	Auto configure GRUB ?
    1.19 +#
    1.20 +
    1.21 +# Internationalization
    1.22 +. /usr/bin/gettext.sh
    1.23 +TEXTDOMAIN='slitaz-tools'
    1.24 +export TEXTDOMAIN
    1.25 +
    1.26 +#
    1.27 +# Functions
    1.28 +#
    1.29 +
    1.30 +# Small help and usage.
    1.31 +usage() {
    1.32 +	name=$(basename $0)
    1.33 +	cat << EOT
    1.34 +
    1.35 +$(boldify $(gettext "Usage:")) $name [iso|command] [--options]
    1.36 +
    1.37 +$(gettext "SliTaz frugal installation")
    1.38 +
    1.39 +$(boldify $(gettext "Commands:"))
    1.40 +  info        $(gettext "Display install path and size stats")
    1.41 +  clean       $(gettext "Remove all frugal files")
    1.42 +  grub-ex     $(gettext "Show GRUB configuration example")
    1.43 +
    1.44 +$(boldify $(gettext "Options:"))
    1.45 +  --root=     $(gettext "Set root installation path")
    1.46 +  --debug     $(gettext "Display some useful debug information")
    1.47 +
    1.48 +$(boldify $(gettext "Examples:"))
    1.49 +  $name slitaz-rolling.iso
    1.50 +  $name slitaz-5.0.iso --root=/boot/frugal
    1.51 +
    1.52 +EOT
    1.53 +}
    1.54 +
    1.55 +# GRUB config example.
    1.56 +grub_example() {
    1.57 +	cat << EOT
    1.58 +title SliTaz GNU/Linux (frugal)
    1.59 +root (hd0,0)
    1.60 +kernel /boot/frugal/bzImage root=/dev/null lang=en kmap=us
    1.61 +initrd /boot/frugal/rootfs.gz
    1.62 +EOT
    1.63 +}
    1.64 +
    1.65 +#
    1.66 +# Commands
    1.67 +#
    1.68 +
    1.69 +case "$1" in
    1.70 +	"") usage ;;
    1.71 +	info)
    1.72 +		newline
    1.73 +		boldify "Frugal info"
    1.74 +		separator 
    1.75 +		# First check if we are running in frugal mode
    1.76 +		if fgrep -q 'root=/dev/null' /proc/cmdline; then
    1.77 +			gettext "Frugal system running detected"; newline
    1.78 +			separator && newline && exit 0
    1.79 +		fi
    1.80 +		gettext "Installation directory:"; indent 30 $(colorize 36 "$root")
    1.81 +		gettext "Kernel size:"
    1.82 +		if [ -f "${root}/bzImage" ]; then
    1.83 +			indent 30 $(du -sh ${root}/bzImage | awk '{print $1}')
    1.84 +		else
    1.85 +			indent 30 $(boldify "N/A")
    1.86 +		fi
    1.87 +		gettext "Rootfs size:"
    1.88 +		if [ -f "${root}/rootfs.gz" ]; then
    1.89 +			indent 30 $(du -sh ${root}/rootfs.gz | awk '{print $1}')
    1.90 +		else
    1.91 +			indent 30 $(boldify "N/A")
    1.92 +		fi
    1.93 +		separator && newline ;;
    1.94 +	clean)
    1.95 +		check_root
    1.96 +		gettext "Cleaning:"; echo " $root"
    1.97 +		rm -rf ${root}/* ;;
    1.98 +	grub-ex)
    1.99 +		newline
   1.100 +		boldify "GRUB config example"
   1.101 +		separator
   1.102 +		grub_example
   1.103 +		separator && newline ;;
   1.104 +	*)
   1.105 +		iso="$1"
   1.106 +		loop="/tmp/frugal-$$"
   1.107 +		check_root
   1.108 +		newline
   1.109 +		boldify "SliTaz Frugal"
   1.110 +		separator
   1.111 +		if [ ! -f "$iso" ]; then
   1.112 +			gettext "Unable to find ISO image:"; colorize 31 " $iso"
   1.113 +			newline && return 1
   1.114 +		fi
   1.115 +		debug "$iso $root"
   1.116 +		gettext "Mounting ISO image..."
   1.117 +		mkdir -p ${loop}
   1.118 +		mount -o loop "$iso" ${loop} 2>/dev/null
   1.119 +		status
   1.120 +		gettext "Installing the Kernel..."
   1.121 +		cp -a ${loop}/boot/bzImage ${root}
   1.122 +		status
   1.123 +		gettext "Installing the root filesystem..."
   1.124 +		if [ -f ${loop}/boot/rootfs1.gz ]; then
   1.125 +			cd ${loop}/boot
   1.126 +			cat $(ls -r rootfs*.gz) > ${root}/rootfs.gz
   1.127 +			cd - >/dev/null
   1.128 +		else
   1.129 +			cp -a ${loop}/boot/rootfs.gz ${root}
   1.130 +		fi
   1.131 +		status
   1.132 +		# Umount the loop device
   1.133 +		gettext "Unmounting ISO image..."
   1.134 +		sleep 1
   1.135 +		umount ${loop} && rm -rf ${loop}
   1.136 +		status
   1.137 +		separator && newline ;;
   1.138 +esac
   1.139 +
   1.140 +exit 0