spk view spk-add @ rev 33

spk-add modifiers: dont add package to itsef
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 20:44:37 2012 +0200 (2012-05-15)
parents bb5a37f13ad6
children 48522fb4d101
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 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 $TMP_DIR || 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 > $package_dir/volatile.cpio.gz
191 # keep user configuration files
192 for conf_file in $confs; do
193 [ -e $conf_file ] || continue
194 cp -a $conf_file fs/$conf_file
195 done
196 status
197 cd - >/dev/null
198 fi
200 # Merge ROOT_FS with Package FS
201 gettext "Installing"; echo -n " $package_name..."
202 cp -a fs/* $ROOT/
203 status
205 # Remove old config files
206 if [ "$files_to_remove" ]; then
207 gettext "Removing old"; echo -n " $package_name..."
208 for file in $files_to_remove; do
209 if [ "$verbose" ]; then
210 gettext "Removing:"; echo " ${root}${file}"
211 fi
212 remove_with_path ${root}${file}
213 done
214 status
215 fi
216 cd - >/dev/null
218 # Remove the temporary directory.
219 gettext "Removing all tmp files... "
220 rm -rf $TMP_DIR
221 status
223 # Post install commands.
224 if grep -q ^post_install $package_dir/receipt; then
225 post_install $ROOT
226 fi
228 # Update-desktop-database if needed.
229 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then
230 updatedesktopdb=yes
231 fi
232 # Update-mime-database if needed.
233 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then
234 updatemimedb=yes
235 fi
236 # Update-icon-database
237 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then
238 updateicondb=yes
239 fi
240 # Compile glib schemas if needed.
241 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then
242 compile_schemas=yes
243 fi
244 # Update depmod list
245 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then
246 updatedepmod=yes
247 fi
248 separator
249 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline
250 newline
251 }
253 # Install .tazpkg packages.
254 # Parameters: package_file
255 install_local() {
256 package_file="$1"
257 check_valid_tazpkg $package_file
258 install_package $package_file
259 update_databases
260 }
262 # Download and install a package. TODO: Handle Undigest Mirrors
263 # Parameters: package_name
264 install_web() {
265 local package_name="$1"
267 # Check if get-Package
268 if ! is_package_mirrored $package_name; then
269 package_name="get-$package_name"
270 AUTOEXEC=true
271 fi
273 # Check if package is mirrored
274 if ! is_package_mirrored $package_name; then
275 gettext "Could not find package on mirror:"; echo " $package_name"
276 exit 1
277 fi
279 # package_full=Package-Version
280 local package_full=$(full_package $package_name)
282 cd $CACHE_DIR > /dev/null
283 if [ -f "$package_full.tazpkg" ]; then
284 echo -n "$(colorize "$package_full" 34)"; echo ": $CACHE_DIR)"
285 # Check package download was finished
286 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then
287 eval_gettext "Continuing \$package_name download"; newline
288 download "$package_full.tazpkg"
289 fi
290 # Check that the package has the correct checksum
291 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then
292 # rm -f $package.tazpkg
293 # download "$package_full.tazpkg"
294 #fi
295 else
296 newline
297 download "$package_full.tazpkg"
298 fi
300 install_package "$CACHE_DIR/$package_full.tazpkg"
302 [ -n "$AUTOEXEC" ] && $package_name $ROOT
303 update_databases
304 }
306 # Install all missing deps. Auto install or ask user then install all missing
307 # deps from local dir, cdrom, media or from the mirror. In case we want to
308 # install packages from local, we need a packages.list to find the version.
309 # Parameters: package List of deps to install
310 install_deps() {
311 local package=$1
312 shift
313 local deps="$@"
315 gettext "Install all missing dependencies? "
317 # Print Yes/No and get result
318 if $AUTO_INSTALL_DEPS || confirm; then
319 for pkgorg in $deps; do
320 local pkg=$(equivalent_pkg $pkgorg)
321 # Check if package is not installed
322 if [ ! -d "$installed/$pkg" ]; then
323 if [ ! -f "$PKGS_DB/packages.list" ]; then
324 tazpkg recharge
325 fi
326 get-install $pkg
327 fi
328 done
329 else
330 newline
331 boldify $(gettext "Package:") $package
332 gettext \
333 "Dependencies unresolved. Installed but will probably not work."
334 newline && newline
335 fi
336 }
338 #
339 # Commands and exit
340 #
342 case "$1" in
343 ""|*usage|*help) usage ;;
344 esac
346 #
347 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg
348 #
350 check_root
352 for pkg in $@
353 do
354 case "$pkg" in
355 *.tazpkg|*.spk)
356 [ "$forced" ] || check_installed $(package_name $package_file)
357 echo "Local package"
358 #install_local $pkg
359 ;;
360 --*) continue ;;
361 *)
362 [ "$forced" ] || check_installed $pkg
363 install_web $pkg ;;
364 esac
365 done
366 exit 0