spk annotate 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 |
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 |
paul@12 | 12 # Set to / for now until we add installing to chroot support |
meshca@11 | 13 # Could we update tools so they do not need this? |
meshca@11 | 14 ROOT="" |
meshca@11 | 15 TMP_DIR="/tmp/$RANDOM" |
meshca@11 | 16 |
pankso@23 | 17 # |
pankso@23 | 18 # Functions |
pankso@23 | 19 # |
pankso@23 | 20 |
pankso@23 | 21 # Help and usage |
pankso@23 | 22 usage() { |
pankso@23 | 23 name=$(basename $0) |
pankso@23 | 24 cat << EOT |
pankso@23 | 25 |
pankso@23 | 26 $(boldify $(gettext "Usage:")) $name [packages|--options] |
pankso@23 | 27 |
pankso@23 | 28 $(gettext "Install SliTaz Packages") |
pankso@23 | 29 |
pankso@23 | 30 $(boldify $(gettext "Options:")) |
pankso@30 | 31 --forced $(gettext "Force package reinstallation") |
pankso@30 | 32 --root= $(gettext "Set the root file system path") |
pankso@23 | 33 |
pankso@23 | 34 $(boldify $(gettext "Examples:")) |
pankso@23 | 35 $name package1 package2 packageN |
pankso@23 | 36 |
pankso@23 | 37 EOT |
pankso@23 | 38 exit 0 |
pankso@23 | 39 } |
meshca@11 | 40 |
pankso@29 | 41 # Update system databases |
pankso@29 | 42 update_databases() { |
pankso@29 | 43 if [ -f $ROOT/usr/bin/update-desktop-database ] && [ -n "$updatedesktopdb" ]; then |
pankso@29 | 44 chroot "$ROOT/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null |
pankso@29 | 45 fi |
pankso@29 | 46 # Mimetypes |
pankso@29 | 47 if [ -f $ROOT/usr/bin/update-mime-database ] && [ -n "$updatemimedb" ]; then |
pankso@29 | 48 chroot "$ROOT/" /usr/bin/update-mime-database /usr/share/mime |
pankso@29 | 49 fi |
pankso@29 | 50 # Icons |
pankso@29 | 51 if [ -f $ROOT/usr/bin/gtk-update-icon-cache ] && [ -n "$updateicondb" ]; then |
pankso@29 | 52 chroot "$ROOT/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor |
pankso@29 | 53 fi |
pankso@29 | 54 # Glib schemas |
pankso@29 | 55 if [ -f $ROOT/usr/bin/glib-compile-schemas ] && [ -n "$compile_schemas" ]; then |
pankso@29 | 56 chroot "$ROOT/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas |
pankso@29 | 57 fi |
pankso@29 | 58 # Kernel modules |
pankso@29 | 59 if [ -f $ROOT/sbin/depmod ] && [ -n "$updatedepmod" ]; then |
pankso@29 | 60 chroot "$ROOT/" /sbin/depmod -a |
pankso@29 | 61 fi |
pankso@29 | 62 } |
pankso@29 | 63 |
meshca@11 | 64 # This function installs a package in the rootfs. |
meshca@11 | 65 # Parameters: package_name package_file |
pankso@23 | 66 install_package() { |
meshca@11 | 67 local package_file=$1 |
pankso@23 | 68 |
pankso@27 | 69 # Never used I think!!! |
meshca@11 | 70 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install() |
pankso@23 | 71 |
meshca@11 | 72 # Create package path early to avoid dependencies loop |
meshca@11 | 73 mkdir -p $TMP_DIR |
meshca@11 | 74 extract_receipt $TMP_DIR $package_file |
meshca@11 | 75 source $TMP_DIR/receipt |
pankso@23 | 76 |
meshca@11 | 77 local package_name=$PACKAGE |
meshca@11 | 78 local package_dir="$installed/$package_name" |
meshca@11 | 79 mkdir -p $package_dir |
meshca@11 | 80 |
meshca@11 | 81 # Run pre_depends from receipt if it exists |
meshca@11 | 82 if grep -q ^pre_depends $TMP_DIR/receipt; then |
meshca@11 | 83 pre_depends $ROOT |
meshca@11 | 84 fi |
meshca@11 | 85 |
meshca@11 | 86 # Create modifiers and files.list if they do not exist |
pankso@27 | 87 # Why ? If missing files.list it's meta packages. |
pankso@27 | 88 #touch $package_dir/modifiers |
pankso@27 | 89 #touch $package_dir/files.list |
meshca@11 | 90 |
pankso@26 | 91 # Add package checksum to pkgsmd5 |
meshca@11 | 92 sed -i "/ $(basename $package_dir)$/d" $pkgsmd5 2> /dev/null |
pankso@26 | 93 cd $(dirname $package_file) || exit 1 |
pankso@26 | 94 $CHECKSUM $(basename $package_file) >> $pkgsmd5 |
pankso@32 | 95 cd - >/dev/null |
pankso@23 | 96 |
meshca@11 | 97 # Resolve package deps. |
meshca@11 | 98 if missing_deps $package_name $DEPENDS; then |
meshca@11 | 99 install_deps $package_name $DEPENDS |
meshca@11 | 100 fi |
pankso@23 | 101 |
pankso@23 | 102 newline |
meshca@11 | 103 boldify $(gettext "Installation of :") $package_name |
meshca@11 | 104 separator |
meshca@11 | 105 eval_gettext "Copying \$package_name... " |
meshca@11 | 106 cp $package_file $TMP_DIR |
meshca@11 | 107 status |
pankso@23 | 108 |
meshca@11 | 109 # Extract Package |
pankso@26 | 110 cd $TMP_DIR || exit 1 |
pankso@26 | 111 rm receipt |
pankso@26 | 112 spk-archive extract $package_file |
pankso@26 | 113 cd - >/dev/null |
pankso@23 | 114 |
meshca@11 | 115 # Get files to remove if upgrading |
meshca@11 | 116 local files_to_remove |
meshca@11 | 117 if [ -f $package_dir/files.list ]; then |
pankso@32 | 118 for file in $(cat $package_dir/files.list) |
pankso@32 | 119 do |
meshca@11 | 120 grep -q "^$(echo $file | grepesc)$" $TMP_DIR/files.list && continue |
pankso@32 | 121 local modifiers=$(cat $package_dir/modifiers 2> /dev/null; \ |
meshca@11 | 122 fgrep -sl $package_dir */modifiers | cut -d/ -f1) |
meshca@11 | 123 for i in modifiers; do |
meshca@11 | 124 grep -qs "^$(echo $file | grepesc)$" $i/files.list && continue 2 |
meshca@11 | 125 done |
meshca@11 | 126 files_to_remove="$files_to_remove $file" |
meshca@11 | 127 done |
meshca@11 | 128 fi |
pankso@23 | 129 |
meshca@11 | 130 local check=false |
meshca@11 | 131 local file_list |
meshca@11 | 132 # Create list of all possibly modified files |
meshca@11 | 133 for i in $(fgrep -v [ $TMP_DIR/files.list); do |
meshca@11 | 134 [ -e "$ROOT$i" ] || continue |
meshca@11 | 135 [ -d "$ROOT$i" ] && continue |
meshca@11 | 136 file_list="$file_list $i" |
meshca@11 | 137 check=true |
meshca@11 | 138 done |
pankso@23 | 139 |
meshca@11 | 140 # Check possibly modified files against other packages file.list |
meshca@11 | 141 if $check; then |
pankso@32 | 142 for pkg in $installed/*; do |
meshca@11 | 143 [ "$pkg" == "$package_name" ] && continue |
meshca@11 | 144 [ -s $pkg/files.list ] || continue |
pankso@23 | 145 |
meshca@11 | 146 for file in $file_list; do |
meshca@11 | 147 # $package_name wants to install $file which is already |
pankso@32 | 148 # installed from $pkg |
meshca@11 | 149 if grep -q ^$file$ $pkg/files.list; then |
paul@12 | 150 # Tell $pkg that $package_name is going to overwrite some of its files |
meshca@11 | 151 if [ -s "$pkg/volatile.cpio.gz" ]; then |
meshca@11 | 152 # We can modify backed up files without notice |
meshca@11 | 153 zcat $pkg/volatile.cpio.gz | cpio -t --quiet | \ |
meshca@11 | 154 grep -q "^${file#/}$" && continue |
meshca@11 | 155 fi |
pankso@33 | 156 base_name=$(basename $pkg) |
pankso@33 | 157 if [ "$package_name" != "$base_name" ]; then |
pankso@33 | 158 [ "$debug" ] && \ |
pankso@33 | 159 echo "DEBUG: Adding $base_name to: $pkg/modifiers" |
pankso@33 | 160 echo "$package_name" >> $pkg/modifiers |
pankso@33 | 161 fi |
meshca@11 | 162 fi |
meshca@11 | 163 done |
meshca@11 | 164 done |
meshca@11 | 165 fi |
pankso@23 | 166 |
pankso@26 | 167 cd $TMP_DIR || exit 1 |
pankso@26 | 168 cp receipt files.list $package_dir |
pankso@33 | 169 |
pankso@26 | 170 # Copy the description if found. |
pankso@26 | 171 [ -f "description.txt" ] && cp description.txt $package_dir |
pankso@23 | 172 |
pankso@26 | 173 # Pre install commands. |
pankso@26 | 174 if grep -q ^pre_install $package_dir/receipt; then |
pankso@26 | 175 pre_install $ROOT |
pankso@26 | 176 fi |
pankso@23 | 177 |
pankso@26 | 178 # Handle Config Files from receipt |
pankso@26 | 179 if [ -n "$CONFIG_FILES" ]; then |
pankso@26 | 180 cd $fs || exit 1 |
pankso@26 | 181 # save 'official' configuration files |
pankso@26 | 182 eval_gettext "Saving configuration files for \$package_name... " |
pankso@23 | 183 |
pankso@26 | 184 local confs |
pankso@26 | 185 for i in $CONFIG_FILES; do |
pankso@26 | 186 confs="$confs $(find ${i#/} -type f 2> /dev/null)" |
pankso@26 | 187 done |
pankso@23 | 188 |
pankso@26 | 189 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz |
pankso@23 | 190 |
pankso@26 | 191 # keep user configuration files |
pankso@26 | 192 for conf_file in $confs; do |
pankso@26 | 193 [ -e $conf_file ] || continue |
pankso@26 | 194 cp -a $conf_file fs/$conf_file |
pankso@26 | 195 done |
pankso@26 | 196 status |
pankso@26 | 197 cd - >/dev/null |
pankso@26 | 198 fi |
pankso@23 | 199 |
pankso@26 | 200 # Merge ROOT_FS with Package FS |
pankso@32 | 201 gettext "Installing"; echo -n " $package_name..." |
pankso@26 | 202 cp -a fs/* $ROOT/ |
pankso@26 | 203 status |
pankso@26 | 204 |
pankso@26 | 205 # Remove old config files |
pankso@32 | 206 if [ "$files_to_remove" ]; then |
pankso@32 | 207 gettext "Removing old"; echo -n " $package_name..." |
pankso@26 | 208 for file in $files_to_remove; do |
pankso@32 | 209 if [ "$verbose" ]; then |
pankso@32 | 210 gettext "Removing:"; echo " ${root}${file}" |
pankso@32 | 211 fi |
pankso@32 | 212 remove_with_path ${root}${file} |
pankso@26 | 213 done |
meshca@11 | 214 status |
pankso@26 | 215 fi |
pankso@26 | 216 cd - >/dev/null |
pankso@23 | 217 |
meshca@11 | 218 # Remove the temporary directory. |
meshca@11 | 219 gettext "Removing all tmp files... " |
meshca@11 | 220 rm -rf $TMP_DIR |
meshca@11 | 221 status |
pankso@23 | 222 |
meshca@11 | 223 # Post install commands. |
meshca@11 | 224 if grep -q ^post_install $package_dir/receipt; then |
meshca@11 | 225 post_install $ROOT |
meshca@11 | 226 fi |
pankso@23 | 227 |
meshca@11 | 228 # Update-desktop-database if needed. |
meshca@11 | 229 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then |
meshca@11 | 230 updatedesktopdb=yes |
meshca@11 | 231 fi |
meshca@11 | 232 # Update-mime-database if needed. |
meshca@11 | 233 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then |
meshca@11 | 234 updatemimedb=yes |
meshca@11 | 235 fi |
meshca@11 | 236 # Update-icon-database |
meshca@11 | 237 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then |
meshca@11 | 238 updateicondb=yes |
meshca@11 | 239 fi |
meshca@11 | 240 # Compile glib schemas if needed. |
meshca@11 | 241 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then |
meshca@11 | 242 compile_schemas=yes |
meshca@11 | 243 fi |
meshca@11 | 244 # Update depmod list |
meshca@11 | 245 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then |
meshca@11 | 246 updatedepmod=yes |
meshca@11 | 247 fi |
meshca@11 | 248 separator |
meshca@11 | 249 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline |
meshca@11 | 250 newline |
meshca@11 | 251 } |
meshca@11 | 252 |
meshca@11 | 253 # Install .tazpkg packages. |
meshca@11 | 254 # Parameters: package_file |
pankso@28 | 255 install_local() { |
meshca@11 | 256 package_file="$1" |
meshca@11 | 257 check_valid_tazpkg $package_file |
meshca@11 | 258 install_package $package_file |
pankso@29 | 259 update_databases |
meshca@11 | 260 } |
meshca@11 | 261 |
meshca@11 | 262 # Download and install a package. TODO: Handle Undigest Mirrors |
meshca@11 | 263 # Parameters: package_name |
pankso@28 | 264 install_web() { |
meshca@11 | 265 local package_name="$1" |
meshca@11 | 266 |
meshca@11 | 267 # Check if get-Package |
meshca@11 | 268 if ! is_package_mirrored $package_name; then |
meshca@11 | 269 package_name="get-$package_name" |
meshca@11 | 270 AUTOEXEC=true |
meshca@11 | 271 fi |
meshca@11 | 272 |
meshca@11 | 273 # Check if package is mirrored |
meshca@11 | 274 if ! is_package_mirrored $package_name; then |
pankso@26 | 275 gettext "Could not find package on mirror:"; echo " $package_name" |
meshca@11 | 276 exit 1 |
meshca@11 | 277 fi |
meshca@11 | 278 |
meshca@11 | 279 # package_full=Package-Version |
meshca@11 | 280 local package_full=$(full_package $package_name) |
pankso@23 | 281 |
pankso@26 | 282 cd $CACHE_DIR > /dev/null |
pankso@26 | 283 if [ -f "$package_full.tazpkg" ]; then |
pankso@31 | 284 echo -n "$(colorize "$package_full" 34)"; echo ": $CACHE_DIR)" |
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@23 | 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@28 | 350 check_root |
pankso@28 | 351 |
pankso@24 | 352 for pkg in $@ |
pankso@24 | 353 do |
pankso@28 | 354 case "$pkg" in |
pankso@30 | 355 *.tazpkg|*.spk) |
pankso@30 | 356 [ "$forced" ] || check_installed $(package_name $package_file) |
pankso@30 | 357 echo "Local package" |
pankso@30 | 358 #install_local $pkg |
pankso@30 | 359 ;; |
pankso@30 | 360 --*) continue ;; |
pankso@30 | 361 *) |
pankso@30 | 362 [ "$forced" ] || check_installed $pkg |
pankso@30 | 363 install_web $pkg ;; |
pankso@28 | 364 esac |
pankso@24 | 365 done |
pankso@24 | 366 exit 0 |