spk view spk-add @ rev 32

A bunch of fix to add an lib
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 20:32:41 2012 +0200 (2012-05-15)
parents ea3c01346d05
children fca271e55b69
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 # Set to / for now until we add installing to chroot support
13 # Could we update tools so they do not need this?
14 ROOT=""
15 TMP_DIR="/tmp/$RANDOM"
17 #
18 # Functions
19 #
21 # Help and usage
22 usage() {
23 name=$(basename $0)
24 cat << EOT
26 $(boldify $(gettext "Usage:")) $name [packages|--options]
28 $(gettext "Install SliTaz Packages")
30 $(boldify $(gettext "Options:"))
31 --forced $(gettext "Force package reinstallation")
32 --root= $(gettext "Set the root file system path")
34 $(boldify $(gettext "Examples:"))
35 $name package1 package2 packageN
37 EOT
38 exit 0
39 }
41 # Update system databases
42 update_databases() {
43 if [ -f $ROOT/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
44 chroot "$ROOT/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
45 fi
46 # Mimetypes
47 if [ -f $ROOT/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
48 chroot "$ROOT/" /usr/bin/update-mime-database /usr/share/mime
49 fi
50 # Icons
51 if [ -f $ROOT/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
52 chroot "$ROOT/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
53 fi
54 # Glib schemas
55 if [ -f $ROOT/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
56 chroot "$ROOT/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
57 fi
58 # Kernel modules
59 if [ -f $ROOT/sbin/depmod ] && [ -n "$updatedepmod" ]; then
60 chroot "$ROOT/" /sbin/depmod -a
61 fi
62 }
64 # This function installs a package in the rootfs.
65 # Parameters: package_name package_file
66 install_package() {
67 local package_file=$1
69 # Never used I think!!!
70 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
72 # Create package path early to avoid dependencies loop
73 mkdir -p $TMP_DIR
74 extract_receipt $TMP_DIR $package_file
75 source $TMP_DIR/receipt
77 local package_name=$PACKAGE
78 local package_dir="$installed/$package_name"
79 mkdir -p $package_dir
81 # Run pre_depends from receipt if it exists
82 if grep -q ^pre_depends $TMP_DIR/receipt; then
83 pre_depends $ROOT
84 fi
86 # Create modifiers and files.list if they do not exist
87 # Why ? If missing files.list it's meta packages.
88 #touch $package_dir/modifiers
89 #touch $package_dir/files.list
91 # Add package checksum to pkgsmd5
92 sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
93 cd $(dirname $package_file) || exit 1
94 $CHECKSUM $(basename $package_file) >> $pkgsmd5
95 cd - >/dev/null
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 $(cat $package_dir/files.list)
119 do
120 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue
121 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
122 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
123 for i in modifiers; do
124 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
125 done
126 files_to_remove="$files_to_remove $file"
127 done
128 fi
130 local check=false
131 local file_list
132 # Create list of all possibly modified files
133 for i in $(fgrep -v [ $TMP_DIR/files.list); do
134 [ -e "$ROOT$i" ] || continue
135 [ -d "$ROOT$i" ] && continue
136 file_list="$file_list $i"
137 check=true
138 done
140 # Check possibly modified files against other packages file.list
141 if $check; then
142 for pkg in $installed/*; do
143 [ "$pkg" == "$package_name" ] && continue
144 [ -s $pkg/files.list ] || continue
146 for file in $file_list; do
147 # $package_name wants to install $file which is already
148 # installed from $pkg
149 if grep -q ^$file$ $pkg/files.list; then
150 # Tell $pkg that $package_name is going to overwrite some of its files
151 if [ -s "$pkg/volatile.cpio.gz" ]; then
152 # We can modify backed up files without notice
153 zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \
154 grep -q "^${file#/}$" && continue
155 fi
156 echo "$package_name" >> $pkg/modifiers
157 fi
158 done
159 done
160 fi
162 cd $TMP_DIR || exit 1
163 cp receipt files.list $package_dir
164 # Copy the description if found.
165 [ -f "description.txt" ] && cp description.txt $package_dir
167 # Pre install commands.
168 if grep -q ^pre_install $package_dir/receipt; then
169 pre_install $ROOT
170 fi
172 # Handle Config Files from receipt
173 if [ -n "$CONFIG_FILES" ]; then
174 cd $fs || exit 1
175 # save 'official' configuration files
176 eval_gettext "Saving configuration files for \$package_name... "
178 local confs
179 for i in $CONFIG_FILES; do
180 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
181 done
183 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz
185 # keep user configuration files
186 for conf_file in $confs; do
187 [ -e $conf_file ] || continue
188 cp -a $conf_file fs/$conf_file
189 done
190 status
191 cd - >/dev/null
192 fi
194 # Merge ROOT_FS with Package FS
195 gettext "Installing"; echo -n " $package_name..."
196 cp -a fs/* $ROOT/
197 status
199 # Remove old config files
200 if [ "$files_to_remove" ]; then
201 gettext "Removing old"; echo -n " $package_name..."
202 for file in $files_to_remove; do
203 if [ "$verbose" ]; then
204 gettext "Removing:"; echo " ${root}${file}"
205 fi
206 remove_with_path ${root}${file}
207 done
208 status
209 fi
210 cd - >/dev/null
212 # Remove the temporary directory.
213 gettext "Removing all tmp files... "
214 rm -rf $TMP_DIR
215 status
217 # Post install commands.
218 if grep -q ^post_install $package_dir/receipt; then
219 post_install $ROOT
220 fi
222 # Update-desktop-database if needed.
223 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
224 updatedesktopdb=yes
225 fi
226 # Update-mime-database if needed.
227 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
228 updatemimedb=yes
229 fi
230 # Update-icon-database
231 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
232 updateicondb=yes
233 fi
234 # Compile glib schemas if needed.
235 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
236 compile_schemas=yes
237 fi
238 # Update depmod list
239 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
240 updatedepmod=yes
241 fi
242 separator
243 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
244 newline
245 }
247 # Install .tazpkg packages.
248 # Parameters: package_file
249 install_local() {
250 package_file="$1"
251 check_valid_tazpkg $package_file
252 install_package $package_file
253 update_databases
254 }
256 # Download and install a package. TODO: Handle Undigest Mirrors
257 # Parameters: package_name
258 install_web() {
259 local package_name="$1"
261 # Check if get-Package
262 if ! is_package_mirrored $package_name; then
263 package_name="get-$package_name"
264 AUTOEXEC=true
265 fi
267 # Check if package is mirrored
268 if ! is_package_mirrored $package_name; then
269 gettext "Could not find package on mirror:"; echo " $package_name"
270 exit 1
271 fi
273 # package_full=Package-Version
274 local package_full=$(full_package $package_name)
276 cd $CACHE_DIR > /dev/null
277 if [ -f "$package_full.tazpkg" ]; then
278 echo -n "$(colorize "$package_full" 34)"; echo ": $CACHE_DIR)"
279 # Check package download was finished
280 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
281 eval_gettext "Continuing \$package_name download"; newline
282 download "$package_full.tazpkg"
283 fi
284 # Check that the package has the correct checksum
285 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
286 # rm -f $package.tazpkg
287 # download "$package_full.tazpkg"
288 #fi
289 else
290 newline
291 download "$package_full.tazpkg"
292 fi
294 install_package "$CACHE_DIR/$package_full.tazpkg"
296 [ -n "$AUTOEXEC" ] && $package_name $ROOT
297 update_databases
298 }
300 # Install all missing deps. Auto install or ask user then install all missing
301 # deps from local dir, cdrom, media or from the mirror. In case we want to
302 # install packages from local, we need a packages.list to find the version.
303 # Parameters: package List of deps to install
304 install_deps() {
305 local package=$1
306 shift
307 local deps="$@"
309 gettext "Install all missing dependencies? "
311 # Print Yes/No and get result
312 if $AUTO_INSTALL_DEPS || confirm; then
313 for pkgorg in $deps; do
314 local pkg=$(equivalent_pkg $pkgorg)
315 # Check if package is not installed
316 if [ ! -d "$installed/$pkg" ]; then
317 if [ ! -f "$PKGS_DB/packages.list" ]; then
318 tazpkg recharge
319 fi
320 get-install $pkg
321 fi
322 done
323 else
324 newline
325 boldify $(gettext "Package:") $package
326 gettext \
327 "Dependencies unresolved. Installed but will probably not work."
328 newline && newline
329 fi
330 }
332 #
333 # Commands and exit
334 #
336 case "$1" in
337 ""|*usage|*help) usage ;;
338 esac
340 #
341 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
342 #
344 check_root
346 for pkg in $@
347 do
348 case "$pkg" in
349 *.tazpkg|*.spk)
350 [ "$forced" ] || check_installed $(package_name $package_file)
351 echo "Local package"
352 #install_local $pkg
353 ;;
354 --*) continue ;;
355 *)
356 [ "$forced" ] || check_installed $pkg
357 install_web $pkg ;;
358 esac
359 done
360 exit 0