spk view spk-add @ rev 56

Show added/removed packages count in verbose mode + some and fixes
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 17 14:07:25 2012 +0200 (2012-05-17)
parents 5cba598bd418
children 85543a2e118c
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 # Update system databases
39 update_databases() {
40 if [ -f $root/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
41 chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
42 fi
43 # Mimetypes
44 if [ -f $root/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
45 chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
46 fi
47 # Icons
48 if [ -f $root/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
49 chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
50 fi
51 # Glib schemas
52 if [ -f $root/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
53 chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
54 fi
55 # Kernel modules
56 if [ -f $root/sbin/depmod ] && [ -n "$updatedepmod" ]; then
57 chroot "$root/" /sbin/depmod -a
58 fi
59 }
61 # This function installs a package in the rootfs.
62 # Parameters: package_name package_file
63 install_package() {
64 local package_file=$1
66 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
68 local package_name=$PACKAGE
69 local package_dir="$installed/$package_name"
70 mkdir -p $package_dir || exit 1
72 # Run pre_depends from receipt if it exists
73 if grep -q ^pre_depends $tmpdir/receipt; then
74 pre_depends $root
75 fi
77 # Resolve package deps.
78 if missing_deps $package_name $DEPENDS; then
79 if [ "$confirm" ]; then
80 gettext "Install missing dependencies"
81 if ! confirm; then
82 gettext "WARNING: Any dependencies installed"; newline
83 else
84 install_deps $package_name $DEPENDS
85 fi
86 else
87 install_deps $package_name $DEPENDS
88 fi
89 else
90 newline
91 fi
93 boldify $(gettext "Installation of:") $package_name
94 separator
95 gettext "Copying"; echo -n " $package_name..."
96 cp $package_file $tmpdir
97 status
99 # Add package checksum to $installed.$SUM
100 if [ "$verbose" ]; then
101 gettext "Incrementing:"; echo -n " $(basename $installed.$SUM)"
102 fi
103 sed -i "/$(basename $package_file)/"d $installed.$SUM 2>/dev/null
104 $CHECKSUM $(basename $package_file) >> $installed.$SUM
105 [ "$verbose" ] && status
107 # Extract Package
108 cd $tmpdir || exit 1
109 rm receipt
110 spk-archive extract $package_file
111 cd - >/dev/null
113 # Get files to remove if upgrading
114 local files_to_remove
115 if [ -f $package_dir/files.list ]; then
116 for file in $(cat $package_dir/files.list)
117 do
118 grep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue
119 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
120 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
121 for i in modifiers; do
122 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
123 done
124 files_to_remove="$files_to_remove $file"
125 done
126 fi
127 debug "file_to_remove: $files_to_remove"
129 # Create list of all possibly modified files
130 local file_list
131 for i in $(fgrep -v [ $tmpdir/files.list); do
132 [ -e "${root}${i}" ] || continue
133 [ -d "${root}${i}" ] && continue
134 file_list="$file_list $i"
135 done
137 debug "file_list is set"
139 # Check possibly modified files against other packages files.list
140 debug "check modified files"
141 for file in $file_list
142 do
143 local filegrep=$(egrep ^${file}$ $installed/*/files.list)
144 if [ "$filegrep" ]; then
145 local list=$(echo $filegrep | cut -d ":" -f 1)
146 local count=0
147 for pkg_file in $list; do
148 local name=$(basename $(dirname $pkg_file))
149 [ "$package_name" == "$name" ] && continue 2
150 count=$(($count +1))
151 [ "$count" == "1" ] && gettext "Modified package:"; \
152 colorize " $name" 31
153 gettext "Overwriting file:"; echo " $file"
154 # If confirm is set, ask to remove. Do we want that ?
155 # If gawk is installed for example we will never remove Busybox
156 # Use CONFLICTS receipt variable to avoid
157 if [ "$confirm" ]; then
158 echo -n "NOTE: confirm: spk-rm $name ???"; read
159 fi
160 done
161 fi
162 done
164 cd $tmpdir || exit 1
165 cp receipt files.list $package_dir || exit 1
167 # Copy the description if found.
168 [ -f "description.txt" ] && cp description.txt $package_dir
170 # Pre install commands.
171 if grep -q ^pre_install $package_dir/receipt; then
172 pre_install $root
173 fi
175 # Handle Config Files from receipt
176 if [ -n "$CONFIG_FILES" ]; then
177 cd $fs || exit 1
178 # save 'official' configuration files
179 eval_gettext "Saving configuration files for \$package_name... "
181 local confs
182 for i in $CONFIG_FILES; do
183 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
184 done
186 echo $confs | cpio -o -H newc --quiet | gzip -9 > \
187 $package_dir/volatile.cpio.gz
189 # keep user configuration files
190 for configfile in $confs; do
191 [ -e $configfile ] || continue
192 cp -a $configfile fs/$configfile
193 done
194 status
195 cd - >/dev/null
196 fi
198 # Merge ROOT_FS with Package FS
199 gettext "Installing in:"; echo -n " $root/"
200 cp -a fs/* $root/
201 status
203 # Remove old config files
204 if [ "$files_to_remove" ]; then
205 gettext "Removing old"; echo -n " $package_name..."
206 for file in $files_to_remove; do
207 if [ "$verbose" ]; then
208 gettext "Removing:"; echo " ${root}${file}"
209 fi
210 remove_with_path ${root}${file}
211 done
212 status
213 fi
214 cd - >/dev/null
216 # Remove the temporary directory.
217 gettext "Removing all tmp files... "
218 rm -rf $tmpdir
219 status
221 # Post install commands.
222 if grep -q ^post_install $package_dir/receipt; then
223 post_install $root
224 fi
226 # Update-desktop-database if needed.
227 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
228 updatedesktopdb=yes
229 fi
230 # Update-mime-database if needed.
231 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
232 updatemimedb=yes
233 fi
234 # Update-icon-database
235 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
236 updateicondb=yes
237 fi
238 # Compile glib schemas if needed.
239 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
240 compile_schemas=yes
241 fi
242 # Update depmod list
243 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
244 updatedepmod=yes
245 fi
246 separator
247 echo -n "$package_name ({$VERSION}${EXTRAVERSION})"
248 gettext "is installed."; newline
249 newline
250 }
252 # Install .tazpkg packages.
253 # Parameters: package_file
254 install_local() {
255 package_file="$1"
256 #check_valid_tazpkg $package_file
257 if [ -f "$package_file" ]; then
258 if [ $(dirname $package_file) == "." ]; then
259 package_file=$(pwd)/$package_file
260 fi
261 debug "package file: $package_file"
262 else
263 gettext "Unable to find:"; echo " $package_file"
264 exit 1
265 fi
267 # Get package name now to check if installed
268 mkdir -p $tmpdir
269 extract_receipt $tmpdir $package_file
270 source $tmpdir/receipt
271 [ "$forced" ] || check_installed $PACKAGE
272 [ "$count" == "1" ] && newline
273 install_package $package_file
274 update_databases
275 }
277 # Download and install a package. TODO: Handle Undigest Mirrors
278 # Parameters: package_name
279 install_web() {
280 local package_name="$1"
282 # Check if get-Package
283 if ! is_package_mirrored $package_name; then
284 package_name="get-$package_name"
285 AUTOEXEC=true
286 fi
288 # Check if package is mirrored
289 if ! is_package_mirrored $package_name; then
290 gettext "Could not find package on mirror:"; echo " $package_name"
291 exit 1
292 fi
294 # package_full=Package-Version
295 local package_full=$(full_package $package_name)
297 cd $CACHE_DIR > /dev/null
298 if [ -f "$package_full.tazpkg" ]; then
299 [ "$count" == 1 ] && newline
300 gettext "Using cache:"; echo " $(colorize "$package_full" 34)"
301 # Check package download was finished
302 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
303 gettext "Continuing download of:"; echo " $package_name"
304 download "$package_full.tazpkg"
305 fi
306 # Check that the package has the correct checksum
307 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
308 # rm -f $package.tazpkg
309 # download "$package_full.tazpkg"
310 #fi
311 else
312 newline && download "$package_full.tazpkg"
313 fi
315 # Create package path early to avoid dependencies loop
316 mkdir -p $tmpdir
317 extract_receipt $tmpdir "$CACHE_DIR/$package_full.tazpkg"
318 source $tmpdir/receipt
320 install_package "$CACHE_DIR/$package_full.tazpkg"
322 #[ "$AUTOEXEC" ] && chroot $root/ $package_name
323 [ "$AUTOEXEC" ] && $package_name $root
324 update_databases
325 }
327 # Install all missing deps of a package.
328 # Usage: install_deps package DEPENDS
329 install_deps() {
330 local package=$1
331 shift
332 local deps="$@"
333 for pkgorg in $deps; do
334 local pkg=$(equivalent_pkg $pkgorg)
335 # Check if package is not installed
336 if [ ! -d "$installed/$pkg" ]; then
337 if [ ! -f "$PKGS_DB/packages.list" ]; then
338 #spk-up --recharge-only
339 tazpkg recharge
340 fi
341 spk-add $pkg
342 fi
343 done
344 }
346 #
347 # Commands and exit
348 #
350 case "$1" in
351 ""|*usage|*help) usage ;;
352 esac
354 #
355 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
356 #
358 : ${count=0}
359 check_root
361 for pkg in $@
362 do
363 case "$pkg" in
364 *.tazpkg|*.spk)
365 count=$(($count + 1))
366 install_local $pkg ;;
367 *.deb|.rmp)
368 echo "TODO: spk-convert then install" ;;
369 *.*) gettext "WARNING: Not a valid package:"; echo " $pkg" ;;
370 --*) continue ;;
371 *)
372 [ "$forced" ] || check_installed $pkg
373 count=$(($count + 1))
374 install_web $pkg ;;
375 esac
376 done
378 # Show all new counted packages in verbose mode
379 if [ "$verbose" ]; then
380 gettext "New installed packages:"; colorize " $count" 34
381 fi
383 exit 0