spk view spk-add @ rev 29

spk-add: one function to update all dbs
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 19:02:53 2012 +0200 (2012-05-15)
parents 19f1b93fd7d8
children daf5adaaa87b
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 # Set to / for now until we add installing to chroot support
12 # Could we update tools so they do not need this?
13 ROOT=""
14 TMP_DIR="/tmp/$RANDOM"
16 #
17 # Functions
18 #
20 # Help and usage
21 usage() {
22 name=$(basename $0)
23 cat << EOT
25 $(boldify $(gettext "Usage:")) $name [packages|--options]
27 $(gettext "Install SliTaz Packages")
29 $(boldify $(gettext "Options:"))
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 $TMP_DIR
71 extract_receipt $TMP_DIR $package_file
72 source $TMP_DIR/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 $TMP_DIR/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 pkgsmd5
89 sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
90 oldpwd=$(pwd)
91 cd $(dirname $package_file) || exit 1
92 $CHECKSUM $(basename $package_file) >> $pkgsmd5
93 cd $oldpwd
95 # Resolve package deps.
96 if missing_deps $package_name $DEPENDS; then
97 install_deps $package_name $DEPENDS
98 fi
100 newline
101 boldify $(gettext "Installation of :") $package_name
102 separator
103 eval_gettext "Copying \$package_name... "
104 cp $package_file $TMP_DIR
105 status
107 # Extract Package
108 cd $TMP_DIR || 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 $($package_dir/files.list); do
117 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/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 [ $TMP_DIR/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/*; do
140 [ "$pkg" == "$package_name" ] && continue
141 [ -s $pkg/files.list ] || continue
143 for file in $file_list; do
144 # $package_name wants to install $file which is already
145 # Installed from $pkg
146 if grep -q ^$file$ $pkg/files.list; then
147 # Tell $pkg that $package_name is going to overwrite some of its files
148 if [ -s "$pkg/volatile.cpio.gz" ]; then
149 # We can modify backed up files without notice
150 zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \
151 grep -q "^${file#/}$" && continue
152 fi
153 echo "$package_name" >> $pkg/modifiers
154 fi
155 done
156 done
157 fi
159 cd $TMP_DIR || exit 1
160 cp receipt files.list $package_dir
161 # Copy the description if found.
162 [ -f "description.txt" ] && cp description.txt $package_dir
164 # Pre install commands.
165 if grep -q ^pre_install $package_dir/receipt; then
166 pre_install $ROOT
167 fi
169 # Handle Config Files from receipt
170 if [ -n "$CONFIG_FILES" ]; then
171 cd $fs || exit 1
172 # save 'official' configuration files
173 eval_gettext "Saving configuration files for \$package_name... "
175 local confs
176 for i in $CONFIG_FILES; do
177 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
178 done
180 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz
182 # keep user configuration files
183 for conf_file in $confs; do
184 [ -e $conf_file ] || continue
185 cp -a $conf_file fs/$conf_file
186 done
187 status
188 cd - >/dev/null
189 fi
191 # Merge ROOT_FS with Package FS
192 eval_gettext "Installing \$package_name... "
193 cp -a fs/* $ROOT/
194 status
196 # Remove old config files
197 if [ -n $files_to_remove ]; then
198 eval_gettext "Removing old \$package_name... "
199 for file in $files_to_remove; do
200 remove_with_path $ROOT$file
201 done
202 status
203 fi
204 cd - >/dev/null
206 # Remove the temporary directory.
207 gettext "Removing all tmp files... "
208 rm -rf $TMP_DIR
209 status
211 # Post install commands.
212 if grep -q ^post_install $package_dir/receipt; then
213 post_install $ROOT
214 fi
216 # Update-desktop-database if needed.
217 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
218 updatedesktopdb=yes
219 fi
220 # Update-mime-database if needed.
221 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
222 updatemimedb=yes
223 fi
224 # Update-icon-database
225 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
226 updateicondb=yes
227 fi
228 # Compile glib schemas if needed.
229 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
230 compile_schemas=yes
231 fi
232 # Update depmod list
233 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
234 updatedepmod=yes
235 fi
236 separator
237 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
238 newline
239 }
241 # Install .tazpkg packages.
242 # Parameters: package_file
243 install_local() {
244 package_file="$1"
245 check_root
246 check_valid_tazpkg $package_file
248 # Check if forced install.
249 if ! [ "$forced" ]; then
250 check_installed $(package_name $package_file)
251 fi
253 install_package $package_file
254 update_databases
255 }
257 # Download and install a package. TODO: Handle Undigest Mirrors
258 # Parameters: package_name
259 install_web() {
260 local package_name="$1"
262 check_root
264 # Check if get-Package
265 if ! is_package_mirrored $package_name; then
266 package_name="get-$package_name"
267 AUTOEXEC=true
268 fi
270 # Check if package is mirrored
271 if ! is_package_mirrored $package_name; then
272 gettext "Could not find package on mirror:"; echo " $package_name"
273 exit 1
274 fi
276 # package_full=Package-Version
277 local package_full=$(full_package $package_name)
279 # Check if forced install.
280 if ! [ "$forced" ]; then
281 check_installed $package_name
282 fi
284 cd $CACHE_DIR > /dev/null
285 if [ -f "$package_full.tazpkg" ]; then
286 eval_gettext "\$package_full is already in the cache : \$CACHE_DIR"; newline
287 # Check package download was finished
288 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
289 eval_gettext "Continuing \$package_name download"; newline
290 download "$package_full.tazpkg"
291 fi
293 # Check that the package has the correct checksum
294 # if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
295 # rm -f $package.tazpkg
296 # download "$package_full.tazpkg"
297 # fi
298 else
299 newline
300 download "$package_full.tazpkg"
301 fi
303 install_package "$CACHE_DIR/$package_full.tazpkg"
305 [ -n "$AUTOEXEC" ] && $package_name $ROOT
306 update_databases
307 }
309 # Install all missing deps. Auto install or ask user then install all missing
310 # deps from local dir, cdrom, media or from the mirror. In case we want to
311 # install packages from local, we need a packages.list to find the version.
312 # Parameters: package List of deps to install
313 install_deps() {
314 local package=$1
315 shift
316 local deps="$@"
318 gettext "Install all missing dependencies? "
320 # Print Yes/No and get result
321 if $AUTO_INSTALL_DEPS || confirm; then
322 for pkgorg in $deps; do
323 local pkg=$(equivalent_pkg $pkgorg)
324 # Check if package is not installed
325 if [ ! -d "$installed/$pkg" ]; then
326 if [ ! -f "$PKGS_DB/packages.list" ]; then
327 tazpkg recharge
328 fi
329 get-install $pkg
330 fi
331 done
332 else
333 newline
334 boldify $(gettext "Package:") $package
335 gettext \
336 "Dependencies unresolved. Installed but will probably not work."
337 newline && newline
338 fi
339 }
341 # Old style
342 case $1 in
343 install|-i)
344 install_local $2 $3
345 exit 0 ;;
346 get-install|-gi)
347 install_web $2
348 exit 0 ;;
349 "") usage ;;
350 esac
352 #
353 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
354 #
356 check_root
358 for pkg in $@
359 do
360 case "$pkg" in
361 *.tazpkg|.spk)
362 echo "Local package" ;;
363 esac
364 echo "Adding: $pkg"
365 done
366 exit 0