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.

133 lines
3.4 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/package/base/sysfiles/sbin_postinstall.sh
  11. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. # Helper functions
  25. is_installed()
  26. {
  27. if [ $install_checks_true == 1 ]; then return 0; fi
  28. [ -e "$1" ];
  29. }
  30. is_removed()
  31. {
  32. if [ $remove_checks_true == 1 ]; then return 0; fi
  33. [ ! -e "$1" ];
  34. }
  35. all_installed() {
  36. while read dummy M; do
  37. [ -e "/$M" ] && echo "/$M"
  38. done < <( find /var/adm/postinstall/ -name "*-install.??????" \
  39. -exec grep "$1" "{}" \; 2> /dev/null ) | sort -u
  40. }
  41. all_removed() {
  42. while read dummy M; do
  43. [ -e "/$M" ] || echo "/$M"
  44. done < <( find /var/adm/postinstall/ -name "*-remove.??????" \
  45. -exec grep "$1" "{}" \; 2> /dev/null ) | sort -u
  46. }
  47. all_touched() {
  48. while read dummy M; do
  49. [ -e "/$M" ] || echo "/$M"
  50. done < <( find /var/adm/postinstall/ \
  51. \( -name "*-install.??????" -o -name "*-remove.??????" \) \
  52. -exec grep "$1" "{}" \; 2> /dev/null ) | sort -u
  53. }
  54. any_installed() {
  55. if [ $install_checks_true == 1 ]; then return 0; fi
  56. find /var/adm/postinstall/ -name "*-install.??????" \
  57. 2> /dev/null | xargs grep -q "$1"
  58. }
  59. any_removed() {
  60. if [ $remove_checks_true == 1 ]; then return 0; fi
  61. find /var/adm/postinstall/ -name "*-remove.??????" \
  62. 2> /dev/null | xargs grep -q "$1"
  63. }
  64. any_touched() {
  65. if [ $install_checks_true == 1 ]; then return 0; fi
  66. if [ $remove_checks_true == 1 ]; then return 0; fi
  67. find /var/adm/postinstall/ -name "*-install.??????" -o \
  68. -name "*-remove.??????" 2> /dev/null | xargs grep -q "$1"
  69. }
  70. install_checks_true=0
  71. remove_checks_true=0
  72. while [ "$#" -ge 1 ]; do
  73. case "$1" in
  74. -a)
  75. install_checks_true=1
  76. shift
  77. ;;
  78. -r)
  79. remove_checks_true=1
  80. shift
  81. ;;
  82. *)
  83. echo
  84. echo "Usage: $0 [ -a ] [ -r ]"
  85. echo
  86. echo " -a execute all postinstall actions"
  87. echo " -r execute all postremove actions"
  88. echo
  89. exit 1
  90. ;;
  91. esac
  92. done
  93. # Backup postinstall scripts for postremove operation
  94. all_installed "etc/postinstall/.*\.sh" | while read M;
  95. do
  96. echo "Creating backup of $M in /etc/postinstall/postremove/"
  97. cp -af "$M" "/etc/postinstall/postremove/${M##*/}"
  98. done
  99. # Execute removed postinstall scripts
  100. all_removed "etc/postinstall/.*\.sh" | while read M;
  101. do
  102. P="/etc/postinstall/postremove/${M##*/}"
  103. if [ -e $P ]; then
  104. echo "Executing postremove script $P"
  105. . "$P"
  106. rm -f "$P"
  107. else
  108. echo "WARNING: backup of $M not found in /etc/postinstall/postremove"
  109. fi
  110. done
  111. # Source postinstall scripts
  112. for N in /etc/postinstall/*.sh;
  113. do
  114. echo "Executing postinstall script $N"
  115. . "$N"
  116. done
  117. # Remove the postinstall/postremove logs
  118. find /var/adm/postinstall/ \( -name "*-install.??????" -o \
  119. -name "*-remove.??????" \) -exec rm -f "{}" \;