From a21d783923affcc8853f0d65ab6d9713dd3de203 Mon Sep 17 00:00:00 2001 From: johndah4x0r Date: Wed, 26 Jul 2017 12:49:13 +0200 Subject: [PATCH] Re-update all --- build | 42 +++++++++----- initramfs/init | 4 +- livekitlib | 147 ++++++++++++++++++++++++++----------------------- 3 files changed, 109 insertions(+), 84 deletions(-) diff --git a/build b/build index 51b20ed..0a97276 100755 --- a/build +++ b/build @@ -6,22 +6,23 @@ # Environment path export PATH="${PATH}:.:./tools:../tools" - -CHANGEDIR="$(dirname $0)" -echo "Changing current directory to $CHANGEDIR" -CWD="$(pwd)" -cd "$CHANGEDIR" - source ./.config || exit 1 source ./livekitlib || exit 1 # only root can continue, because only root can read all files from your system allow_only_root +# Change directory to build environment +CHANGEDIR="$(dirname $0)" +echo "Changing current directory to $CHANGEDIR" +CWD="$(pwd)" +cd "$CHANGEDIR" + + # It's building time! clear -echo_livekit_msg "build: Linux Live Kit version 2.0 Improved" +echo_sign "BUILD SCRIPT" echo_livekit_msg "build: Doing a self-check..." # Start with 0 errors @@ -40,9 +41,11 @@ MKISOFS="$(which mkisofs 2>/dev/null || \ which genisoimage 2>/dev/null)" if [ -z "$MKISOFS" ]; then echo_err "build: 'mkisofs' / 'genisoimage': not-avail" - (( ERRS+=1 )) + + # Hahaha! 'false'?!?!? + MKISOFS="false" else - echo_livekit_msg "build: '`basename $MKISOFS`': avail" + echo_livekit_msg "build: '$(basename $MKISOFS)': avail" fi # Check if we have 'zip' @@ -114,7 +117,7 @@ cat bootfiles/BootInstall.sh | sed -r "s:MyLinux:$LIVEKITNAME:" > $BOOT/BootInst echo_livekit_msg "build: Copying kernel..." cp $VMLINUZ $BOOT/ -# Copy files from include_bund/, but +# Copy files from include_bund/, but # do not skip bundle creation # if [ -n "$(ls -A include_bund/ | grep ".$BEXT")" ]; then @@ -165,9 +168,14 @@ echo_livekit_msg "build: Creating ISO file for CD boot..." -R -D -A "$LIVEKITNAME" -V "$LIVEKITNAME" \ -no-emul-boot -boot-info-table -boot-load-size 4 \ -b "$LIVEKITNAME"/boot/isolinux.bin -c \ -"$LIVEKITNAME"/boot/isolinux.boot . &>/dev/null && \ -echo_livekit_msg "build: Output file: $OUT_FILE.iso" || \ -echo_err "build: $OUT_FILE.iso: Failed to generate ISO file!" +"$LIVEKITNAME"/boot/isolinux.boot . &>/dev/null +if [ $? -ne 0 ]; then + echo_warn "build: Failed to generate ISO image!" + SCAN= +else + echo_livekit_msg "build: ISO image: $OUT_FILE.iso" + SCAN=1 +fi # Substitute 'mylinux' with $LIVEKITNAME cat "$CWD/bootinfo.txt" | fgrep -v "#" | \ @@ -188,7 +196,13 @@ echo_livekit_msg "build: Process ID: $PID - Your results is in $TARGET" # Generate checksum(s) echo_livekit_msg "build: Generating MD5 checksums: Please wait..." -MD5_ISO="$(md5sum $TARGET/$OUT_FILE.iso 2>/dev/null | cut -d ' ' -f 1)" + +if [ "$SCAN" ]; then + MD5_ISO="$(md5sum $TARGET/$OUT_FILE.iso 2>/dev/null | cut -d ' ' -f 1)" +else + MD5_ISO="< FAILED TO GENERATE ISO IMAGE! >" +fi + MD5_ZIP="$(md5sum $TARGET/$OUT_FILE.zip 2>/dev/null | cut -d ' ' -f 1)" cat >"$SUM_FILE" <&2 + if [ "$DEBUG_IS_ENABLED" ]; then + echo "[${GREEN}"' debug '"${NC}]: $@" >&2 log "debug_log: $*" fi } +# echo related functions + # echo fatal tag # $1 = text to show echo_fatal() { - echo -e "[${RED}"' fatal '"${NC}] $@" >&2 + echo "[${RED}"' fatal '"${NC}] $@" >&2 } # echo bold @@ -72,30 +75,36 @@ echo_fatal() # echo_bold() { - echo -e "$BOLD""$@""$NC" + echo "$BOLD""$@""$NC" } # echo livekit tag echo_livekit() { - echo -ne "[${BLUE}"'livekit'"${NC}] " + echo "[${BLUE}"'livekit'"${NC}] " } echo_livekit_msg() { - echo -e "[${BLUE}"'livekit'"${NC}] $@" + echo "[${BLUE}"'livekit'"${NC}] $@" } # echo error echo_err() { - echo -e "[${RED}"' error '"${NC}] $@" >&2 + echo "[${RED}"' error '"${NC}] $@" >&2 } # echo warn echo_warn() { - echo -e "[${YELLOW}"' warn! '"${NC}] $@" >&2 + echo "[${YELLOW}"' warn! '"${NC}] $@" >&2 +} + +# echo signature +echo_sign() +{ + echo "${BOLD}"' Linux Live Kit Improved v1.0 - '"$* ${NC}" } # log - store given text in /var/log/livedbg @@ -113,11 +122,10 @@ echolog() # show information about the debug shell show_debug_banner() { - echo_livekit >&2 - echo "Debugging shell started." >&2 + echo_sign "DEBUGGING MODE" echo "The root shell is prepared for you!" >&2 echo "Type your desired commands or press Ctrl-D to continue booting." >&2 - echo + echo >&2 } # debug_shell @@ -125,7 +133,7 @@ show_debug_banner() # debug_shell() { - if [ "$DEBUG_IS_ENABLED" ]; then + if [ "$DBG_SHELL" ]; then show_debug_banner setsid sh -c 'exec sh < /dev/tty1 >/dev/tty1 2>&1' echo @@ -136,9 +144,8 @@ fatal() { log "FatalError: $@" echo_fatal "$@" - echo -e "${RED}"'Please reboot this system now!'"${NC}" - echo -e "${BOLD}"'Live Kig Log: /var/log/livekit-log'"${NC}" - echo -e "${BOLD}"'To get more information, please consult Live Kit Log for more info.'"${NC}" + echo_sign "EMERGENCY MODE" >&2 + echo_bold "Please consult /var/log/livekit-log for more info." >&2 setsid sh -c 'exec sh < /dev/tty1 >/dev/tty1 2>&1' } @@ -148,7 +155,7 @@ fatal() allow_only_root() { if [ "0$UID" -ne 0 ]; then - echo_err "Only root can run `basename $0`"; exit 1 + echo_err "Only root can run $(basename $0)"; exit 1 fi } @@ -207,7 +214,7 @@ transfer_initramfs() fi } -# mount virtual filesystems like proc etc +# mount virtual filesystems like proc, sys and such # init_proc_sysfs() { @@ -276,13 +283,14 @@ init_aufs() debug_log "init_aufs" "$*" # TODO maybe check here if aufs support is working at all # and produce useful error message if user has no aufs - modprobe aufs 2>/dev/null + modprobe aufs 2>/var/log/livekit-log - # if aufs module failed to load, panic immidiately + # TODO ACCOMPLISHED: + # If aufs module failed to load, panic immidiately if [ $? -ne 0 ]; then fatal "Failed to load AUFS module!" fi - + # finally, refresh all devices refresh_devs } @@ -344,16 +352,19 @@ mounted_dir() # device_bestfs() { - debug_log "device_bestfs" "$*" - local FS + debug_log "device_bestfs" "$*" + local FS - FS="$(blkid "$1" | sed -r "s/.*TYPE=//" | tr -d '"' | tr [A-Z] [a-z] | cut -d ' ' -f 1)" - if [ "$FS" = "msdos" -o "$FS" = "fat" ]; then - FS="vfat" - elif [ "$FS" = "ntfs" ]; then - FS="ntfs-3g" - fi - echo "-t $FS" + FS="$(blkid "$1" | sed -r "s/.*TYPE=//" | tr -d '"' | \ + tr "[A-Z]" "[a-z]" | cut -d ' ' -f 1)" + if [ "$FS" = "msdos" -o "$FS" = "fat" ]; then + FS="vfat" + elif [ "$FS" = "ntfs" ]; then + FS="ntfs-3g" + else + FS="$FS" + fi + echo "-t $FS" } # Filesystem options for mount @@ -463,38 +474,38 @@ download_data_pxe() # find_data_try() { - debug_log "find_data_try" "$*" + debug_log "find_data_try" "$*" - local DEVICE FS FROM OPTIONS + local DEVICE FS FROM OPTIONS - mkdir -p "$1" - blkid | sort | cut -d: -f 1 | grep -E -v "/loop|/ram|/zram" | while read DEVICE; do - FROM="$2" - FS="$(device_bestfs "$DEVICE")" - OPTIONS="$(fs_options $FS)" - mount -r "$DEVICE" "$1" $FS $OPTIONS 2>/dev/null + mkdir -p "$1" + blkid | sort | cut -d: -f 1 | grep -E -v "/loop|/ram|/zram" | while read DEVICE; do + FROM="$2" + FS="$(device_bestfs "$DEVICE")" + OPTIONS="$(fs_options $FS)" + mount -r "$DEVICE" "$1" $FS $OPTIONS 2>/dev/null - # if the FROM parameter is actual file, mount it again as loop (eg. iso) - if [ -f "$1/$FROM" ]; then - mount -o remount,rw "$DEVICE" "$1" 2>/dev/null - mkdir -p "$1/../iso" - mount -o loop,ro "$1/$FROM" "$1/../iso" 2>/dev/null - FROM="../iso/$LIVEKITNAME" - fi + # if the FROM parameter is actual file, mount it again as loop (eg. iso) + if [ -f "$1/$FROM" ]; then + mount -o remount,rw "$DEVICE" "$1" 2>/dev/null + mkdir -p "$1/../file" + mount -o loop,ro "$1/$FROM" "$1/../file" 2>/dev/null + FROM="../file/$LIVEKITNAME" + fi - # search for bundles in the mounted directory - if [ "$(find "$1/$FROM" -maxdepth 1 -name "*.$BEXT" 2>/dev/null)" != "" ]; then - # we found at least one bundle/module here - mount -o remount,rw "$DEVICE" "$1" 2>/dev/null - echo "$1/$FROM" | tr -s "/" | sed -r "s:/[^/]+/[.][.]/:/:g" - return - fi + # search for bundles in the mounted directory + if [ "$(find "$1/$FROM" -maxdepth 1 -name "*.$BEXT" 2>/dev/null)" != "" ]; then + # we found at least one bundle/module here + mount -o remount,rw "$DEVICE" "$1" 2>/dev/null + echo "$1/$FROM" | tr -s "/" | sed -r "s:/[^/]+/[.][.]/:/:g" + return + fi - # unmount twice, since there could be mounted ISO as loop too. If not, it doesn't hurt - umount "$1" 2>/dev/null - umount "$1" 2>/dev/null - done -} + # unmount twice, since there could be mounted ISO as loop too. If not, it doesn't hurt + umount "$1" 2>/dev/null + umount "$1" 2>/dev/null + done + } # Retry finding LIVEKIT data several times, # until timeouted or until data is found