OpenSDE Packages Database (without history before r20070)
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.

189 lines
5.7 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../sysfiles/parse-config
  5. # Copyright (C) 2004 - 2006 The T2 SDE Project
  6. # Copyright (C) 1998 - 2003 Clifford Wolf
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. # We need to store some bookkeeping for later runs. With this
  16. # information better error messages are possible, but most
  17. # importantly it allows packages to be updated (with possibly
  18. # different mimetypes).
  19. parse_config_data=$root/usr/share/rock-registry/parse-config
  20. if [ "$pkg" != "sysfiles" ]; then
  21. var_append flistdel "|" "etc/mtab"
  22. fi
  23. if atstage native && [ -f $confdir/postsysfiles.in ] ; then
  24. var_append flistdel "|" "etc/passwd"
  25. var_append flistdel "|" "etc/shadow"
  26. var_append flistdel "|" "etc/gshadow"
  27. var_append flistdel "|" "etc/mime.types"
  28. var_append flistdel "|" "etc/mailcap"
  29. var_append flistdel "|" "usr/share/rock-registry/parse-config.*"
  30. hook_add preconf 2 ". $confdir/postsysfiles.in"
  31. fi
  32. # Usage: safe_useradd name uid gid desc homedir shell pass
  33. #
  34. # uid and name must be registered in
  35. # Documentation/Developers/REGISTER
  36. #
  37. # pass is already encrypted and might be one of:
  38. # "*" ... system account, wont ever have a password
  39. # "!" ... real user, admin needs to define a password later
  40. #
  41. safe_useradd() {
  42. if grep -q "^$1:" $root/etc/passwd; then
  43. echo "Found already existing user '$1'."
  44. else
  45. if grep -q ":$2:" $root/etc/passwd; then
  46. echo "UID $2 exists"
  47. exit -1
  48. fi
  49. echo "Creating user '$1' ..."
  50. echo "$1:x:$2:$3:$4:$5:$6" >> $root/etc/passwd
  51. echo "$1:$7:::::::" >> $root/etc/shadow
  52. fi
  53. }
  54. # Usage: safe_groupadd name id
  55. #
  56. # gid and name must be registered in
  57. # Documentation/Developers/REGISTER
  58. #
  59. safe_groupadd() {
  60. if grep -q "^$1:" $root/etc/group; then
  61. echo "Found already existing group '$1'."
  62. else
  63. if grep -q ":$2:" $root/etc/passwd; then
  64. echo "GID $2 exists"
  65. exit -1
  66. fi
  67. echo "Creating group '$1' ..."
  68. echo "$1:x:$2:" >> $root/etc/group
  69. fi
  70. }
  71. # Usage: safe_mimetypeadd mimetype exts cmd
  72. #
  73. # mimetype is the type to be registered
  74. # exts is one of more extension to be tied to the mimetype.
  75. # cmd the command to be tied to the mimetype
  76. #
  77. # Bookkeeping files:
  78. # -----------------
  79. # mimetypes: <mimetype> <package>
  80. # extensions: <extension> <mimetype>
  81. #
  82. # Configuration files: (simplified)
  83. # -------------------
  84. # /etc/mime.types <mimetype> <extensions>
  85. # /etc/mailcap <mimetype>; <command>
  86. #
  87. safe_mimetypeadd() {
  88. # Get the arguments.
  89. local mimetype=$1
  90. local extensions=$2
  91. local command=$3
  92. # If bookkeeping dir does not exist, create it.
  93. mkdir -p $parse_config_data
  94. # Check if the mimetype has been registered before.
  95. local add_allowed=yes; # until we know better.
  96. if grep -q "^$mimetype" $root/etc/mime.types; then
  97. # The mime type has already been registered. Determine
  98. # what package registered the mimetype.
  99. local package=$(grep "^$mimetype" $parse_config_data/mimetypes | cut -d' ' -f2)
  100. # Is it the current package, in other words is the
  101. # package being updated?
  102. if [ "$package" == "$pkg" ] ; then
  103. # Apparently the package needs to be updated. To
  104. # smoothen this process we remove any current mimetype
  105. # information for the package.
  106. remove_mimetype $mimetype
  107. else
  108. # Some other package has registered the mimetype.
  109. # Since we practise first come first served, we are
  110. # not allowed to change it.
  111. echo "Mime type '$mimetype' already registered by $package"
  112. add_allowed=no
  113. fi
  114. unset package
  115. fi
  116. # Are we allowed to add the mimetype.
  117. if [ "$add_allowed" == "yes" ] ; then
  118. # Before doing all necessary mimetype binding, we first have
  119. # to check if the requested extensions are still free.
  120. free_extensions=
  121. local mt=
  122. # Loop though all extensions and try to bind them to the
  123. # given mimetype. However, first check if the extension
  124. # is already bound to another mimetype.
  125. for extension in $extensions; do
  126. mt=$(grep "^$extention" $parse_config_data/extensions | cut -d' ' -f2)
  127. if [ -n "$mt" ] ; then
  128. # The extension is already bound to another
  129. # mimetype.
  130. echo "Extension '$extension' already bound to $mt"
  131. else
  132. # Add this extensions to the list.
  133. var_append free_extensions " " "$extension"
  134. # Register this binding in our bookkeeping.
  135. echo "$extension $mimetype" >> $parse_config_data/extensions
  136. fi
  137. done
  138. # Bind all remaining extensions to the mimetype
  139. echo "Adding mime type '$mimetype' ..."
  140. echo "$mimetype $free_extensions" >> $root/etc/mime.types
  141. unset free_extensions
  142. unset extension
  143. # Now the mimetype is set we can set the mailcap as well.
  144. echo "$mimetype; $command" >> $root/etc/mailcap
  145. # Also do the necessary bookkeeping.
  146. echo "$mimetype $pkg" >> $parse_config_data/mimetypes
  147. fi
  148. }
  149. # Usage: remove_mimetype <mimetype>
  150. #
  151. # safely removes the given mimetype from both mimetype and mailcap
  152. # configuration files. Also the proprietary T2 information regarding
  153. # mimetypes is updated.
  154. #
  155. # <mimetype> The mimetype to be removed.
  156. #
  157. remove_mimetype() {
  158. local mimetype=$1
  159. mimetype=${mimetype//\//\\/}
  160. # Remove the mimetype from /etc/mime.types
  161. sed -i "/^$mimetype .*\$/d" $root/etc/mime.types
  162. # Remove the mimetype from /etc/mailcap
  163. # TODO: mailcap entries can be multiline.
  164. sed -i "/^$mimetype; .*\$/d" $root/etc/mailcap
  165. # Remove the mimetype from .../mimetypes
  166. sed -i "/^$mimetype .*\$/d" $parse_config_data/mimetypes
  167. # Remove the extensions binding to the given mimetype.
  168. sed -i "/^.* $mimetype\$/d" $parse_config_data/extensions
  169. }