spk view spk-add @ rev 115
Successfully converted a arch package\!
author | Christian Mesh <meshca@clarkson.edu> |
---|---|
date | Sat Jun 09 16:38:58 2012 -0500 (2012-06-09) |
parents | 0df5690de5fd |
children | d95be6d0e9b7 |
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 --nodeps $(gettext "Don't resolve packages dependencies")
28 --debug $(gettext "Display some useful debug information")
30 $(boldify $(gettext "Examples:"))
31 $name package1 package2 packageN
33 EOT
34 exit 0
35 }
37 # Log install messages
38 # Parameters: package
39 log_install() {
40 local pkg=$1
41 debug "log_install: $logdir/$pkg/install.log"
42 mkdir -p $logdir/$pkg
43 tee $logdir/$pkg/install.log
44 }
46 # Update system databases
47 update_databases() {
48 if [ -f $root/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
49 chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
50 fi
51 # Mimetypes
52 if [ -f $root/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
53 chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
54 fi
55 # Icons
56 if [ -f $root/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
57 chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
58 fi
59 # Glib schemas
60 if [ -f $root/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
61 chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
62 fi
63 # Kernel modules
64 if [ -f $root/sbin/depmod ] && [ -n "$updatedepmod" ]; then
65 chroot "$root/" /sbin/depmod -a
66 fi
67 }
69 # This function installs a package in the rootfs.
70 # Parameters: package_name package_file
71 install_package() {
72 local package_file=$1
74 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
76 local package_name=$PACKAGE
77 local package_dir="$installed/$package_name"
78 mkdir -p $package_dir || exit 1
80 # Run pre_depends from receipt if it exists
81 if grep -q ^pre_depends $tmpdir/receipt; then
82 pre_depends $root
83 fi
85 # Resolve package deps. Disable with: --nodeps
86 if missing_deps $package_name $DEPENDS && [ ! "$nodeps" ]; then
87 if [ "$confirm" ]; then
88 gettext "Install missing dependencies"
89 if ! confirm; then
90 gettext "WARNING: Any dependencies installed"; newline
91 else
92 install_deps $package_name $DEPENDS
93 fi
94 else
95 # Default is to install all missing deps
96 install_deps $package_name $DEPENDS
97 fi
98 else
99 newline
100 fi
102 boldify $(gettext "Adding"; echo " $package_name")
103 separator
104 gettext "Copying package..."
105 cp $package_file $tmpdir && status
106 cd $tmpdir
108 # Add package checksum to $installed.$SUM
109 if [ "$verbose" ]; then
110 gettext "Incrementing:"; echo -n " $(basename $installed.$SUM)"
111 fi
112 sed -i "/ $PACKAGE-$VERSION*/"d $installed.$SUM 2>/dev/null
113 $CHECKSUM $(basename $package_file) >> $installed.$SUM
114 [ "$verbose" ] && status
116 # Remove receipt that will be overwritten by extraction
117 rm $tmpdir/receipt
119 # Extract Package
120 #debug "extract_package $package_file $tmpdir"
121 extract_package $package_file $tmpdir
123 # Handle cross compiled packages
124 case "$SLITAZ_ARCH" in
125 arm|x86_64) arch="-${SLITAZ_ARCH}" ;;
126 esac
127 tmpdir="$tmpdir/$PACKAGE-${VERSION}${arch}"
129 # Get files to remove if upgrading
130 local files_to_remove
131 if [ -f $package_dir/files.list ]; then
132 for file in $(cat $package_dir/files.list)
133 do
134 grep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue
135 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
136 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
137 for i in modifiers; do
138 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
139 done
140 files_to_remove="$files_to_remove $file"
141 done
142 fi
143 debug "file_to_remove: $files_to_remove"
145 # Create list of all possibly modified files
146 local file_list
147 for i in $(fgrep -v [ $tmpdir/files.list); do
148 [ -e "${root}${i}" ] || continue
149 [ -d "${root}${i}" ] && continue
150 file_list="$file_list $i"
151 done
153 debug "file_list is set"
155 # Check possibly modified files against other packages files.list
156 debug "check modified files"
157 for file in $file_list
158 do
159 local filegrep=$(egrep ^${file}$ $installed/*/files.list)
160 if [ "$filegrep" ]; then
161 local list=$(echo $filegrep | cut -d ":" -f 1)
162 local count=0
163 for pkg_file in $list; do
164 local name=$(basename $(dirname $pkg_file))
165 [ "$package_name" == "$name" ] && continue 2
166 count=$(($count +1))
167 [ "$count" == "1" ] && gettext "Modified package:"; \
168 colorize 31 " $name"
169 gettext "Overwriting file:"; echo " $file"
170 # If confirm is set, ask to remove. Do we want that ?
171 # If gawk is installed for example we will never remove Busybox
172 # Use CONFLICTS receipt variable to avoid
173 if [ "$confirm" ]; then
174 echo -n "NOTE: confirm: spk-rm $name ???";
175 if ! confirm; then
176 exit 1
177 fi
178 fi
179 done
180 fi
181 done
183 cd $tmpdir || exit 1
184 cp receipt files.list $package_dir || exit 1
186 # Copy the description if found.
187 [ -f "description.txt" ] && cp description.txt $package_dir
189 # Pre install commands.
190 if grep -q ^pre_install $package_dir/receipt; then
191 pre_install $root
192 fi
194 # Handle Config Files from receipt
195 if [ -n "$CONFIG_FILES" ]; then
196 cd $fs || exit 1
197 # save 'official' configuration files
198 eval_gettext "Saving configuration files for \$package_name... "
200 local confs
201 for i in $CONFIG_FILES; do
202 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
203 done
205 echo $confs | cpio -o -H newc --quiet | gzip -9 > \
206 $package_dir/volatile.cpio.gz
208 # keep user configuration files
209 for configfile in $confs; do
210 [ -e $configfile ] || continue
211 cp -a $configfile fs/$configfile
212 done
213 status
214 cd - >/dev/null
215 fi
216 # Merge package FS with $root
217 nb=$(cat files.list | wc -l)
218 gettext "Installing files:"; echo -n " $nb"
219 cp -a fs/* $root/
220 status
222 # Remove old config files
223 if [ "$files_to_remove" ]; then
224 gettext "Removing old files..."
225 for file in $files_to_remove; do
226 if [ "$verbose" ]; then
227 gettext "Removing:"; echo " ${root}${file}"
228 fi
229 remove_with_path ${root}${file}
230 done
231 status
232 fi
233 cd - >/dev/null
235 # Remove the temporary directory.
236 if [ "$verbose" ]; then
237 gettext "Removing all tmp files... "
238 rm -rf $tmpdir && status
239 else
240 rm -rf $tmpdir
241 fi
243 # Post install commands.
244 if grep -q ^post_install $package_dir/receipt; then
245 post_install $root
246 fi
248 # Update-desktop-database if needed.
249 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
250 updatedesktopdb=yes
251 fi
252 # Update-mime-database if needed.
253 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
254 updatemimedb=yes
255 fi
256 # Update-icon-database
257 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
258 updateicondb=yes
259 fi
260 # Compile glib schemas if needed.
261 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
262 compile_schemas=yes
263 fi
264 # Update depmod list
265 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
266 updatedepmod=yes
267 fi
268 separator
269 echo -n "$package_name ${VERSION}${EXTRAVERSION} "
270 gettext "is installed"; newline
271 newline
272 }
274 # Install .tazpkg packages.
275 # Parameters: package_file
276 install_local() {
277 local package_file="$1"
278 #check_valid_tazpkg $package_file
279 if [ -f "$package_file" ]; then
280 if [ $(dirname $package_file) == "." ]; then
281 package_file=$(pwd)/$package_file
282 fi
283 debug "package file: $package_file"
284 else
285 gettext "Unable to find:"; echo " $package_file"
286 exit 1
287 fi
289 # Get package name now to check if installed
290 mkdir -p $tmpdir
291 extract_receipt $tmpdir $package_file
292 source $tmpdir/receipt
293 [ "$forced" ] || check_installed $PACKAGE
294 [ "$count" == "1" ] && newline
295 install_package $package_file
296 update_databases
297 }
299 # Download and install a package. TODO: Handle Undigest Mirrors
300 # Parameters: package_name
301 install_web() {
302 local package_name="$1"
304 # Check if get-Package
305 #if mirrored_pkg get-$package_name; then
306 #package_name="get-$package_name"
307 #exec=true
308 #fi
310 # Check if package is mirrored
311 mirrored_pkg $package_name
312 if [ ! "$mirrored" ]; then
313 gettext "Could not find package on mirror:"
314 boldify " $package_name" && exit 1
315 fi
317 # We want: package-version.tazpkg
318 local package_full=$(full_package ${package_name})
320 # Add architecture string to package full name
321 case "$SLITAZ_ARCH" in
322 arm|x86_64)
323 pkgarch="-${SLITAZ_ARCH}.tazpkg"
324 package_full=$(echo $package_full | sed s/.tazpkg/$pkgarch/) ;;
325 esac
327 # Lets fetch the package by download()
328 [ "$count" == 1 ] && newline
329 debug "spk-add package: $package_name"
330 download "$package_full" $mirror
331 cd $CACHE_DIR
333 # Create package path early to avoid dependencies loop
334 mkdir -p $tmpdir
335 extract_receipt $tmpdir "$CACHE_DIR/$package_full"
336 source $tmpdir/receipt
338 install_package "$CACHE_DIR/$package_full"
340 #[ "$exec" ] && chroot $root/ $package_name
341 [ "$exec" ] && $package_name $root
342 update_databases
343 unset_mirrored
344 }
346 # Install all missing deps of a package.
347 # Usage: install_deps package DEPENDS
348 install_deps() {
349 local package=$1
350 shift
351 local deps="$@"
352 for pkgorg in $deps; do
353 local pkg=$(equivalent_pkg $pkgorg)
354 # Check if package is not installed
355 if [ ! -d "$installed/$pkg" ]; then
356 if [ ! -f "$pkgsdesc" ]; then
357 spk-up --list
358 fi
359 spk-add $pkg
360 fi
361 done
362 }
364 #
365 # Commands and exit
366 #
368 case "$1" in
369 ""|*usage|*help) usage ;;
370 esac
372 #
373 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
374 #
376 : ${count=0}
377 check_root
379 for pkg in $@
380 do
381 case "$pkg" in
382 *.tazpkg|*.spk)
383 count=$(($count + 1))
384 install_local $pkg | log_install $pkg;;
385 *.deb|.rpm)
386 echo "TODO: spk-convert then install" ;;
387 *.*) gettext "WARNING: Not a valid package:"; echo " $pkg" ;;
388 --*) continue ;;
389 *)
390 [ "$forced" ] || check_installed $pkg
391 count=$(($count + 1))
392 install_web $pkg | log_install $pkg;;
393 esac
394 done
396 # Show all new counted packages in verbose mode
397 if [ "$verbose" ]; then
398 gettext "Handled packages:"; colorize 34 " $count"
399 fi
401 exit 0