/[baselayout]/trunk/sbin/functions.sh
Gentoo

Contents of /trunk/sbin/functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 161 - (show annotations) (download) (as text)
Fri Apr 5 23:18:27 2002 UTC (11 years, 2 months ago) by azarah
File MIME type: text/x-sh
File size: 4700 byte(s)
move to /sbin

1 # Copyright 1999-2002 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License, v2 or later
3 # $Header$
4
5 #setup a basic $PATH
6 [ -z "${PATH}" ] && PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin"
7
8 #daemontools dir
9 SVCDIR=/var/lib/supervise
10
11 #rc-scripts dir
12 svcdir=/mnt/.init.d
13
14 #size of $svcdir in KB
15 svcsize=1024
16
17 #different types of dependancies
18 deptypes="need use"
19
20 #different types of order deps
21 ordtypes="before after"
22
23 QUIET_STDOUT="no"
24
25 getcols() {
26 echo "${2}"
27 }
28
29 COLS="$(stty size)"
30 COLS="$(getcols $COLS)"
31 COLS=$((${COLS} -7))
32 ENDCOL=$'\e[A\e['${COLS}'G'
33 #now, ${ENDCOL} will move us to the end of the column; irregardless of character width
34
35 NORMAL="\033[0m"
36 GOOD=$'\e[32;01m'
37 WARN=$'\e[33;01m'
38 BAD=$'\e[31;01m'
39 NORMAL=$'\e[0m'
40
41 HILITE=$'\e[36;01m'
42
43 ebegin() {
44 if [ "${QUIET_STDOUT}" = "yes" ]
45 then
46 return
47 else
48 echo -e " ${GOOD}*${NORMAL} ${*}..."
49 fi
50 }
51
52 ewarn() {
53 if [ "${QUIET_STDOUT}" = "yes" ]
54 then
55 echo " ${*}"
56 else
57 echo -e " ${WARN}*${NORMAL} ${*}"
58 fi
59 }
60
61 eerror() {
62 if [ "${QUIET_STDOUT}" = "yes" ]
63 then
64 echo " ${*}" >/dev/stderr
65 else
66 echo -e " ${BAD}*${NORMAL} ${*}"
67 fi
68 }
69
70 einfo() {
71 if [ "${QUIET_STDOUT}" = "yes" ]
72 then
73 return
74 else
75 echo -e " ${GOOD}*${NORMAL} ${*}"
76 fi
77 }
78
79 einfon() {
80 if [ "${QUIET_STDOUT}" = "yes" ]
81 then
82 return
83 else
84 echo -ne " ${GOOD}*${NORMAL} ${*}"
85 fi
86 }
87
88 # void eend(int error, char *errstr)
89 #
90 eend() {
91 if [ "$#" -eq 0 ] || [ "${1}" -eq 0 ]
92 then
93 if [ "${QUIET_STDOUT}" != "yes" ]
94 then
95 echo -e "${ENDCOL} \e[34;01m[ ${GOOD}ok \e[34;01m]${NORMAL}"
96 fi
97 else
98 local returnme="${1}"
99 if [ "$#" -ge 2 ]
100 then
101 shift
102 eerror "${*}"
103 fi
104 if [ "${QUIET_STDOUT}" != "yes" ]
105 then
106 echo -e "${ENDCOL} \e[34;01m[ ${BAD}!! \e[34;01m]${NORMAL}"
107 #extra spacing makes it easier to read
108 echo
109 fi
110 return ${returnme}
111 fi
112 }
113
114 # void ewend(int error, char *errstr)
115 #
116 ewend() {
117 if [ "$#" -eq 0 ] || [ "${1}" -eq 0 ]
118 then
119 if [ "${QUIET_STDOUT}" != "yes" ]
120 then
121 echo -e "${ENDCOL} \e[34;01m[ ${GOOD}ok \e[34;01m]${NORMAL}"
122 fi
123 else
124 local returnme="${1}"
125 if [ "$#" -ge 2 ]
126 then
127 shift
128 ewarn "${*}"
129 fi
130 if [ "${QUIET_STDOUT}" != "yes" ]
131 then
132 echo -e "${ENDCOL} \e[34;01m[ ${WARN}!! \e[34;01m]${NORMAL}"
133 #extra spacing makes it easier to read
134 echo
135 fi
136 return ${returnme}
137 fi
138 }
139
140 # bool wrap_rcscript(full_path_and_name_of_rc-script)
141 #
142 # return 0 if the script have no syntax errors in it
143 #
144 wrap_rcscript() {
145 local retval=1
146
147 ( echo "function test_script() {" ; cat ${1}; echo "}" ) > ${svcdir}/foo.sh
148
149 if source ${svcdir}/foo.sh &>/dev/null
150 then
151 test_script &>/dev/null
152 retval=0
153 fi
154 rm -f ${svcdir}/foo.sh
155 return ${retval}
156 }
157
158 # bool get_bootparam(param)
159 #
160 # return 0 if gentoo=param was passed to the kernel
161 #
162 # NOTE: you should always query the longer argument, for instance
163 # if you have 'nodevfs' and 'devfs', query 'nodevfs', or
164 # results may be unpredictable.
165 #
166 # if get_bootparam "nodevfs" -eq 0 ; then ....
167 #
168 get_bootparam() {
169 local copt=""
170 local parms=""
171 local retval=1
172 for copt in $(cat /proc/cmdline)
173 do
174 if [ "${copt%=*}" = "gentoo" ]
175 then
176 parms="${copt##*=}"
177 #parse gentoo option
178 if [ "$(eval echo \${parms/${1}/})" != "${parms}" ]
179 then
180 retval=0
181 fi
182 fi
183 done
184 return ${retval}
185 }
186
187 # Safer way to list the contents of a directory,
188 # as it do not have the "empty dir bug".
189 #
190 # char *dolisting(param)
191 #
192 # print a list of the directory contents
193 #
194 # NOTE: quote the params if they contain globs.
195 # also, error checking is not that extensive ...
196 #
197 dolisting() {
198 local x=""
199 local y=""
200 local tmpstr=""
201 local mylist=""
202 local mypath="${*}"
203
204 if [ "${mypath%/\*}" != "${mypath}" ]
205 then
206 mypath="${mypath%/\*}"
207 fi
208 for x in ${mypath}
209 do
210 if [ ! -e ${x} ]
211 then
212 continue
213 fi
214 if [ ! -d ${x} ] && ( [ -L ${x} ] || [ -f ${x} ] )
215 then
216 mylist="${mylist} $(ls ${x} 2>/dev/null)"
217 else
218 if [ "${x%/}" != "${x}" ]
219 then
220 x="${x%/}"
221 fi
222 cd ${x}
223 tmpstr="$(ls)"
224 for y in ${tmpstr}
225 do
226 mylist="${mylist} ${x}/${y}"
227 done
228 fi
229 done
230 echo "${mylist}"
231 }
232
233 # void save_options(char *option, char *optstring)
234 #
235 # save the settings ("optstring") for "option"
236 #
237 save_options() {
238 local myopts="${1}"
239 shift
240 if [ ! -d ${svcdir}/options/${myservice} ]
241 then
242 install -d -m0755 ${svcdir}/options/${myservice}
243 fi
244 echo "${*}" > ${svcdir}/options/${myservice}/${myopts}
245 }
246
247 # char *get_options(char *option)
248 #
249 # get the "optstring" for "option" that was saved
250 # by calling the save_options function
251 #
252 get_options() {
253 if [ -f ${svcdir}/options/${myservice}/${1} ]
254 then
255 cat ${svcdir}/options/${myservice}/${1}
256 fi
257 }
258
259
260 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20