-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bash_funcs.host-name
executable file
·117 lines (98 loc) · 3.78 KB
/
.bash_funcs.host-name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# file: ~/.bash_funcs.`hostname -s`
# docs at the end ...
#
# call by: doParseCnfEnvVars cnf/qto.dev.host-name.cnf
# ---------------------------------------------------------
doParseCnfEnvVars(){
cnf_file=$1;shift 1;
test -z "$cnf_file" && echo " you should set the cnf_file !!!"
cnf_dir=$(perl -e 'use File::Basename; use Cwd "abs_path"; print dirname(abs_path(@ARGV[0]));' -- "$cnf_file")
product_instance_dir=${cnf_dir%/*}
INI_SECTION=MainSection
( set -o posix ; set ) | sort >~/vars.before
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/#.*$//' \
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s|%ProductInstanceDir%|${product_instance_dir}|" \
-e "s/^\(.*\)=\([^\"']*\)$/export \1=\"\2\"/" \
< $cnf_file \
| sed -n -e "/^\[$INI_SECTION\]/,/^\s*\[/{/^[^#].*\=.*/p;}"`
# and post-register for nice logging
( set -o posix ; set ) | sort >~/vars.after
echo "INFO added the following vars from section: [$INI_SECTION]"
comm -3 ~/vars.before ~/vars.after | perl -ne 's#\s+##g;print "\n $_ "'
}
#
# ---------------------------------------------------------
# call by: doParseIniEnvVars sfw/sh/isg-pub/isg-pub.mini-nz.ysg-host-name.conf
#; file: mini-nz.sh.hostname.conf docs at the end
#[MainSection]
#; the name of the project
#project=mini-nz
#;
#; the alias of the project - used for the logical html link and the db names
#; eof file: mini-nz.sh.hostname.conf
#proj_alias=mini_nz
# ---------------------------------------------------------
doParseIniEnvVars(){
ini_file=$1;shift 1;
#debug ok echo ini_file:: $ini_file
#debug ok sleep 2
test -z "$ini_file" && ini_file="$component_dir/$component_name.$host_name.conf"
test -f "$ini_file" || \
cp -v $component_dir/$component_name.host_name.conf \
$component_dir/$component_name.$host_name.conf
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/;.*$//' \
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/export \1=\"\2\"/" \
< $ini_file \
| sed -n -e "/^\[MainSection\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`
}
#eof func doParseIniEnvVars
#
# ---------------------------------------------------------
# call by: doParseCnfEnvVars cnf/ysg-issues.prd.doc-pub-host.cnf
#proj_alias=mini_nz
# ---------------------------------------------------------
doSetUndefinedShellVarsFromCnfFile(){
cnf_file=$1;shift 1;
test -z "$cnf_file" && echo "You need to pass cnf_file as 1st cmd arg to this func !!!"
vars_to_set=`sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/;.*$//' \
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/test -z \"\$\1\" \&\& export \1=\"\2\"/" \
< $cnf_file \
| sed -n -e "/^\[MainSection\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`
while IFS=' ' read -r var_to_set
do
echo "running: $var_to_set"
eval "$var_to_set"
done < "$vars_to_set"
}
#eof func doSetShellVarsFromCnfFile
#
#----------------------------------------------------------
# Purpose:
# do not mess with .bashrc, but simply include functions to
# the shell sessions of the current user
#
#----------------------------------------------------------
# Prerequisites: bash
#
#----------------------------------------------------------
#
#
# VersionHistory:
#------------------------------------------------------------------------------
# export version=1.0.2
#
# 1.0.2 --- 2016-11-11 09:52:45 -- syste file size and lines override ...
# 1.0.1 --- 2016-08-24 09:35:13 -- added docs - put into version system
# 1.0.0 --- 2016-08-01 22:04:33 -- initial version during host install
#----------------------------------------------------------
#
#eof file: ~/.bash_funcs.`hostname -s`