spk view spk-add @ rev 34

spk-add: use lower case interanal var, use $root, show install path
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 21:03:40 2012 +0200 (2012-05-15)
parents fca271e55b69
children d703999f686b
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
13 tmpdir="/tmp/$RANDOM"
15 #
16 # Functions
17 #
19 # Help and usage
20 usage() {
21 name=$(basename $0)
22 cat << EOT
24 $(boldify $(gettext "Usage:")) $name [packages|--options]
26 $(gettext "Install SliTaz Packages")
28 $(boldify $(gettext "Options:"))
29 --forced $(gettext "Force package reinstallation")
30 --root= $(gettext "Set the root file system path")
32 $(boldify $(gettext "Examples:"))
33 $name package1 package2 packageN
35 EOT
36 exit 0
37 }
39 # Update system databases
40 update_databases() {
41 if [ -f $root/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then
42 chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
43 fi
44 # Mimetypes
45 if [ -f $root/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then
46 chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
47 fi
48 # Icons
49 if [ -f $root/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then
50 chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
51 fi
52 # Glib schemas
53 if [ -f $root/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then
54 chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
55 fi
56 # Kernel modules
57 if [ -f $root/sbin/depmod ] && [ -n "$updatedepmod" ]; then
58 chroot "$root/" /sbin/depmod -a
59 fi
60 }
62 # This function installs a package in the rootfs.
63 # Parameters: package_name package_file
64 install_package() {
65 local package_file=$1
67 # Never used I think!!!
68 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install()
70 # Create package path early to avoid dependencies loop
71 mkdir -p $tmpdir
72 extract_receipt $tmpdir $package_file
73 source $tmpdir/receipt
75 local package_name=$PACKAGE
76 local package_dir="$installed/$package_name"
77 mkdir -p $package_dir
79 # Run pre_depends from receipt if it exists
80 if grep -q ^pre_depends $tmpdir/receipt; then
81 pre_depends $root
82 fi
84 # Create modifiers and files.list if they do not exist
85 # Why ? If missing files.list it's meta packages.
86 #touch $package_dir/modifiers
87 #touch $package_dir/files.list
89 # Add package checksum to pkgsmd5
90 sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null
91 cd $(dirname $package_file) || exit 1
92 $CHECKSUM $(basename $package_file) >> $pkgsmd5
93 cd - >/dev/null
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 gettext "Copying"; echo -n " $package_name..."
104 cp $package_file $tmpdir
105 status
107 # Extract Package
108 cd $tmpdir || 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 $(cat $package_dir/files.list)
117 do
118 grep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue
119 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \
120 fgrep -sl $package_dir */modifiers | cut -d/ -f1)
121 for i in modifiers; do
122 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2
123 done
124 files_to_remove="$files_to_remove $file"
125 done
126 fi
128 local check=false
129 local file_list
130 # Create list of all possibly modified files
131 for i in $(fgrep -v [ $tmpdir/files.list); do
132 [ -e "${root}${i}" ] || continue
133 [ -d "${root}${i}" ] && continue
134 file_list="$file_list $i"
135 check=true
136 done
138 # Check possibly modified files against other packages file.list
139 if $check; then
140 for pkg in $installed/*
141 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
150 # 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 base_name=$(basename $pkg)
157 if [ "$package_name" != "$base_name" ]; then
158 [ "$debug" ] && \
159 echo "DEBUG: Adding $base_name to: $pkg/modifiers"
160 echo "$package_name" >> $pkg/modifiers
161 fi
162 fi
163 done
164 done
165 fi
167 cd $tmpdir || exit 1
168 cp receipt files.list $package_dir
170 # Copy the description if found.
171 [ -f "description.txt" ] && cp description.txt $package_dir
173 # Pre install commands.
174 if grep -q ^pre_install $package_dir/receipt; then
175 pre_install $root
176 fi
178 # Handle Config Files from receipt
179 if [ -n "$CONFIG_FILES" ]; then
180 cd $fs || exit 1
181 # save 'official' configuration files
182 eval_gettext "Saving configuration files for \$package_name... "
184 local confs
185 for i in $CONFIG_FILES; do
186 confs="$confs $(find ${i#/} -type f 2> /dev/null)"
187 done
189 echo $confs | cpio -o -H newc --quiet | gzip -9 > \
190 $package_dir/volatile.cpio.gz
192 # keep user configuration files
193 for configfile in $confs; do
194 [ -e $configfile ] || continue
195 cp -a $configfile fs/$configfile
196 done
197 status
198 cd - >/dev/null
199 fi
201 # Merge ROOT_FS with Package FS
202 gettext "Installing in:"; echo -n " $root/"
203 cp -a fs/* $root/
204 status
206 # Remove old config files
207 if [ "$files_to_remove" ]; then
208 gettext "Removing old"; echo -n " $package_name..."
209 for file in $files_to_remove; do
210 if [ "$verbose" ]; then
211 gettext "Removing:"; echo " ${root}${file}"
212 fi
213 remove_with_path ${root}${file}
214 done
215 status
216 fi
217 cd - >/dev/null
219 # Remove the temporary directory.
220 gettext "Removing all tmp files... "
221 rm -rf $tmpdir
222 status
224 # Post install commands.
225 if grep -q ^post_install $package_dir/receipt; then
226 post_install $root
227 fi
229 # Update-desktop-database if needed.
230 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
231 updatedesktopdb=yes
232 fi
233 # Update-mime-database if needed.
234 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
235 updatemimedb=yes
236 fi
237 # Update-icon-database
238 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
239 updateicondb=yes
240 fi
241 # Compile glib schemas if needed.
242 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
243 compile_schemas=yes
244 fi
245 # Update depmod list
246 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
247 updatedepmod=yes
248 fi
249 separator
250 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
251 newline
252 }
254 # Install .tazpkg packages.
255 # Parameters: package_file
256 install_local() {
257 package_file="$1"
258 check_valid_tazpkg $package_file
259 install_package $package_file
260 update_databases
261 }
263 # Download and install a package. TODO: Handle Undigest Mirrors
264 # Parameters: package_name
265 install_web() {
266 local package_name="$1"
268 # Check if get-Package
269 if ! is_package_mirrored $package_name; then
270 package_name="get-$package_name"
271 AUTOEXEC=true
272 fi
274 # Check if package is mirrored
275 if ! is_package_mirrored $package_name; then
276 gettext "Could not find package on mirror:"; echo " $package_name"
277 exit 1
278 fi
280 # package_full=Package-Version
281 local package_full=$(full_package $package_name)
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