1 | #!/bin/bash |
---|
2 | |
---|
3 | declare distcc_env_is_subshell; |
---|
4 | declare distcc_env_file="${HOME}/.distcc_env"; |
---|
5 | |
---|
6 | #-----[ distcc_env_usage ]--------------------------------- |
---|
7 | function distcc_env_usage() |
---|
8 | { |
---|
9 | echo "${0} option"; |
---|
10 | echo " -h : print this message"; |
---|
11 | echo " -d : load default DISTCC_HOSTS"; |
---|
12 | echo " -t : from DISTCC_HOSTS, test hosts"; |
---|
13 | echo " -s : save DISTCC_HOSTS in file ${distcc_env_file} (if -t, save after test host)"; |
---|
14 | echo " -l : load file ${distcc_env_file} and set DISTCC_HOSTS"; |
---|
15 | echo ""; |
---|
16 | echo " 2 methode to set DISTCC_HOSTS : "; |
---|
17 | echo " * 1) \". $0\""; |
---|
18 | echo " * 2) DISTCC_HOSTS=\$($0);"; |
---|
19 | |
---|
20 | # exit 1; |
---|
21 | } |
---|
22 | |
---|
23 | #-----[ distcc_env_default ]------------------------------- |
---|
24 | function distcc_env_default () |
---|
25 | { |
---|
26 | export DISTCC_HOSTS=""; |
---|
27 | export DISTCC_HOSTS="${DISTCC_HOSTS} houla/16,lzo" ; # serveur recherche |
---|
28 | export DISTCC_HOSTS="${DISTCC_HOSTS} hop/16,lzo" ; # serveur recherche |
---|
29 | export DISTCC_HOSTS="${DISTCC_HOSTS} fox/8,lzo" ; # serveur recherche |
---|
30 | export DISTCC_HOSTS="${DISTCC_HOSTS} trot/8,lzo" ; # serveur recherche |
---|
31 | export DISTCC_HOSTS="${DISTCC_HOSTS} bip/8,lzo" ; # serveur recherche |
---|
32 | export DISTCC_HOSTS="${DISTCC_HOSTS} bop/8,lzo" ; # serveur recherche |
---|
33 | #export DISTCC_HOSTS="${DISTCC_HOSTS} polka/8,lzo" ; # serveur recherche - réservé |
---|
34 | #export DISTCC_HOSTS="${DISTCC_HOSTS} debussy/8,lzo" ; # serveur enseignement |
---|
35 | export DISTCC_HOSTS="${DISTCC_HOSTS} do/8,lzo" ; # serveur recherche |
---|
36 | export DISTCC_HOSTS="${DISTCC_HOSTS} re/8,lzo" ; # serveur recherche |
---|
37 | export DISTCC_HOSTS="${DISTCC_HOSTS} mi/8,lzo" ; # serveur recherche |
---|
38 | export DISTCC_HOSTS="${DISTCC_HOSTS} fa/8,lzo" ; # serveur recherche |
---|
39 | export DISTCC_HOSTS="${DISTCC_HOSTS} fusion/8,lzo" ; # serveur recherche |
---|
40 | export DISTCC_HOSTS="${DISTCC_HOSTS} heavy/4,lzo" ; # serveur recherche |
---|
41 | #export DISTCC_HOSTS="${DISTCC_HOSTS} berlioz/4,lzo" ; # serveur enseignement - g++ 3.4.6 |
---|
42 | export DISTCC_HOSTS="${DISTCC_HOSTS} roll/4,lzo" ; # serveur recherche |
---|
43 | #export DISTCC_HOSTS="${DISTCC_HOSTS} rock/2,lzo" ; # serveur recherche - g++ 3.4.6 |
---|
44 | export DISTCC_HOSTS="${DISTCC_HOSTS} waller/2,lzo" ; # desktop |
---|
45 | export DISTCC_HOSTS="${DISTCC_HOSTS} lin/2,lzo" ; # desktop |
---|
46 | export DISTCC_HOSTS="${DISTCC_HOSTS} eric/2,lzo" ; # desktop |
---|
47 | export DISTCC_HOSTS="${DISTCC_HOSTS} amouri/2,lzo" ; # desktop |
---|
48 | export DISTCC_HOSTS="${DISTCC_HOSTS} nemu/2,lzo" ; # desktop |
---|
49 | #export DISTCC_HOSTS="${DISTCC_HOSTS} cherry/2,lzo" ; # desktop |
---|
50 | export DISTCC_HOSTS="${DISTCC_HOSTS} gamoudi/2,lzo" ; # desktop |
---|
51 | #export DISTCC_HOSTS="${DISTCC_HOSTS} grunge/2,lzo" ; # desktop |
---|
52 | #export DISTCC_HOSTS="${DISTCC_HOSTS} mitra/2,lzo" ; # desktop |
---|
53 | #export DISTCC_HOSTS="${DISTCC_HOSTS} pronky/2,lzo" ; # desktop |
---|
54 | #export DISTCC_HOSTS="${DISTCC_HOSTS} babylone/2,lzo" ; # desktop |
---|
55 | |
---|
56 | if test ${1} -eq 1; then |
---|
57 | echo "${DISTCC_HOSTS}"; |
---|
58 | fi; |
---|
59 | } |
---|
60 | |
---|
61 | #-----[ distcc_env_load ]---------------------------------- |
---|
62 | function distcc_env_load () |
---|
63 | { |
---|
64 | if test -f ${distcc_env_file}; then |
---|
65 | DISTCC_HOSTS=$(cat ${distcc_env_file}); |
---|
66 | fi; |
---|
67 | } |
---|
68 | |
---|
69 | #-----[ distcc_env_save ]---------------------------------- |
---|
70 | function distcc_env_save () |
---|
71 | { |
---|
72 | echo ${DISTCC_HOSTS} > ${distcc_env_file}; |
---|
73 | } |
---|
74 | |
---|
75 | #-----[ distcc_env_test ]---------------------------------- |
---|
76 | function distcc_env_test () |
---|
77 | { |
---|
78 | local hosts="${DISTCC_HOSTS}"; |
---|
79 | |
---|
80 | # re init DISTCC_HOSTS |
---|
81 | |
---|
82 | export DISTCC_HOSTS=""; |
---|
83 | for line in ${hosts}; do |
---|
84 | host=$(echo ${line} | cut -d/ -f1); |
---|
85 | |
---|
86 | if test ${1} -eq 0; then |
---|
87 | echo -n " * station : ${host} ... "; |
---|
88 | fi; |
---|
89 | |
---|
90 | # ping host ... |
---|
91 | ping -w 1 ${host} &> /dev/null; |
---|
92 | |
---|
93 | if test "$?" -eq "0"; then |
---|
94 | # ... if ok, reinsert |
---|
95 | if test ${1} -eq 0; then |
---|
96 | echo "online"; |
---|
97 | fi; |
---|
98 | export DISTCC_HOSTS="${DISTCC_HOSTS} ${line}"; |
---|
99 | else |
---|
100 | if test ${1} -eq 0; then |
---|
101 | echo "offline"; |
---|
102 | fi; |
---|
103 | fi; |
---|
104 | done; |
---|
105 | |
---|
106 | if test ${1} -eq 1; then |
---|
107 | echo "${DISTCC_HOSTS}"; |
---|
108 | fi; |
---|
109 | } |
---|
110 | |
---|
111 | #-----[ distcc_env ]--------------------------------------- |
---|
112 | function distcc_env () |
---|
113 | { |
---|
114 | if test "${0}" = "$(basename ${SHELL})"; then |
---|
115 | distcc_env_is_subshell=0; |
---|
116 | else |
---|
117 | distcc_env_is_subshell=1; |
---|
118 | fi; |
---|
119 | |
---|
120 | local exec_distcc_env_default=0; |
---|
121 | local exec_distcc_env_test=0; |
---|
122 | local exec_distcc_env_save=0; |
---|
123 | local exec_distcc_env_load=0; |
---|
124 | local exec_distcc_env_usage=0; |
---|
125 | local no_option=1; |
---|
126 | |
---|
127 | set -- $(getopt :sldth "$@") |
---|
128 | for arg |
---|
129 | do case "$arg" in |
---|
130 | -d) exec_distcc_env_default=1; no_option=0; ;; |
---|
131 | -t) exec_distcc_env_test=1; no_option=0; ;; |
---|
132 | -s) exec_distcc_env_save=1; no_option=0; ;; |
---|
133 | -l) exec_distcc_env_load=1; no_option=0; ;; |
---|
134 | -h) exec_distcc_env_usage=1; break; ;; |
---|
135 | --) if test $no_option -eq 1; then |
---|
136 | exec_distcc_env_usage=1; |
---|
137 | fi; |
---|
138 | break;; |
---|
139 | esac |
---|
140 | done |
---|
141 | |
---|
142 | |
---|
143 | if test $exec_distcc_env_usage -eq 1; then |
---|
144 | distcc_env_usage ${*}; |
---|
145 | |
---|
146 | if test ${distcc_env_is_subshell} -eq 1; then |
---|
147 | exit 1; |
---|
148 | fi; |
---|
149 | else |
---|
150 | if test $exec_distcc_env_default -eq 1; then |
---|
151 | if test $exec_distcc_env_test -eq 1; then |
---|
152 | distcc_env_default 0; |
---|
153 | else |
---|
154 | distcc_env_default ${distcc_env_is_subshell}; |
---|
155 | fi; |
---|
156 | fi; |
---|
157 | if test $exec_distcc_env_load -eq 1; then |
---|
158 | distcc_env_load; |
---|
159 | fi; |
---|
160 | if test $exec_distcc_env_test -eq 1; then |
---|
161 | distcc_env_test ${distcc_env_is_subshell}; |
---|
162 | fi; |
---|
163 | if test $exec_distcc_env_save -eq 1; then |
---|
164 | distcc_env_save; |
---|
165 | fi; |
---|
166 | fi; |
---|
167 | |
---|
168 | unset distcc_env_file; |
---|
169 | unset distcc_env_is_subshell; |
---|
170 | } |
---|
171 | |
---|
172 | #-----[ Corps ]--------------------------------------------- |
---|
173 | distcc_env ${*}; |
---|