init-functions 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  1. #!/bin/sh
  2. ########################################################################
  3. #
  4. # Begin /lib/services/init-funtions
  5. #
  6. # Description : Run Level Control Functions
  7. #
  8. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  9. # : DJ Lucas - dj@linuxfromscratch.org
  10. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  11. # : Thierry Nuttens - tnut@nutyx.org
  12. # : milisarge@gmail.com
  13. # Version : LFS 7.0
  14. # : milis
  15. #
  16. # Notes : With code based on Matthias Benkmann's simpleinit-msb
  17. # http://winterdrache.de/linux/newboot/index.html
  18. #
  19. # The file should be located in /lib/lsb, means
  20. # a symbolic link to service folder is done
  21. #
  22. ########################################################################
  23. ## Environmental setup
  24. # Setup default values for environment
  25. umask 022
  26. export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
  27. ## Screen Dimensions
  28. # Find current screen size
  29. if [ -z "${COLUMNS}" ]; then
  30. COLUMNS=$(stty size)
  31. COLUMNS=${COLUMNS##* }
  32. fi
  33. # When using remote connections, such as a serial port, stty size returns 0
  34. if [ "${COLUMNS}" = "0" ]; then
  35. COLUMNS=80
  36. fi
  37. ## Measurements for positioning result messages
  38. COL=$((${COLUMNS} - 12))
  39. WCOL=$((${COL} - 2))
  40. ## Set Cursor Position Commands, used via echo
  41. SET_COL="\\033[${COL}G" # at the $COL char
  42. SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
  43. CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
  44. CURS_ZERO="\\033[0G"
  45. ## Set color commands, used via echo
  46. # Please consult `man console_codes for more information
  47. # under the "ECMA-48 Set Graphics Rendition" section
  48. #
  49. # Warning: when switching from a 8bit to a 9bit font,
  50. # the linux console will reinterpret the bold (1;) to
  51. # the top 256 glyphs of the 9bit font. This does
  52. # not affect framebuffer consoles
  53. NORMAL="\\033[0;39m" # Standard console grey
  54. SUCCESS="\\033[1;32m" # Success is green
  55. WARNING="\\033[1;33m" # Warnings are yellow
  56. FAILURE="\\033[1;31m" # Failures are red
  57. INFO="\\033[1;36m" # Information is light cyan
  58. BRACKET="\\033[1;34m" # Brackets are blue
  59. # Use a colored prefix
  60. BMPREFIX=" "
  61. SUCCESS_PREFIX="${SUCCESS} * ${NORMAL}"
  62. FAILURE_PREFIX="${FAILURE}*****${NORMAL}"
  63. WARNING_PREFIX="${WARNING} *** ${NORMAL}"
  64. SUCCESS_SUFFIX="${BRACKET}[${SUCCESS} TAMAM ${BRACKET}]${NORMAL}"
  65. FAILURE_SUFFIX="${BRACKET}[${FAILURE} BASARISIZ ${BRACKET}]${NORMAL}"
  66. WARNING_SUFFIX="${BRACKET}[${WARNING} UYARI ${BRACKET}]${NORMAL}"
  67. BOOTLOG=/run/bootlog
  68. KILLDELAY=0
  69. [ "$verbose" == "no" ] && echo "" > $BOOTLOG
  70. # Set any user specified environment variables e.g. HEADLESS
  71. [ -r /etc/sysconfig/rc.site ] && . /etc/sysconfig/rc.site
  72. ################################################################################
  73. # start_daemon() #
  74. # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] #
  75. # #
  76. # Purpose: This runs the specified program as a daemon #
  77. # #
  78. # Inputs: -f: (force) run the program even if it is already running. #
  79. # -n nicelevel: specify a nice level. See 'man nice(1)'. #
  80. # -p pidfile: use the specified file to determine PIDs. #
  81. # pathname: the complete path to the specified program #
  82. # args: additional arguments passed to the program (pathname) #
  83. # #
  84. # Return values (as defined by LSB exit codes): #
  85. # 0 - program is running or service is OK #
  86. # 1 - generic or unspecified error #
  87. # 2 - invalid or excessive argument(s) #
  88. # 5 - program is not installed #
  89. ################################################################################
  90. start_daemon()
  91. {
  92. local force=""
  93. local nice="0"
  94. local pidfile=""
  95. local pidlist=""
  96. local retval=""
  97. # Process arguments
  98. while true
  99. do
  100. case "${1}" in
  101. -f)
  102. force="1"
  103. shift 1
  104. ;;
  105. -n)
  106. nice="${2}"
  107. shift 2
  108. ;;
  109. -p)
  110. pidfile="${2}"
  111. shift 2
  112. ;;
  113. -*)
  114. return 2
  115. ;;
  116. *)
  117. program="${1}"
  118. break
  119. ;;
  120. esac
  121. done
  122. # Check for a valid program
  123. if [ ! -e "${program}" ]; then return 5; fi
  124. # Execute
  125. if [ -z "${force}" ]; then
  126. if [ -z "${pidfile}" ]; then
  127. # Determine the pid by discovery
  128. pidlist=`pidofproc "${1}"`
  129. retval="${?}"
  130. else
  131. # The PID file contains the needed PIDs
  132. # Note that by LSB requirement, the path must be given to pidofproc,
  133. # however, it is not used by the current implementation or standard.
  134. pidlist=`pidofproc -p "${pidfile}" "${1}"`
  135. retval="${?}"
  136. fi
  137. # Return a value ONLY
  138. # It is the init script's (or distribution's functions) responsibilty
  139. # to log messages!
  140. case "${retval}" in
  141. 0)
  142. # Program is already running correctly, this is a
  143. # successful start.
  144. return 0
  145. ;;
  146. 1)
  147. # Program is not running, but an invalid pid file exists
  148. # remove the pid file and continue
  149. rm -f "${pidfile}"
  150. ;;
  151. 3)
  152. # Program is not running and no pidfile exists
  153. # do nothing here, let start_deamon continue.
  154. ;;
  155. *)
  156. # Others as returned by status values shall not be interpreted
  157. # and returned as an unspecified error.
  158. return 1
  159. ;;
  160. esac
  161. fi
  162. # Do the start!
  163. nice -n "${nice}" "${@}"
  164. }
  165. ################################################################################
  166. # killproc() #
  167. # Usage: killproc [-p pidfile] pathname [signal] #
  168. # #
  169. # Purpose: Send control signals to running processes #
  170. # #
  171. # Inputs: -p pidfile, uses the specified pidfile #
  172. # pathname, pathname to the specified program #
  173. # signal, send this signal to pathname #
  174. # #
  175. # Return values (as defined by LSB exit codes): #
  176. # 0 - program (pathname) has stopped/is already stopped or a #
  177. # running program has been sent specified signal and stopped #
  178. # successfully #
  179. # 1 - generic or unspecified error #
  180. # 2 - invalid or excessive argument(s) #
  181. # 5 - program is not installed #
  182. # 7 - program is not running and a signal was supplied #
  183. ################################################################################
  184. killproc()
  185. {
  186. local pidfile
  187. local program
  188. local prefix
  189. local progname
  190. local signal="-TERM"
  191. local fallback="-KILL"
  192. local nosig
  193. local pidlist
  194. local retval
  195. local pid
  196. local delay="30"
  197. local piddead
  198. local dtime
  199. # Process arguments
  200. while true; do
  201. case "${1}" in
  202. -p)
  203. pidfile="${2}"
  204. shift 2
  205. ;;
  206. *)
  207. program="${1}"
  208. if [ -n "${2}" ]; then
  209. signal="${2}"
  210. fallback=""
  211. else
  212. nosig=1
  213. fi
  214. # Error on additional arguments
  215. if [ -n "${3}" ]; then
  216. return 2
  217. else
  218. break
  219. fi
  220. ;;
  221. esac
  222. done
  223. # Check for a valid program
  224. if [ ! -e "${program}" ]; then return 5; fi
  225. # Check for a valid signal
  226. check_signal "${signal}"
  227. if [ "${?}" -ne "0" ]; then return 2; fi
  228. # Get a list of pids
  229. if [ -z "${pidfile}" ]; then
  230. # determine the pid by discovery
  231. pidlist=`pidofproc "${1}"`
  232. retval="${?}"
  233. else
  234. # The PID file contains the needed PIDs
  235. # Note that by LSB requirement, the path must be given to pidofproc,
  236. # however, it is not used by the current implementation or standard.
  237. pidlist=`pidofproc -p "${pidfile}" "${1}"`
  238. retval="${?}"
  239. fi
  240. # Return a value ONLY
  241. # It is the init script's (or distribution's functions) responsibilty
  242. # to log messages!
  243. case "${retval}" in
  244. 0)
  245. # Program is running correctly
  246. # Do nothing here, let killproc continue.
  247. ;;
  248. 1)
  249. # Program is not running, but an invalid pid file exists
  250. # Remove the pid file.
  251. rm -f "${pidfile}"
  252. # This is only a success if no signal was passed.
  253. if [ -n "${nosig}" ]; then
  254. return 0
  255. else
  256. return 7
  257. fi
  258. ;;
  259. 3)
  260. # Program is not running and no pidfile exists
  261. # This is only a success if no signal was passed.
  262. if [ -n "${nosig}" ]; then
  263. return 0
  264. else
  265. return 7
  266. fi
  267. ;;
  268. *)
  269. # Others as returned by status values shall not be interpreted
  270. # and returned as an unspecified error.
  271. return 1
  272. ;;
  273. esac
  274. # Perform different actions for exit signals and control signals
  275. check_sig_type "${signal}"
  276. if [ "${?}" -eq "0" ]; then # Signal is used to terminate the program
  277. # Account for empty pidlist (pid file still exists and no
  278. # signal was given)
  279. if [ "${pidlist}" != "" ]; then
  280. # Kill the list of pids
  281. for pid in ${pidlist}; do
  282. kill -0 "${pid}" 2> /dev/null
  283. if [ "${?}" -ne "0" ]; then
  284. # Process is dead, continue to next and assume all is well
  285. continue
  286. else
  287. kill "${signal}" "${pid}" 2> /dev/null
  288. # Wait up to ${delay}/10 seconds to for "${pid}" to
  289. # terminate in 10ths of a second
  290. while [ "${delay}" -ne "0" ]; do
  291. kill -0 "${pid}" 2> /dev/null || piddead="1"
  292. if [ "${piddead}" = "1" ]; then break; fi
  293. sleep 0.1
  294. delay="$(( ${delay} - 1 ))"
  295. done
  296. # If a fallback is set, and program is still running, then
  297. # use the fallback
  298. if [ -n "${fallback}" -a "${piddead}" != "1" ]; then
  299. kill "${fallback}" "${pid}" 2> /dev/null
  300. sleep 1
  301. # Check again, and fail if still running
  302. kill -0 "${pid}" 2> /dev/null && return 1
  303. fi
  304. fi
  305. done
  306. fi
  307. # Check for and remove stale PID files.
  308. if [ -z "${pidfile}" ]; then
  309. # Find the basename of $program
  310. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  311. progname=`echo "${program}" | sed "s@${prefix}@@"`
  312. if [ -e "/var/run/${progname}.pid" ]; then
  313. rm -f "/var/run/${progname}.pid" 2> /dev/null
  314. fi
  315. else
  316. if [ -e "${pidfile}" ]; then rm -f "${pidfile}" 2> /dev/null; fi
  317. fi
  318. # For signals that do not expect a program to exit, simply
  319. # let kill do its job, and evaluate kill's return for value
  320. else # check_sig_type - signal is not used to terminate program
  321. for pid in ${pidlist}; do
  322. kill "${signal}" "${pid}"
  323. if [ "${?}" -ne "0" ]; then return 1; fi
  324. done
  325. fi
  326. }
  327. ################################################################################
  328. # pidofproc() #
  329. # Usage: pidofproc [-p pidfile] pathname #
  330. # #
  331. # Purpose: This function returns one or more pid(s) for a particular daemon #
  332. # #
  333. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  334. # pathname, path to the specified program #
  335. # #
  336. # Return values (as defined by LSB status codes): #
  337. # 0 - Success (PIDs to stdout) #
  338. # 1 - Program is dead, PID file still exists (remaining PIDs output) #
  339. # 3 - Program is not running (no output) #
  340. ################################################################################
  341. pidofproc()
  342. {
  343. local pidfile
  344. local program
  345. local prefix
  346. local progname
  347. local pidlist
  348. local lpids
  349. local exitstatus="0"
  350. # Process arguments
  351. while true; do
  352. case "${1}" in
  353. -p)
  354. pidfile="${2}"
  355. shift 2
  356. ;;
  357. *)
  358. program="${1}"
  359. if [ -n "${2}" ]; then
  360. # Too many arguments
  361. # Since this is status, return unknown
  362. return 4
  363. else
  364. break
  365. fi
  366. ;;
  367. esac
  368. done
  369. # If a PID file is not specified, try and find one.
  370. if [ -z "${pidfile}" ]; then
  371. # Get the program's basename
  372. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  373. if [ -z "${prefix}" ]; then
  374. progname="${program}"
  375. else
  376. progname=`echo "${program}" | sed "s@${prefix}@@"`
  377. fi
  378. # If a PID file exists with that name, assume that is it.
  379. if [ -e "/var/run/${progname}.pid" ]; then
  380. pidfile="/var/run/${progname}.pid"
  381. fi
  382. fi
  383. # If a PID file is set and exists, use it.
  384. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  385. # Use the value in the first line of the pidfile
  386. pidlist=`/bin/head -n1 "${pidfile}"`
  387. # This can optionally be written as 'sed 1q' to repalce 'head -n1'
  388. # should LFS move /bin/head to /usr/bin/head
  389. else
  390. # Use pidof
  391. pidlist=`pidof "${program}"`
  392. fi
  393. # Figure out if all listed PIDs are running.
  394. for pid in ${pidlist}; do
  395. kill -0 ${pid} 2> /dev/null
  396. if [ "${?}" -eq "0" ]; then
  397. lpids="${lpids}${pid} "
  398. else
  399. exitstatus="1"
  400. fi
  401. done
  402. if [ -z "${lpids}" -a ! -f "${pidfile}" ]; then
  403. return 3
  404. else
  405. echo "${lpids}"
  406. return "${exitstatus}"
  407. fi
  408. }
  409. ################################################################################
  410. # statusproc() #
  411. # Usage: statusproc [-p pidfile] pathname #
  412. # #
  413. # Purpose: This function prints the status of a particular daemon to stdout #
  414. # #
  415. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  416. # pathname, path to the specified program #
  417. # #
  418. # Return values: #
  419. # 0 - Status printed #
  420. # 1 - Input error. The daemon to check was not specified. #
  421. ################################################################################
  422. statusproc()
  423. {
  424. local pidfile
  425. local pidlist
  426. if [ "${#}" = "0" ]; then
  427. echo "Usage: statusproc [-p pidfle] {program}"
  428. exit 1
  429. fi
  430. # Process arguments
  431. while true; do
  432. case "${1}" in
  433. -p)
  434. pidfile="${2}"
  435. shift 2
  436. ;;
  437. *)
  438. if [ -n "${2}" ]; then
  439. echo "Too many arguments"
  440. return 1
  441. else
  442. break
  443. fi
  444. ;;
  445. esac
  446. done
  447. if [ -n "${pidfile}" ]; then
  448. pidlist=`pidofproc -p "${pidfile}" $@`
  449. else
  450. pidlist=`pidofproc $@`
  451. fi
  452. # Trim trailing blanks
  453. pidlist=`echo "${pidlist}" | sed -r 's/ +$//'`
  454. base="${1##*/}"
  455. if [ -n "${pidlist}" ]; then
  456. /bin/echo -e "${INFO}${base} is running with Process" \
  457. "ID(s) ${pidlist}.${NORMAL}"
  458. else
  459. if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
  460. /bin/echo -e "${WARNING}${1} is not running but" \
  461. "/var/run/${base}.pid exists.${NORMAL}"
  462. else
  463. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  464. /bin/echo -e "${WARNING}${1} is not running" \
  465. "but ${pidfile} exists.${NORMAL}"
  466. else
  467. /bin/echo -e "${INFO}${1} is not running.${NORMAL}"
  468. fi
  469. fi
  470. fi
  471. }
  472. ################################################################################
  473. # timespec() #
  474. # #
  475. # Purpose: An internal utility function to format a timestamp #
  476. # a boot log file. Sets the STAMP variable. #
  477. # #
  478. # Return value: Not used #
  479. ################################################################################
  480. timespec()
  481. {
  482. STAMP="$(echo `date +"%b %d %T %:z"` `hostname`) "
  483. return 0
  484. }
  485. ################################################################################
  486. # log_success_msg() #
  487. # Usage: log_success_msg ["message"] #
  488. # #
  489. # Purpose: Print a successful status message to the screen and #
  490. # a boot log file. #
  491. # #
  492. # Inputs: $@ - Message #
  493. # #
  494. # Return values: Not used #
  495. ################################################################################
  496. log_success_msg()
  497. {
  498. if [ "$verbose" == "no" ]; then
  499. return 0
  500. fi
  501. /bin/echo -n -e "${BMPREFIX}${@}"
  502. /bin/echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
  503. # Strip non-printable characters from log file
  504. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  505. timespec
  506. /bin/echo -e "${STAMP} ${logmessage} OK" >> ${BOOTLOG}
  507. return 0
  508. }
  509. log_success_msg2()
  510. {
  511. if [ "$verbose" == "no" ]; then
  512. return 0
  513. fi
  514. /bin/echo -n -e "${BMPREFIX}${@}"
  515. /bin/echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
  516. echo " OK" >> ${BOOTLOG}
  517. return 0
  518. }
  519. ################################################################################
  520. # log_failure_msg() #
  521. # Usage: log_failure_msg ["message"] #
  522. # #
  523. # Purpose: Print a failure status message to the screen and #
  524. # a boot log file. #
  525. # #
  526. # Inputs: $@ - Message #
  527. # #
  528. # Return values: Not used #
  529. ################################################################################
  530. log_failure_msg()
  531. {
  532. /bin/echo -n -e "${BMPREFIX}${@}"
  533. /bin/echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
  534. # Strip non-printable characters from log file
  535. timespec
  536. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  537. /bin/echo -e "${STAMP} ${logmessage} BAŞARISIZ" >> ${BOOTLOG}
  538. return 0
  539. }
  540. log_failure_msg2()
  541. {
  542. /bin/echo -n -e "${BMPREFIX}${@}"
  543. /bin/echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
  544. echo "BAŞARISIZ" >> ${BOOTLOG}
  545. return 0
  546. }
  547. ################################################################################
  548. # log_warning_msg() #
  549. # Usage: log_warning_msg ["message"] #
  550. # #
  551. # Purpose: Print a warning status message to the screen and #
  552. # a boot log file. #
  553. # #
  554. # Return values: Not used #
  555. ################################################################################
  556. log_warning_msg()
  557. {
  558. /bin/echo -n -e "${BMPREFIX}${@}"
  559. /bin/echo -e "${CURS_ZERO}${WARNING_PREFIX}${SET_COL}${WARNING_SUFFIX}"
  560. # Strip non-printable characters from log file
  561. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  562. timespec
  563. /bin/echo -e "${STAMP} ${logmessage} UYARI" >> ${BOOTLOG}
  564. return 0
  565. }
  566. ################################################################################
  567. # log_info_msg() #
  568. # Usage: log_info_msg message #
  569. # #
  570. # Purpose: Print an information message to the screen and #
  571. # a boot log file. Does not print a trailing newline character. #
  572. # #
  573. # Return values: Not used #
  574. ################################################################################
  575. log_info_msg()
  576. {
  577. if [ "$verbose" == "no" ]; then
  578. return 0
  579. fi
  580. /bin/echo -n -e "${BMPREFIX}${@}"
  581. # Strip non-printable characters from log file
  582. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  583. timespec
  584. /bin/echo -n -e "${STAMP} ${logmessage}" >> ${BOOTLOG}
  585. return 0
  586. }
  587. log_info_msg2()
  588. {
  589. if [ "$verbose" == "no" ] ; then
  590. return 0
  591. fi
  592. /bin/echo -n -e "${@}"
  593. # Strip non-printable characters from log file
  594. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  595. /bin/echo -n -e "${logmessage}" >> ${BOOTLOG}
  596. return 0
  597. }
  598. ################################################################################
  599. # evaluate_retval() #
  600. # Usage: Evaluate a return value and print success or failyure as appropriate #
  601. # #
  602. # Purpose: Convenience function to terminate an info message #
  603. # #
  604. # Return values: Not used #
  605. ################################################################################
  606. evaluate_retval()
  607. {
  608. local error_value="${?}"
  609. if [ ${error_value} = 0 ]; then
  610. if [ "$verbose" != "no" ]; then
  611. log_success_msg2
  612. fi
  613. else
  614. log_failure_msg2
  615. fi
  616. }
  617. ################################################################################
  618. # check_signal() #
  619. # Usage: check_signal [ -{signal} | {signal} ] #
  620. # #
  621. # Purpose: Check for a valid signal. This is not defined by any LSB draft, #
  622. # however, it is required to check the signals to determine if the #
  623. # signals chosen are invalid arguments to the other functions. #
  624. # #
  625. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  626. # #
  627. # Return values: #
  628. # 0 - Success (signal is valid #
  629. # 1 - Signal is not valid #
  630. ################################################################################
  631. check_signal()
  632. {
  633. local valsig
  634. # Add error handling for invalid signals
  635. valsig="-ALRM -HUP -INT -KILL -PIPE -POLL -PROF -TERM -USR1 -USR2"
  636. valsig="${valsig} -VTALRM -STKFLT -PWR -WINCH -CHLD -URG -TSTP -TTIN"
  637. valsig="${valsig} -TTOU -STOP -CONT -ABRT -FPE -ILL -QUIT -SEGV -TRAP"
  638. valsig="${valsig} -SYS -EMT -BUS -XCPU -XFSZ -0 -1 -2 -3 -4 -5 -6 -8 -9"
  639. valsig="${valsig} -11 -13 -14 -15"
  640. echo "${valsig}" | grep -- " ${1} " > /dev/null
  641. if [ "${?}" -eq "0" ]; then
  642. return 0
  643. else
  644. return 1
  645. fi
  646. }
  647. ################################################################################
  648. # check_sig_type() #
  649. # Usage: check_signal [ -{signal} | {signal} ] #
  650. # #
  651. # Purpose: Check if signal is a program termination signal or a control signal #
  652. # This is not defined by any LSB draft, however, it is required to #
  653. # check the signals to determine if they are intended to end a #
  654. # program or simply to control it. #
  655. # #
  656. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  657. # #
  658. # Return values: #
  659. # 0 - Signal is used for program termination #
  660. # 1 - Signal is used for program control #
  661. ################################################################################
  662. check_sig_type()
  663. {
  664. local valsig
  665. # The list of termination signals (limited to generally used items)
  666. valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15"
  667. echo "${valsig}" | grep -- " ${1} " > /dev/null
  668. if [ "${?}" -eq "0" ]; then
  669. return 0
  670. else
  671. return 1
  672. fi
  673. }
  674. ################################################################################
  675. # wait_for_user() #
  676. # #
  677. # Purpose: Wait for the user to respond if not a headless system #
  678. # #
  679. ################################################################################
  680. wait_for_user()
  681. {
  682. # Wait for the user by default
  683. [ "${HEADLESS=0}" = "0" ] && read ENTER
  684. return 0
  685. }
  686. ################################################################################
  687. # is_true() #
  688. # #
  689. # Purpose: Utility to test if a variable is true | yes | 1 #
  690. # #
  691. ################################################################################
  692. is_true()
  693. {
  694. [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "y" ] ||
  695. [ "$1" = "t" ]
  696. }
  697. ################################################################################
  698. # create_files() #
  699. # #
  700. # Purpose: create files from ${name}, ${maj}, ${min}, ${usr}, ${grp}, ${perm} #
  701. # ${type} ${dtype} #
  702. ################################################################################
  703. create_files()
  704. {
  705. # Input to file descriptor 9 and output to stdin (redirection)
  706. exec 9>&0 < /etc/sysconfig/createfiles
  707. while read name type perm usr grp dtype maj min junk
  708. do
  709. # Ignore comments and blank lines.
  710. case "${name}" in
  711. ""|\#*) continue ;;
  712. esac
  713. # Ignore existing files.
  714. if [ ! -e "${name}" ]; then
  715. # Create stuff based on its type.
  716. case "${type}" in
  717. dir)
  718. mkdir "${name}"
  719. ;;
  720. file)
  721. :> "${name}"
  722. ;;
  723. dev)
  724. case "${dtype}" in
  725. char)
  726. mknod "${name}" c ${maj} ${min}
  727. ;;
  728. block)
  729. mknod "${name}" b ${maj} ${min}
  730. ;;
  731. pipe)
  732. mknod "${name}" p
  733. ;;
  734. *)
  735. log_warning_msg "\nUnknown device type: ${dtype}"
  736. ;;
  737. esac
  738. ;;
  739. *)
  740. log_warning_msg "\nUnknown type: ${type}"
  741. continue
  742. ;;
  743. esac
  744. fi
  745. # Set up the permissions, too even if it exist allready
  746. chown ${usr}:${grp} "${name}"
  747. chmod ${perm} "${name}"
  748. done
  749. # Close file descriptor 9 (end redirection)
  750. exec 0>&9 9>&-
  751. return 0
  752. }
  753. ################################################################################
  754. # do_mount_virtualfs() #
  755. # #
  756. # Purpose: first mounting process, all the virtual system must be mounted #
  757. # prior anything #
  758. # #
  759. ################################################################################
  760. do_mount_virtualfs()
  761. {
  762. if ! mountpoint /run >/dev/null; then
  763. mount /run || failed=1
  764. fi
  765. mkdir -p /run/lock /run/shm
  766. chmod 1777 /run/shm
  767. log_info_msg "Mounting virtual file systems: ${INFO}/run"
  768. if ! mountpoint /proc >/dev/null; then
  769. log_info_msg2 " ${INFO}/proc"
  770. mount -o nosuid,noexec,nodev /proc || failed=1
  771. fi
  772. if ! mountpoint /sys >/dev/null; then
  773. log_info_msg2 " ${INFO}/sys"
  774. mount -o nosuid,noexec,nodev /sys || failed=1
  775. fi
  776. if ! mountpoint /dev >/dev/null; then
  777. log_info_msg2 " ${INFO}/dev"
  778. mount -o mode=0755,nosuid /dev || failed=1
  779. fi
  780. ln -sfn /run/shm /dev/shm
  781. (exit ${failed})
  782. evaluate_retval
  783. }
  784. ################################################################################
  785. # do_start_localnet() do_stop_localnet() #
  786. # #
  787. # Purpose: Sets the hostname of the machine and starts the #
  788. # loopback interface. #
  789. ################################################################################
  790. do_start_localnet()
  791. {
  792. [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
  793. [ -r /etc/hostname ] && HOSTNAME=`cat /etc/hostname`
  794. log_info_msg "Bringing up the loopback interface..."
  795. ip addr add 127.0.0.1/8 label lo dev lo
  796. ip link set lo up
  797. evaluate_retval
  798. log_info_msg "Setting hostname to ${HOSTNAME}..."
  799. hostname ${HOSTNAME}
  800. evaluate_retval
  801. }
  802. do_stop_localnet()
  803. {
  804. log_info_msg "Bringing down the loopback interface..."
  805. ip link set lo down
  806. evaluate_retval
  807. }
  808. ################################################################################
  809. # do_load_modules() #
  810. # #
  811. # Purpose: Module auto-loading function #
  812. # #
  813. ################################################################################
  814. do_load_modules()
  815. {
  816. # Assure that the kernel has module support.
  817. [ -e /proc/modules ] || return 0
  818. for FILE in /etc/sysconfig/modules /etc/sysconfig/modules.d/*.conf
  819. do
  820. [ ! -f $FILE ] && continue
  821. # Continue with next if there's no modules file or there are no
  822. # valid entries
  823. [ -r $FILE ] || continue
  824. egrep -qv '^($|#)' $FILE || continue
  825. log_info_msg "Loading modules:"
  826. break
  827. done
  828. for FILE in /etc/sysconfig/modules /etc/sysconfig/modules.d/*.conf
  829. do
  830. [ ! -f $FILE ] && continue
  831. [ -r $FILE ] || continue
  832. egrep -qv '^($|#)' $FILE || continue
  833. while read module args; do
  834. # Ignore comments and blank lines.
  835. case "$module" in
  836. ""|"#"*) continue ;;
  837. esac
  838. # Attempt to load the module, passing any arguments provided.
  839. modprobe ${module} ${args} >/dev/null
  840. # Print the module name if successful, otherwise take note.
  841. if [ $? -eq 0 ]; then
  842. log_info_msg2 " ${module}"
  843. else
  844. failedmod="${failedmod} ${module}"
  845. fi
  846. done < $FILE
  847. done
  848. # fi
  849. # Print a message about successfully loaded modules on the correct line.
  850. log_success_msg2
  851. # Print a failure message with a list of any modules that
  852. # may have failed to load.
  853. if [ -n "${failedmod}" ]; then
  854. log_failure_msg "Failed to load modules:${failedmod}"
  855. fi
  856. return 0
  857. }
  858. ################################################################################
  859. # do_start_udev do_stop_udev #
  860. # #
  861. # Purpose: Udev cold-plugging start and shutdown functions #
  862. # #
  863. ################################################################################
  864. do_start_udev()
  865. {
  866. log_info_msg "Populating /dev with device nodes... "
  867. if ! grep -q '[[:space:]]sysfs' /proc/mounts; then
  868. log_failure_msg2
  869. msg="FAILURE:\n\nUnable to create "
  870. msg="${msg}devices without a SysFS filesystem\n\n"
  871. msg="${msg}After you press Enter, this system "
  872. msg="${msg}will be halted and powered off.\n\n"
  873. log_info_msg "$msg"
  874. log_info_msg "Press Enter to continue..."
  875. wait_for_user
  876. /etc/rc.d/init.d/halt stop
  877. fi
  878. # Udev handles uevents itself, so we don't need to have
  879. # the kernel call out to any binary in response to them
  880. [ -f /proc/sys/kernel/hotplug ] && echo > /proc/sys/kernel/hotplug
  881. # Start the udev daemon to continually watch for, and act on,
  882. # uevents
  883. /sbin/udevd --daemon --resolve-names=never
  884. # Now traverse /sys in order to "coldplug" devices that have
  885. # already been discovered
  886. /sbin/udevadm trigger --action=add --type=subsystems
  887. /sbin/udevadm trigger --action=add --type=devices
  888. /sbin/udevadm trigger --action=change --type=devices
  889. # Now wait for udevd to process the uevents we triggered
  890. if ! is_true "$OMIT_UDEV_SETTLE"; then
  891. /sbin/udevadm settle
  892. fi
  893. # If any LVM based partitions are on the system, ensure they
  894. # are activated so they can be used.
  895. if [ -x /sbin/vgchange ]; then /sbin/vgchange -a y >/dev/null; fi
  896. log_success_msg2
  897. }
  898. do_stop_udev()
  899. {
  900. udevadm control --exit
  901. udevadm info --cleanup-db
  902. }
  903. ################################################################################
  904. # do_start_clock() do_stop_clock() #
  905. # #
  906. # Purpose: On boot, system time is obtained from hwclock. The #
  907. # hardware clock can also be set on shutdown. #
  908. ################################################################################
  909. do_start_clock()
  910. {
  911. [ -r /etc/sysconfig/clock ] && . /etc/sysconfig/clock
  912. case "${UTC}" in
  913. yes|true|1)
  914. CLOCKPARAMS="${CLOCKPARAMS} --utc"
  915. CLOCKMODE="utc"
  916. ;;
  917. no|false|0)
  918. CLOCKPARAMS="${CLOCKPARAMS} --localtime"
  919. CLOCKMODE="localtime"
  920. ;;
  921. esac
  922. hwclock --hctosys ${CLOCKPARAMS} >/dev/null
  923. log_info_msg "Setting hardware clock to ${CLOCKMODE}..."
  924. evaluate_retval
  925. }
  926. do_stop_clock()
  927. {
  928. log_info_msg "Setting hardware clock..."
  929. hwclock --systohc ${CLOCKPARAMS} >/dev/null
  930. evaluate_retval
  931. }
  932. ################################################################################
  933. # do_start_checkfs() #
  934. # #
  935. # Purpose: Checks local filesystmes before mounting. #
  936. # #
  937. ################################################################################
  938. do_start_checkfs()
  939. {
  940. if [ -f /fastboot ]; then
  941. msg="/fastboot found, will omit "
  942. msg="${msg} file system checks as requested.\n"
  943. log_info_msg "${msg}"
  944. return 0
  945. fi
  946. log_info_msg "Mounting root file system in read-only mode... "
  947. mount -n -o remount,ro / >/dev/null
  948. if [ ${?} != 0 ]; then
  949. log_failure_msg2
  950. msg="\n\nCannot check root "
  951. msg="${msg}filesystem because it could not be mounted "
  952. msg="${msg}in read-only mode.\n\n"
  953. msg="${msg}After you press Enter, this system will be "
  954. msg="${msg}halted and powered off.\n\n"
  955. log_failure_msg "${msg}"
  956. log_info_msg "Press Enter to continue..."
  957. wait_for_user
  958. /etc/rc.d/init.d/halt stop
  959. else
  960. log_success_msg2
  961. fi
  962. if [ -f /forcefsck ]; then
  963. msg="\n/forcefsck found, forcing file"
  964. msg="${msg} system checks as requested."
  965. log_success_msg "$msg"
  966. options="-f"
  967. else
  968. options=""
  969. fi
  970. log_info_msg "Checking file systems..."
  971. # Note: -a option used to be -p; but this fails e.g. on fsck.minix
  972. if is_true "$VERBOSE_FSCK"; then
  973. fsck ${options} -a -A -C -T
  974. else
  975. fsck ${options} -a -A -C -T >/dev/null
  976. fi
  977. error_value=${?}
  978. if [ "${error_value}" = 0 ]; then
  979. log_success_msg2
  980. fi
  981. if [ "${error_value}" = 1 ]; then
  982. msg="\nWARNING:\n\nFile system errors "
  983. msg="${msg}were found and have been corrected.\n"
  984. msg="${msg}You may want to double-check that "
  985. msg="${msg}everything was fixed properly."
  986. log_warning_msg "$msg"
  987. fi
  988. if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
  989. msg="\nWARNING:\n\nFile system errors "
  990. msg="${msg}were found and have been been "
  991. msg="${msg}corrected, but the nature of the "
  992. msg="${msg}errors require this system to be rebooted.\n\n"
  993. msg="${msg}After you press enter, "
  994. msg="${msg}this system will be rebooted\n\n"
  995. log_failure_msg "$msg"
  996. log_info_msg "Press Enter to continue..."
  997. wait_for_user
  998. reboot -f
  999. fi
  1000. if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
  1001. msg="\nFAILURE:\n\nFile system errors "
  1002. msg="${msg}were encountered that could not be "
  1003. msg="${msg}fixed automatically. This system "
  1004. msg="${msg}cannot continue to boot and will "
  1005. msg="${msg}therefore be halted until those "
  1006. msg="${msg}errors are fixed manually by a "
  1007. msg="${msg}System Administrator.\n\n"
  1008. msg="${msg}After you press Enter, this system will be "
  1009. msg="${msg}halted and powered off.\n\n"
  1010. log_failure_msg "$msg"
  1011. log_info_msg "Press Enter to continue..."
  1012. wait_for_user
  1013. /etc/rc.d/init.d/halt stop
  1014. fi
  1015. if [ "${error_value}" -ge 16 ]; then
  1016. msg="\nFAILURE:\n\nUnexpected Failure "
  1017. msg="${msg}running fsck. Exited with error "
  1018. msg="${msg} code: ${error_value}."
  1019. log_failure_msg $msg
  1020. return ${error_value}
  1021. fi
  1022. return 0
  1023. }
  1024. do_start_mountfs()
  1025. {
  1026. log_info_msg "Remounting root file system in read-write mode..."
  1027. mount -o remount,rw / >/dev/null
  1028. evaluate_retval
  1029. # Remove fsck-related file system watermarks.
  1030. rm -f /fastboot /forcefsck
  1031. # Make sure /dev/pts exists
  1032. mkdir -p /dev/pts
  1033. # This will mount all filesystems that do not have _netdev in
  1034. # their option list. _netdev denotes a network filesystem.
  1035. log_info_msg "Mounting remaining file systems..."
  1036. mount -a -O no_netdev >/dev/null
  1037. evaluate_retval
  1038. return $failed
  1039. }
  1040. do_stop_mountfs()
  1041. {
  1042. # Don't unmount virtual file systems like /run
  1043. log_info_msg "Unmounting all other currently mounted file systems..."
  1044. umount -a -d -r -t notmpfs,nosysfs,nodevtmpfs,noproc,nodevpts >/dev/null
  1045. evaluate_retval
  1046. # Make sure / is mounted read only (umount bug)
  1047. log_info_msg "Remonting root file system in read-only mode..."
  1048. mount -o remount,ro /
  1049. evaluate_retval
  1050. # Make all LVM volume groups unavailable, if appropriate
  1051. # This fails if swap or / are on an LVM partition
  1052. #if [ -x /sbin/vgchange ]; then /sbin/vgchange -an > /dev/null; fi
  1053. }
  1054. do_start_cleanfs()
  1055. {
  1056. log_info_msg "Cleaning file systems:"
  1057. if [ "${SKIPTMPCLEAN}" = "" ]; then
  1058. log_info_msg2 " /tmp"
  1059. chmod 1777 /tmp
  1060. cd /tmp &&
  1061. find . -xdev -mindepth 1 ! -name lost+found -delete || failed=1
  1062. fi
  1063. > /var/run/utmp
  1064. if grep -q '^utmp:' /etc/group ; then
  1065. chmod 664 /var/run/utmp
  1066. chgrp utmp /var/run/utmp
  1067. fi
  1068. (return ${failed})
  1069. evaluate_retval
  1070. if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then
  1071. log_info_msg "Creating files and directories... "
  1072. create_files # Always returns 0
  1073. evaluate_retval
  1074. fi
  1075. return $failed
  1076. }
  1077. ###############################################################################
  1078. # do_start_udev_retry() #
  1079. # Description: Replays any failed uevents that were skipped due to #
  1080. # slow hardware initialization, and creates those needed #
  1081. # device nodes #
  1082. ###############################################################################
  1083. do_start_udev_retry()
  1084. {
  1085. log_info_msg "Retrying failed uevents, if any..."
  1086. # As of udev-186, the --run option is no longer valid
  1087. #rundir=$(/sbin/udevadm info --run)
  1088. rundir=/run/udev
  1089. # From Debian: "copy the rules generated before / was mounted
  1090. # read-write":
  1091. for file in ${rundir}/tmp-rules--*; do
  1092. dest=${file##*tmp-rules--}
  1093. [ "$dest" = '*' ] && break
  1094. cat $file >> /etc/udev/rules.d/$dest
  1095. rm -f $file
  1096. done
  1097. # Re-trigger the uevents that may have failed,
  1098. # in hope they will succeed now
  1099. /bin/sed -e 's/#.*$//' /etc/sysconfig/udev_retry | /bin/grep -v '^$' | \
  1100. while read line ; do
  1101. for subsystem in $line ; do
  1102. /sbin/udevadm trigger --subsystem-match=$subsystem --action=add
  1103. done
  1104. done
  1105. # Now wait for udevd to process the uevents we triggered
  1106. if ! is_true "$OMIT_UDEV_RETRY_SETTLE"; then
  1107. /sbin/udevadm settle
  1108. fi
  1109. evaluate_retval
  1110. }
  1111. ################################################################################
  1112. # do_start_swap() do_stop_swap() #
  1113. # #
  1114. # Description: Mounts and unmounts swap partitions defined in #
  1115. # /etc/fstab. #
  1116. ################################################################################
  1117. do_start_swap()
  1118. {
  1119. log_info_msg "Activating all swap files/partitions..."
  1120. swapon -a
  1121. evaluate_retval
  1122. }
  1123. do_stop_swap()
  1124. {
  1125. log_info_msg "Deactivating all swap files/partitions..."
  1126. swapoff -a
  1127. evaluate_retval
  1128. }
  1129. do_start_console()
  1130. {
  1131. failed=0
  1132. [ -r /etc/sysconfig/console ] && . /etc/sysconfig/console
  1133. # See if we need to do anything
  1134. if [ -z "${KEYMAP}" ] && [ -z "${KEYMAP_CORRECTIONS}" ] &&
  1135. [ -z "${FONT}" ] && [ -z "${LEGACY_CHARSET}" ] &&
  1136. ! is_true "${UNICODE}"; then
  1137. return 0
  1138. fi
  1139. # There should be no bogus failures below this line!
  1140. log_info_msg "Setting up Linux console..."
  1141. # Figure out if a framebuffer console is used
  1142. [ -d /sys/class/graphics/fb0 ] && use_fb=1 || use_fb=0
  1143. # Figure out the command to set the console into the
  1144. # desired mode
  1145. is_true "${UNICODE}" &&
  1146. MODE_COMMAND="echo -en '\033%G' && kbd_mode -u" ||
  1147. MODE_COMMAND="echo -en '\033%@\033(K' && kbd_mode -a"
  1148. # On framebuffer consoles, font has to be set for each vt in
  1149. # UTF-8 mode. This doesn't hurt in non-UTF-8 mode also.
  1150. ! is_true "${use_fb}" || [ -z "${FONT}" ] ||
  1151. MODE_COMMAND="${MODE_COMMAND} && setfont ${FONT}"
  1152. # Apply that command to all consoles mentioned in
  1153. # /etc/inittab. Important: in the UTF-8 mode this should
  1154. # happen before setfont, otherwise a kernel bug will
  1155. # show up and the unicode map of the font will not be
  1156. # used.
  1157. for TTY in `grep '^[^#].*respawn:/sbin/agetty' /etc/inittab |
  1158. grep -o '\btty[[:digit:]]*\b'`
  1159. do
  1160. openvt -f -w -c ${TTY#tty} -- \
  1161. /bin/sh -c "${MODE_COMMAND}" || failed=1
  1162. done
  1163. # Set the font (if not already set above) and the keymap
  1164. [ "${use_fb}" == "1" ] || [ -z "${FONT}" ] || setfont $FONT || failed=1
  1165. [ -z "${KEYMAP}" ] ||
  1166. loadkeys ${KEYMAP} >/dev/null 2>&1 ||
  1167. failed=1
  1168. [ -z "${KEYMAP_CORRECTIONS}" ] ||
  1169. loadkeys ${KEYMAP_CORRECTIONS} >/dev/null 2>&1 ||
  1170. failed=1
  1171. # Convert the keymap from $LEGACY_CHARSET to UTF-8
  1172. [ -z "$LEGACY_CHARSET" ] ||
  1173. dumpkeys -c "$LEGACY_CHARSET" | loadkeys -u >/dev/null 2>&1 ||
  1174. failed=1
  1175. # If any of the commands above failed, the trap at the
  1176. # top would set $failed to 1
  1177. ( return $failed )
  1178. evaluate_retval
  1179. return $failed
  1180. }
  1181. ################################################################################
  1182. # do_start_sysctl() #
  1183. # #
  1184. # Description : File uses /etc/sysctl.conf to set kernel runtime #
  1185. # #
  1186. ################################################################################
  1187. do_start_sysctl()
  1188. {
  1189. if [ -f "/etc/sysctl.conf" ]; then
  1190. log_info_msg "Setting kernel runtime parameters..."
  1191. sysctl -q -p
  1192. evaluate_retval
  1193. fi
  1194. }
  1195. ################################################################################
  1196. # bolumleri_bagla() #
  1197. # #
  1198. # Description : disk bolumlerinin otomatik baglanması #
  1199. # #
  1200. ################################################################################
  1201. bolumleri_bagla()
  1202. {
  1203. if [ -f /usr/bin/devmon ]; then
  1204. devmon --internal 2>&1 > /tmp/devmon.log &
  1205. fi
  1206. }
  1207. ################################################################################
  1208. # klavye_ayar() #
  1209. # #
  1210. # Description : klavye ayarlama #
  1211. # #
  1212. ################################################################################
  1213. klavye_ayar()
  1214. {
  1215. log_info_msg "Setting Keyboard...."
  1216. local KLAVYE
  1217. KLAVYE="`cat /proc/cmdline | tr " " "\n" | grep -E "^KEYBOARD=.*" | cut -d'=' -f2`"
  1218. # Klavye tanımlı değilse öntanımlı Türkçe Q
  1219. if [ -z $KLAVYE ];then
  1220. KLAVYE=trq
  1221. fi
  1222. loadkeys $KLAVYE
  1223. [ "$?" = "0" ] && log_success_msg "" || log_failure_msg ""
  1224. }
  1225. ################################################################################
  1226. # yerel_ayar() #
  1227. # #
  1228. # Description : yerel ayarlama #
  1229. # #
  1230. ################################################################################
  1231. yerel_ayar()
  1232. {
  1233. log_info_msg "Setting Locale...."
  1234. local DIL
  1235. DIL="`cat /proc/cmdline | tr " " "\n" | grep -E "^LANGUAGE=.*" | cut -d'=' -f2`"
  1236. if [ -z $DIL ];then
  1237. if [ ! -f /etc/environment ];then
  1238. touch /etc/environment
  1239. # Dil tanımlı değilse öntanımlı Türkçe
  1240. echo "LANGUAGE="\""tr_TR.UTF-8"\""" >> /etc/environment
  1241. echo "LANG="\""tr_TR.UTF-8"\""" >> /etc/environment
  1242. echo "LC_NUMERIC="\""tr_TR.UTF-8"\""" >> /etc/environment
  1243. echo "LC_TIME="\""tr_TR.UTF-8"\""" >> /etc/environment
  1244. echo "LC_MONETARY="\""tr_TR.UTF-8"\""" >> /etc/environment
  1245. echo "LC_PAPER="\""tr_TR.UTF-8"\""" >> /etc/environment
  1246. echo "LC_IDENTIFICATION="\""tr_TR.UTF-8"\""" >> /etc/environment
  1247. echo "LC_NAME="\""tr_TR.UTF-8"\""" >> /etc/environment
  1248. echo "LC_ADDRESS="\""tr_TR.UTF-8"\""" >> /etc/environment
  1249. echo "LC_TELEPHONE="\""tr_TR.UTF-8"\""" >> /etc/environment
  1250. echo "LC_MEASUREMENT="\""tr_TR.UTF-8"\""" >> /etc/environment
  1251. echo "BROWSER=/usr/bin/firefox" >> /etc/environment
  1252. echo "EDITOR=nano" >> /etc/environment
  1253. fi
  1254. if [ ! -f /etc/locale.conf ];then
  1255. touch /etc/locale.conf
  1256. # Dil tanımlı değilse öntanımlı Türkçe
  1257. echo "LC_ALL="\""tr_TR.UTF-8"\""" >> /etc/locale.conf
  1258. echo "LANG="\""tr_TR.UTF-8"\""" >> /etc/locale.conf
  1259. echo "LANGUAGE="\""tr_TR.UTF-8"\""" >> /etc/locale.conf
  1260. fi
  1261. else
  1262. [ -f /etc/environment ] && mv /etc/environment /etc/environment.old
  1263. [ -f /etc/locale.conf ] && mv /etc/locale.conf /etc/locale.conf.old
  1264. echo "LANGUAGE="\""$DIL"\""" >> /etc/environment
  1265. echo "LANG="\""$DIL"\""" >> /etc/environment
  1266. echo "LC_NUMERIC="\""$DIL"\""" >> /etc/environment
  1267. echo "LC_TIME="\""$DIL"\""" >> /etc/environment
  1268. echo "LC_MONETARY="\""$DIL"\""" >> /etc/environment
  1269. echo "LC_PAPER="\""$DIL"\""" >> /etc/environment
  1270. echo "LC_IDENTIFICATION="\""$DIL"\""" >> /etc/environment
  1271. echo "LC_NAME="\""$DIL"\""" >> /etc/environment
  1272. echo "LC_ADDRESS="\""$DIL"\""" >> /etc/environment
  1273. echo "LC_TELEPHONE="\""$DIL"\""" >> /etc/environment
  1274. echo "LC_MEASUREMENT="\""$DIL"\""" >> /etc/environment
  1275. echo "BROWSER=/usr/bin/firefox" >> /etc/environment
  1276. echo "EDITOR=nano" >> /etc/environment
  1277. echo "LC_ALL="\""$DIL"\""" >> /etc/locale.conf
  1278. echo "LANG="\""$DIL"\""" >> /etc/locale.conf
  1279. echo "LANGUAGE="\""$DIL"\""" >> /etc/locale.conf
  1280. fi
  1281. [ "$?" = "0" ] && log_success_msg "" || log_failure_msg ""
  1282. }
  1283. ################################################################################
  1284. # do_start_network() #
  1285. # #
  1286. # Description: Start the network depending on what's available nothing, wicd #
  1287. # or networkmanager #
  1288. # #
  1289. ################################################################################
  1290. do_config_network()
  1291. {
  1292. NETWORKCONFIG_FILE="/etc/sysconfig/network"
  1293. if [ ! -f /etc/sysconfig/network ]; then
  1294. cat > ${NETWORKCONFIG_FILE} << "EOF"
  1295. HOSTNAME='milis'
  1296. MANAGER='cli'
  1297. EOF
  1298. fi
  1299. # Network configuration
  1300. . ${NETWORKCONFIG_FILE}
  1301. NM_PIDFILE="/var/run/NetworkManager.pid"
  1302. WICD_PIDFILE="/var/run/wicd/wicd.pid"
  1303. if [ "${MANAGER}" == "" ]; then
  1304. MANAGER="cli"
  1305. if [ -f /usr/sbin/NetworkManager ]; then
  1306. MANAGER="networkmanager"
  1307. fi
  1308. if [ -f /usr/bin/wicd ]; then
  1309. MANAGER="wicd"
  1310. fi
  1311. fi
  1312. }
  1313. do_start_network()
  1314. {
  1315. do_config_network
  1316. case "${MANAGER}" in
  1317. networkmanager)
  1318. if [ -f /usr/sbin/NetworkManager ]; then
  1319. if [ ! -d /var/run/NetworkManager ]; then
  1320. install -d -o root -g root -m 755 /var/run/NetworkManager
  1321. fi
  1322. log_info_msg "Starting NetworkManager daemon..."
  1323. start_daemon /usr/sbin/NetworkManager
  1324. if [ "${NETWORKWAIT}" == "yes" ]; then
  1325. [ -z "${LINKDELAY}" ] && LINKDELAY=10
  1326. log_info_msg "Waiting for network..."
  1327. nm-online -q --timeout=$LINKDELAY || nm-online -q -x --timeout=30
  1328. [ "$?" = "0" ] && log_success_msg "Network startup" || log_failure_msg "Network startup"
  1329. [ -n "${NETWORKDELAY}" ] && /bin/sleep ${NETWORKDELAY}
  1330. fi
  1331. else
  1332. echo "the package networkmanager seems not to be install"
  1333. echo "check the ${NETWORKCONFIG_FILE} file"
  1334. fi
  1335. ;;
  1336. wicd)
  1337. if [ -f /usr/bin/wicd ]; then
  1338. if [ -e $WICD_PIDFILE ]; then
  1339. echo "Wicd appears to already be running"
  1340. echo "If this is NOT the case, then remove"
  1341. echo "$WICD_PIDFILE, check the ${NETWORKCONFIG_FILE} file"
  1342. echo "and try again"
  1343. else
  1344. log_info_msg "Baslatiliyor the wicd Daemon..."
  1345. start_daemon /usr/bin/wicd 1>/dev/null
  1346. evaluate_retval
  1347. if grep -v ^# /etc/fstab | grep _netdev > /dev/null; then
  1348. while ! grep "nameserver" /etc/resolv.conf ;
  1349. do
  1350. if [ $NETWORKDELAY -gt 0 ]; then
  1351. sleep 1
  1352. echo -n .
  1353. let NETWORKDELAY=$NETWORKDELAY-1
  1354. if [ $NETWORKDELAY -lt 1 ]; then
  1355. log_failure_msg2 "Time out"
  1356. exit 1
  1357. fi
  1358. fi
  1359. done
  1360. log_success_msg2 "Ag duzgun ayarlandi..."
  1361. fi
  1362. fi
  1363. else
  1364. echo "the package wicd seems not to be install"
  1365. echo "check the ${NETWORKCONFIG_FILE} file"
  1366. fi
  1367. ;;
  1368. cli)
  1369. # Start all network interfaces
  1370. for file in /etc/sysconfig/ifconfig.*
  1371. do
  1372. interface=${file##*/ifconfig.}
  1373. # Skip if $file is * (because nothing was found)
  1374. if [ "${interface}" = "*" ]; then
  1375. continue
  1376. fi
  1377. if [ -f /etc/wpa_supplicant.conf.${interface} ] && [ -x /sbin/wpa_supplicant ]; then
  1378. wpa_supplicant -B -c/etc/wpa_supplicant.conf.${interface} -i${interface} \
  1379. -P /var/run/wpa_supplicant.${interface}
  1380. sleep 2
  1381. fi
  1382. /sbin/ifup ${interface}
  1383. done
  1384. ;;
  1385. esac
  1386. }
  1387. do_stop_network()
  1388. {
  1389. do_config_network
  1390. case "${MANAGER}" in
  1391. networkmanager)
  1392. if [ -f /usr/sbin/NetworkManager ]; then
  1393. log_info_msg "Stopping NetworkManager daemon..."
  1394. killproc /usr/sbin/NetworkManager
  1395. else
  1396. echo "the package networkmanager seems not to be install"
  1397. echo "check the ${NETWORKCONFIG_FILE} file"
  1398. fi
  1399. ;;
  1400. wicd)
  1401. if [ -e $WICD_PIDFILE ]; then
  1402. log_info_msg "Stopping the wicd Daemon..."
  1403. wicd-cli -xyz 1>/dev/null
  1404. kill $(cat $WICD_PIDFILE)
  1405. evaluate_retval
  1406. else
  1407. echo "wicd appears not to be running..."
  1408. echo "check the ${NETWORKCONFIG_FILE} file"
  1409. fi
  1410. ;;
  1411. cli)
  1412. # Reverse list
  1413. net_files=""
  1414. for file in /etc/sysconfig/ifconfig.*
  1415. do
  1416. net_files="${file} ${net_files}"
  1417. done
  1418. # Stop all network interfaces
  1419. for file in ${net_files}
  1420. do
  1421. interface=${file##*/ifconfig.}
  1422. # Skip if $file is * (because nothing was found)
  1423. if [ "${interface}" = "*" ]; then
  1424. continue
  1425. fi
  1426. /sbin/ifdown ${interface}
  1427. if [ -f /var/run/wpa_supplicant.${interface} ]; then
  1428. kill `cat /var/run/wpa_supplicant.${interface}`
  1429. fi
  1430. done
  1431. ;;
  1432. esac
  1433. }
  1434. ################################################################################
  1435. # print_file_system() #
  1436. # #
  1437. # Purpose: printout the file system of the partition passed as argument #
  1438. # #
  1439. # Return value: #
  1440. # - the file system name #
  1441. # - "no" if not found #
  1442. ################################################################################
  1443. print_file_system() {
  1444. local PI FS
  1445. PI=`/sbin/blkid ${1}`
  1446. for param in $PI; do
  1447. case $param in TYPE=*)
  1448. FS=`echo ${param#TYPE=}|sed s/\"//g`;;
  1449. esac
  1450. done
  1451. if [ "$FS" == "" ]; then
  1452. echo "no"
  1453. else
  1454. echo $FS
  1455. fi
  1456. }
  1457. # End /lib/services/init-functions