spk view spk-add @ rev 35

spk-add: add installed packges to installed.md5 not packages.md5
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 21:11:07 2012 +0200 (2012-05-15)
parents 48522fb4d101
children 70c2d1ac2887
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
10 . lib/libspk.sh
12 tmpdir="/tmp/$RANDOM"
14 #
15 # Functions
16 #
18 # Help and usage
19 usage() {
20 name=$(basename $0)
21 cat << EOT
23 $(boldify $(gettext "Usage:")) $name [packages|--options]
25 $(gettext "Install SliTaz Packages")
27 $(boldify $(gettext "Options:"))
28 --forced $(gettext "Force package reinstallation")
29 --root= $(gettext "Set the root file system path")
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 # Never used I think!!!
67 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
69 # Create package path early to avoid dependencies loop
70 mkdir -p $tmpdir
71 extract_receipt $tmpdir $package_file
72 source $tmpdir/receipt
74 local package_name=$PACKAGE
75 local package_dir="$installed/$package_name"
76 mkdir -p $package_dir
78 # Run pre_depends from receipt if it exists
79 if grep -q ^pre_depends $tmpdir/receipt; then
80 pre_depends $root
81 fi
83 # Create modifiers and files.list if they do not exist
84 # Why ? If missing files.list it's meta packages.
85 #touch $package_dir/modifiers
86 #touch $package_dir/files.list
88 # Add package checksum to $installed.$SUM
89 sed -i "/ $(basename $package_dir)$/d" $installed.$SUM 2> /dev/null
90 cd $(dirname $package_file) || exit 1
91 $CHECKSUM $(basename $package_file) >> $installed.$SUM
92 cd - >/dev/null
94 # Resolve package deps.
95 if missing_deps $package_name $DEPENDS; then
96 install_deps $package_name $DEPENDS
97 fi
99 newline
100 boldify $(gettext "Installation of:") $package_name
101 separator
102 gettext "Copying"; echo -n " $package_name..."
103 cp $package_file $tmpdir
104 status
106 # Extract Package
107 cd $tmpdir || exit 1
108 rm receipt
109 spk-archive extract $package_file
110 cd - >/dev/null
112 # Get files to remove if upgrading
113 local files_to_remove
114 if [ -f $package_dir/files.list ]; then
115 for file in $(cat $package_dir/files.list)
116 do
117 grep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue
118 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
119 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
120 for i in modifiers; do
121 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
122 done
123 files_to_remove="$files_to_remove $file"
124 done
125 fi
127 local check=false
128 local file_list
129 # Create list of all possibly modified files
130 for i in $(fgrep -v [ $tmpdir/files.list); do
131 [ -e "${root}${i}" ] || continue
132 [ -d "${root}${i}" ] && continue
133 file_list="$file_list $i"
134 check=true
135 done
137 # Check possibly modified files against other packages file.list
138 if $check; then
139 for pkg in $installed/*
140 do
141 [ "$pkg" == "$package_name" ] && continue
142 [ -s $pkg/files.list ] || continue
144 for file in $file_list; do
145 # $package_name wants to install $file which is already
146 # installed from $pkg
147 if grep -q ^$file$ $pkg/files.list; then
148 # Tell $pkg that $package_name is going to overwrite some
149 # of its files
150 if [ -s "$pkg/volatile.cpio.gz" ]; then
151 # We can modify backed up files without notice
152 zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \
153 grep -q "^${file#/}$" && continue
154 fi
155 base_name=$(basename $pkg)
156 if [ "$package_name" != "$base_name" ]; then
157 [ "$debug" ] && \
158 echo "DEBUG: Adding $base_name to: $pkg/modifiers"
159 echo "$package_name" >> $pkg/modifiers
160 fi
161 fi
162 done
163 done
164 fi
166 cd $tmpdir || exit 1
167 cp receipt files.list $package_dir
169 # Copy the description if found.
170 [ -f "description.txt" ] && cp description.txt $package_dir
172 # Pre install commands.
173 if grep -q ^pre_install $package_dir/receipt; then
174 pre_install $root
175 fi
177 # Handle Config Files from receipt
178 if [ -n "$CONFIG_FILES" ]; then
179 cd $fs || exit 1
180 # save 'official' configuration files
181 eval_gettext "Saving configuration files for \$package_name... "
183 local confs
184 for i in $CONFIG_FILES; do
185 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
186 done
188 echo $confs | cpio -o -H newc --quiet | gzip -9 > \
189 $package_dir/volatile.cpio.gz
191 # keep user configuration files
192 for configfile in $confs; do
193 [ -e $configfile ] || continue
194 cp -a $configfile fs/$configfile
195 done
196 status
197 cd - >/dev/null
198 fi
200 # Merge ROOT_FS with Package FS
201 gettext "Installing in:"; echo -n " $root/"
202 cp -a fs/* $root/
203 status
205 # Remove old config files
206 if [ "$files_to_remove" ]; then
207 gettext "Removing old"; echo -n " $package_name..."
208 for file in $files_to_remove; do
209 if [ "$verbose" ]; then
210 gettext "Removing:"; echo " ${root}${file}"
211 fi
212 remove_with_path ${root}${file}
213 done
214 status
215 fi
216 cd - >/dev/null
218 # Remove the temporary directory.
219 gettext "Removing all tmp files... "
220 rm -rf $tmpdir
221 status
223 # Post install commands.
224 if grep -q ^post_install $package_dir/receipt; then
225 post_install $root
226 fi
228 # Update-desktop-database if needed.
229 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
230 updatedesktopdb=yes
231 fi
232 # Update-mime-database if needed.
233 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
234 updatemimedb=yes
235 fi
236 # Update-icon-database
237 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
238 updateicondb=yes
239 fi
240 # Compile glib schemas if needed.
241 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
242 compile_schemas=yes
243 fi
244 # Update depmod list
245 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
246 updatedepmod=yes
247 fi
248 separator
249 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
250 newline
251 }
253 # Install .tazpkg packages.
254 # Parameters: package_file
255 install_local() {
256 package_file="$1"
257 check_valid_tazpkg $package_file
258 install_package $package_file
259 update_databases
260 }
262 # Download and install a package. TODO: Handle Undigest Mirrors
263 # Parameters: package_name
264 install_web() {
265 local package_name="$1"
267 # Check if get-Package
268 if ! is_package_mirrored $package_name; then
269 package_name="get-$package_name"
270 AUTOEXEC=true
271 fi
273 # Check if package is mirrored
274 if ! is_package_mirrored $package_name; then
275 gettext "Could not find package on mirror:"; echo " $package_name"
276 exit 1
277 fi
279 # package_full=Package-Version
280 local package_full=$(full_package $package_name)
282 cd $CACHE_DIR > /dev/null
283 if [ -f "$package_full.tazpkg" ]; then
284 echo -n "$(colorize "$package_full" 34)"; echo ": $CACHE_DIR"
285 # Check package download was finished
286 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
287 eval_gettext "Continuing \$package_name download"; newline
288 download "$package_full.tazpkg"
289 fi
290 # Check that the package has the correct checksum
291 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
292 # rm -f $package.tazpkg
293 # download "$package_full.tazpkg"
294 #fi
295 else
296 newline
297 download "$package_full.tazpkg"
298 fi
300 install_package "$CACHE_DIR/$package_full.tazpkg"
302 [ -n "$AUTOEXEC" ] && $package_name $root
303 update_databases
304 }
306 # Install all missing deps. Auto install or ask user then install all missing
307 # deps from local dir, cdrom, media or from the mirror. In case we want to
308 # install packages from local, we need a packages.list to find the version.
309 # Parameters: package List of deps to install
310 install_deps() {
311 local package=$1
312 shift
313 local deps="$@"
315 gettext "Install all missing dependencies? "
317 # Print Yes/No and get result
318 if $AUTO_INSTALL_DEPS || confirm; then
319 for pkgorg in $deps; do
320 local pkg=$(equivalent_pkg $pkgorg)
321 # Check if package is not installed
322 if [ ! -d "$installed/$pkg" ]; then
323 if [ ! -f "$PKGS_DB/packages.list" ]; then
324 tazpkg recharge
325 fi
326 get-install $pkg
327 fi
328 done
329 else
330 newline
331 boldify $(gettext "Package:") $package
332 gettext \
333 "Dependencies unresolved. Installed but will probably not work."
334 newline && newline
335 fi
336 }
338 #
339 # Commands and exit
340 #
342 case "$1" in
343 ""|*usage|*help) usage ;;
344 esac
346 #
347 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
348 #
350 check_root
352 for pkg in $@
353 do
354 case "$pkg" in
355 *.tazpkg|*.spk)
356 [ "$forced" ] || check_installed $(package_name $package_file)
357 echo "Local package"
358 #install_local $pkg
359 ;;
360 --*) continue ;;
361 *)
362 [ "$forced" ] || check_installed $pkg
363 install_web $pkg ;;
364 esac
365 done
366 exit 0