spk view spk-add @ rev 57

spk-add: log install message
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 17 15:04:31 2012 +0200 (2012-05-17)
parents 256ff61b7248
children 17ac07667767
line source
1 #!/bin/sh
2 #
3 # Spk-add - Install SliTaz packages. Read the README before adding or
4 # modifing any code in spk!
5 #
6 # Copyright (C) SliTaz GNU/Linux - BSD License
7 # Author: See AUTHORS files
8 #
9 . /usr/lib/slitaz/libspk.sh
11 tmpdir="/tmp/spk/$RANDOM"
13 #
14 # Functions
15 #
17 # Help and usage
18 usage() {
19 name=$(basename $0)
20 cat << EOT
22 $(boldify $(gettext "Usage:")) $name [packages|--options]
24 $(gettext "Install SliTaz Packages")
26 $(boldify $(gettext "Options:"))
27 --forced $(gettext "Force package reinstallation")
28 --root= $(gettext "Set the root file system path")
29 --debug $(gettext "Display some usefull debug information")
31 $(boldify $(gettext "Examples:"))
32 $name package1 package2 packageN
34 EOT
35 exit 0
36 }
38 # Log install messages
39 log_install() {
40 debug "log_install: $logdir/$pkg/install.log"
41 mkdir -p $logdir/$pkg
42 tee $logdir/$pkg/install.log
43 }
45 # Update system databases
46 update_databases() {
47 if [ -f $root/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
48 chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
49 fi
50 # Mimetypes
51 if [ -f $root/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
52 chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
53 fi
54 # Icons
55 if [ -f $root/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
56 chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
57 fi
58 # Glib schemas
59 if [ -f $root/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
60 chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
61 fi
62 # Kernel modules
63 if [ -f $root/sbin/depmod ] && [ -n "$updatedepmod" ]; then
64 chroot "$root/" /sbin/depmod -a
65 fi
66 }
68 # This function installs a package in the rootfs.
69 # Parameters: package_name package_file
70 install_package() {
71 local package_file=$1
73 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
75 local package_name=$PACKAGE
76 local package_dir="$installed/$package_name"
77 mkdir -p $package_dir || exit 1
79 # Run pre_depends from receipt if it exists
80 if grep -q ^pre_depends $tmpdir/receipt; then
81 pre_depends $root
82 fi
84 # Resolve package deps.
85 if missing_deps $package_name $DEPENDS; then
86 if [ "$confirm" ]; then
87 gettext "Install missing dependencies"
88 if ! confirm; then
89 gettext "WARNING: Any dependencies installed"; newline
90 else
91 install_deps $package_name $DEPENDS
92 fi
93 else
94 install_deps $package_name $DEPENDS
95 fi
96 else
97 newline
98 fi
100 boldify $(gettext "Adding"; echo " $package_name")
101 separator
102 gettext "Copying"; echo -n " $package_name..."
103 cp $package_file $tmpdir
104 status
106 # Add package checksum to $installed.$SUM
107 if [ "$verbose" ]; then
108 gettext "Incrementing:"; echo -n " $(basename $installed.$SUM)"
109 fi
110 sed -i "/$(basename $package_file)/"d $installed.$SUM 2>/dev/null
111 $CHECKSUM $(basename $package_file) >> $installed.$SUM
112 [ "$verbose" ] && status
114 # Extract Package
115 cd $tmpdir || exit 1
116 rm receipt
117 spk-archive extract $package_file
118 cd - >/dev/null
120 # Get files to remove if upgrading
121 local files_to_remove
122 if [ -f $package_dir/files.list ]; then
123 for file in $(cat $package_dir/files.list)
124 do
125 grep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue
126 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
127 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
128 for i in modifiers; do
129 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
130 done
131 files_to_remove="$files_to_remove $file"
132 done
133 fi
134 debug "file_to_remove: $files_to_remove"
136 # Create list of all possibly modified files
137 local file_list
138 for i in $(fgrep -v [ $tmpdir/files.list); do
139 [ -e "${root}${i}" ] || continue
140 [ -d "${root}${i}" ] && continue
141 file_list="$file_list $i"
142 done
144 debug "file_list is set"
146 # Check possibly modified files against other packages files.list
147 debug "check modified files"
148 for file in $file_list
149 do
150 local filegrep=$(egrep ^${file}$ $installed/*/files.list)
151 if [ "$filegrep" ]; then
152 local list=$(echo $filegrep | cut -d ":" -f 1)
153 local count=0
154 for pkg_file in $list; do
155 local name=$(basename $(dirname $pkg_file))
156 [ "$package_name" == "$name" ] && continue 2
157 count=$(($count +1))
158 [ "$count" == "1" ] && gettext "Modified package:"; \
159 colorize " $name" 31
160 gettext "Overwriting file:"; echo " $file"
161 # If confirm is set, ask to remove. Do we want that ?
162 # If gawk is installed for example we will never remove Busybox
163 # Use CONFLICTS receipt variable to avoid
164 if [ "$confirm" ]; then
165 echo -n "NOTE: confirm: spk-rm $name ???"; read
166 fi
167 done
168 fi
169 done
171 cd $tmpdir || exit 1
172 cp receipt files.list $package_dir || exit 1
174 # Copy the description if found.
175 [ -f "description.txt" ] && cp description.txt $package_dir
177 # Pre install commands.
178 if grep -q ^pre_install $package_dir/receipt; then
179 pre_install $root
180 fi
182 # Handle Config Files from receipt
183 if [ -n "$CONFIG_FILES" ]; then
184 cd $fs || exit 1
185 # save 'official' configuration files
186 eval_gettext "Saving configuration files for \$package_name... "
188 local confs
189 for i in $CONFIG_FILES; do
190 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
191 done
193 echo $confs | cpio -o -H newc --quiet | gzip -9 > \
194 $package_dir/volatile.cpio.gz
196 # keep user configuration files
197 for configfile in $confs; do
198 [ -e $configfile ] || continue
199 cp -a $configfile fs/$configfile
200 done
201 status
202 cd - >/dev/null
203 fi
205 # Merge ROOT_FS with Package FS
206 gettext "Installing in:"; echo -n " $root/"
207 cp -a fs/* $root/
208 status
210 # Remove old config files
211 if [ "$files_to_remove" ]; then
212 gettext "Removing old"; echo -n " $package_name..."
213 for file in $files_to_remove; do
214 if [ "$verbose" ]; then
215 gettext "Removing:"; echo " ${root}${file}"
216 fi
217 remove_with_path ${root}${file}
218 done
219 status
220 fi
221 cd - >/dev/null
223 # Remove the temporary directory.
224 gettext "Removing all tmp files... "
225 rm -rf $tmpdir
226 status
228 # Post install commands.
229 if grep -q ^post_install $package_dir/receipt; then
230 post_install $root
231 fi
233 # Update-desktop-database if needed.
234 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
235 updatedesktopdb=yes
236 fi
237 # Update-mime-database if needed.
238 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
239 updatemimedb=yes
240 fi
241 # Update-icon-database
242 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
243 updateicondb=yes
244 fi
245 # Compile glib schemas if needed.
246 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
247 compile_schemas=yes
248 fi
249 # Update depmod list
250 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
251 updatedepmod=yes
252 fi
253 separator
254 echo -n "$package_name ${VERSION}${EXTRAVERSION} "
255 gettext "is installed"; newline
256 newline
257 }
259 # Install .tazpkg packages.
260 # Parameters: package_file
261 install_local() {
262 package_file="$1"
263 #check_valid_tazpkg $package_file
264 if [ -f "$package_file" ]; then
265 if [ $(dirname $package_file) == "." ]; then
266 package_file=$(pwd)/$package_file
267 fi
268 debug "package file: $package_file"
269 else
270 gettext "Unable to find:"; echo " $package_file"
271 exit 1
272 fi
274 # Get package name now to check if installed
275 mkdir -p $tmpdir
276 extract_receipt $tmpdir $package_file
277 source $tmpdir/receipt
278 [ "$forced" ] || check_installed $PACKAGE
279 [ "$count" == "1" ] && newline
280 install_package $package_file
281 update_databases
282 }
284 # Download and install a package. TODO: Handle Undigest Mirrors
285 # Parameters: package_name
286 install_web() {
287 local package_name="$1"
289 # Check if get-Package
290 if ! is_package_mirrored $package_name; then
291 package_name="get-$package_name"
292 AUTOEXEC=true
293 fi
295 # Check if package is mirrored
296 if ! is_package_mirrored $package_name; then
297 gettext "Could not find package on mirror:"; echo " $package_name"
298 exit 1
299 fi
301 # package_full=Package-Version
302 local package_full=$(full_package $package_name)
304 cd $CACHE_DIR > /dev/null
305 if [ -f "$package_full.tazpkg" ]; then
306 [ "$count" == 1 ] && newline
307 gettext "Using cache:"; echo " $(colorize "$package_full" 34)"
308 # Check package download was finished
309 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
310 gettext "Continuing download of:"; echo " $package_name"
311 download "$package_full.tazpkg"
312 fi
313 # Check that the package has the correct checksum
314 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
315 # rm -f $package.tazpkg
316 # download "$package_full.tazpkg"
317 #fi
318 else
319 newline && download "$package_full.tazpkg"
320 fi
322 # Create package path early to avoid dependencies loop
323 mkdir -p $tmpdir
324 extract_receipt $tmpdir "$CACHE_DIR/$package_full.tazpkg"
325 source $tmpdir/receipt
327 install_package "$CACHE_DIR/$package_full.tazpkg"
329 #[ "$AUTOEXEC" ] && chroot $root/ $package_name
330 [ "$AUTOEXEC" ] && $package_name $root
331 update_databases
332 }
334 # Install all missing deps of a package.
335 # Usage: install_deps package DEPENDS
336 install_deps() {
337 local package=$1
338 shift
339 local deps="$@"
340 for pkgorg in $deps; do
341 local pkg=$(equivalent_pkg $pkgorg)
342 # Check if package is not installed
343 if [ ! -d "$installed/$pkg" ]; then
344 if [ ! -f "$PKGS_DB/packages.list" ]; then
345 #spk-up --recharge-only
346 tazpkg recharge
347 fi
348 spk-add $pkg
349 fi
350 done
351 }
353 #
354 # Commands and exit
355 #
357 case "$1" in
358 ""|*usage|*help) usage ;;
359 esac
361 #
362 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
363 #
365 : ${count=0}
366 check_root
368 for pkg in $@
369 do
370 case "$pkg" in
371 *.tazpkg|*.spk)
372 count=$(($count + 1))
373 install_local $pkg | log_install ;;
374 *.deb|.rmp)
375 echo "TODO: spk-convert then install" ;;
376 *.*) gettext "WARNING: Not a valid package:"; echo " $pkg" ;;
377 --*) continue ;;
378 *)
379 [ "$forced" ] || check_installed $pkg
380 count=$(($count + 1))
381 install_web $pkg | log_install ;;
382 esac
383 done
385 # Show all new counted packages in verbose mode
386 if [ "$verbose" ]; then
387 gettext "New installed packages:"; colorize " $count" 34
388 fi
390 exit 0