home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / initramfs-tools / scripts / functions < prev    next >
Encoding:
Text File  |  2006-07-12  |  4.4 KB  |  264 lines

  1. # -*- shell-script -*-
  2.  
  3. _log_msg()
  4. {
  5.     if [ "$quiet" = "y" ]; then return; fi
  6.     echo "$@"
  7. }
  8.  
  9. log_success_msg()
  10. {
  11.     _log_msg "Success: $@"
  12. }
  13.  
  14. log_failure_msg()
  15. {
  16.     _log_msg "Failure: $@"
  17. }
  18.  
  19. log_warning_msg()
  20. {
  21.     _log_msg "Warning: $@"
  22. }
  23.  
  24. log_begin_msg()
  25. {
  26.     if [ -x /sbin/usplash_write ]; then
  27.         /sbin/usplash_write "TEXT $@"
  28.     fi
  29.     _log_msg "Begin: $@ ..."
  30. }
  31.  
  32. log_end_msg()
  33. {
  34.     if [ -x /sbin/usplash_write ]; then
  35.         /sbin/usplash_write "SUCCESS ok"
  36.     fi
  37.     _log_msg "Done."
  38.     update_progress
  39. }
  40.  
  41. update_progress()
  42. {
  43.     [ -d /dev/.initramfs ] || return
  44.  
  45.     if [ -z "$PROGRESS_STATE" ]; then
  46.         export PROGRESS_STATE=0
  47.     fi
  48.  
  49.     PROGRESS_STATE=$(($PROGRESS_STATE + 1))
  50.     echo "PROGRESS_STATE=${PROGRESS_STATE}" > /dev/.initramfs/progress_state
  51.  
  52.     if [ -x /sbin/usplash_write ]; then
  53.         /sbin/usplash_write "PROGRESS $PROGRESS_STATE"
  54.     fi
  55. }
  56.  
  57. panic()
  58. {
  59.     if [ -x /sbin/usplash_write ]; then
  60.         /sbin/usplash_write "QUIT"
  61.     fi
  62.     modprobe -q i8042
  63.     modprobe -q atkbd
  64.     echo $@
  65.     PS1='(initramfs) ' /bin/sh </dev/console >/dev/console 2>&1
  66. }
  67.  
  68. maybe_break()
  69. {
  70.     if [ x$1 = x${break} ]; then
  71.         panic "Spawning shell within the initramfs"
  72.     fi
  73. }
  74.  
  75. render()
  76. {
  77.     eval "echo -n \${$@}"
  78. }
  79.  
  80. set_initlist()
  81. {
  82.     unset initlist
  83.     for si_x in ${initdir}/*; do
  84.         if [ ! -x ${si_x} ]; then
  85.             continue
  86.         fi
  87.         initlist="${initlist} $(basename ${si_x})"
  88.     done
  89. }
  90.  
  91. reduce_satisfied()
  92. {
  93.     deplist="$(render array_${1})"
  94.     unset tmpdeplist
  95.     for rs_y in ${deplist}; do
  96.         if [ ! -f ${initdir}/${rs_y} ]; then
  97.             continue
  98.         fi
  99.         tmpdeplist="${tmpdeplist} ${rs_y}"
  100.     done
  101.     deplist=${tmpdeplist}
  102.     for rs_x in ${runlist}; do
  103.         pop_list_item ${rs_x} ${deplist}
  104.         deplist=${tmppop}
  105.     done
  106.     eval array_${1}=\"${deplist}\"
  107. }
  108.  
  109. get_prereqs()
  110. {
  111.     set_initlist
  112.     for gp_x in ${initlist}; do
  113.         tmp=$(${initdir}/${gp_x} prereqs)
  114.         eval array_${gp_x}=\"${tmp}\"
  115.     done
  116. }
  117.  
  118. count_unsatisfied()
  119. {
  120.     set - ${@}
  121.     return ${#}
  122. }
  123.  
  124. # Removes $1 from initlist
  125. pop_list_item()
  126. {
  127.     item=${1}
  128.     shift
  129.     set - ${@}
  130.     unset tmppop
  131.     # Iterate
  132.     for pop in ${@}; do
  133.         if [ ${pop} = ${item} ]; then
  134.             continue
  135.         fi
  136.         tmppop="${tmppop} ${pop}"
  137.     done
  138.  
  139. }
  140.  
  141. # This function generates the runlist, so we clear it first.
  142. reduce_prereqs()
  143. {
  144.     unset runlist
  145.     set_initlist
  146.     set - ${initlist}
  147.     i=$#
  148.     # Loop until there's no more in the queue to loop through
  149.     while [ ${i} -ne 0 ]; do
  150.         oldi=${i}
  151.         for rp_x in ${initlist}; do
  152.             reduce_satisfied ${rp_x}
  153.             count_unsatisfied $(render array_${rp_x})
  154.             cnt=${?}
  155.             if [ ${cnt} -eq 0 ]; then
  156.                 runlist="${runlist} ${rp_x}"
  157.                 pop_list_item ${rp_x} ${initlist}
  158.                 initlist=${tmppop}
  159.                 i=$((${i} - 1))
  160.             fi
  161.         done
  162.         if [ ${i} -eq ${oldi} ]; then
  163.             echo "PANIC: Circular dependancy.  Exiting." >&2
  164.             exit 1
  165.         fi
  166.     done
  167. }
  168.  
  169. call_scripts()
  170. {
  171.     for cs_x in ${runlist}; do
  172.         ${initdir}/${cs_x}
  173.         # allow boot scripts to modify exported boot paramaters
  174.         if [ -e /conf/param.conf ]; then
  175.             . /conf/param.conf
  176.         fi
  177.     done
  178. }
  179.  
  180. run_scripts()
  181. {
  182.     initdir=${1}
  183.     get_prereqs
  184.     reduce_prereqs
  185.     call_scripts
  186. }
  187.  
  188. check_minkver()
  189. {
  190.     curversion=${1}
  191.     initdir=${2}
  192.     set_initlist
  193.     if [ -z ${initdir} ]; then
  194.         DPKG_ARCH=`dpkg --print-installation-architecture`
  195.         case ${DPKG_ARCH} in
  196.             ia64|hppa)
  197.                 minversion="2.6.15"
  198.             ;;
  199.             *)
  200.                 minversion="2.6.12"
  201.             ;;
  202.         esac
  203.         if dpkg --compare-versions "${curversion}" lt "${minversion}"; then
  204.             echo "W: kernerl ${curversion} too old for initramfs on ${DPKG_ARCH}" >&2
  205.             echo "W: not generating requested initramfs for kernel ${curversion}" >&2
  206.             exit 2
  207.         fi
  208.     fi
  209.     [ -z ${initdir} ] || for cm_x in ${initlist}; do
  210.         tmp=$(eval echo $(grep ^MINKVER ${initdir}/${cm_x} | cut -d'=' -f2))
  211.         if dpkg --compare-versions "${curversion}" lt "${tmp}"; then
  212.             echo "W: ${cm_x} hook script requires at least kernel version ${tmp}" >&2
  213.             echo "W: not generating requested initramfs for kernel ${curversion}" >&2
  214.             exit 2
  215.         fi
  216.     done
  217. }
  218.  
  219. # Load custom modules first
  220. load_modules()
  221. {
  222.     if [ -e /conf/modules ]; then
  223.         cat /conf/modules | while read m; do
  224.             # Skip empty lines
  225.             if [ -z "$m" ];  then 
  226.                 continue
  227.             fi
  228.             # Skip comments - d?ash removes whitespace prefix
  229.             com=$(printf "%.1s" "${m}")
  230.             if [ "$com" = "#" ]; then
  231.                 continue
  232.             fi
  233.             modprobe -q $m
  234.         done
  235.     fi
  236. }
  237.  
  238. # lilo compatibility
  239. parse_numeric() {
  240.     case $1 in
  241.     "")
  242.         return
  243.         ;;
  244.     /*)
  245.         return
  246.         ;;
  247.     *:*)
  248.         minor=${1#*:}
  249.         major=${1%:*}
  250.         ;;
  251.     [0-9][0-9][0-9])
  252.         minor=$((0x${1#?}))
  253.         major=$((0x${1%??}))
  254.         ;;
  255.     *)
  256.         minor=$((0x${1#??}))
  257.         major=$((0x${1%??}))
  258.         ;;
  259.     esac
  260.  
  261.     mknod /dev/root b ${major} ${minor}
  262.     ROOT=/dev/root
  263. }
  264.