13 Commits

Author SHA1 Message Date
2ffe939f5c Merge branch 'develop' into feature-lxc
lxc version aktuall.
2018-06-02 22:16:16 +02:00
268e327351 mod proj template 2018-05-22 02:12:28 +02:00
f5a2ddb0c4 apply changes to main script too 2018-05-22 02:10:45 +02:00
27b9155cd9 apply all new changes 2018-05-22 02:07:01 +02:00
226c2567d9 Merge pull request #23 from 6543/develop
update feature branch
2018-05-20 23:51:20 +02:00
fb524720f4 Merge pull request #19 from 6543/develop
update feature-fxc branch
2018-05-17 01:13:02 +02:00
adc9f4f7b5 Merge branch 'fix-standalone_executable' into feature-lxc
fix-standalone_executable
2018-05-11 00:06:48 +02:00
edfeec5868 Merge branch 'hotfix-1.9.3' into feature-lxc
hotfix-1.9.3
2018-05-10 22:48:08 +02:00
a5de57abb7 Merge branch 'bugfix-1.9.2' into feature-lxc
docu
2018-05-10 18:52:04 +02:00
127d682cfb bugfix-1.9.2++ 2018-05-10 17:27:36 +02:00
d4b7654769 Merge branch 'bugfix-1.9.2' into feature-lxc
finished bugfix-1.9.2
2018-05-10 17:15:04 +02:00
a45c267641 use lxc 2018-05-10 15:12:36 +02:00
76fc7b342f merge diff 2018-05-10 15:12:06 +02:00
13 changed files with 188 additions and 200 deletions

View File

@ -1,7 +0,0 @@
#!/bin/bash
echo doja loadet
function ja() {
echo ja
}

View File

@ -1,11 +0,0 @@
#!/bin/bash
echo try to import functions of script "$1"
export "mod=$1"
[[ -s "$mod" ]] && source "$mod"
ja
[ "$?" != "0" ] && echo use $0 with doja.sh next time ;)

View File

@ -1,39 +1,36 @@
#cfg
#########################################################
## sample-config rename it to config.cfg after changes ##
#########################################################
## Quelle der Project CD/DVD
iso_source="/data/local/Desinfect_Remaster/tmp/desinfect-2017.iso"
#CD/DVD
#entweder iso_source oder squashfs_path alls quelle
# -> bei iso gen erforderlich!
iso_source="/data/remaster/desinfect-2017.iso"
#destination optinal
iso_aim="/data/remaster/result/custom_desinfect_`date '+%Y-%m-%d'`.iso"
iso_lable="DESINFECT_`date '+%Y-%m-%d'`"
## Pfad zum gepakten Live System
## (kann anstat einer ISO auch als Quelle dienen, dann aber auch zwingend als Ziel)
# squashfs_path="/data/local/Desinfect_Remaster/tmp/filesystem.squashfs"
#Filesystem (for pxe)
#entweder iso_source oder squashfs_path alls quelle
squashfs_path="/data/remaster/result/filesystem.squashfs"
## Ziel, Lable der zu erstellenden CD/DVD
iso_aim="/data/local/Desinfect_Remaster/tmp/custom_desinfect_<date>.iso"
iso_lable="DESINFECT_<date>"
#Network
proxy_host="proxy.local"
proxy_port="8080"
domain="local"
nameserver="10.x.x.2,10.x.x.1"
## Netzwerk Sinstellungen
## Proxy:
# proxy_host="10.40.8.108"
# proxy_port="8080"
domain="fritz.box"
nameserver="10.40.255.254"
## Project / Distro
## Aktuell unterstützt: debian; ubuntu; ubuntu.14.04; ubuntu.16.04; desinfect.17
#remaster_script
project="desinfect.17"
## LOG Einstellungen
## log_file ist optionall
log_file="/data/local/Desinfect_Remaster/tmp/logs/<date>.log"
## Senden mit sendmail einen Report
# log_mail_source="desinfect@email.clocal"
# log_mail_smtp="smtp.mail.local:25"
# log_mail_aim="6543@email.clocal"
# log_mail_subject="Desinfect_Remaster"
#LOG
log_file="/data/remaster/logs/`date '+%Y-%m-%d'`.log"
log_mail_source="desinfect@email.clocal"
log_mail_smtp="smtp.mail.local:25"
log_mail_aim="6543@email.clocal"
log_mail_subject="Desinfect_Remaster"
#Sonstiges
tools_list="xrdp clamav nano htop nmon iftop tmux dsniff nmap openssh-server tightvncserver rsync e2fsprogs foremost gddrescue recoverjpeg safecopy sleuthkit testdisk arp-scan"

View File

@ -2,8 +2,8 @@
#remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }
#config_check
function config_check() {
#check_config
function check_config() {
#Project
[ -f "<LIBDIR>/proj/$project" ] || {
@ -24,7 +24,7 @@ function config_check() {
echo 'iso_source -> squashfs'
else
# ERROR
echo "Settings: No corect AIM"
echo "No corect AIM in Settings"
return 3
fi
fi
@ -32,14 +32,14 @@ function config_check() {
if [ -f "$squashfs_path" ]; then
if [ -n "$iso_aim" ]; then
# ERROR
echo "Settings: only Squashfs source in Settings, cant creat ISO"
echo "only Squashfs source in Settings, cant creat ISO"
return 3
else
echo 'squashfs -> squashfs'
fi
else
# ERROR
echo "Settings: No corect Source"
echo "No corect Source in Settings"
return 3
fi
fi
@ -51,5 +51,5 @@ function config_check() {
#this func is standalone executable
[ -n "$1" ] && {
config_check $@
check_config $@
}

View File

@ -5,7 +5,7 @@
#check_dependency
# -> 0 | -> 16
function check_dependency() {
for packet in squashfs-tools xorriso wget sed sendemail; do
for packet in squashfs-tools xorriso lxc 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

32
src/func/chroot Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
#remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }
## overload chroot with lxc
function chroot() {
lxc-attach -n _remaster_ -- "$2" "$3" "$4" "$5" "$6" "$7"
}
## create lxc config
#chroot_config [chroot_dir]
function chroot_config() {
chroot_dir="$1"
# Container specific configuration
echo "lxc.rootfs = $chroot_dir"
echo "lxc.rootfs.backend = dir"
echo "lxc.utsname = _remaster_"
# Network configuration
echo "lxc.network.type = veth"
echo "lxc.network.link = lxcbr0"
echo "lxc.network.flags = up"
echo "lxc.network.hwaddr = 00:16:3e:5a:ba:1e"
}
[ -n "$1" ] && {
echo param
$1
}

View File

@ -13,11 +13,13 @@ function chroot_initial() {
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"
[ -d "/var/lib/lxc/_remaster_/" ] && {
echo "### Warning ### chroot_initial: lxc container exists"
[ -f "/var/lib/lxc/_remaster_/config" ] && {
mv -f "/var/lib/lxc/_remaster_/config" "/var/lib/lxc/_remaster_/config.old"
}
}
mkdir -p "/var/lib/lxc/_remaster_/"
rm "$chroot_dir/etc/resolv.conf"
cp "/etc/resolv.conf" "$chroot_dir/etc/resolv.conf"

View File

@ -7,12 +7,15 @@
function chroot_is_mounted() {
#$1 = chroot directory
if [ "`mount | grep "$1"`" != "" ] ; then
#ther is smething mounted
echo "true"
else
#nothing mounted
#get state of _remaster from lxc
STATE=`lxc-ls _remaster_ -f -F STATE | tail -n 1 | sed 's/ //g'`
if [ "#$STATE#" == "#STOPPED#" ] ; then
#nothing running
echo "false"
else
#container is running
echo "true"
fi
}

View File

@ -1,69 +0,0 @@
#!/bin/bash
#remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }
#config_build jobfile configenv
function config_build() {
config_file="$1"
config_env="$2"
echo "### S e t t i n g s ###"
[ -f "$config_file" ] || {
echo "Config: wrong path for jobfile"
exit 3
}
[ -f "$config_env" ] || {
echo "Config: wrong path for config enviroment"
exit 3
}
##load project
export "`cat "$config_file" | grep ^[^#] | grep ^project= | cut -d "#" -f 1 | tr -d '"'`"
#check if project template exist
[ -f "<LIBDIR>/proj/$project" ] || {
echo "No Project \"$project\" is not supported"
return 3
}
# loard project
source "<LIBDIR>/proj/$project"
echo; echo #space
cat "$config_file" | grep ^[^#] | cut -d "#" -f 1 | grep '=' | while read line; do
#read each var line
config_key=`echo $line | cut -d "=" -f 1`
config_value=`echo $line | cut -d "=" -f 2 | tr -d '"'`
config_corect="false"
#check if this is a alowed config key
for i in $config_keys; do
[ "$i" == "$config_key" ] && config_corect="true"
done
if [ "$config_corect" == "true" ]; then
#load config key
#replace value strings
config_value="${config_value/<date>/`date '+%Y-%m-%d'`}"
config_value="${config_value/<time>/`date '+%H:%M:%S'`}"
onfig_value="${config_value/<DATE>/`date '+%Y-%m-%d'`}"
config_value="${config_value/<TIME>/`date '+%H:%M:%S'`}"
#save seting in environment var
echo "$config_key='$config_value'" | tee $config_env
else
echo "WARNUNG: $config_key is an inconrect setting. This will be ignored"
fi
done
}
#this func is standalone executable
[ -n "$1" ] && {
config_build $@
}

View File

@ -10,6 +10,9 @@ function workspace_erase() {
[ -d "$dir" ] && rm -r -f "$dir"
done
#lxc
[ -d /var/lib/lxc/_remaster_/ ] && rm -R /var/lib/lxc/_remaster_/
echo "done"
}

View File

@ -6,12 +6,8 @@
##### B a s e ####
##################
# .
# Enviroment
project_relation=""
[ -z "$project" ] && project=base
config_keys="iso_source iso_aim iso_lable squashfs_path proxy_host proxy_port domain nameserver project log_file log_mail_source log_mail_smtp log_mail_aim log_mail_subject tools_list"
#tools_add [chroot_dir] [tools_list]
function tools_add() {

View File

@ -261,3 +261,22 @@ function project_mods-desinfect.17() {
}
}
function project_mods() { project_mods-desinfect.17 $@; }
function chroot_initial-desinfect2017() {
#$1 = chroot dir
<LIBDIR>/func/chroot_initial "$1"
#LXC Start
config="/var/lib/lxc/_remaster_/config"
#special conf for distros:
echo "lxc.include = /usr/share/lxc/config/nesting.conf" > $config
echo "lxc.include = /usr/share/lxc/config/ubuntu.common.conf" >> $config
echo "lxc.arch = x86_64" >> $config
#normal config
chroot_config "$chroot_dir" >> $config
#LXC End
}
function chroot_initial() { chroot_initial-desinfect.17 $@; }

View File

@ -5,7 +5,7 @@
#@licence GNUv3
#####################################################################################
################## F u n c t i o n s ################################################
################## S e t t i n g s ##################################################
#####################################################################################
#set functions
@ -14,6 +14,44 @@
exit 1
}
#read main setting
if [ -f "<ROOTDIR>/etc/remaster/config.cfg" ]; then
source "<ROOTDIR>/etc/remaster/config.cfg"
else
if [ -f "<ROOTDIR>/etc/remaster/config.sample.cfg" ]; then
source "<ROOTDIR>/etc/remaster/config.sample.cfg"
else
echo "ERROR config not found"
exit 1
fi
fi
#check LOG
{
[ -z "$log_file" ] && log_file="/tmp/remaster_`date '+%Y-%m-%d'`"
if [ -f "$log_file" ]; then
echo > "$log_file"
else
#check if folder exist
[ -d "${log_file%/*}" ] || {
# N-> exit 3
echo "Directory for Log didnt exist"
exit 3
}
#create LOG
touch "$log_file"
fi
}
#####################################################################################
################## F u n c t i o n s ################################################
#####################################################################################
### Error Handlings ###
#check_config
source <LIBDIR>/func/check_config
#on_exit [error_level]
source <LIBDIR>/func/on_exit
@ -58,6 +96,9 @@ source <LIBDIR>/func/iso_create
### chroot ###
## overload chroot with lxc
source <LIBDIR>/func/chroot
#chroot_initial [chroot_dir]
source <LIBDIR>/func/chroot_initial
@ -74,78 +115,64 @@ source <LIBDIR>/func/chroot_is_mounted
#chroot_sh [chroot_dir] [command]
source <LIBDIR>/func/chroot_sh
### config ###
#config_build jobfile configenv
source <LIBDIR>/func/config_build
#config_check
source <LIBDIR>/func/config_check
#####################################################################################
################## S e t t i n g s ##################################################
#####################################################################################
#read main setting
if [ -f "<ROOTDIR>/etc/remaster/config.cfg" ]; then
config="<ROOTDIR>/etc/remaster/config.cfg"
else
if [ -f "<ROOTDIR>/etc/remaster/config.sample.cfg" ]; then
config="<ROOTDIR>/etc/remaster/config.sample.cfg"
else
echo "ERROR config not found"
exit 1
fi
fi
### -> $1 jobfile, if zero and onlyone file exist ues this else print error and list
#check LOG
{
export "`cat "$config" | grep ^[^#] | grep ^log_file= | cut -d "#" -f 1 | tr -d '"'`"
[ -z "$log_file" ] && log_file="/tmp/remaster_`date '+%Y-%m-%d'`"
if [ -f "$log_file" ]; then
echo > "$log_file"
else
#check if folder exist
[ -d "${log_file%/*}" ] || {
# N-> exit 3
echo "Directory for Log didnt exist"
exit 3
}
#create LOG
touch "$log_file"
fi
}
####################################
### Workaround - set Project
source <LIBDIR>/proj/desinfect.17
####################################
###########################################################
################# P r o c e s s ... #######################
###########################################################
### Start LOG ###
#Start LOG
tail -f "$log_file" --pid="$$" &
echo "Remaster LOG `date '+%Y-%m-%d'`" > "$log_file"
echo >> "$log_file"
### S e t t i n g s ###
config_env=`mktemp`
config_build $config $config_env >> "$log_file"
error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file"
source $config_env
### Enviroment ###
echo "### Enviroment ###" >> "$log_file"
chroot_path="`mktemp -d`"
iso_extr_dir="`mktemp -d`"
echo "Remaster LOG `date '+%Y-%m-%d'`" > "$log_file"
echo "MODE: renew" >> "$log_file"
echo "HOST: `hostname`" >> "$log_file"
echo >> "$log_file"
echo "### S e t t i n g s ###" >> "$log_file"
echo "#CD/DVD" >> "$log_file"
echo "iso_source=\"$iso_source\"" >> "$log_file"
echo "iso_aim=\"$iso_aim\"" >> "$log_file"
echo "iso_lable=\"$iso_lable\"" >> "$log_file"
echo >> "$log_file"
echo "#Filesystem (for pxe)" >> "$log_file"
echo "squashfs_path=\"$squashfs_path\"" >> "$log_file"
echo >> "$log_file"
echo "#Network" >> "$log_file"
echo "proxy_host=\"$proxy_host\"" >> "$log_file"
echo "proxy_port=\"$proxy_port\"" >> "$log_file"
echo "domain=\"$domain\"" >> "$log_file"
echo "nameserver=\"$nameserver\"" >> "$log_file"
echo >> "$log_file"
echo "#remaster_script" >> "$log_file"
echo "project=\"$project\"" >> "$log_file"
echo >> "$log_file"
echo "log_file=\"$log_file\""
echo "log_mail_aim=\"$log_mail_aim\""
echo "log_mail_subject=\"$log_mail_subj >> "$log_file"ect\""
echo ""
echo "#Sonstiges" >> "$log_file"
echo "tools_list=\"$tools_list\"" >> "$log_file"
echo $'\n' >> "$log_file"
echo "### Enviroment ###"
echo "iso_extr_dir=\"$iso_extr_dir\"" >> "$log_file"
echo "chroot_path=\"$chroot_path\"" >> "$log_file"
echo "HOST: `hostname`" >> "$log_file"
#env >> "$log_file"
echo $'\n\n' >> "$log_file"
echo $'### R U N ... ###\n' >> "$log_file"
#1. Set and Check Enviroment
check_user >> "$log_file"
@ -154,15 +181,11 @@ error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_fil
check_dependency >> "$log_file"
error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file"
config_check >> "$log_file"
check_config >> "$log_file"
error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file"
check_update >> "$log_file"
### R U N ... ###
echo $'### R U N ... ###\n' >> "$log_file"
# 2. Entpacke ISO
iso_extract "$iso_source" "$iso_extr_dir" >> "$log_file"