blob: 28a0fa2b1abd56c71c1441d6ae713d20b4ccbf66 (
plain) (
blame)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#!/bin/bash
# dotfiles -- install
# author: johannst
gInstallConfigFile=install.config
#"<config_tag>:<dep_binary>:<installer_fct_name>"
gToolsConfig=(
"bashrc:bash:bashrcInstaller"
"cgdb:cgdb:cgdbrcInstaller"
"conkyrc:conky:conkyrcInstaller"
"gitconfig:git:gitConfigInstaller"
"tmux.conf:tmux:tmuxConfigInstaller"
"vimrc:vim:vimConfigInstaller"
"Xresources:xterm:xtermConfigInstaller"
)
#{{{ bashrcInstaller
function bashrcInstaller() {
echo "bashInstaller called!"
}
#}}}
#{{{ cgdbrcInstaller
function cgdbrcInstaller() {
echo "cgdbrcInstaller called"
}
#}}}
#{{{ conkyrcInstaller
function conkyrcInstaller() {
echo "conkyrcInstaller called"
}
#}}}
#{{{ gitConfigInstaller
function gitConfigInstaller() {
echo "gitConfigInstaller called"
}
#}}}
#{{{ tmuxConfigInstaller
function tmuxConfigInstaller() {
echo "tmuxConfigInstaller called"
}
#}}}
#{{{ vimConfigInstaller
function vimConfigInstaller() {
echo "vimConfigInstaller called"
}
#}}}
#{{{ xtermConfigInstaller
function xtermConfigInstaller() {
echo "xtermConfigInstaller called"
}
#}}}
#{{{ Installer Main Loop
function main() {
# parse gInstallConfigFile to see what should be installed
configToInstall=()
while read line; do
if [[ ! $line =~ ^[yYnN][[:blank:]]?- ]]; then
continue
fi
flag=$(echo $line | cut -d '-' -f 1 | sed 's/ //g')
if [[ $flag =~ ^[yY]$ ]]; then
config=$(echo $line | cut -d '-' -f 2 | sed 's/ //g')
configToInstall+=("$config")
fi
done < $gInstallConfigFile
echo "[Info]: List of tags found to install:"
for conf in ${configToInstall[@]}; do
echo -e "\t$conf"
done
for conf in ${configToInstall[@]}; do
installConfig $conf
done
}
#}}}
#{{{ Installer Core
installConfig() {
local config=$1
local binary=$(getDepenentBinaryName $config)
isBinaryInstalled $binary
if [[ $? -eq 1 ]]; then
echo "[Warning]: Skipping $config... $config is not installed!"
return
fi
local installerFctPtr=$(getConfigInstallerFctPtr $config)
if [[ -z $installerFctPtr ]]; then
echo "[Warning]: Skipping $config... installer function pointer loopup error!"
return
fi
isInstallerDefined $installerFctPtr
if [[ $? -eq 1 ]]; then
echo "[Warning]: Skipping $config... $installerFctPtr not defined!"
return
fi
echo "[Info]: Intalling config for $binary using $installerFctPtr!"
$installerFctPtr
}
getValue() {
local search_key=$1
for k in ${gToolsConfig[@]}; do
local key=$(echo $k | cut -d ':' -f 1)
if [[ "$key" == "$search_key" ]]; then
local entry=$(echo $k | cut -d ':' -f 2,3)
echo ${entry}
break
fi
done
}
getDepenentBinaryName() {
local result=$(echo $(getValue $1) | cut -d ':' -f 1)
echo $result
}
getConfigInstallerFctPtr() {
local result=$(echo $(getValue $1) | cut -d ':' -f 2)
echo $result
}
isBinaryInstalled() {
local binary=$1
type $binary >/dev/null 2>&1 || { return 1; }
return 0
}
isInstallerDefined () {
local func=$1
declare -F $func >/dev/null 2>&1 || { return 1; }
return 0
}
#}}}
main
|