From 666742f226aa21a54b1012f6b107ec3ad51643ce Mon Sep 17 00:00:00 2001 From: Tomas M Date: Sat, 1 Sep 2012 11:15:50 +0100 Subject: [PATCH] initial functions --- .config | 4 +-- README | 7 ++-- build | 6 ++++ tools/linuxkitlib | 89 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 100 insertions(+), 6 deletions(-) diff --git a/.config b/.config index 4b7121b..618cbc7 100644 --- a/.config +++ b/.config @@ -1,6 +1,6 @@ #!/bin/bash -# This is a config file for build script. -# You shouldn't need to change anything +# This is a config file for Linux Live Kit build script. +# You shouldn't need to change anything expect LIVEKITNAME # Live Kit Name. Defaults to 'mylinux'; # For example, Slax changes it to 'slax' diff --git a/README b/README index 3440069..86da425 100644 --- a/README +++ b/README @@ -4,9 +4,12 @@ Linux Live Kit Use this set of scripts to turn your existing preinstalled Linux distribution into a Live Kit (formely known as Live CD). -First of all, edit the file ./.config +* First of all, read files in ./DOC directory + +* Before you start building your Kit, edit the file ./.config + +* When done editing, run the ./build script to create your Live Kit -Then run the build script to create your Live Kit Author: Tomas M. See DOC/GNU_GPL and DOC/LICENSE for license information diff --git a/build b/build index d00b441..1ae0a48 100755 --- a/build +++ b/build @@ -13,3 +13,9 @@ cd $CHANGEDIR # only root can continue, because only root can read all files from your system allow_only_root +# find necessary tools (mksquashfs, namely) + +# build initramfs image + +# create compressed bundles + diff --git a/tools/linuxkitlib b/tools/linuxkitlib index 623b5a7..e2d5d53 100644 --- a/tools/linuxkitlib +++ b/tools/linuxkitlib @@ -1,14 +1,99 @@ #!/bin/bash -# Functions library :: for Linux Kit scripts 7 +# Functions library :: for Linux Live Kit scripts # Author: Tomas M. # +# ================================================================= +# debug and output functions +# ================================================================= + +# global variable +DEBUG_IS_ENABLED=$(cat /proc/cmdline 2>/dev/null | grep debug) + +debug_log() +{ + if [ "$DEBUG_IS_ENABLED" ]; then + echo "- debug: $*" >&2 + log "- debug: $*" + fi +} + +# header +# $1 = text to show +# +header() +{ + echo """$@""" +} + + +# echogreen will echo $@ in green color +# $1 = text +# +echogreen() +{ + echo -ne """$@""" +} + +# log - store given text in /var/log/livedbg +log() +{ + echo "$@" 2>/dev/null >>/var/log/livedbg +} + +# show information about the debug shell +show_debug_banner() +{ + echo + echo "=====" + echo ": Debugging started. Here is the root shell for you." + echo ": Type your desired commands or hit Ctrl+D to continue booting." + echo +} + +# debug_shell +# executed when debug boot parameter is present +# +debug_shell() +{ + if [ "$DEBUG_IS_ENABLED" ]; then + show_debug_banner + bash < /dev/console + echo + fi +} + +fatal() +{ + echolog + header "Fatal error occured - $1" + echolog "Something went wrong and we can't continue. This should never happen." + echolog "Please reboot your computer with Ctrl+Alt+Delete ..." + echolog + bash < /dev/console +} + + +# test if the script is started by root user. If not, exit +# allow_only_root() { - # test if the script is started by root user. If not, exit if [ "0$UID" -ne 0 ]; then echo "Only root can run $(basename $0)"; exit 1 fi } +# Create bundle +# call mksquashfs with apropriate arguments +# $1 = directory which will be compressed to squashfs bundle +# $2 = output file +# $3..$9 = optional arguments like -keep-as-directory or -b 123456789 +# +create_bundle() +{ + debug_log "create_module" "$*" + rm -f "$2" # overwrite, never append to existing file + mksquashfs "$1" "$2" -comp xz -b 512K $3 $4 $5 $6 $7 $8 $9>/dev/null +} +