spk annotate spk-add @ rev 40
Better modifiers and rdeps handler in spk-rm and fixes
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed May 16 02:32:22 2012 +0200 (2012-05-16) |
parents | 8ed83db5a0be |
children | ddb3c10c0a4b |
rev | line source |
---|---|
pankso@27 | 1 #!/bin/sh |
meshca@11 | 2 # |
pankso@23 | 3 # Spk-add - Install SliTaz packages. Read the README before adding or |
pankso@23 | 4 # modifing any code in spk! |
pankso@23 | 5 # |
pankso@23 | 6 # Copyright (C) SliTaz GNU/Linux - BSD License |
pankso@23 | 7 # Author: See AUTHORS files |
pankso@23 | 8 # |
pankso@32 | 9 #. /usr/lib/slitaz/libspk.sh |
pankso@32 | 10 . lib/libspk.sh |
meshca@11 | 11 |
pankso@34 | 12 tmpdir="/tmp/$RANDOM" |
meshca@11 | 13 |
pankso@23 | 14 # |
pankso@23 | 15 # Functions |
pankso@23 | 16 # |
pankso@23 | 17 |
pankso@23 | 18 # Help and usage |
pankso@23 | 19 usage() { |
pankso@23 | 20 name=$(basename $0) |
pankso@23 | 21 cat << EOT |
pankso@23 | 22 |
pankso@23 | 23 $(boldify $(gettext "Usage:")) $name [packages|--options] |
pankso@23 | 24 |
pankso@23 | 25 $(gettext "Install SliTaz Packages") |
pankso@23 | 26 |
pankso@23 | 27 $(boldify $(gettext "Options:")) |
pankso@30 | 28 --forced $(gettext "Force package reinstallation") |
pankso@30 | 29 --root= $(gettext "Set the root file system path") |
pankso@40 | 30 --debug $(gettext "Display some usefull debug information") |
pankso@23 | 31 |
pankso@23 | 32 $(boldify $(gettext "Examples:")) |
pankso@23 | 33 $name package1 package2 packageN |
pankso@23 | 34 |
pankso@23 | 35 EOT |
pankso@23 | 36 exit 0 |
pankso@23 | 37 } |
meshca@11 | 38 |
pankso@29 | 39 # Update system databases |
pankso@29 | 40 update_databases() { |
pankso@34 | 41 if [ -f $root/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then |
pankso@34 | 42 chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null |
pankso@29 | 43 fi |
pankso@29 | 44 # Mimetypes |
pankso@34 | 45 if [ -f $root/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then |
pankso@34 | 46 chroot "$root/" /usr/bin/update-mime-database /usr/share/mime |
pankso@29 | 47 fi |
pankso@29 | 48 # Icons |
pankso@34 | 49 if [ -f $root/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then |
pankso@34 | 50 chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor |
pankso@29 | 51 fi |
pankso@29 | 52 # Glib schemas |
pankso@34 | 53 if [ -f $root/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then |
pankso@34 | 54 chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas |
pankso@29 | 55 fi |
pankso@29 | 56 # Kernel modules |
pankso@34 | 57 if [ -f $root/sbin/depmod ] && [ -n "$updatedepmod" ]; then |
pankso@34 | 58 chroot "$root/" /sbin/depmod -a |
pankso@29 | 59 fi |
pankso@29 | 60 } |
pankso@29 | 61 |
meshca@11 | 62 # This function installs a package in the rootfs. |
meshca@11 | 63 # Parameters: package_name package_file |
pankso@23 | 64 install_package() { |
meshca@11 | 65 local package_file=$1 |
pankso@23 | 66 |
pankso@27 | 67 # Never used I think!!! |
meshca@11 | 68 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install() |
pankso@23 | 69 |
meshca@11 | 70 # Create package path early to avoid dependencies loop |
pankso@34 | 71 mkdir -p $tmpdir |
pankso@34 | 72 extract_receipt $tmpdir $package_file |
pankso@34 | 73 source $tmpdir/receipt |
pankso@23 | 74 |
meshca@11 | 75 local package_name=$PACKAGE |
meshca@11 | 76 local package_dir="$installed/$package_name" |
meshca@11 | 77 mkdir -p $package_dir |
meshca@11 | 78 |
meshca@11 | 79 # Run pre_depends from receipt if it exists |
pankso@34 | 80 if grep -q ^pre_depends $tmpdir/receipt; then |
pankso@34 | 81 pre_depends $root |
meshca@11 | 82 fi |
meshca@11 | 83 |
meshca@11 | 84 # Create modifiers and files.list if they do not exist |
pankso@27 | 85 # Why ? If missing files.list it's meta packages. |
pankso@27 | 86 #touch $package_dir/modifiers |
pankso@27 | 87 #touch $package_dir/files.list |
meshca@11 | 88 |
pankso@35 | 89 # Add package checksum to $installed.$SUM |
pankso@35 | 90 sed -i "/ $(basename $package_dir)$/d" $installed.$SUM 2> /dev/null |
pankso@26 | 91 cd $(dirname $package_file) || exit 1 |
pankso@35 | 92 $CHECKSUM $(basename $package_file) >> $installed.$SUM |
pankso@32 | 93 cd - >/dev/null |
pankso@23 | 94 |
meshca@11 | 95 # Resolve package deps. |
meshca@11 | 96 if missing_deps $package_name $DEPENDS; then |
meshca@11 | 97 install_deps $package_name $DEPENDS |
meshca@11 | 98 fi |
pankso@23 | 99 |
pankso@23 | 100 newline |
pankso@34 | 101 boldify $(gettext "Installation of:") $package_name |
meshca@11 | 102 separator |
pankso@34 | 103 gettext "Copying"; echo -n " $package_name..." |
pankso@34 | 104 cp $package_file $tmpdir |
meshca@11 | 105 status |
pankso@23 | 106 |
meshca@11 | 107 # Extract Package |
pankso@34 | 108 cd $tmpdir || exit 1 |
pankso@26 | 109 rm receipt |
pankso@26 | 110 spk-archive extract $package_file |
pankso@26 | 111 cd - >/dev/null |
pankso@23 | 112 |
meshca@11 | 113 # Get files to remove if upgrading |
meshca@11 | 114 local files_to_remove |
meshca@11 | 115 if [ -f $package_dir/files.list ]; then |
pankso@32 | 116 for file in $(cat $package_dir/files.list) |
pankso@32 | 117 do |
pankso@37 | 118 egrep -q "^$(echo $file | grepesc)$" $tmpdir/files.list && continue |
pankso@32 | 119 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \ |
pankso@37 | 120 fgrep -sl $package_dir */modifiers | cut -d/ -f1) |
meshca@11 | 121 for i in modifiers; do |
pankso@37 | 122 egrep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2 |
meshca@11 | 123 done |
meshca@11 | 124 files_to_remove="$files_to_remove $file" |
meshca@11 | 125 done |
meshca@11 | 126 fi |
pankso@37 | 127 [ "$debug" ] && echo "DEBUG: file_to_remove: $files_to_remove" |
pankso@23 | 128 |
pankso@38 | 129 # Create list of all possibly modified files |
meshca@11 | 130 local file_list |
pankso@34 | 131 for i in $(fgrep -v [ $tmpdir/files.list); do |
pankso@34 | 132 [ -e "${root}${i}" ] || continue |
pankso@34 | 133 [ -d "${root}${i}" ] && continue |
meshca@11 | 134 file_list="$file_list $i" |
meshca@11 | 135 done |
pankso@37 | 136 [ "$debug" ] && echo "DEBUG: file_list is set" |
pankso@23 | 137 |
pankso@37 | 138 # Check possibly modified files against other packages files.list |
pankso@38 | 139 [ "$debug" ] && echo "DEBUG: check modified files" |
pankso@38 | 140 for file in $file_list |
pankso@38 | 141 do |
pankso@38 | 142 filegrep=$(egrep ^${file}$ $installed/*/files.list) |
pankso@38 | 143 if [ "$filegrep" ]; then |
pankso@38 | 144 local list=$(echo $filegrep | cut -d ":" -f 1) |
pankso@38 | 145 local name=$(basename $(dirname $list)) |
pankso@38 | 146 [ "$pkg" == "$name" ] && continue |
pankso@38 | 147 echo -n "Modified package: $name" |
pankso@38 | 148 # Tell $name that $pkg is going to overwrite some of its files |
pankso@38 | 149 if [ -s "$installed/$name/volatile.cpio.gz" ]; then |
pankso@38 | 150 # We can modify backed up files without notice |
pankso@38 | 151 zcat $installed/$name/volatile.cpio.gz | cpio -t --quiet | \ |
pankso@38 | 152 grep -q "^${file#/}$" && continue |
pankso@38 | 153 fi |
pankso@38 | 154 # Add $pkg to the modifiers list og $name |
pankso@38 | 155 if ! egrep -q ^${package_name}$ $installed/$name/modifiers; then |
pankso@38 | 156 [ "$debug" ] && \ |
pankso@38 | 157 echo -en "\nDEBUG: Added $pkg to: $name/modifiers" |
pankso@38 | 158 echo "$package_name" >> $installed/$name/modifiers |
pankso@38 | 159 fi |
pankso@38 | 160 status |
pankso@38 | 161 fi |
pankso@38 | 162 done |
pankso@23 | 163 |
pankso@23 | 164 |
pankso@34 | 165 cd $tmpdir || exit 1 |
pankso@26 | 166 cp receipt files.list $package_dir |
pankso@33 | 167 |
pankso@26 | 168 # Copy the description if found. |
pankso@26 | 169 [ -f "description.txt" ] && cp description.txt $package_dir |
pankso@23 | 170 |
pankso@26 | 171 # Pre install commands. |
pankso@26 | 172 if grep -q ^pre_install $package_dir/receipt; then |
pankso@34 | 173 pre_install $root |
pankso@26 | 174 fi |
pankso@23 | 175 |
pankso@26 | 176 # Handle Config Files from receipt |
pankso@26 | 177 if [ -n "$CONFIG_FILES" ]; then |
pankso@26 | 178 cd $fs || exit 1 |
pankso@26 | 179 # save 'official' configuration files |
pankso@26 | 180 eval_gettext "Saving configuration files for \$package_name... " |
pankso@23 | 181 |
pankso@26 | 182 local confs |
pankso@26 | 183 for i in $CONFIG_FILES; do |
pankso@26 | 184 confs="$confs $(find ${i#/} -type f 2> /dev/null)" |
pankso@26 | 185 done |
pankso@23 | 186 |
pankso@34 | 187 echo $confs | cpio -o -H newc --quiet | gzip -9 > \ |
pankso@34 | 188 $package_dir/volatile.cpio.gz |
pankso@23 | 189 |
pankso@26 | 190 # keep user configuration files |
pankso@34 | 191 for configfile in $confs; do |
pankso@34 | 192 [ -e $configfile ] || continue |
pankso@34 | 193 cp -a $configfile fs/$configfile |
pankso@26 | 194 done |
pankso@26 | 195 status |
pankso@26 | 196 cd - >/dev/null |
pankso@26 | 197 fi |
pankso@23 | 198 |
pankso@26 | 199 # Merge ROOT_FS with Package FS |
pankso@34 | 200 gettext "Installing in:"; echo -n " $root/" |
pankso@34 | 201 cp -a fs/* $root/ |
pankso@26 | 202 status |
pankso@26 | 203 |
pankso@26 | 204 # Remove old config files |
pankso@32 | 205 if [ "$files_to_remove" ]; then |
pankso@32 | 206 gettext "Removing old"; echo -n " $package_name..." |
pankso@26 | 207 for file in $files_to_remove; do |
pankso@32 | 208 if [ "$verbose" ]; then |
pankso@32 | 209 gettext "Removing:"; echo " ${root}${file}" |
pankso@32 | 210 fi |
pankso@32 | 211 remove_with_path ${root}${file} |
pankso@26 | 212 done |
meshca@11 | 213 status |
pankso@26 | 214 fi |
pankso@26 | 215 cd - >/dev/null |
pankso@23 | 216 |
meshca@11 | 217 # Remove the temporary directory. |
meshca@11 | 218 gettext "Removing all tmp files... " |
pankso@34 | 219 rm -rf $tmpdir |
meshca@11 | 220 status |
pankso@23 | 221 |
meshca@11 | 222 # Post install commands. |
meshca@11 | 223 if grep -q ^post_install $package_dir/receipt; then |
pankso@34 | 224 post_install $root |
meshca@11 | 225 fi |
pankso@23 | 226 |
meshca@11 | 227 # Update-desktop-database if needed. |
meshca@11 | 228 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then |
meshca@11 | 229 updatedesktopdb=yes |
meshca@11 | 230 fi |
meshca@11 | 231 # Update-mime-database if needed. |
meshca@11 | 232 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then |
meshca@11 | 233 updatemimedb=yes |
meshca@11 | 234 fi |
meshca@11 | 235 # Update-icon-database |
meshca@11 | 236 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then |
meshca@11 | 237 updateicondb=yes |
meshca@11 | 238 fi |
meshca@11 | 239 # Compile glib schemas if needed. |
meshca@11 | 240 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then |
meshca@11 | 241 compile_schemas=yes |
meshca@11 | 242 fi |
meshca@11 | 243 # Update depmod list |
meshca@11 | 244 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then |
meshca@11 | 245 updatedepmod=yes |
meshca@11 | 246 fi |
meshca@11 | 247 separator |
meshca@11 | 248 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline |
meshca@11 | 249 newline |
meshca@11 | 250 } |
meshca@11 | 251 |
meshca@11 | 252 # Install .tazpkg packages. |
meshca@11 | 253 # Parameters: package_file |
pankso@28 | 254 install_local() { |
meshca@11 | 255 package_file="$1" |
meshca@11 | 256 check_valid_tazpkg $package_file |
meshca@11 | 257 install_package $package_file |
pankso@29 | 258 update_databases |
meshca@11 | 259 } |
meshca@11 | 260 |
meshca@11 | 261 # Download and install a package. TODO: Handle Undigest Mirrors |
meshca@11 | 262 # Parameters: package_name |
pankso@28 | 263 install_web() { |
meshca@11 | 264 local package_name="$1" |
meshca@11 | 265 |
meshca@11 | 266 # Check if get-Package |
meshca@11 | 267 if ! is_package_mirrored $package_name; then |
meshca@11 | 268 package_name="get-$package_name" |
meshca@11 | 269 AUTOEXEC=true |
meshca@11 | 270 fi |
meshca@11 | 271 |
meshca@11 | 272 # Check if package is mirrored |
meshca@11 | 273 if ! is_package_mirrored $package_name; then |
pankso@26 | 274 gettext "Could not find package on mirror:"; echo " $package_name" |
meshca@11 | 275 exit 1 |
meshca@11 | 276 fi |
meshca@11 | 277 |
meshca@11 | 278 # package_full=Package-Version |
meshca@11 | 279 local package_full=$(full_package $package_name) |
pankso@23 | 280 |
pankso@26 | 281 cd $CACHE_DIR > /dev/null |
pankso@26 | 282 if [ -f "$package_full.tazpkg" ]; then |
pankso@39 | 283 [ "$count" == 1 ] && newline |
pankso@39 | 284 gettext "Using cache:"; echo " $(colorize "$package_full" 34)" |
pankso@26 | 285 # Check package download was finished |
pankso@26 | 286 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then |
pankso@26 | 287 eval_gettext "Continuing \$package_name download"; newline |
pankso@26 | 288 download "$package_full.tazpkg" |
pankso@26 | 289 fi |
pankso@26 | 290 # Check that the package has the correct checksum |
pankso@30 | 291 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then |
pankso@30 | 292 # rm -f $package.tazpkg |
pankso@30 | 293 # download "$package_full.tazpkg" |
pankso@30 | 294 #fi |
pankso@26 | 295 else |
pankso@26 | 296 newline |
pankso@26 | 297 download "$package_full.tazpkg" |
pankso@26 | 298 fi |
pankso@23 | 299 |
meshca@11 | 300 install_package "$CACHE_DIR/$package_full.tazpkg" |
pankso@23 | 301 |
pankso@34 | 302 [ -n "$AUTOEXEC" ] && $package_name $root |
pankso@29 | 303 update_databases |
meshca@11 | 304 } |
meshca@11 | 305 |
pankso@23 | 306 # Install all missing deps. Auto install or ask user then install all missing |
meshca@11 | 307 # deps from local dir, cdrom, media or from the mirror. In case we want to |
meshca@11 | 308 # install packages from local, we need a packages.list to find the version. |
meshca@11 | 309 # Parameters: package List of deps to install |
meshca@11 | 310 install_deps() { |
meshca@11 | 311 local package=$1 |
meshca@11 | 312 shift |
meshca@11 | 313 local deps="$@" |
pankso@23 | 314 |
meshca@11 | 315 gettext "Install all missing dependencies? " |
pankso@23 | 316 |
meshca@11 | 317 # Print Yes/No and get result |
meshca@11 | 318 if $AUTO_INSTALL_DEPS || confirm; then |
meshca@11 | 319 for pkgorg in $deps; do |
meshca@11 | 320 local pkg=$(equivalent_pkg $pkgorg) |
meshca@11 | 321 # Check if package is not installed |
meshca@11 | 322 if [ ! -d "$installed/$pkg" ]; then |
meshca@11 | 323 if [ ! -f "$PKGS_DB/packages.list" ]; then |
meshca@11 | 324 tazpkg recharge |
meshca@11 | 325 fi |
meshca@11 | 326 get-install $pkg |
meshca@11 | 327 fi |
meshca@11 | 328 done |
meshca@11 | 329 else |
meshca@11 | 330 newline |
pankso@27 | 331 boldify $(gettext "Package:") $package |
pankso@27 | 332 gettext \ |
pankso@27 | 333 "Dependencies unresolved. Installed but will probably not work." |
pankso@27 | 334 newline && newline |
meshca@11 | 335 fi |
meshca@11 | 336 } |
meshca@11 | 337 |
pankso@30 | 338 # |
pankso@30 | 339 # Commands and exit |
pankso@30 | 340 # |
pankso@30 | 341 |
pankso@30 | 342 case "$1" in |
pankso@30 | 343 ""|*usage|*help) usage ;; |
meshca@11 | 344 esac |
pankso@24 | 345 |
pankso@28 | 346 # |
pankso@28 | 347 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg |
pankso@28 | 348 # |
pankso@28 | 349 |
pankso@39 | 350 count=0 |
pankso@28 | 351 check_root |
pankso@28 | 352 |
pankso@24 | 353 for pkg in $@ |
pankso@24 | 354 do |
pankso@28 | 355 case "$pkg" in |
pankso@30 | 356 *.tazpkg|*.spk) |
pankso@30 | 357 [ "$forced" ] || check_installed $(package_name $package_file) |
pankso@30 | 358 echo "Local package" |
pankso@30 | 359 #install_local $pkg |
pankso@30 | 360 ;; |
pankso@30 | 361 --*) continue ;; |
pankso@30 | 362 *) |
pankso@30 | 363 [ "$forced" ] || check_installed $pkg |
pankso@39 | 364 count=$(($count + 1)) |
pankso@30 | 365 install_web $pkg ;; |
pankso@28 | 366 esac |
pankso@24 | 367 done |
pankso@24 | 368 exit 0 |