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