From f2b3b5f5303f0985b7d82c785ce90317144d81c5 Mon Sep 17 00:00:00 2001 From: 6543 Date: Mon, 30 Apr 2018 18:57:01 +0200 Subject: [PATCH] Split main func (no os/proj dependency) --- autogen.sh | 5 +- src/func/check_dependency | 16 ++ src/func/check_user | 13 ++ src/func/chroot_clean | 18 ++ src/func/chroot_initial | 27 +++ src/func/chroot_is_mounted | 18 ++ src/func/chroot_sh | 25 +++ src/func/chroot_umount | 27 +++ src/func/error_code | 61 +++++++ src/func/filesystem_extract | 44 +++++ src/func/filesystem_get_type | 11 ++ src/func/filesystem_pack | 33 ++++ src/func/iso_create | 27 +++ src/func/iso_extract | 48 +++++ src/func/on_exit | 30 +++ src/func/workspace_erase | 15 ++ src/remaster.sh | 341 ++--------------------------------- 17 files changed, 432 insertions(+), 327 deletions(-) create mode 100644 src/func/check_dependency create mode 100644 src/func/check_user create mode 100644 src/func/chroot_initial create mode 100644 src/func/chroot_is_mounted create mode 100644 src/func/chroot_sh create mode 100644 src/func/chroot_umount create mode 100644 src/func/error_code create mode 100644 src/func/filesystem_extract create mode 100644 src/func/filesystem_get_type create mode 100644 src/func/filesystem_pack create mode 100644 src/func/iso_create create mode 100644 src/func/iso_extract create mode 100644 src/func/on_exit create mode 100644 src/func/workspace_erase diff --git a/autogen.sh b/autogen.sh index c984e1b..30fe4ad 100755 --- a/autogen.sh +++ b/autogen.sh @@ -23,8 +23,9 @@ chmod +x $rootdir/usr/bin/remaster # modules mkdir -p $rootdir/usr/lib/remaster/ -for i in dist functions mods; do - cp -v src/$i/* $rootdir/usr/lib/remaster/ +for i in proj func mods; do + mkdir -p $rootdir/usr/lib/remaster/$i + cp -v src/$i/* $rootdir/usr/lib/remaster/$i/ done # setting diff --git a/src/func/check_dependency b/src/func/check_dependency new file mode 100644 index 0000000..f4d773c --- /dev/null +++ b/src/func/check_dependency @@ -0,0 +1,16 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#check_dependency +# -> 0 | -> 16 +function check_dependency() { + for packet in squashfs-tools xorriso wget sed sendemail; do + [ "`dpkg -l $packet 2>&1`" == "dpkg-query: Kein Paket gefunden, das auf $packet passt" ] && { + echo "### ERROR ### Packet $packet not installed" + return 16 + } + done + return 0 +} diff --git a/src/func/check_user b/src/func/check_user new file mode 100644 index 0000000..e12019a --- /dev/null +++ b/src/func/check_user @@ -0,0 +1,13 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#check_user +function check_user() { + #check root + [ "`whoami`" == "root" ] || { + echo "### ERROR ### Remaster need ROOT permision!" + return 10 + } +} diff --git a/src/func/chroot_clean b/src/func/chroot_clean index e69de29..1ea9543 100644 --- a/src/func/chroot_clean +++ b/src/func/chroot_clean @@ -0,0 +1,18 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#chroot_clean [chroot_dir] +function chroot_clean() { + echo "clean chroot ... " + + chroot_dir="$1" + + chroot "$chroot_dir" /bin/bash -c "apt-get clean" + chroot "$chroot_dir" /bin/bash -c "rm -r /var/cache/apt/*" + chroot "$chroot_dir" /bin/bash -c "apt-get update" + chroot "$chroot_dir" /bin/bash -c "apt-get check" + + echo "done" +} diff --git a/src/func/chroot_initial b/src/func/chroot_initial new file mode 100644 index 0000000..c341464 --- /dev/null +++ b/src/func/chroot_initial @@ -0,0 +1,27 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#chroot_initial [chroot_dir] +function chroot_initial() { + echo -n "initial chroot ... " + + #check chroot dir + chroot_dir="$1" + [ -d "$chroot_dir" ] || { + echo "### ERROR ### chroot_initial: chroot directory not exist" + return 12 + } + + #mount virus definitions + mount -t tmpfs tmpfs "$chroot_dir/tmp" + mount -t tmpfs tmpfs "$chroot_dir/root" + mount --bind /dev "$chroot_dir/dev" + mount --bind /proc "$chroot_dir/proc" + + rm "$chroot_dir/etc/resolv.conf" + cp "/etc/resolv.conf" "$chroot_dir/etc/resolv.conf" + + echo "done" +} diff --git a/src/func/chroot_is_mounted b/src/func/chroot_is_mounted new file mode 100644 index 0000000..8f46f45 --- /dev/null +++ b/src/func/chroot_is_mounted @@ -0,0 +1,18 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#chroot_is_mounted [chroot_dir] +#(Boolean)-> true | false +function chroot_is_mounted() { + #$1 = chroot directory + + if [ "`mount | grep "$1"`" != "" ] ; then + #ther is smething mounted + echo "true" + else + #nothing mounted + echo "false" + fi +} diff --git a/src/func/chroot_sh b/src/func/chroot_sh new file mode 100644 index 0000000..9055051 --- /dev/null +++ b/src/func/chroot_sh @@ -0,0 +1,25 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#chroot_sh [chroot_dir] [command] +function chroot_sh() { + #check chroot dir + chroot_dir="$1" + [ -d "$chroot_dir" ] || { + echo "### ERROR ### chroot_sh: chroot directory not exist!" + return 12 + } + + command="$2" + + [ -f "$chroot_dir/tmp/env.sh" ] || { + #if not exist create environment skript + cat "$chroot_dir/etc/environment" | grep -v "#" | grep "=" > "$chroot_dir/tmp/env" + while read line; do echo export $line; done < "$chroot_dir/tmp/env" > "$chroot_dir/tmp/env.sh" + chmod +x "$chroot_dir/tmp/env.sh" && rm "$chroot_dir/tmp/env" + } + + chroot "$chroot_dir" /bin/bash --login -c ". /tmp/env.sh; $command" +} diff --git a/src/func/chroot_umount b/src/func/chroot_umount new file mode 100644 index 0000000..613998b --- /dev/null +++ b/src/func/chroot_umount @@ -0,0 +1,27 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#chroot_umount [chroot_dir] +function chroot_umount() { + echo -n "unmount chroot ... " + + #check chroot dir + chroot_dir="$1" + [ -d "$chroot_dir" ] || { + echo "### ERROR ### chroot_umount: chroot directory not exist!" + return 12 + } + + for d in "$chroot_dir/tmp" "$chroot_dir/root" "$chroot_dir/proc" "$chroot_dir/dev" ; do + umount $d + retval=$? + [ "$retval" -gt 0 ] && { + echo "### ERROR ### chroot_umount: can't umount \"$d\"!" + return 21 + } + done + + echo "done" +} diff --git a/src/func/error_code b/src/func/error_code new file mode 100644 index 0000000..a150e8b --- /dev/null +++ b/src/func/error_code @@ -0,0 +1,61 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#error_code [error_level] +function error_code() { + code="$1" + case $code in + "") + echo $'ID:\tDescription\n----------------------------------------------------\n1\tAllgemeiner Fehler\n2\tNo Paramters / wrong parameters' + echo $'3\tWrong Settings\n4\tProgramm missing\n\n10\tno root\n11\tfile no found\n12\tdir not found\n13\tcant create/delete file/dir' + echo $'14\tcorrupt file (unsquashfs, mount iso, ...)\n15\twrong file (iso has no squashfs-file ...)\n16\trequired Packet not found\n\n20\tmount error\n21\tunmoun error\n22\twrong filesystem' + ;; + 1) + echo "Allgemeiner Fehler" + ;; + 2) + echo "No Paramters / wrong parameters" + ;; + 3) + echo "Wrong Settings" + ;; + 4) + echo "Programm missing" + ;; + 10) + echo "not executed as Root" + ;; + 11) + echo "file no found" + ;; + 12) + echo "dir not found" + ;; + 13) + echo "cant create/delete file/dir" + ;; + 14) + echo "corrupt file (unsquashfs, mount iso, ...)" + ;; + 15) + echo "wrong file (iso has no squashfs-file ...)" + ;; + 16) + echo "required Packet not found" + ;; + 20) + echo "tmount error" + ;; + 21) + echo "unmoun error" + ;; + 22) + echo "wrong filesystem" + ;; + *) + echo $'No Defined Error Code.\nPerhaps an Error ocure on a Command wich was started by this Skritp.' + ;; + esac +} diff --git a/src/func/filesystem_extract b/src/func/filesystem_extract new file mode 100644 index 0000000..9c86de2 --- /dev/null +++ b/src/func/filesystem_extract @@ -0,0 +1,44 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#filesystem_extract [filesystem_img_source] [chroot_path] +function filesystem_extract() { + echo "extract filesystem ..." + + #$1 = filesystem_img_source + #$2 = chroot_path + filesystem_img_source="$1" + chroot_path="$2" + filesystem_log="`mktemp`" + + #Überfrüfen der Parameter + [ -f "$filesystem_img_source" ] || { + echo "### ERROR ### filesystem_extract: squashfs \"$filesystem_img_source\" not exist!" + return 11 + } + + [ "`mkdir -p "$chroot_path"`" != "" ] && { + echo "### ERROR ### filesystem_extract: chroot_path \"$chroot_path\" can't create!" + return 13 + } + + [ "`filesystem_get_type $chroot_path`" != "ext4" ] && [ "`filesystem_get_type $chroot_path`" != "btrfs" ] && { + echo "### ERROR ### filesystem_extract: wrong filesystem (`filesystem_get_type $chroot_path`)!" + return 22 + } + + rm -r "$chroot_path" + + #eigendliches entpacken + unsquashfs -d "$chroot_path" "$filesystem_img_source" > "$filesystem_log" || { + echo "### ERROR ### filesystem_extract: unsquashfs failed!" + return 14 + } + + grep -v "\[" "$filesystem_log" + rm "$filesystem_log" + + echo "done" +} diff --git a/src/func/filesystem_get_type b/src/func/filesystem_get_type new file mode 100644 index 0000000..927ee8f --- /dev/null +++ b/src/func/filesystem_get_type @@ -0,0 +1,11 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#filesystem_get_type [dir] +#(String)-> ext4, ext2, btfs, fuse, ... +function filesystem_get_type() { + fs_aTemp=(`df -T "$1"`) + echo ${fs_aTemp[9]} +} diff --git a/src/func/filesystem_pack b/src/func/filesystem_pack new file mode 100644 index 0000000..884498e --- /dev/null +++ b/src/func/filesystem_pack @@ -0,0 +1,33 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#filesystem_pack [chroot_path] [filesystem_img_destination] +function filesystem_pack() { + echo "pack filesystem ..." + + #$1 = chroot_path + #$2 = filesystem_img_destination + chroot_path="$1" + filesystem_img_destination="$2" + filesystem_log="`mktemp`" + + #Überfrüfen der Parameter + [ -d "$chroot_path" ] || { + echo "### ERROR ### filesystem_extract: chroot_path \"$chroot_path\" not exist!" + return 12 + } + + #loslegen ... + rm -f "$filesystem_img_destination" + mksquashfs "$chroot_path" "$filesystem_img_destination" > "$filesystem_log" || { + echo "### ERROR ### filesystem_pack: mksquashfs failed!" + return 13 + } + + grep -v "\[" "$filesystem_log" + rm "$filesystem_log" + + echo "done" +} diff --git a/src/func/iso_create b/src/func/iso_create new file mode 100644 index 0000000..ba58400 --- /dev/null +++ b/src/func/iso_create @@ -0,0 +1,27 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#iso_create [chroot_path] [iso_extr_dir] [iso_destination] [iso_lable] +function iso_create() { + echo -n "create iso ..." + + chroot_path="$1" + iso_extr_dir="$2" + iso_destination="$3" + iso_lable="$4" + + [ -e "$iso_destination" ] && rm "$iso_destination" + + xorriso -as mkisofs -graft-points -c isolinux/boot.cat -b isolinux/isolinux.bin \ + -no-emul-boot -boot-info-table -boot-load-size 4 -isohybrid-mbr \ + "$iso_extr_dir/isolinux/isolinux.bin" \ + -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \ + -isohybrid-gpt-basdat -V "$iso_lable" \ + -o "$iso_destination" \ + -r -J "$iso_extr_dir" \ + --sort-weight 0 / --sort-weight 2 /boot --sort-weight 1 /isolinux + + echo "done" +} diff --git a/src/func/iso_extract b/src/func/iso_extract new file mode 100644 index 0000000..3d6dd75 --- /dev/null +++ b/src/func/iso_extract @@ -0,0 +1,48 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#iso_extract [iso_source] [iso_extr_dir] +function iso_extract() { + echo -n "extract iso ... " + + #$1 = iso_source + #$2 = iso_extr_dir + + #check root + [ "`whoami`" == "root" ] || { + echo "### ERROR ### iso_extract: need root permision!" + return 10 + } + + iso_source="$1" + [ -f "$iso_source" ] || { + echo "### ERROR ### iso_extract: ISO \"$iso_source\" not exist!" + return 11 + } + + iso_extr_dir="$2" + [ -d "$iso_extr_dir" ] || { + echo "### ERROR ### iso_extract: aim directory not exist!" + return 12 + } + + #mace tmp mountpoint + tmpdir="`mktemp -d`" + [ -d "$iso_extr_dir" ] && { + rm -r "$iso_extr_dir/" + mkdir "$iso_extr_dir" + } + + #copy files ... + mount -o loop,ro "$iso_source" "$tmpdir" + cp -f -r "$tmpdir/"* "$iso_extr_dir" + + #clear tmp mountpoint + umount "$iso_source" + rm -r "$tmpdir" + tmpdir= + + echo "done" +} diff --git a/src/func/on_exit b/src/func/on_exit new file mode 100644 index 0000000..9c2bcb6 --- /dev/null +++ b/src/func/on_exit @@ -0,0 +1,30 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#on_exit [error_level] +function on_exit() { + #send log and errorlevel[success/errorr xy] + + if [ "$1" != "0" ]; then + log_mail_subject="$log_mail_subject [ERROR]" + else + log_mail_subject="$log_mail_subject [Success]" + fi + + #Mail Body: + for mail_aim in `echo "$log_mail_aim" | tr "," " "`; do + { + echo "$log_mail_subject" + echo $'####################################################################################\n\n' + cat "$log_file" + } | sendemail -s "$log_mail_smtp" -f "$log_mail_source" -t "$mail_aim" -u "$log_mail_subject" -o tls=no + done + + [ "$1" != "0" ] && { + chroot_umount$distro "$chroot_path" 2> /dev/null + workspace_erase "$iso_extr_dir/" "$chroot_path/" 2> /dev/null + } + exit $1 +} diff --git a/src/func/workspace_erase b/src/func/workspace_erase new file mode 100644 index 0000000..004f8b5 --- /dev/null +++ b/src/func/workspace_erase @@ -0,0 +1,15 @@ +#!/bin/bash +#remaster lib +[ -d "$LIBDR"] || export LIBDIR="/usr/lib/remaster/" +[ -d "$LIBDR"] || { echo "LIBDR not exist"; exit 1; } + +#workspace_erase [workspace_path] +function workspace_erase() { + echo -n "erase workspace ... " + + for dir in "$@"; do + [ -d "$dir" ] && rm -r -f "$dir" + done + + echo "done" +} diff --git a/src/remaster.sh b/src/remaster.sh index c509da1..a711897 100755 --- a/src/remaster.sh +++ b/src/remaster.sh @@ -14,7 +14,6 @@ export "rootdir=`readlink -e $rootdir`" #set functions if [ -p "$rootdir/usr/lib/remaster/" ]; then #source "$rootdir/usr/lib/remaster/" ... - export PATH="$rootdir/usr/lib/remaster/":$PATH export LIBDIR="$rootdir/usr/lib/remaster/" else echo "ERROR functions not found" @@ -477,11 +476,6 @@ function main_update() { main_update_pxe } -#remaster.sh error_code [error_level] -function main_error_code() { - error_code $1 -} - ##################################################################################### ################## F u n c t i o n s ################################################ ##################################################################################### @@ -489,268 +483,44 @@ function main_error_code() { ### Error Handlings ### #on_exit [error_level] -function on_exit() { - #send log and errorlevel[success/errorr xy] - - if [ "$1" != "0" ]; then - log_mail_subject="$log_mail_subject [ERROR]" - else - log_mail_subject="$log_mail_subject [Success]" - fi - - #Mail Body: - for mail_aim in `echo "$log_mail_aim" | tr "," " "`; do - { - echo "$log_mail_subject" - echo $'####################################################################################\n\n' - cat "$log_file" - } | sendemail -s "$log_mail_smtp" -f "$log_mail_source" -t "$mail_aim" -u "$log_mail_subject" -o tls=no - done - - [ "$1" != "0" ] && { - chroot_umount$distro "$chroot_path" 2> /dev/null - workspace_erase "$iso_extr_dir/" "$chroot_path/" 2> /dev/null - } - exit $1 -} +source $LIBDR/func/on_exit #error_code [error_level] -function error_code() { - code="$1" - case $code in - "") - echo $'ID:\tDescription\n----------------------------------------------------\n1\tAllgemeiner Fehler\n2\tNo Paramters / wrong parameters' - echo $'3\tWrong Settings\n4\tProgramm missing\n\n10\tno root\n11\tfile no found\n12\tdir not found\n13\tcant create/delete file/dir' - echo $'14\tcorrupt file (unsquashfs, mount iso, ...)\n15\twrong file (iso has no squashfs-file ...)\n16\trequired Packet not found\n\n20\tmount error\n21\tunmoun error\n22\twrong filesystem' - ;; - 1) - echo "Allgemeiner Fehler" - ;; - 2) - echo "No Paramters / wrong parameters" - ;; - 3) - echo "Wrong Settings" - ;; - 4) - echo "Programm missing" - ;; - 10) - echo "not executed as Root" - ;; - 11) - echo "file no found" - ;; - 12) - echo "dir not found" - ;; - 13) - echo "cant create/delete file/dir" - ;; - 14) - echo "corrupt file (unsquashfs, mount iso, ...)" - ;; - 15) - echo "wrong file (iso has no squashfs-file ...)" - ;; - 16) - echo "required Packet not found" - ;; - 20) - echo "tmount error" - ;; - 21) - echo "unmoun error" - ;; - 22) - echo "wrong filesystem" - ;; - *) - echo $'No Defined Error Code.\nPerhaps an Error ocure on a Command wich was started by this Skritp.' - ;; - esac -} +source $LIBDR/func/error_code #check_user -function check_user() { - #check root - [ "`whoami`" == "root" ] || { - echo "### ERROR ### Remaster need ROOT permision!" - return 10 - } -} +source $LIBDR/func/check_user #check_dependency -function check_dependency() { - for packet in squashfs-tools xorriso wget sed sendemail; do - [ "`dpkg -l $packet 2>&1`" == "dpkg-query: Kein Paket gefunden, das auf $packet passt" ] && { - echo "### ERROR ### Packet $packet not installed" - return 16 - } - done - return 0 -} +# -> 0 | -> 16 +source $LIBDR/func/check_dependency ### Workspace ### #workspace_erase [workspace_path] -function workspace_erase() { - echo -n "erase workspace ... " +source $LIBDR/func/workspace_erase - for dir in "$@"; do - [ -d "$dir" ] && rm -r -f "$dir" - done - - echo "done" -} ### Filesystem ### #filesystem_extract [filesystem_img_source] [chroot_path] -function filesystem_extract() { - echo "extract filesystem ..." - - #$1 = filesystem_img_source - #$2 = chroot_path - filesystem_img_source="$1" - chroot_path="$2" - filesystem_log="`mktemp`" - - #Überfrüfen der Parameter - [ -f "$filesystem_img_source" ] || { - echo "### ERROR ### filesystem_extract: squashfs \"$filesystem_img_source\" not exist!" - return 11 - } - - [ "`mkdir -p "$chroot_path"`" != "" ] && { - echo "### ERROR ### filesystem_extract: chroot_path \"$chroot_path\" can't create!" - return 13 - } - - [ "`filesystem_get_type $chroot_path`" != "ext4" ] && [ "`filesystem_get_type $chroot_path`" != "btrfs" ] && { - echo "### ERROR ### filesystem_extract: wrong filesystem (`filesystem_get_type $chroot_path`)!" - return 22 - } - - rm -r "$chroot_path" - - #eigendliches entpacken - unsquashfs -d "$chroot_path" "$filesystem_img_source" > "$filesystem_log" || { - echo "### ERROR ### filesystem_extract: unsquashfs failed!" - return 14 - } - - grep -v "\[" "$filesystem_log" - rm "$filesystem_log" - - echo "done" -} +source $LIBDR/func/filesystem_extract #filesystem_pack [chroot_path] [filesystem_img_destination] -function filesystem_pack() { - echo "pack filesystem ..." - - #$1 = chroot_path - #$2 = filesystem_img_destination - chroot_path="$1" - filesystem_img_destination="$2" - filesystem_log="`mktemp`" - - #Überfrüfen der Parameter - [ -d "$chroot_path" ] || { - echo "### ERROR ### filesystem_extract: chroot_path \"$chroot_path\" not exist!" - return 12 - } - - #loslegen ... - rm -f "$filesystem_img_destination" - mksquashfs "$chroot_path" "$filesystem_img_destination" > "$filesystem_log" || { - echo "### ERROR ### filesystem_pack: mksquashfs failed!" - return 13 - } - - grep -v "\[" "$filesystem_log" - rm "$filesystem_log" - - echo "done" -} +source $LIBDR/func/filesystem_pack #filesystem_get_type [dir] #(String)-> ext4, ext2, btfs, fuse, ... -function filesystem_get_type() { - fs_aTemp=(`df -T "$1"`) - echo ${fs_aTemp[9]} -} +source $LIBDR/func/filesystem_get_type ### ISO ### #iso_extract [iso_source] [iso_extr_dir] -function iso_extract() { - echo -n "extract iso ... " - - #$1 = iso_source - #$2 = iso_extr_dir - - #check root - [ "`whoami`" == "root" ] || { - echo "### ERROR ### iso_extract: need root permision!" - return 10 - } - - iso_source="$1" - [ -f "$iso_source" ] || { - echo "### ERROR ### iso_extract: ISO \"$iso_source\" not exist!" - return 11 - } - - iso_extr_dir="$2" - [ -d "$iso_extr_dir" ] || { - echo "### ERROR ### iso_extract: aim directory not exist!" - return 12 - } - - #mace tmp mountpoint - tmpdir="`mktemp -d`" - [ -d "$iso_extr_dir" ] && { - rm -r "$iso_extr_dir/" - mkdir "$iso_extr_dir" - } - - #copy files ... - mount -o loop,ro "$iso_source" "$tmpdir" - cp -f -r "$tmpdir/"* "$iso_extr_dir" - - #clear tmp mountpoint - umount "$iso_source" - rm -r "$tmpdir" - tmpdir= - - echo "done" -} +source $LIBDR/func/iso_extract #iso_create [chroot_path] [iso_extr_dir] [iso_destination] [iso_lable] -function iso_create() { - echo -n "create iso ..." - - chroot_path="$1" - iso_extr_dir="$2" - iso_destination="$3" - iso_lable="$4" - - [ -e "$iso_destination" ] && rm "$iso_destination" - - xorriso -as mkisofs -graft-points -c isolinux/boot.cat -b isolinux/isolinux.bin \ - -no-emul-boot -boot-info-table -boot-load-size 4 -isohybrid-mbr \ - "$iso_extr_dir/isolinux/isolinux.bin" \ - -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \ - -isohybrid-gpt-basdat -V "$iso_lable" \ - -o "$iso_destination" \ - -r -J "$iso_extr_dir" \ - --sort-weight 0 / --sort-weight 2 /boot --sort-weight 1 /isolinux - - echo "done" -} +source $LIBDR/func/iso_create #iso_create_desinfect2015 [chroot_path] [iso_extr_dir] [iso_destination] [iso_lable] function iso_create_desinfect2015() { @@ -803,27 +573,7 @@ function iso_create_desinfect2017() { ### chroot ### #chroot_initial [chroot_dir] -function chroot_initial() { - echo -n "initial chroot ... " - - #check chroot dir - chroot_dir="$1" - [ -d "$chroot_dir" ] || { - echo "### ERROR ### chroot_initial: chroot directory not exist" - return 12 - } - - #mount virus definitions - mount -t tmpfs tmpfs "$chroot_dir/tmp" - mount -t tmpfs tmpfs "$chroot_dir/root" - mount --bind /dev "$chroot_dir/dev" - mount --bind /proc "$chroot_dir/proc" - - rm "$chroot_dir/etc/resolv.conf" - cp "/etc/resolv.conf" "$chroot_dir/etc/resolv.conf" - - echo "done" -} +source $LIBDR/func/chroot_initial #chroot_initial_desinfect2015 [chroot_dir] function chroot_initial_desinfect2015() { @@ -879,41 +629,10 @@ function chroot_initial_desinfect2017() { #chroot_clean [chroot_dir] -function chroot_clean() { - echo "clean chroot ... " - - chroot_dir="$1" - - chroot "$chroot_dir" /bin/bash -c "apt-get clean" - chroot "$chroot_dir" /bin/bash -c "rm -r /var/cache/apt/*" - chroot "$chroot_dir" /bin/bash -c "apt-get update" - chroot "$chroot_dir" /bin/bash -c "apt-get check" - - echo "done" -} +source $LIBDR/func/chroot_clean #chroot_umount [chroot_dir] -function chroot_umount() { - echo -n "unmount chroot ... " - - #check chroot dir - chroot_dir="$1" - [ -d "$chroot_dir" ] || { - echo "### ERROR ### chroot_umount: chroot directory not exist!" - return 12 - } - - for d in "$chroot_dir/tmp" "$chroot_dir/root" "$chroot_dir/proc" "$chroot_dir/dev" ; do - umount $d - retval=$? - [ "$retval" -gt 0 ] && { - echo "### ERROR ### chroot_umount: can't umount \"$d\"!" - return 21 - } - done - - echo "done" -} +source $LIBDR/func/chroot_umount #chroot_umount_desinfect2015 [chroot_dir] function chroot_umount_desinfect2015() { @@ -970,38 +689,10 @@ function chroot_umount_desinfect2017() { #chroot_is_mounted [chroot_dir] #(Boolean)-> true | false -function chroot_is_mounted() { - #$1 = chroot directory - - if [ "`mount | grep "$1"`" != "" ] ; then - #ther is smething mounted - echo "true" - else - #nothing mounted - echo "false" - fi -} +source $LIBDR/func/chroot_is_mounted #chroot_sh [chroot_dir] [command] -function chroot_sh() { - #check chroot dir - chroot_dir="$1" - [ -d "$chroot_dir" ] || { - echo "### ERROR ### chroot_sh: chroot directory not exist!" - return 12 - } - - command="$2" - - [ -f "$chroot_dir/tmp/env.sh" ] || { - #if not exist create environment skript - cat "$chroot_dir/etc/environment" | grep -v "#" | grep "=" > "$chroot_dir/tmp/env" - while read line; do echo export $line; done < "$chroot_dir/tmp/env" > "$chroot_dir/tmp/env.sh" - chmod +x "$chroot_dir/tmp/env.sh" && rm "$chroot_dir/tmp/env" - } - - chroot "$chroot_dir" /bin/bash --login -c ". /tmp/env.sh; $command" -} +source $LIBDR/func/chroot_sh ### Settings ### ### proxy