spk view spk-add @ rev 31

Tiny fixes and update Makefile
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 19:40:29 2012 +0200 (2012-05-15)
parents daf5adaaa87b
children bb5a37f13ad6
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:"))
30 --forced $(gettext "Force package reinstallation")
31 --root= $(gettext "Set the root file system path")
33 $(boldify $(gettext "Examples:"))
34 $name package1 package2 packageN
36 EOT
37 exit 0
38 }
40 # Update system databases
41 update_databases() {
42 if [ -f $ROOT/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
43 chroot "$ROOT/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
44 fi
45 # Mimetypes
46 if [ -f $ROOT/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
47 chroot "$ROOT/" /usr/bin/update-mime-database /usr/share/mime
48 fi
49 # Icons
50 if [ -f $ROOT/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
51 chroot "$ROOT/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
52 fi
53 # Glib schemas
54 if [ -f $ROOT/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
55 chroot "$ROOT/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
56 fi
57 # Kernel modules
58 if [ -f $ROOT/sbin/depmod ] && [ -n "$updatedepmod" ]; then
59 chroot "$ROOT/" /sbin/depmod -a
60 fi
61 }
63 # This function installs a package in the rootfs.
64 # Parameters: package_name package_file
65 install_package() {
66 local package_file=$1
68 # Never used I think!!!
69 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
71 # Create package path early to avoid dependencies loop
72 mkdir -p $TMP_DIR
73 extract_receipt $TMP_DIR $package_file
74 source $TMP_DIR/receipt
76 local package_name=$PACKAGE
77 local package_dir="$installed/$package_name"
78 mkdir -p $package_dir
80 # Run pre_depends from receipt if it exists
81 if grep -q ^pre_depends $TMP_DIR/receipt; then
82 pre_depends $ROOT
83 fi
85 # Create modifiers and files.list if they do not exist
86 # Why ? If missing files.list it's meta packages.
87 #touch $package_dir/modifiers
88 #touch $package_dir/files.list
90 # Add package checksum to pkgsmd5
91 sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
92 oldpwd=$(pwd)
93 cd $(dirname $package_file) || exit 1
94 $CHECKSUM $(basename $package_file) >> $pkgsmd5
95 cd $oldpwd
97 # Resolve package deps.
98 if missing_deps $package_name $DEPENDS; then
99 install_deps $package_name $DEPENDS
100 fi
102 newline
103 boldify $(gettext "Installation of :") $package_name
104 separator
105 eval_gettext "Copying \$package_name... "
106 cp $package_file $TMP_DIR
107 status
109 # Extract Package
110 cd $TMP_DIR || exit 1
111 rm receipt
112 spk-archive extract $package_file
113 cd - >/dev/null
115 # Get files to remove if upgrading
116 local files_to_remove
117 if [ -f $package_dir/files.list ]; then
118 for file in $($package_dir/files.list); do
119 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
120 local modifiers=$(cat $package_dir/modifiers 2> /dev/null;\
121 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
122 for i in modifiers; do
123 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
124 done
125 files_to_remove="$files_to_remove $file"
126 done
127 fi
129 local check=false
130 local file_list
131 # Create list of all possibly modified files
132 for i in $(fgrep -v [ $TMP_DIR/files.list); do
133 [ -e "$ROOT$i" ] || continue
134 [ -d "$ROOT$i" ] && continue
135 file_list="$file_list $i"
136 check=true
137 done
139 # Check possibly modified files against other packages file.list
140 if $check; then
141 for pkg in $INSTALLED/*; do
142 [ "$pkg" == "$package_name" ] && continue
143 [ -s $pkg/files.list ] || continue
145 for file in $file_list; do
146 # $package_name wants to install $file which is already
147 # Installed from $pkg
148 if grep -q ^$file$ $pkg/files.list; then
149 # Tell $pkg that $package_name is going to overwrite some 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 echo "$package_name" >> $pkg/modifiers
156 fi
157 done
158 done
159 fi
161 cd $TMP_DIR || exit 1
162 cp receipt files.list $package_dir
163 # Copy the description if found.
164 [ -f "description.txt" ] && cp description.txt $package_dir
166 # Pre install commands.
167 if grep -q ^pre_install $package_dir/receipt; then
168 pre_install $ROOT
169 fi
171 # Handle Config Files from receipt
172 if [ -n "$CONFIG_FILES" ]; then
173 cd $fs || exit 1
174 # save 'official' configuration files
175 eval_gettext "Saving configuration files for \$package_name... "
177 local confs
178 for i in $CONFIG_FILES; do
179 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
180 done
182 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz
184 # keep user configuration files
185 for conf_file in $confs; do
186 [ -e $conf_file ] || continue
187 cp -a $conf_file fs/$conf_file
188 done
189 status
190 cd - >/dev/null
191 fi
193 # Merge ROOT_FS with Package FS
194 eval_gettext "Installing \$package_name... "
195 cp -a fs/* $ROOT/
196 status
198 # Remove old config files
199 if [ -n $files_to_remove ]; then
200 eval_gettext "Removing old \$package_name... "
201 for file in $files_to_remove; do
202 remove_with_path $ROOT$file
203 done
204 status
205 fi
206 cd - >/dev/null
208 # Remove the temporary directory.
209 gettext "Removing all tmp files... "
210 rm -rf $TMP_DIR
211 status
213 # Post install commands.
214 if grep -q ^post_install $package_dir/receipt; then
215 post_install $ROOT
216 fi
218 # Update-desktop-database if needed.
219 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
220 updatedesktopdb=yes
221 fi
222 # Update-mime-database if needed.
223 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
224 updatemimedb=yes
225 fi
226 # Update-icon-database
227 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
228 updateicondb=yes
229 fi
230 # Compile glib schemas if needed.
231 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
232 compile_schemas=yes
233 fi
234 # Update depmod list
235 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
236 updatedepmod=yes
237 fi
238 separator
239 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
240 newline
241 }
243 # Install .tazpkg packages.
244 # Parameters: package_file
245 install_local() {
246 package_file="$1"
247 check_valid_tazpkg $package_file
249 # Check if forced install.
250 if ! [ "$forced" ]; then
251 check_installed $(package_name $package_file)
252 fi
254 install_package $package_file
255 update_databases
256 }
258 # Download and install a package. TODO: Handle Undigest Mirrors
259 # Parameters: package_name
260 install_web() {
261 local package_name="$1"
263 # Check if get-Package
264 if ! is_package_mirrored $package_name; then
265 package_name="get-$package_name"
266 AUTOEXEC=true
267 fi
269 # Check if package is mirrored
270 if ! is_package_mirrored $package_name; then
271 gettext "Could not find package on mirror:"; echo " $package_name"
272 exit 1
273 fi
275 # package_full=Package-Version
276 local package_full=$(full_package $package_name)
278 # Check if forced install.
279 if ! [ "$forced" ]; then
280 check_installed $package_name
281 fi
283 cd $CACHE_DIR > /dev/null
284 if [ -f "$package_full.tazpkg" ]; then
285 echo -n "$(colorize "$package_full" 34)"; echo ": $CACHE_DIR)"
286 # Check package download was finished
287 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
288 eval_gettext "Continuing \$package_name download"; newline
289 download "$package_full.tazpkg"
290 fi
291 # Check that the package has the correct checksum
292 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
293 # rm -f $package.tazpkg
294 # download "$package_full.tazpkg"
295 #fi
296 else
297 newline
298 download "$package_full.tazpkg"
299 fi
301 install_package "$CACHE_DIR/$package_full.tazpkg"
303 [ -n "$AUTOEXEC" ] && $package_name $ROOT
304 update_databases
305 }
307 # Install all missing deps. Auto install or ask user then install all missing
308 # deps from local dir, cdrom, media or from the mirror. In case we want to
309 # install packages from local, we need a packages.list to find the version.
310 # Parameters: package List of deps to install
311 install_deps() {
312 local package=$1
313 shift
314 local deps="$@"
316 gettext "Install all missing dependencies? "
318 # Print Yes/No and get result
319 if $AUTO_INSTALL_DEPS || confirm; then
320 for pkgorg in $deps; do
321 local pkg=$(equivalent_pkg $pkgorg)
322 # Check if package is not installed
323 if [ ! -d "$installed/$pkg" ]; then
324 if [ ! -f "$PKGS_DB/packages.list" ]; then
325 tazpkg recharge
326 fi
327 get-install $pkg
328 fi
329 done
330 else
331 newline
332 boldify $(gettext "Package:") $package
333 gettext \
334 "Dependencies unresolved. Installed but will probably not work."
335 newline && newline
336 fi
337 }
339 #
340 # Commands and exit
341 #
343 case "$1" in
344 ""|*usage|*help) usage ;;
345 esac
347 #
348 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
349 #
351 check_root
353 for pkg in $@
354 do
355 case "$pkg" in
356 *.tazpkg|*.spk)
357 [ "$forced" ] || check_installed $(package_name $package_file)
358 echo "Local package"
359 #install_local $pkg
360 ;;
361 --*) continue ;;
362 *)
363 [ "$forced" ] || check_installed $pkg
364 install_web $pkg ;;
365 esac
366 done
367 exit 0