home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / initramfs-tools / examples / example_hook < prev    next >
Encoding:
Text File  |  2005-09-17  |  3.4 KB  |  115 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # This is an example hook script.  It will be run by 'mkinitramfs'
  5. # when it creates the image.  It's job is to decide which files to
  6. # install, then install them into the staging area, where the
  7. # initramfs is being created.  This happens when a new 'linux-image'
  8. # package is installed, or when the administrator runs 'mkinitramfs'
  9. # by hand to update an initramfs image.
  10. #
  11. # TODO: What about the case where you install something that should be
  12. #    added to the initramfs, but the linux-image it relates to has
  13. #    already been installed previously?  Does this happen often
  14. #    enough that it needs to be handled?  How can it be handled?
  15. #    
  16. #    * Think about the 'usplash'.  The initramfs will need to be
  17. #     updated if a theme change or update is desired.  Maybe it
  18. #     should not be totally automatic, but offered on upgrade
  19. #     predicated on a user response to a debconf question?  That
  20. #     issue needs to be explored and a solution specified.
  21. #
  22. #  * Do not assume that any needed subdirectories have been created
  23. #    yet, but don't bail out if they are already there.
  24. #
  25. #  * All of the standard system tools are available, of course, since
  26. #    this hook is running in the real system, not the initramfs.
  27. #
  28. #  * TODO: ... ?  Anything else to tell them in this bullet-list?
  29. #
  30.  
  31. #
  32. # The environment contains at least:
  33. #
  34. #  CONFDIR -- usually /etc/mkinitramfs, can be set on mkinitramfs
  35. #         command line.
  36. #
  37. #  DESTDIR -- The staging directory where we are building the image.
  38. #
  39. # TODO: Decide what environment variables are meaningful and defined
  40. #    in this context, then document them as part of the interface.
  41. #
  42. # TODO: May need a version_compare function for comparison of VERSION?
  43.  
  44.  
  45. #
  46. # List the soft prerequisites here.  This is a space separated list of
  47. # names, of scripts that are in the same directory as this one, that
  48. # must be run before this one can be.
  49. #
  50. PREREQ=""
  51.  
  52. prereqs()
  53. {
  54.     echo "$PREREQ"
  55. }
  56.  
  57. case $1 in
  58. # get pre-requisites
  59. prereqs)
  60.     prereqs
  61.     exit 0
  62.     ;;
  63. esac
  64.  
  65.  
  66. # You can do anything you need to from here on.
  67. #
  68.  
  69. # Source the optional 'hook-functions' scriptlet, if you need the
  70. # functions defined within it.  Read it to see what is available to
  71. # you.  It contains functions for copying dynamically linked program
  72. # binaries, and kernel modules into the DESTDIR.
  73. #
  74. . /usr/share/initramfs-tools/hook-functions
  75.  
  76.  
  77. # If this hook script is a conffile (and thus stored in
  78. # /etc/mkinitramfs/hooks), it must take care to do the right thing
  79. # when the package containing it is removed but not purged.  There of
  80. # course may be other reasons to have custom logic deciding what to
  81. # install.  The version variable may be useful for this.
  82. #
  83. if [ -x /usr/bin/myprog ]; then
  84.     copy_exec /usr/bin/myprog usr/bin
  85. fi
  86.  
  87. # To accompany this, there should usually be a script for inside the
  88. # initramfs named something like:
  89. #
  90. #   "/etc/mkinitramfs/local-premount/myprog"
  91. #
  92. # ... and it should do what is necessary to have 'myprog' get run
  93. # inside the early runtime environment.
  94.  
  95. # Handle an error:
  96. #
  97. if [ -n "$an_error_occured" ];
  98. then
  99.     # 
  100.     # TODO: Do we need 'warn()', 'error()', and/or 'fatal()' for this?
  101.     # 
  102.     echo "An error occured in $0: $an_error_occured" >&2
  103.     exit 1
  104.     #
  105.     # TODO: Decide if different error codes are meaningful, what they
  106.     #    mean, and what the semantics of them are wrt 'mkinitramfs'
  107.     #    pass or fail.  Consider naming the error values with
  108.     #    mnemonic symbols rather than magic numbers.  They may or
  109.     #    may not be the same set of errors as the set for
  110.     #    in-initramfs scripts.
  111.     #
  112. fi
  113.  
  114. exit 0
  115.