mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
5.9 KiB

  1. #!/bin/bash
  2. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  3. #
  4. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. # Please add additional copyright information _after_ the line containing
  6. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  7. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  8. #
  9. # ROCK Linux: rock-src/target/lvp/x86/release_skeleton/scripts/functions
  10. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version. A copy of the GNU General Public
  16. # License can be found at Documentation/COPYING.
  17. #
  18. # Many people helped and are helping developing ROCK Linux. Please
  19. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  20. # file for details.
  21. #
  22. # --- ROCK-COPYRIGHT-NOTE-END ---
  23. bold=""
  24. red=""
  25. green=""
  26. yellow=""
  27. blue=""
  28. normal=""
  29. # {{{ usage_functions
  30. usage_functions(){
  31. echo -n
  32. }
  33. # }}}
  34. # {{{ human readable
  35. human_readable() {
  36. size=${1}
  37. if [ ${size} -gt 1024 ] ; then
  38. if [ ${size} -gt $(( 1024*1024 )) ] ; then
  39. size="$(( ${size} / ( 1024*1024 ) )) MB"
  40. else
  41. size="$(( ${size} / 1024 )) kB"
  42. fi
  43. else
  44. size="${size} Byte"
  45. fi
  46. echo "${size}"
  47. }
  48. # }}}
  49. # {{{ lvp_read
  50. function lvp_read {
  51. var=$1
  52. shift
  53. default=${1}
  54. shift
  55. if [ ${LVP_USE_DEFAULTS} -eq 1 ] ; then
  56. echo "${@} ${default} (batch mode)"
  57. eval "${var}=\"${default}\""
  58. return
  59. fi
  60. eval "read -p \"${@}\" ${var}"
  61. return
  62. }
  63. # }}}
  64. # {{{ confirm
  65. function confirm {
  66. unset yesno
  67. if [ ${LVP_USE_DEFAULTS:-0} -eq 1 ] ; then
  68. echo "${@} [yes|no] ? yes (batch mode)"
  69. yesno="yes"
  70. fi
  71. while [ "${yesno}" != "yes" -a "${yesno}" != "no" ] ; do
  72. echo -n "${@} [yes|no] ? "
  73. read yesno
  74. done
  75. [ "${yesno}" = "yes" ] && return 0
  76. return 1
  77. }
  78. # }}}
  79. if [ ! -e .license_accepted ] ; then
  80. echo "You must accept this software's license first."
  81. echo "Press -<enter>- to do so now or press Ctrl-C to stop now"
  82. read
  83. more COPYING || cat COPYING
  84. if confirm "Accept license?" ; then
  85. touch .license_accepted
  86. else
  87. echo "Without accepting the license you can't use this software."
  88. echo "Have a nice day."
  89. exit 1
  90. fi
  91. fi
  92. # {{{ menu_init
  93. menu_init () {
  94. block_level=0
  95. items=0
  96. }
  97. # }}}
  98. # {{{ block_start
  99. block_start () {
  100. block_level=$(( ${block_level} + 2 ))
  101. echo "${@}"
  102. }
  103. # }}}
  104. # {{{ block_end
  105. block_end () {
  106. block_level=$(( ${block_level} - 2 ))
  107. }
  108. # }}}
  109. # {{{ bool
  110. bool () {
  111. # bool LVPCFG_FOO 1 "This is Option FOO"
  112. items=$(( ${items} + 1 ))
  113. eval "type_${items}=\"bool\""
  114. eval "option_${items}=\"${1}\""
  115. eval "value=\${${1}}"
  116. [ -z "${value}" ] && \
  117. eval "${1}=\"${2}\""
  118. eval "text_${items}=\"${3}\""
  119. }
  120. # }}}
  121. # {{{ multi
  122. multi () {
  123. # multi LVPCFG_FOO default "This is Multioption FOO" foo default bar
  124. items=$(( ${items} + 1 ))
  125. eval "type_${items}=\"multi\""
  126. eval "option_${items}=\"${1}\""
  127. eval "value=\${${1}}"
  128. [ -z "${value}" ] && \
  129. eval "${1}=\"${2}\""
  130. eval "text_${items}=\"${3}\""
  131. shift; shift; shift
  132. eval "values_${items}=\"\""
  133. while [ -n "${1}" ] ; do
  134. eval "values_${items}=\"\${values_${items}} ${1}\""
  135. shift
  136. done
  137. }
  138. # }}}
  139. # {{{ text
  140. text () {
  141. # text LVPCFG_FOO "default text" "This is textoption FOO"
  142. items=$(( ${items} + 1 ))
  143. eval "type_${items}=\"text\""
  144. eval "option_${items}=\"${1}\""
  145. eval "value=\${${1}}"
  146. [ -z "${value}" ] && \
  147. eval "${1}=\"${2}\""
  148. eval "text_${items}=\"${3}\""
  149. }
  150. # }}}
  151. # {{{ comment
  152. comment (){
  153. items=$(( ${items} + 1 ))
  154. eval "type_${items}=\"comment\""
  155. eval "text_${items}=\"${@}\""
  156. }
  157. # }}}
  158. # {{{ display
  159. display () {
  160. i=1
  161. echo -e "\t\tWelcome to the LVP configuration\n"
  162. while [ ${i} -le ${items} ] ; do
  163. eval "type=\${type_${i}}"
  164. case "${type}" in
  165. bool)
  166. eval "option=\${option_${i}}"
  167. eval "value=\${${option}}"
  168. desc="X"
  169. [ "${value}" == "0" ] && desc=" "
  170. eval "echo \"${i} - [${desc}] \${text_${i}}\""
  171. ;;
  172. multi)
  173. eval "option=\${option_${i}}"
  174. eval "value=\${${option}}"
  175. eval "echo \"${i} - (${value}) \${text_${i}}\""
  176. ;;
  177. text)
  178. eval "option=\${option_${i}}"
  179. eval "value=\${${option}}"
  180. dots="..."
  181. [ "${value:0:20}" == "${value}" ] && dots=""
  182. eval "echo \"${i} - (${value:0:17}${dots}) \${text_${i}}\""
  183. ;;
  184. comment)
  185. eval "echo \"\${text_${i}}\""
  186. ;;
  187. *)
  188. echo "${type} NOT IMPLEMENTED"
  189. ;;
  190. esac
  191. i=$(( ${i} + 1 ))
  192. done
  193. }
  194. # }}}
  195. # {{{ save
  196. save () {
  197. i=1
  198. echo "# LVP Configuration" > .config
  199. while [ ${i} -le ${items} ] ; do
  200. eval "option=\${option_${i}}"
  201. eval "value=\${${option}}" 2>/dev/null
  202. eval "type=\${type_${i}}"
  203. case "${type}" in
  204. bool)
  205. echo "${option}=${value}" >>.config
  206. ;;
  207. multi)
  208. echo "${option}=\"${value}\"" >>.config
  209. ;;
  210. text)
  211. echo "${option}=\"${value}\"" >>.config
  212. ;;
  213. esac
  214. i=$(( ${i} + 1 ))
  215. done
  216. }
  217. # }}}
  218. # {{{ load
  219. load () {
  220. . .config
  221. }
  222. # }}}
  223. # {{{ get
  224. get () {
  225. # get 3
  226. eval "option=\${option_${1}}"
  227. if [ -z "${option}" ] ; then
  228. echo "${bold}${red}No such option: ${1}${normal}"
  229. sleep 1
  230. return
  231. fi
  232. eval "type=\${type_${1}}"
  233. case "${type}" in
  234. text)
  235. eval "value=\${${option}}"
  236. read -erp "Enter new value for ${option} [${value}]> " new
  237. [ -n "${new}" ] && eval "${option}=\"${new}\""
  238. ;;
  239. multi)
  240. eval "value=\${${option}}"
  241. eval "values=\${values_${1}}"
  242. x=1
  243. for v in ${values} ; do
  244. [ "${value}" == "${v}" ] && echo -n "${bold}"
  245. echo "${x} - ${v}${normal}"
  246. eval "nval_${1}_${x}=\"${v}\""
  247. x=$(( ${x} + 1 ))
  248. done
  249. read -ep "Enter new value by number> " new
  250. [ -z "${new}" ] && return
  251. eval "new=\${nval_${1}_${new}}"
  252. if [ -z "${new}" ] ; then
  253. echo "${bold}${red}No such option!${normal}"
  254. sleep 1
  255. return
  256. else
  257. eval "${option}=\"${new}\""
  258. fi
  259. ;;
  260. bool)
  261. eval "value=\${${option}}"
  262. if [ ${value} -eq 1 ] ; then
  263. eval "${option}=0"
  264. else
  265. eval "${option}=1"
  266. fi
  267. ;;
  268. *)
  269. echo "${bold}${red}NOT IMPLEMENTED${normal}"
  270. sleep 1
  271. ;;
  272. esac
  273. }
  274. # }}}