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.

126 lines
3.2 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/scripts/Build-Pkg
  11. # ROCK Linux is Copyright (C) 1998 - 2005 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 < <( cat /var/adm/postinstall/*-install.?????? 2> /dev/null | grep "$1"; ) | sort -u
  39. }
  40. all_removed() {
  41. while read dummy M; do
  42. [ -e "/$M" ] || echo "/$M"
  43. done < <( cat /var/adm/postinstall/*-remove.?????? 2> /dev/null | grep "$1"; ) | sort -u
  44. }
  45. all_touched() {
  46. while read dummy M; do
  47. [ -e "/$M" ] || echo "/$M"
  48. done < <( cat /var/adm/postinstall/*-install.?????? /var/adm/postinstall/*-remove.?????? 2> /dev/null | grep "$1"; ) | sort -u
  49. }
  50. any_installed() {
  51. if [ $install_checks_true == 1 ]; then return 0; fi
  52. cat /var/adm/postinstall/*-install.?????? 2> /dev/null | grep -q "$1"
  53. }
  54. any_removed() {
  55. if [ $remove_checks_true == 1 ]; then return 0; fi
  56. cat /var/adm/postinstall/*-remove.?????? 2> /dev/null | grep -q "$1"
  57. }
  58. any_touched() {
  59. if [ $install_checks_true == 1 ]; then return 0; fi
  60. if [ $remove_checks_true == 1 ]; then return 0; fi
  61. cat /var/adm/postinstall/*-install.?????? /var/adm/postinstall/*-remove.?????? 2> /dev/null | grep -q "$1"
  62. }
  63. install_checks_true=0
  64. remove_checks_true=0
  65. while [ "$#" -ge 1 ]; do
  66. case "$1" in
  67. -a)
  68. install_checks_true=1
  69. shift
  70. ;;
  71. -r)
  72. remove_checks_true=1
  73. shift
  74. ;;
  75. *)
  76. echo
  77. echo "Usage: $0 [ -a ] [ -r ]"
  78. echo
  79. echo " -a execute all postinstall actions"
  80. echo " -r execute all postremove actions"
  81. echo
  82. exit 1
  83. ;;
  84. esac
  85. done
  86. # Backup postinstall scripts for postremove operation
  87. all_installed "etc/postinstall/.*\.sh" | while read M;
  88. do
  89. echo "Creating backup of $M in /etc/postinstall/postremove/"
  90. cp -af "$M" "/etc/postinstall/postremove/${M##*/}"
  91. done
  92. # Execute removed postinstall scripts
  93. all_removed "etc/postinstall/.*\.sh" | while read M;
  94. do
  95. P="/etc/postinstall/postremove/${M##*/}"
  96. if [ -e $P ]; then
  97. echo "Executing postremove script $P"
  98. . "$P"
  99. rm -f "$P"
  100. else
  101. echo "WARNING: backup of $M not found in /etc/postinstall/postremove"
  102. fi
  103. done
  104. # Source postinstall scripts
  105. for N in /etc/postinstall/*.sh;
  106. do
  107. echo "Executing postinstall script $N"
  108. . "$N"
  109. done
  110. # Remove the postinstall/postremove logs
  111. rm -f /var/adm/postinstall/*-{install,remove}.??????