spk annotate spk-add @ rev 32
A bunch of fix to add an lib
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue May 15 20:32:41 2012 +0200 (2012-05-15) |
parents | ea3c01346d05 |
children | fca271e55b69 |
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 |
meshca@11 | 156 echo "$package_name" >> $pkg/modifiers |
meshca@11 | 157 fi |
meshca@11 | 158 done |
meshca@11 | 159 done |
meshca@11 | 160 fi |
pankso@23 | 161 |
pankso@26 | 162 cd $TMP_DIR || exit 1 |
pankso@26 | 163 cp receipt files.list $package_dir |
pankso@26 | 164 # Copy the description if found. |
pankso@26 | 165 [ -f "description.txt" ] && cp description.txt $package_dir |
pankso@23 | 166 |
pankso@26 | 167 # Pre install commands. |
pankso@26 | 168 if grep -q ^pre_install $package_dir/receipt; then |
pankso@26 | 169 pre_install $ROOT |
pankso@26 | 170 fi |
pankso@23 | 171 |
pankso@26 | 172 # Handle Config Files from receipt |
pankso@26 | 173 if [ -n "$CONFIG_FILES" ]; then |
pankso@26 | 174 cd $fs || exit 1 |
pankso@26 | 175 # save 'official' configuration files |
pankso@26 | 176 eval_gettext "Saving configuration files for \$package_name... " |
pankso@23 | 177 |
pankso@26 | 178 local confs |
pankso@26 | 179 for i in $CONFIG_FILES; do |
pankso@26 | 180 confs="$confs $(find ${i#/} -type f 2> /dev/null)" |
pankso@26 | 181 done |
pankso@23 | 182 |
pankso@26 | 183 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz |
pankso@23 | 184 |
pankso@26 | 185 # keep user configuration files |
pankso@26 | 186 for conf_file in $confs; do |
pankso@26 | 187 [ -e $conf_file ] || continue |
pankso@26 | 188 cp -a $conf_file fs/$conf_file |
pankso@26 | 189 done |
pankso@26 | 190 status |
pankso@26 | 191 cd - >/dev/null |
pankso@26 | 192 fi |
pankso@23 | 193 |
pankso@26 | 194 # Merge ROOT_FS with Package FS |
pankso@32 | 195 gettext "Installing"; echo -n " $package_name..." |
pankso@26 | 196 cp -a fs/* $ROOT/ |
pankso@26 | 197 status |
pankso@26 | 198 |
pankso@26 | 199 # Remove old config files |
pankso@32 | 200 if [ "$files_to_remove" ]; then |
pankso@32 | 201 gettext "Removing old"; echo -n " $package_name..." |
pankso@26 | 202 for file in $files_to_remove; do |
pankso@32 | 203 if [ "$verbose" ]; then |
pankso@32 | 204 gettext "Removing:"; echo " ${root}${file}" |
pankso@32 | 205 fi |
pankso@32 | 206 remove_with_path ${root}${file} |
pankso@26 | 207 done |
meshca@11 | 208 status |
pankso@26 | 209 fi |
pankso@26 | 210 cd - >/dev/null |
pankso@23 | 211 |
meshca@11 | 212 # Remove the temporary directory. |
meshca@11 | 213 gettext "Removing all tmp files... " |
meshca@11 | 214 rm -rf $TMP_DIR |
meshca@11 | 215 status |
pankso@23 | 216 |
meshca@11 | 217 # Post install commands. |
meshca@11 | 218 if grep -q ^post_install $package_dir/receipt; then |
meshca@11 | 219 post_install $ROOT |
meshca@11 | 220 fi |
pankso@23 | 221 |
meshca@11 | 222 # Update-desktop-database if needed. |
meshca@11 | 223 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then |
meshca@11 | 224 updatedesktopdb=yes |
meshca@11 | 225 fi |
meshca@11 | 226 # Update-mime-database if needed. |
meshca@11 | 227 if [ "$(fgrep /usr/share/mime $package_dir/files.list)" ]; then |
meshca@11 | 228 updatemimedb=yes |
meshca@11 | 229 fi |
meshca@11 | 230 # Update-icon-database |
meshca@11 | 231 if [ "$(fgrep /usr/share/icon/hicolor $package_dir/files.list)" ]; then |
meshca@11 | 232 updateicondb=yes |
meshca@11 | 233 fi |
meshca@11 | 234 # Compile glib schemas if needed. |
meshca@11 | 235 if [ "$(fgrep /usr/share/glib-2.0/schemas $package_dir/files.list)" ]; then |
meshca@11 | 236 compile_schemas=yes |
meshca@11 | 237 fi |
meshca@11 | 238 # Update depmod list |
meshca@11 | 239 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then |
meshca@11 | 240 updatedepmod=yes |
meshca@11 | 241 fi |
meshca@11 | 242 separator |
meshca@11 | 243 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline |
meshca@11 | 244 newline |
meshca@11 | 245 } |
meshca@11 | 246 |
meshca@11 | 247 # Install .tazpkg packages. |
meshca@11 | 248 # Parameters: package_file |
pankso@28 | 249 install_local() { |
meshca@11 | 250 package_file="$1" |
meshca@11 | 251 check_valid_tazpkg $package_file |
meshca@11 | 252 install_package $package_file |
pankso@29 | 253 update_databases |
meshca@11 | 254 } |
meshca@11 | 255 |
meshca@11 | 256 # Download and install a package. TODO: Handle Undigest Mirrors |
meshca@11 | 257 # Parameters: package_name |
pankso@28 | 258 install_web() { |
meshca@11 | 259 local package_name="$1" |
meshca@11 | 260 |
meshca@11 | 261 # Check if get-Package |
meshca@11 | 262 if ! is_package_mirrored $package_name; then |
meshca@11 | 263 package_name="get-$package_name" |
meshca@11 | 264 AUTOEXEC=true |
meshca@11 | 265 fi |
meshca@11 | 266 |
meshca@11 | 267 # Check if package is mirrored |
meshca@11 | 268 if ! is_package_mirrored $package_name; then |
pankso@26 | 269 gettext "Could not find package on mirror:"; echo " $package_name" |
meshca@11 | 270 exit 1 |
meshca@11 | 271 fi |
meshca@11 | 272 |
meshca@11 | 273 # package_full=Package-Version |
meshca@11 | 274 local package_full=$(full_package $package_name) |
pankso@23 | 275 |
pankso@26 | 276 cd $CACHE_DIR > /dev/null |
pankso@26 | 277 if [ -f "$package_full.tazpkg" ]; then |
pankso@31 | 278 echo -n "$(colorize "$package_full" 34)"; echo ": $CACHE_DIR)" |
pankso@26 | 279 # Check package download was finished |
pankso@26 | 280 if ! tail -c 2k $package_full.tazpkg | fgrep -q 00000000TRAILER; then |
pankso@26 | 281 eval_gettext "Continuing \$package_name download"; newline |
pankso@26 | 282 download "$package_full.tazpkg" |
pankso@26 | 283 fi |
pankso@26 | 284 # Check that the package has the correct checksum |
pankso@30 | 285 #if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then |
pankso@30 | 286 # rm -f $package.tazpkg |
pankso@30 | 287 # download "$package_full.tazpkg" |
pankso@30 | 288 #fi |
pankso@26 | 289 else |
pankso@26 | 290 newline |
pankso@26 | 291 download "$package_full.tazpkg" |
pankso@26 | 292 fi |
pankso@23 | 293 |
meshca@11 | 294 install_package "$CACHE_DIR/$package_full.tazpkg" |
pankso@23 | 295 |
pankso@23 | 296 [ -n "$AUTOEXEC" ] && $package_name $ROOT |
pankso@29 | 297 update_databases |
meshca@11 | 298 } |
meshca@11 | 299 |
pankso@23 | 300 # Install all missing deps. Auto install or ask user then install all missing |
meshca@11 | 301 # deps from local dir, cdrom, media or from the mirror. In case we want to |
meshca@11 | 302 # install packages from local, we need a packages.list to find the version. |
meshca@11 | 303 # Parameters: package List of deps to install |
meshca@11 | 304 install_deps() { |
meshca@11 | 305 local package=$1 |
meshca@11 | 306 shift |
meshca@11 | 307 local deps="$@" |
pankso@23 | 308 |
meshca@11 | 309 gettext "Install all missing dependencies? " |
pankso@23 | 310 |
meshca@11 | 311 # Print Yes/No and get result |
meshca@11 | 312 if $AUTO_INSTALL_DEPS || confirm; then |
meshca@11 | 313 for pkgorg in $deps; do |
meshca@11 | 314 local pkg=$(equivalent_pkg $pkgorg) |
meshca@11 | 315 # Check if package is not installed |
meshca@11 | 316 if [ ! -d "$installed/$pkg" ]; then |
meshca@11 | 317 if [ ! -f "$PKGS_DB/packages.list" ]; then |
meshca@11 | 318 tazpkg recharge |
meshca@11 | 319 fi |
meshca@11 | 320 get-install $pkg |
meshca@11 | 321 fi |
meshca@11 | 322 done |
meshca@11 | 323 else |
meshca@11 | 324 newline |
pankso@27 | 325 boldify $(gettext "Package:") $package |
pankso@27 | 326 gettext \ |
pankso@27 | 327 "Dependencies unresolved. Installed but will probably not work." |
pankso@27 | 328 newline && newline |
meshca@11 | 329 fi |
meshca@11 | 330 } |
meshca@11 | 331 |
pankso@30 | 332 # |
pankso@30 | 333 # Commands and exit |
pankso@30 | 334 # |
pankso@30 | 335 |
pankso@30 | 336 case "$1" in |
pankso@30 | 337 ""|*usage|*help) usage ;; |
meshca@11 | 338 esac |
pankso@24 | 339 |
pankso@28 | 340 # |
pankso@28 | 341 # Handle packages: package package.tazpkg ... packageN packageN.tazpkg |
pankso@28 | 342 # |
pankso@28 | 343 |
pankso@28 | 344 check_root |
pankso@28 | 345 |
pankso@24 | 346 for pkg in $@ |
pankso@24 | 347 do |
pankso@28 | 348 case "$pkg" in |
pankso@30 | 349 *.tazpkg|*.spk) |
pankso@30 | 350 [ "$forced" ] || check_installed $(package_name $package_file) |
pankso@30 | 351 echo "Local package" |
pankso@30 | 352 #install_local $pkg |
pankso@30 | 353 ;; |
pankso@30 | 354 --*) continue ;; |
pankso@30 | 355 *) |
pankso@30 | 356 [ "$forced" ] || check_installed $pkg |
pankso@30 | 357 install_web $pkg ;; |
pankso@28 | 358 esac |
pankso@24 | 359 done |
pankso@24 | 360 exit 0 |