/[baselayout]/trunk/init.d/functions.sh
Gentoo

Contents of /trunk/init.d/functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (show annotations) (download) (as text)
Sun Mar 10 22:57:28 2002 UTC (17 years, 8 months ago) by azarah
File MIME type: text/x-sh
File size: 4156 byte(s)
lost of fixes

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 getcols() {
24 echo "${2}"
25 }
26
27 COLS="$(stty size)"
28 COLS="$(getcols $COLS)"
29 COLS=$((${COLS} -7))
30 ENDCOL=$'\e[A\e['${COLS}'G'
31 #now, ${ENDCOL} will move us to the end of the column; irregardless of character width
32
33 NORMAL="\033[0m"
34 GOOD=$'\e[32;01m'
35 WARN=$'\e[33;01m'
36 BAD=$'\e[31;01m'
37 NORMAL=$'\e[0m'
38
39 HILITE=$'\e[36;01m'
40
41 ebegin() {
42 echo -e " ${GOOD}*${NORMAL} ${*}..."
43 }
44
45 ewarn() {
46 echo -e " ${WARN}*${NORMAL} ${*}"
47 }
48
49 eerror() {
50 echo -e " ${BAD}*${NORMAL} ${*}"
51 }
52
53 einfo() {
54 echo -e " ${GOOD}*${NORMAL} ${*}"
55 }
56
57 einfon() {
58 echo -ne " ${GOOD}*${NORMAL} ${*}"
59 }
60
61 # void eend(int error, char *errstr)
62 #
63 eend() {
64 if [ "$#" -eq 0 ] || [ "${1}" -eq 0 ]
65 then
66 echo -e "${ENDCOL} \e[34;01m[ ${GOOD}ok \e[34;01m]${NORMAL}"
67 else
68 local returnme="${1}"
69 if [ "$#" -ge 2 ]
70 then
71 shift
72 eerror "${*}"
73 fi
74 echo -e "${ENDCOL} \e[34;01m[ ${BAD}!! \e[34;01m]${NORMAL}"
75 echo
76 #extra spacing makes it easier to read
77 return ${returnme}
78 fi
79 }
80
81 # void ewend(int error, char *errstr)
82 #
83 ewend() {
84 if [ "$#" -eq 0 ] || [ "${1}" -eq 0 ]
85 then
86 echo -e "${ENDCOL} \e[34;01m[ ${GOOD}ok \e[34;01m]${NORMAL}"
87 else
88 local returnme="${1}"
89 if [ "$#" -ge 2 ]
90 then
91 shift
92 ewarn "${*}"
93 fi
94 echo -e "${ENDCOL} \e[34;01m[ ${WARN}!! \e[34;01m]${NORMAL}"
95 echo
96 #extra spacing makes it easier to read
97 return ${returnme}
98 fi
99 }
100
101 # bool wrap_rcscript(full_path_and_name_of_rc-script)
102 #
103 # return 0 if the script have no syntax errors in it
104 #
105 wrap_rcscript() {
106 local retval=1
107
108 ( echo "function test_script() {" ; cat ${1}; echo "}" ) > ${svcdir}/foo.sh
109
110 if source ${svcdir}/foo.sh &>/dev/null
111 then
112 test_script &>/dev/null
113 retval=0
114 fi
115 rm -f ${svcdir}/foo.sh
116 return ${retval}
117 }
118
119 # bool get_bootparam(param)
120 #
121 # return 0 if gentoo=param was passed to the kernel
122 #
123 # NOTE: you should always query the longer argument, for instance
124 # if you have 'nodevfs' and 'devfs', query 'nodevfs', or
125 # results may be unpredictable.
126 #
127 # if get_bootparam "nodevfs" -eq 0 ; then ....
128 #
129 get_bootparam() {
130 local copt=""
131 local parms=""
132 local retval=1
133 for copt in $(cat /proc/cmdline)
134 do
135 if [ "${copt%=*}" = "gentoo" ]
136 then
137 parms="${copt##*=}"
138 #parse gentoo option
139 if [ "$(eval echo \${parms/${1}/})" != "${parms}" ]
140 then
141 retval=0
142 fi
143 fi
144 done
145 return ${retval}
146 }
147
148 # Safer way to list the contents of a directory,
149 # as it do not have the "empty dir bug".
150 #
151 # char *dolisting(param)
152 #
153 # print a list of the directory contents
154 #
155 # NOTE: quote the params if they contain globs.
156 # also, error checking is not that extensive ...
157 #
158 dolisting() {
159 local x=""
160 local y=""
161 local tmpstr=""
162 local mylist=""
163 local mypath="${*}"
164
165 if [ "${mypath%/\*}" != "${mypath}" ]
166 then
167 mypath="${mypath%/\*}"
168 fi
169 for x in ${mypath}
170 do
171 if [ ! -e ${x} ]
172 then
173 continue
174 fi
175 if [ ! -d ${x} ] && ( [ -L ${x} ] || [ -f ${x} ] )
176 then
177 mylist="${mylist} $(ls ${x})"
178 else
179 if [ "${x%/}" != "${x}" ]
180 then
181 x="${x%/}"
182 fi
183 cd ${x}
184 tmpstr="$(ls)"
185 for y in ${tmpstr}
186 do
187 mylist="${mylist} ${x}/$(basename ${y})"
188 done
189 fi
190 done
191 echo "${mylist}"
192 }
193
194 # void save_options(char *option, char *optstring)
195 #
196 # save the settings ("optstring") for "option"
197 #
198 save_options() {
199 local myopts="${1}"
200 shift
201 if [ ! -d ${svcdir}/options/${myservice} ]
202 then
203 install -d -m0755 ${svcdir}/options/${myservice}
204 fi
205 echo "${*}" > ${svcdir}/options/${myservice}/${myopts}
206 }
207
208 # char *get_options(char *option)
209 #
210 # get the "optstring" for "option" that was saved
211 # by calling the save_options function
212 #
213 get_options() {
214 if [ -f ${svcdir}/options/${myservice}/${1} ]
215 then
216 cat ${svcdir}/options/${myservice}/${1}
217 fi
218 }
219
220
221 # vim:ts=4

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20