Magellan Linux

Annotation of /mcore-src/trunk/mcore-tools/src/include/common.global.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2227 - (hide annotations) (download)
Fri Jan 10 23:50:18 2014 UTC (10 years, 4 months ago) by niro
File size: 4061 byte(s)
-renamed common.global.class -> common.global.class.in
1 niro 2140 # $Id$
2    
3     # message only echo | disabled in quiet mode
4     mecho()
5     {
6     local COLCYAN="\033[1;36m"
7     local COLDEFAULT="\033[0m"
8     local opts
9     local webcrlf
10    
11     # print nothing if quiet mode was requested
12     [[ ${QUIET} = true ]] && return
13    
14     if [[ ${NOCOLORS} = true ]]
15     then
16     COLCYAN=""
17     COLDEFAULT=""
18     fi
19    
20     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
21    
22     # respect -n
23     case $1 in
24     -n) shift; opts="n" ;;
25     esac
26    
27     echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"
28     }
29    
30     # prints error messages | enabled even in quiet mode
31     eecho()
32     {
33     local COLRED="\033[1;31m"
34     local COLDEFAULT="\033[0m"
35     local opts
36     local webcrlf
37    
38     if [[ ${NOCOLORS} = true ]]
39     then
40     COLRED=""
41     COLDEFAULT=""
42     fi
43    
44     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
45    
46     # respect -n
47     case $1 in
48     -n) shift; opts="n" ;;
49     esac
50    
51     echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"
52     }
53    
54     # prints return values of get | enabled even in quiet mode
55     rvecho()
56     {
57     local COLPURPLE="\033[1;35m"
58     local COLDEFAULT="\033[0m"
59     local opts
60     local webcrlf
61    
62     if [[ ${NOCOLORS} = true ]]
63     then
64     COLPURPLE=""
65     COLDEFAULT=""
66     fi
67    
68     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
69    
70     # respect -n
71     case $1 in
72     -n) shift; opts="n" ;;
73     esac
74    
75     echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}"
76     }
77    
78     # prints debug messages if requested | enabled even in quiet mode
79     decho()
80     {
81     # print nothing if debug mode was *not* requested
82     [[ ${DEBUG} != 1 ]] && return
83    
84     eecho "DEBUG: ${@}"
85     }
86    
87     # adds a line to a configuration file defined by the $CONFIG variable
88     # $CONFIG="/etc/conf.d/mcore" addconfig 'LIBDIR="/usr/lib"'
89     addconfig()
90     {
91     local opts
92    
93     if [[ -z ${CONFIG} ]]
94     then
95     eecho "You must define \$CONFIG varibale first!"
96     return 1
97     fi
98    
99     if [[ ! -d $(dirname ${CONFIG}) ]]
100     then
101     install -d $(dirname ${CONFIG})
102     fi
103    
104     # check for opts
105     case $1 in
106     -n) shift; opts=" -n" ;;
107     -e) shift; opts=" -e" ;;
108     esac
109    
110     echo ${opts} "$@" >> ${CONFIG}
111     }
112    
113     # creates or clears a configuration file defined by the $CONFIG variable
114     # CONFIG="/etc/conf.d/mcore" clearconfig
115     clearconfig()
116     {
117     if [[ -z ${CONFIG} ]]
118     then
119     eecho "You must define \$CONFIG varibale first!"
120     return 1
121     fi
122    
123     if [[ ! -d $(dirname ${CONFIG}) ]]
124     then
125     install -d $(dirname ${CONFIG})
126     fi
127     : > ${CONFIG}
128     }
129    
130     # root is not allowed to run progs in a user session with newer xorg-servers
131     # this wrapper runs a command in the xsession of the unpriv_user
132     x11runas()
133     {
134     if [[ -n $(pidof X) ]]
135     then
136     su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"
137     fi
138     }
139    
140     # no_duplicate $list $item
141     no_duplicate()
142     {
143     local i
144     local list="$1"
145     local item="$2"
146    
147     for i in ${list}
148     do
149     [[ ${i} = ${item} ]] && return 1
150     done
151    
152     return 0
153     }
154    
155     # checks if given path is empty
156     path_not_empty()
157     {
158     local path="$1"
159     [[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1
160    
161     # return ERR if path does not exist
162     [[ ! -d ${path} ]] && return 1
163     # return ERR if path empty
164     [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1
165    
166     # every thing went ok, directory not empty
167     return 0
168     }
169    
170     # list all files in a given directory
171     list_files_in_directory()
172     {
173     local i
174     local retval
175     local path
176     local opts
177     local type
178    
179     # basic getops
180     for i in $*
181     do
182     case $1 in
183     -mindepth) shift; opts+=" -mindepth $1" ;;
184     -maxdepth) shift; opts+=" -maxdepth $1" ;;
185     -type) shift; type="$1" ;;
186     -name) shift; opts+=" -name $1" ;;
187     '') continue ;;
188     *) path="$1" ;;
189     esac
190     shift
191     done
192    
193     if [[ -z ${path} ]]
194     then
195     eecho "No path given."
196     return 1
197     fi
198    
199     if [[ ! -d ${path} ]]
200     then
201     eecho "Directory '${path}' does not exist."
202     return 1
203     fi
204    
205     # default to files
206     [[ -z ${type} ]] && type=f
207    
208     for i in $(find ${path} ${opts} -type ${type} -printf '%f\n' | sort)
209     do
210     if [[ -z ${retval} ]]
211     then
212     retval="${i}"
213     else
214     retval+=" ${i}"
215     fi
216     done
217    
218     rvecho "${retval}"
219     }
220    
221     # runs a command in the chroot of $MROOT
222     system_chroot()
223     {
224     local cmd="$@"
225     if [[ -z ${MROOT} ]]
226     then
227     echo "system_chroot(): \$MROOT was not set, doing nothing!"
228     return 1
229     fi
230     if [ ! -d ${MROOT} ]
231     then
232     eecho "system_chroot(): MROOT='${MROOT}' does not exist."
233     return 1
234     fi
235    
236     chroot ${MROOT} ${cmd}
237     }