spk view spk-add @ rev 95
spk-up: improve extra local package
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 25 16:42:10 2012 +0200 (2012-05-25) |
parents | 91bb16e4eb16 |
children | 1433c665171e |
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 #
12 # Functions
13 #
15 # Help and usage
16 usage() {
17 name=$(basename $0)
18 cat << EOT
20 $(boldify $(gettext "Usage:")) $name [packages|--options]
22 $(gettext "Install SliTaz Packages")
24 $(boldify $(gettext "Options:"))
25 --forced $(gettext "Force package reinstallation")
26 --root= $(gettext "Set the root file system path")
27 --debug $(gettext "Display some useful debug information")
29 $(boldify $(gettext "Examples:"))
30 $name package1 package2 packageN
32 EOT
33 exit 0
34 }
36 # Log install messages
37 # Parameters: package
38 log_install() {
39 local pkg=$1
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 fi
91 install_deps $package_name $DEPENDS
92 fi
93 else
94 newline
95 fi
97 boldify $(gettext "Adding"; echo " $package_name")
98 separator
99 gettext "Copying package..."
100 cp $package_file $tmpdir && status
101 cd $tmpdir
103 # Add package checksum to $installed.$SUM
104 if [ "$verbose" ]; then
105 gettext "Incrementing:"; echo -n " $(basename $installed.$SUM)"
106 fi
107 sed -i "/ $PACKAGE-$VERSION*/"d $installed.$SUM 2>/dev/null
108 $CHECKSUM $(basename $package_file) >> $installed.$SUM
109 [ "$verbose" ] && status
111 # Remove receipt that will be overwritten by extraction
112 rm $tmpdir/receipt
114 # Extract Package
115 #debug "extract_package $package_file $tmpdir"
116 extract_package $package_file $tmpdir
118 # Handle cross compiled packages
119 case "$SLITAZ_ARCH" in
120 arm|x86_64) arch="-${SLITAZ_ARCH}" ;;
121 esac
122 tmpdir="$tmpdir/$PACKAGE-${VERSION}${arch}"
124 # Get files to remove if upgrading
125 local files_to_remove
126 if [ -f $package_dir/files.list ]; then
127 for file in $(cat $package_dir/files.list)
128 do
129 grep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue
130 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
131 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
132 for i in modifiers; do
133 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
134 done
135 files_to_remove="$files_to_remove $file"
136 done
137 fi
138 debug "file_to_remove: $files_to_remove"
140 # Create list of all possibly modified files
141 local file_list
142 for i in $(fgrep -v [ $tmpdir/files.list); do
143 [ -e "${root}${i}" ] || continue
144 [ -d "${root}${i}" ] && continue
145 file_list="$file_list $i"
146 done
148 debug "file_list is set"
150 # Check possibly modified files against other packages files.list
151 debug "check modified files"
152 for file in $file_list
153 do
154 local filegrep=$(egrep ^${file}$ $installed/*/files.list)
155 if [ "$filegrep" ]; then
156 local list=$(echo $filegrep | cut -d ":" -f 1)
157 local count=0
158 for pkg_file in $list; do
159 local name=$(basename $(dirname $pkg_file))
160 [ "$package_name" == "$name" ] && continue 2
161 count=$(($count +1))
162 [ "$count" == "1" ] && gettext "Modified package:"; \
163 colorize 31 " $name"
164 gettext "Overwriting file:"; echo " $file"
165 # If confirm is set, ask to remove. Do we want that ?
166 # If gawk is installed for example we will never remove Busybox
167 # Use CONFLICTS receipt variable to avoid
168 if [ "$confirm" ]; then
169 echo -n "NOTE: confirm: spk-rm $name ???"; read
170 fi
171 done
172 fi
173 done
175 cd $tmpdir || exit 1
176 cp receipt files.list $package_dir || exit 1
178 # Copy the description if found.
179 [ -f "description.txt" ] && cp description.txt $package_dir
181 # Pre install commands.
182 if grep -q ^pre_install $package_dir/receipt; then
183 pre_install $root
184 fi
186 # Handle Config Files from receipt
187 if [ -n "$CONFIG_FILES" ]; then
188 cd $fs || exit 1
189 # save 'official' configuration files
190 eval_gettext "Saving configuration files for \$package_name... "
192 local confs
193 for i in $CONFIG_FILES; do
194 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
195 done
197 echo $confs | cpio -o -H newc --quiet | gzip -9 > \
198 $package_dir/volatile.cpio.gz
200 # keep user configuration files
201 for configfile in $confs; do
202 [ -e $configfile ] || continue
203 cp -a $configfile fs/$configfile
204 done
205 status
206 cd - >/dev/null
207 fi
208 # Merge package FS with $root
209 nb=$(cat files.list | wc -l)
210 gettext "Installing files:"; echo -n " $nb"
211 cp -a fs/* $root/
212 status
214 # Remove old config files
215 if [ "$files_to_remove" ]; then
216 gettext "Removing old files..."
217 for file in $files_to_remove; do
218 if [ "$verbose" ]; then
219 gettext "Removing:"; echo " ${root}${file}"
220 fi
221 remove_with_path ${root}${file}
222 done
223 status
224 fi
225 cd - >/dev/null
227 # Remove the temporary directory.
228 if [ "$verbose" ]; then
229 gettext "Removing all tmp files... "
230 rm -rf $tmpdir && status
231 else
232 rm -rf $tmpdir
233 fi
235 # Post install commands.
236 if grep -q ^post_install $package_dir/receipt; then
237 post_install $root
238 fi
240 # Update-desktop-database if needed.
241 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
242 updatedesktopdb=yes
243 fi
244 # Update-mime-database if needed.
245 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
246 updatemimedb=yes
247 fi
248 # Update-icon-database
249 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
250 updateicondb=yes
251 fi
252 # Compile glib schemas if needed.
253 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
254 compile_schemas=yes
255 fi
256 # Update depmod list
257 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
258 updatedepmod=yes
259 fi
260 separator
261 echo -n "$package_name ${VERSION}${EXTRAVERSION} "
262 gettext "is installed"; newline
263 newline
264 }
266 # Install .tazpkg packages.
267 # Parameters: package_file
268 install_local() {
269 package_file="$1"
270 #check_valid_tazpkg $package_file
271 if [ -f "$package_file" ]; then
272 if [ $(dirname $package_file) == "." ]; then
273 package_file=$(pwd)/$package_file
274 fi
275 debug "package file: $package_file"
276 else
277 gettext "Unable to find:"; echo " $package_file"
278 exit 1
279 fi
281 # Get package name now to check if installed
282 mkdir -p $tmpdir
283 extract_receipt $tmpdir $package_file
284 source $tmpdir/receipt
285 [ "$forced" ] || check_installed $PACKAGE
286 [ "$count" == "1" ] && newline
287 install_package $package_file
288 update_databases
289 }
291 # Download and install a package. TODO: Handle Undigest Mirrors
292 # Parameters: package_name
293 install_web() {
294 local package_name="$1"
296 # Check if get-Package
297 #if mirrored_pkg get-$package_name; then
298 #package_name="get-$package_name"
299 #exec=true
300 #fi
302 # Check if package is mirrored
303 mirrored_pkg $package_name
304 if [ ! "$mirrored" ]; then
305 gettext "Could not find package on mirror:"
306 boldify " $package_name" && exit 1
307 fi
309 # We want: package-version.tazpkg
310 local package_full=$(full_package ${package_name})
312 # Add architecture string to package full name
313 case "$SLITAZ_ARCH" in
314 arm|x86_64)
315 pkgarch="-${SLITAZ_ARCH}.tazpkg"
316 package_full=$(echo $package_full | sed s/.tazpkg/$pkgarch/) ;;
317 esac
319 # Let fetch the package by download()
320 [ "$count" == 1 ] && newline
321 debug "spk-add package: $package_name"
322 download "$package_full" $mirror
323 cd $CACHE_DIR
325 # Create package path early to avoid dependencies loop
326 mkdir -p $tmpdir
327 extract_receipt $tmpdir "$CACHE_DIR/$package_full"
328 source $tmpdir/receipt
330 install_package "$CACHE_DIR/$package_full"
332 #[ "$exec" ] && chroot $root/ $package_name
333 [ "$exec" ] && $package_name $root
334 update_databases
335 unset_mirrored
336 }
338 # Install all missing deps of a package.
339 # Usage: install_deps package DEPENDS
340 install_deps() {
341 local package=$1
342 shift
343 local deps="$@"
344 for pkgorg in $deps; do
345 local pkg=$(equivalent_pkg $pkgorg)
346 # Check if package is not installed
347 if [ ! -d "$installed/$pkg" ]; then
348 if [ ! -f "$pkgsdesc" ]; then
349 spk-up --list
350 fi
351 spk-add $pkg
352 fi
353 done
354 }
356 #
357 # Commands and exit
358 #
360 case "$1" in
361 ""|*usage|*help) usage ;;
362 esac
364 #
365 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
366 #
368 : ${count=0}
369 check_root
371 for pkg in $@
372 do
373 case "$pkg" in
374 *.tazpkg|*.spk)
375 count=$(($count + 1))
376 install_local $pkg | log_install $pkg;;
377 *.deb|.rmp)
378 echo "TODO: spk-convert then install" ;;
379 *.*) gettext "WARNING: Not a valid package:"; echo " $pkg" ;;
380 --*) continue ;;
381 *)
382 [ "$forced" ] || check_installed $pkg
383 count=$(($count + 1))
384 install_web $pkg | log_install $pkg;;
385 esac
386 done
388 # Show all new counted packages in verbose mode
389 if [ "$verbose" ]; then
390 gettext "Handled packages:"; colorize 34 " $count"
391 fi
393 exit 0