1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../sysfiles/parse-config
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
8 # More information can be found in the files COPYING and README.
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 # --- T2-COPYRIGHT-NOTE-END ---
16 # We need to store some bookkeeping for later runs. With this
17 # information better error messages are possible, but most
18 # importantly it allows packages to be updated (with possibly
19 # different mimetypes).
20 parse_config_data=$root/usr/share/rock-registry/parse-config
22 if [ "$pkg" != "sysfiles" ]; then
23 var_append flistdel "|" "etc/mtab"
26 if atstage native && [ -f $confdir/postsysfiles.in ] ; then
27 var_append flistdel "|" "etc/passwd"
28 var_append flistdel "|" "etc/shadow"
29 var_append flistdel "|" "etc/gshadow"
30 var_append flistdel "|" "etc/mime.types"
31 var_append flistdel "|" "etc/mailcap"
32 var_append flistdel "|" "usr/share/rock-registry/parse-config.*"
33 hook_add preconf 2 ". $confdir/postsysfiles.in"
36 # Usage: safe_useradd name uid gid desc homedir shell pass
38 # uid and name must be registered in
39 # Documentation/Developers/REGISTER
41 # pass is already encrypted and might be one of:
42 # "*" ... system account, wont ever have a password
43 # "!" ... real user, admin needs to define a password later
46 if grep -q "^$1:" $root/etc/passwd; then
47 echo "Found already existing user '$1'."
49 if grep -q ":$2:" $root/etc/passwd; then
54 echo "Creating user '$1' ..."
55 echo "$1:x:$2:$3:$4:$5:$6" >> $root/etc/passwd
56 echo "$1:$7:::::::" >> $root/etc/shadow
60 # Usage: safe_groupadd name id
62 # gid and name must be registered in
63 # Documentation/Developers/REGISTER
66 if grep -q "^$1:" $root/etc/group; then
67 echo "Found already existing group '$1'."
69 if grep -q ":$2:" $root/etc/passwd; then
74 echo "Creating group '$1' ..."
75 echo "$1:x:$2:" >> $root/etc/group
79 # Usage: safe_mimetypeadd mimetype exts cmd
81 # mimetype is the type to be registered
82 # exts is one of more extension to be tied to the mimetype.
83 # cmd the command to be tied to the mimetype
87 # mimetypes: <mimetype> <package>
88 # extensions: <extension> <mimetype>
90 # Configuration files: (simplified)
92 # /etc/mime.types <mimetype> <extensions>
93 # /etc/mailcap <mimetype>; <command>
101 # If bookkeeping dir does not exist, create it.
102 mkdir -p $parse_config_data
104 # Check if the mimetype has been registered before.
105 local add_allowed=yes; # until we know better.
106 if grep -q "^$mimetype" $root/etc/mime.types; then
107 # The mime type has already been registered. Determine
108 # what package registered the mimetype.
109 local package=$(grep "^$mimetype" $parse_config_data/mimetypes | cut -d' ' -f2)
111 # Is it the current package, in other words is the
112 # package being updated?
113 if [ "$package" == "$pkg" ] ; then
114 # Apparently the package needs to be updated. To
115 # smoothen this process we remove any current mimetype
116 # information for the package.
117 remove_mimetype $mimetype
119 # Some other package has registered the mimetype.
120 # Since we practise first come first served, we are
121 # not allowed to change it.
122 echo "Mime type '$mimetype' already registered by $package"
128 # Are we allowed to add the mimetype.
129 if [ "$add_allowed" == "yes" ] ; then
130 # Before doing all necessary mimetype binding, we first have
131 # to check if the requested extensions are still free.
134 # Loop though all extensions and try to bind them to the
135 # given mimetype. However, first check if the extension
136 # is already bound to another mimetype.
137 for extension in $extensions; do
138 mt=$(grep "^$extention" $parse_config_data/extensions | cut -d' ' -f2)
139 if [ -n "$mt" ] ; then
140 # The extension is already bound to another
142 echo "Extension '$extension' already bound to $mt"
144 # Add this extensions to the list.
145 var_append free_extensions " " "$extension"
147 # Register this binding in our bookkeeping.
148 echo "$extension $mimetype" >> $parse_config_data/extensions
151 # Bind all remaining extensions to the mimetype
152 echo "Adding mime type '$mimetype' ..."
153 echo "$mimetype $free_extensions" >> $root/etc/mime.types
154 unset free_extensions
157 # Now the mimetype is set we can set the mailcap as well.
158 echo "$mimetype; $command" >> $root/etc/mailcap
160 # Also do the necessary bookkeeping.
161 echo "$mimetype $pkg" >> $parse_config_data/mimetypes
165 # Usage: remove_mimetype <mimetype>
167 # safely removes the given mimetype from both mimetype and mailcap
168 # configuration files. Also the proprietary T2 information regarding
169 # mimetypes is updated.
171 # <mimetype> The mimetype to be removed.
175 mimetype=${mimetype//\//\\/}
177 # Remove the mimetype from /etc/mime.types
178 sed -i "/^$mimetype .*\$/d" $root/etc/mime.types
180 # Remove the mimetype from /etc/mailcap
181 # TODO: mailcap entries can be multiline.
182 sed -i "/^$mimetype; .*\$/d" $root/etc/mailcap
184 # Remove the mimetype from .../mimetypes
185 sed -i "/^$mimetype .*\$/d" $parse_config_data/mimetypes
187 # Remove the extensions binding to the given mimetype.
188 sed -i "/^.* $mimetype\$/d" $parse_config_data/extensions