dont exec config, parse it

This commit is contained in:
6543 2018-06-01 01:52:11 +02:00
parent 5df896a47e
commit 495bbb5f4a
6 changed files with 188 additions and 92 deletions

View File

@ -9,8 +9,8 @@
# -> bei iso gen erforderlich! # -> bei iso gen erforderlich!
iso_source="/data/remaster/desinfect-2017.iso" iso_source="/data/remaster/desinfect-2017.iso"
#destination optinal #destination optinal
iso_aim="/data/remaster/result/custom_desinfect_`date '+%Y-%m-%d'`.iso" iso_aim="/data/remaster/result/custom_desinfect_<date>.iso"
iso_lable="DESINFECT_`date '+%Y-%m-%d'`" iso_lable="DESINFECT_<date>"


#Filesystem (for pxe) #Filesystem (for pxe)
#entweder iso_source oder squashfs_path alls quelle #entweder iso_source oder squashfs_path alls quelle
@ -26,7 +26,7 @@ nameserver="10.x.x.2,10.x.x.1"
project="desinfect.17" project="desinfect.17"


#LOG #LOG
log_file="/data/remaster/logs/`date '+%Y-%m-%d'`.log" log_file="/data/remaster/logs/<date>.log"
log_mail_source="desinfect@email.clocal" log_mail_source="desinfect@email.clocal"
log_mail_smtp="smtp.mail.local:25" log_mail_smtp="smtp.mail.local:25"
log_mail_aim="6543@email.clocal" log_mail_aim="6543@email.clocal"

6
src/func/check_config Executable file → Normal file
View File

@ -2,8 +2,8 @@
#remaster lib #remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; } [ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }


#check_config #config_check
function check_config() { function config_check() {


#Project #Project
[ -f "<LIBDIR>/proj/$project" ] || { [ -f "<LIBDIR>/proj/$project" ] || {
@ -51,5 +51,5 @@ function check_config() {


#this func is standalone executable #this func is standalone executable
[ -n "$1" ] && { [ -n "$1" ] && {
check_config $@ config_check $@
} }

55
src/func/config_check Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
#remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }

#config_check
function config_check() {

#Project
[ -f "<LIBDIR>/proj/$project" ] || {
echo "No Project \"$project\" is not supported"
return 3
}

#live-system files
if [ -f "$iso_source" ]; then
if [ -n "$iso_aim" ] && [ -d "${iso_aim%/*}" ]; then
#Lable
[ -z "$iso_lable" ] && iso_lable="$project"

echo 'iso_source -> iso_aim'
echo 'iso_source -> squashfs [optinal]'
else
if [ -n "$squashfs_path" ] && [ -d "${squashfs_path%/*}" ]; then
echo 'iso_source -> squashfs'
else
# ERROR
echo "No corect AIM in Settings"
return 3
fi
fi
else
if [ -f "$squashfs_path" ]; then
if [ -n "$iso_aim" ]; then
# ERROR
echo "only Squashfs source in Settings, cant creat ISO"
return 3
else
echo 'squashfs -> squashfs'
fi
else
# ERROR
echo "No corect Source in Settings"
return 3
fi
fi




}

#this func is standalone executable
[ -n "$1" ] && {
config_check $@
}

59
src/func/config_load Normal file
View File

@ -0,0 +1,59 @@
#!/bin/bash
#remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }

#config_load config
function config_load() {
config="$1"

echo "### S e t t i n g s ###"

##load project
export "`cat "$config" | 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" | 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
export "$config_key=$config_value"
echo "$config_key=$config_value"

else
echo "WARNUNG: $config_key is an inconrect setting. This will be ignored"
fi

done

}

#this func is standalone executable
[ -n "$1" ] && {
config_load $@
}

View File

@ -6,8 +6,12 @@
##### B a s e #### ##### B a s e ####
################## ##################
# . # .

# Enviroment
project_relation="" project_relation=""
[ -z "$project" ] && project=base [ -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] #tools_add [chroot_dir] [tools_list]
function tools_add() { function tools_add() {

View File

@ -5,7 +5,7 @@
#@licence GNUv3 #@licence GNUv3


##################################################################################### #####################################################################################
################## S e t t i n g s ################################################## ################## F u n c t i o n s ################################################
##################################################################################### #####################################################################################


#set functions #set functions
@ -14,44 +14,6 @@
exit 1 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] #on_exit [error_level]
source <LIBDIR>/func/on_exit source <LIBDIR>/func/on_exit


@ -112,64 +74,76 @@ source <LIBDIR>/func/chroot_is_mounted
#chroot_sh [chroot_dir] [command] #chroot_sh [chroot_dir] [command]
source <LIBDIR>/func/chroot_sh source <LIBDIR>/func/chroot_sh


#################################### ### config ###
### Workaround - set Project
source <LIBDIR>/proj/desinfect.17 #config_load [config]
#################################### source <LIBDIR>/func/config_load

#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
#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
}



########################################################### ###########################################################
################# P r o c e s s ... ####################### ################# P r o c e s s ... #######################
########################################################### ###########################################################


#Start LOG ### Start LOG ###
tail -f "$log_file" --pid="$$" & 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_load $config >> "$log_file"
error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file"
echo $'\n\n' >> "$log_file"


### Enviroment ###
echo "### Enviroment ###" >> "$log_file"

chroot_path="`mktemp -d`" chroot_path="`mktemp -d`"
iso_extr_dir="`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 "iso_extr_dir=\"$iso_extr_dir\"" >> "$log_file"
echo "chroot_path=\"$chroot_path\"" >> "$log_file" echo "chroot_path=\"$chroot_path\"" >> "$log_file"
#env >> "$log_file" echo "HOST: `hostname`" >> "$log_file"
echo $'\n\n' >> "$log_file"

echo $'### R U N ... ###\n' >> "$log_file"


#1. Set and Check Enviroment #1. Set and Check Enviroment
check_user >> "$log_file" check_user >> "$log_file"
@ -178,11 +152,15 @@ error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_fil
check_dependency >> "$log_file" check_dependency >> "$log_file"
error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file" error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file"


check_config >> "$log_file" config_check >> "$log_file"
error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file" error_level="$?"; [ "$error_level" != "0" ] && on_exit $error_level >> "$log_file"


check_update >> "$log_file" check_update >> "$log_file"



### R U N ... ###
echo $'### R U N ... ###\n' >> "$log_file"

# 2. Entpacke ISO # 2. Entpacke ISO
iso_extract "$iso_source" "$iso_extr_dir" >> "$log_file" iso_extract "$iso_source" "$iso_extr_dir" >> "$log_file"