spk view spk-add @ rev 12

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun May 13 13:42:38 2012 +0100 (2012-05-13)
parents db99af6fac70
children 8fd53f8759ad
line source
1 #!/bin/sh
2 #
3 # Authors : See the AUTHORS files
5 # Set to / for now until we add installing to chroot support
6 # Could we update tools so they do not need this?
7 ROOT=""
8 TMP_DIR="/tmp/$RANDOM"
10 source /usr/lib/slitaz/libspk.sh
12 # This function installs a package in the rootfs.
13 # Parameters: package_name package_file
14 install_package() {
15 local package_file=$1
17 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
19 # Create package path early to avoid dependencies loop
20 mkdir -p $TMP_DIR
21 extract_receipt $TMP_DIR $package_file
22 source $TMP_DIR/receipt
24 local package_name=$PACKAGE
25 local package_dir="$installed/$package_name"
26 mkdir -p $package_dir
28 # Run pre_depends from receipt if it exists
29 if grep -q ^pre_depends $TMP_DIR/receipt; then
30 pre_depends $ROOT
31 fi
33 # Create modifiers and files.list if they do not exist
34 # touch $package_dir/modifiers
35 # touch $package_dir/files.list
37 # add package checksum to pkgsmd5
38 sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
39 pushd $(dirname $package_file) > /dev/null
40 $CHECKSUM $(basename $package_file) >> $pkgsmd5
41 popd > /dev/null
43 # Resolve package deps.
44 if missing_deps $package_name $DEPENDS; then
45 install_deps $package_name $DEPENDS
46 fi
48 newline
49 boldify $(gettext "Installation of :") $package_name
50 separator
51 eval_gettext "Copying \$package_name... "
52 cp $package_file $TMP_DIR
53 status
55 # Extract Package
56 pushd $TMP_DIR > /dev/null
57 rm receipt
58 spk-archive extract $package_file
59 popd > /dev/null
61 # Get files to remove if upgrading
62 local files_to_remove
63 if [ -f $package_dir/files.list ]; then
64 for file in $($package_dir/files.list); do
65 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
66 local modifiers=$(cat $package_dir/modifiers 2> /dev/null;\
67 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
68 for i in modifiers; do
69 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
70 done
71 files_to_remove="$files_to_remove $file"
72 done
73 fi
75 local check=false
76 local file_list
77 # Create list of all possibly modified files
78 for i in $(fgrep -v [ $TMP_DIR/files.list); do
79 [ -e "$ROOT$i" ] || continue
80 [ -d "$ROOT$i" ] && continue
81 file_list="$file_list $i"
82 check=true
83 done
85 # Check possibly modified files against other packages file.list
86 if $check; then
87 for pkg in $INSTALLED/*; do
88 [ "$pkg" == "$package_name" ] && continue
89 [ -s $pkg/files.list ] || continue
91 for file in $file_list; do
92 # $package_name wants to install $file which is already
93 # Installed from $pkg
94 if grep -q ^$file$ $pkg/files.list; then
95 # Tell $pkg that $package_name is going to overwrite some of its files
96 if [ -s "$pkg/volatile.cpio.gz" ]; then
97 # We can modify backed up files without notice
98 zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \
99 grep -q "^${file#/}$" && continue
100 fi
101 echo "$package_name" >> $pkg/modifiers
102 fi
103 done
104 done
105 fi
107 pushd $TMP_DIR > /dev/null
108 cp receipt files.list $package_dir
109 # Copy the description if found.
110 [ -f "description.txt" ] && cp description.txt $package_dir
112 # Pre install commands.
113 if grep -q ^pre_install $package_dir/receipt; then
114 pre_install $ROOT
115 fi
117 # Handle Config Files from receipt
118 if [ -n "$CONFIG_FILES" ]; then
119 pushd $fs > /dev/null
120 # save 'official' configuration files
121 eval_gettext "Saving configuration files for \$package_name... "
123 local confs
124 for i in $CONFIG_FILES; do
125 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
126 done
128 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz
130 # keep user configuration files
131 for conf_file in $confs; do
132 [ -e $conf_file ] || continue
133 cp -a $conf_file fs/$conf_file
134 done
135 status
136 popd > /dev/null
137 fi
139 # Merge ROOT_FS with Package FS
140 eval_gettext "Installing \$package_name... "
141 cp -a fs/* $ROOT/
142 status
144 # Remove old config files
145 if [ -n $files_to_remove ]; then
146 eval_gettext "Removing old \$package_name... "
147 for file in $files_to_remove; do
148 remove_with_path $ROOT$file
149 done
150 status
151 fi
152 popd > /dev/null
154 # Remove the temporary directory.
155 gettext "Removing all tmp files... "
156 rm -rf $TMP_DIR
157 status
159 # Post install commands.
160 if grep -q ^post_install $package_dir/receipt; then
161 post_install $ROOT
162 fi
164 # Update-desktop-database if needed.
165 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
166 updatedesktopdb=yes
167 fi
168 # Update-mime-database if needed.
169 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
170 updatemimedb=yes
171 fi
172 # Update-icon-database
173 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
174 updateicondb=yes
175 fi
176 # Compile glib schemas if needed.
177 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
178 compile_schemas=yes
179 fi
180 # Update depmod list
181 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
182 updatedepmod=yes
183 fi
185 separator
186 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
187 newline
188 }
191 # Install .tazpkg packages.
192 # Parameters: package_file
193 install_pkg() {
194 package_file="$1"
196 check_root
197 check_valid_tazpkg $package_file
199 # Check if forced install.
200 if ! [ "$forced" ]; then
201 check_for_installed_package $(package_name $package_file)
202 fi
204 install_package $package_file
206 update_desktop_database
207 update_mime_database
208 update_icon_database
209 compile_glib_schemas
210 }
212 # Download and install a package. TODO: Handle Undigest Mirrors
213 # Parameters: package_name
214 get_install() {
215 local package_name="$1"
217 check_root
219 # Check if get-Package
220 if ! is_package_mirrored $package_name; then
221 package_name="get-$package_name"
222 AUTOEXEC=true
223 fi
225 # Check if package is mirrored
226 if ! is_package_mirrored $package_name; then
227 gettext "Could not find \$package_name in repositories"; newline
228 exit 1
229 fi
231 # package_full=Package-Version
232 local package_full=$(full_package $package_name)
234 # Check if forced install.
235 if ! [ "$forced" ]; then
236 check_for_installed_package $package_name
237 fi
239 pushd $CACHE_DIR > /dev/null
240 if [ -f "$package_full.tazpkg" ]; then
241 eval_gettext "\$package_full is already in the cache : \$CACHE_DIR"; newline
242 # Check package download was finished
243 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
244 eval_gettext "Continuing \$package_name download"; newline
245 download "$package_full.tazpkg"
246 fi
248 # Check that the package has the correct checksum
249 # if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
250 # rm -f $package.tazpkg
251 # download "$package_full.tazpkg"
252 # fi
253 else
254 newline
255 download "$package_full.tazpkg"
256 fi
257 popd > /dev/null
259 install_package "$CACHE_DIR/$package_full.tazpkg"
261 [ -n "$AUTOEXEC" ] && $package_name $ROOT
262 update_desktop_database
263 update_mime_database
264 }
266 # Install all missing deps. Auto install or ask user then install all missing
267 # deps from local dir, cdrom, media or from the mirror. In case we want to
268 # install packages from local, we need a packages.list to find the version.
269 # Parameters: package List of deps to install
270 install_deps() {
271 local package=$1
272 shift
273 local deps="$@"
275 gettext "Install all missing dependencies? "
277 # Print Yes/No and get result
278 if $AUTO_INSTALL_DEPS || confirm; then
279 for pkgorg in $deps; do
280 local pkg=$(equivalent_pkg $pkgorg)
281 # Check if package is not installed
282 if [ ! -d "$installed/$pkg" ]; then
283 if [ ! -f "$PKGS_DB/packages.list" ]; then
284 tazpkg recharge
285 fi
286 get-install $pkg
287 fi
288 done
289 else
290 newline
291 eval_gettext \
292 "Leaving dependencies for \$package unresolved. The package is installed but
293 will probably not work."; newline
294 newline
295 fi
296 }
298 # Check for ELF file
299 is_elf() {
300 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
301 }
303 # Print shared library dependencies
304 ldd() {
305 LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
306 }
309 update_desktop_database() {
310 if [ -f $ROOT/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
311 chroot "$ROOT/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
312 fi
313 }
315 update_mime_database() {
316 if [ -f $ROOT/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
317 chroot "$ROOT/" /usr/bin/update-mime-database /usr/share/mime
318 fi
319 }
321 update_icon_database() {
322 if [ -f $ROOT/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
323 chroot "$ROOT/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
324 fi
325 }
327 compile_glib_schemas() {
328 if [ -f $ROOT/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
329 chroot "$ROOT/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
330 fi
331 }
333 update_kernel_modules() {
334 if [ -f $ROOT/sbin/depmod ] && [ -n "$updatedepmod" ]; then
335 chroot "$ROOT/" /sbin/depmod -a
336 fi
337 }
339 case $1 in
340 install|-i)
341 install_pkg $2 $3 ;;
342 get-install|-gi)
343 get_install $2 ;;
344 *)
345 usage ;;
346 esac