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