Guest User

mdadm.postinst

a guest
Feb 21st, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.53 KB | None | 0 0
  1. #!/bin/sh
  2. # Copyright © 2001-2005 Mario Jou/3en <joussen@debian.org>
  3. # Copyright © 2005-2008 Martin F. Krafft <madduck@debian.org>
  4. # Distributable under the terms of the GNU GPL version 2.
  5. #
  6.  
  7. . /usr/share/debconf/confmodule
  8. # See #369953 for ordering
  9. set -eu
  10.  
  11. case "${1:-}" in
  12.   configure|reconfigure)
  13.  
  14.     if [ ! -f /proc/mdstat ] && [ -x $(command -v modprobe 2>/dev/null) ]; then
  15.       modprobe md >/dev/null 2>&1 || :
  16.     fi
  17.     if [ ! -f /proc/mdstat ]; then
  18.       echo 'W: mdadm: failed to load MD subsystem.' >&2
  19.     fi
  20.  
  21.     MAKEDEV=/dev/MAKEDEV
  22.     if [ ! -e /dev/md15 ] \
  23.       && [ ! -e /dev/.static/dev/md15 ] \
  24.       && [ ! -e /dev/.devfsd ] \
  25.       && [ -x $MAKEDEV ]; then
  26.  
  27.         echo -n 'Generating array device nodes... ' >&2
  28.         cd /dev
  29.         if $MAKEDEV md >&2 >/dev/null; then
  30.           echo 'done.' >&2
  31.         else
  32.           echo 'failed.' >&2
  33.         fi
  34.     fi
  35.  
  36.     DEBIANCONFIG=/etc/default/mdadm
  37.     CONFIG=/etc/mdadm/mdadm.conf
  38.     ALTCONFIG=/etc/mdadm.conf
  39.     MDADM=/sbin/mdadm
  40.  
  41.     if [ -z "${2:-}" ] && [ -s /etc/mdctl/mdctl.conf ] \
  42.         && [ ! -f /etc/mdadm/mdadm.conf ]; then
  43.       cp -a /etc/mdctl/mdctl.conf /etc/mdadm/mdadm.conf
  44.     fi
  45.  
  46.     # load current settings, most of which will be overwritten.
  47.     [ -f $DEBIANCONFIG ] && . $DEBIANCONFIG
  48.  
  49.     db_get mdadm/mail_to
  50.     MAILADDR="${RET:-root}"
  51.  
  52.     [ ! -f $CONFIG ] && [ -f $ALTCONFIG ] && CONFIG=$ALTCONFIG
  53.     if [ ! -f $CONFIG ]; then
  54.       echo -n 'Generating mdadm.conf... ' >&2
  55.       # pass the MAILADDR variable into the script
  56.       MDADM_MAILADDR__="$MAILADDR"; export MDADM_MAILADDR__
  57.       if /usr/share/mdadm/mkconf generate $CONFIG 2>/dev/null; then
  58.         echo done. >&2
  59.       else
  60.         echo "done (failed to scan arrays; /proc probably not mounted)." >&2
  61.       fi
  62.     elif dpkg --compare-versions "${2:-2.5.3-1}" le 2.5.3-1; then
  63.       # we're upgrading from before 2.5.3-1 and there's apparently already
  64.       # a configuration file which we cannot verify. We'll use the sentinel
  65.       # during initramfs creation.
  66.       md5sum $CONFIG > /var/lib/mdadm/CONF-UNCHECKED
  67.     fi
  68.  
  69.     if [ -w $CONFIG ] && [ -z "${MDADM_MAILADDR__:-}" ]; then
  70.       # if the configuration is writeable but has not been written just
  71.       # before, then edit it to reflect the MAILADDR preference
  72.       if grep -q '^MAILADDR' $CONFIG; then
  73.         sed -i -e "s/^MAILADDR.*/MAILADDR $MAILADDR/" $CONFIG
  74.       else
  75.         echo "MAILADDR $MAILADDR" >> $CONFIG
  76.       fi
  77.     fi
  78.     unset MDADM_MAILADDR__
  79.  
  80.     db_get mdadm/autocheck
  81.     AUTOCHECK="${RET:-true}"
  82.     db_get mdadm/start_daemon
  83.     START_DAEMON="${RET:-true}"
  84.     #db_get mdadm/daemon_options
  85.     [ -n "${DAEMON_OPTIONS:-}" ] || DAEMON_OPTIONS='--syslog'
  86.  
  87.     cat <<_eof > $DEBIANCONFIG
  88. # mdadm Debian configuration
  89. #
  90. # You can run 'dpkg-reconfigure mdadm' to modify the values in this file, if
  91. # you want. You can also change the values here and changes will be preserved.
  92. # Do note that only the values are preserved; the rest of the file is
  93. # rewritten.
  94. #
  95.  
  96. # AUTOCHECK:
  97. #   should mdadm run periodic redundancy checks over your arrays? See
  98. #   /etc/cron.d/mdadm.
  99. AUTOCHECK=$AUTOCHECK
  100.  
  101. # START_DAEMON:
  102. #   should mdadm start the MD monitoring daemon during boot?
  103. START_DAEMON=$START_DAEMON
  104.  
  105. # DAEMON_OPTIONS:
  106. #   additional options to pass to the daemon.
  107. DAEMON_OPTIONS="$DAEMON_OPTIONS"
  108.  
  109. # VERBOSE:
  110. #   if this variable is set to true, mdadm will be a little more verbose e.g.
  111. #   when creating the initramfs.
  112. VERBOSE=${VERBOSE:-false}
  113.  
  114. # MAIL_TO:
  115. #   this variable is now managed in /etc/mdadm/mdadm.conf (MAILADDR).
  116. #   Please see mdadm.conf(5).
  117. _eof
  118.  
  119.     db_stop
  120.  
  121.     # try to undo udev rules (installed by 2.5.2-10, see 2.5.3.git200608202239-1
  122.     # changelog). Do this before update-initramfs, which copies udev into
  123.     # initrd.
  124.     V=2.5.3.git200608202239-1~
  125.     if [ "${1:-}" = "configure" ] && [ -n "${2:-}" ] \
  126.         && dpkg --compare-versions $2 ge 2.5.2-10 \
  127.         && dpkg --compare-versions $2 lt $V; then
  128.  
  129.       # first, disable the rules
  130.       rm -f /etc/udev/rules.d/z60_mdadm.rules
  131.  
  132.       if echo "0843432c9c01ed95c42481eee0cf6fbf  /etc/udev/mdadm.rules" \
  133.           | md5sum -c >/dev/null; then
  134.         # no changes by user, so remove
  135.         rm -f /etc/udev/mdadm.rules
  136.       else
  137.         echo "W: mdadm: I tried to remove /etc/udev/mdadm.rules (see changelog)," >&2
  138.         echo "W: mdadm: but you have modified it, so I won't touch it. Please" >&2
  139.         echo "W: mdadm: remove the file at your leisure." >&2
  140.       fi
  141.     fi
  142.  
  143.     # Remove old init script
  144.     update-rc.d mdadm-raid remove
  145.  
  146.     update-initramfs -u
  147.     if type update-grub2 1>/dev/null 2>/dev/null; then
  148.         update-grub || true
  149.     fi
  150.     ;;
  151. esac
  152.  
  153. # See #369953
  154. set +u
  155. # Automatically added by dh_installinit
  156. if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
  157.     if [ -x "/etc/init.d/mdadm" ]; then
  158.         update-rc.d mdadm defaults 25 >/dev/null
  159.     fi
  160.     if [ -x "/etc/init.d/mdadm" ] || [ -e "/etc/init/mdadm.conf" ]; then
  161.         invoke-rc.d mdadm start || exit $?
  162.     fi
  163. fi
  164. # End automatically added section
  165. # Automatically added by dh_installinit
  166. if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
  167.     if [ -x "/etc/init.d/mdadm-waitidle" ]; then
  168.         update-rc.d mdadm-waitidle stop 98 0 6 . >/dev/null || exit $?
  169.     fi
  170. fi
  171. # End automatically added section
  172. # Automatically added by dh_installdeb
  173. dpkg-maintscript-helper rm_conffile /etc/default/grub.d/dmraid2mdadm.cfg 3.3-2ubuntu5~ -- "$@"
  174. # End automatically added section
Add Comment
Please, Sign In to add comment