spk annotate lib/libspk.sh @ rev 66
Bunch od small improvments and better package_full to handle extra repos
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 18 06:36:19 2012 +0200 (2012-05-18) |
parents | de880358af6d |
children | 885b195a5d69 |
rev | line source |
---|---|
pankso@5 | 1 #!/bin/sh |
pankso@5 | 2 # |
paul@12 | 3 # Libspk - The Spk base function and internal variables used by almost all |
pankso@5 | 4 # spk-tools. Read the README before adding or modifing any code in spk! |
pankso@5 | 5 # |
pankso@5 | 6 # Copyright (C) SliTaz GNU/Linux - BSD License |
pankso@5 | 7 # Author: See AUTHORS files |
pankso@5 | 8 # |
pankso@5 | 9 . /lib/libtaz.sh |
pankso@5 | 10 . /usr/lib/slitaz/libpkg.sh |
pankso@5 | 11 . /etc/slitaz/slitaz.conf |
pankso@5 | 12 |
pankso@5 | 13 # Internal variables. |
pankso@17 | 14 mirrorurl="${root}${PKGS_DB}/mirror" |
pankso@59 | 15 mirrors="${root}${PKGS_DB}/mirrors" |
pankso@17 | 16 installed="${root}${PKGS_DB}/installed" |
pankso@17 | 17 pkgsdesc="${root}${PKGS_DB}/packages.desc" |
pankso@32 | 18 pkgsmd5="${root}${PKGS_DB}/packages.$SUM" |
pankso@60 | 19 pkgsequiv="${root}${PKGS_DB}/packages.equiv" |
pankso@19 | 20 blocked="${root}${PKGS_DB}/blocked.list" |
pankso@17 | 21 activity="${root}${PKGS_DB}/activity" |
pankso@57 | 22 logdir="${root}/var/log/spk" |
pankso@59 | 23 extradb="${root}${PKGS_DB}/extra" |
pankso@60 | 24 tmpdir="/tmp/spk/$RANDOM" |
pankso@5 | 25 |
pankso@5 | 26 # |
pankso@19 | 27 # Sanity checks |
pankso@19 | 28 # |
pankso@19 | 29 |
pankso@19 | 30 if [ ! -d "${root}${PKGS_DB}" ]; then |
pankso@19 | 31 gettext "Can't find DB:"; echo " ${root}${PKGS_DB}" |
pankso@19 | 32 exit 1 |
pankso@19 | 33 fi |
pankso@19 | 34 |
pankso@19 | 35 # |
pankso@5 | 36 # Functions |
pankso@18 | 37 # |
meshca@11 | 38 |
pankso@14 | 39 # Display receipt information. Expects a receipt to be sourced |
pankso@5 | 40 receipt_info() { |
pankso@5 | 41 cat << EOT |
pankso@5 | 42 $(gettext "Version :") ${VERSION}${EXTRAVERSION} |
pankso@5 | 43 $(gettext "Short desc :") $SHORT_DESC |
pankso@5 | 44 $(gettext "Category :") $CATEGORY |
pankso@5 | 45 EOT |
pankso@5 | 46 } |
pankso@5 | 47 |
pankso@62 | 48 # Display package info from a packages.desc list |
pankso@62 | 49 # Usage: read_pkgsdesc /path/to/packages.desc |
pankso@62 | 50 read_pkgsdesc() { |
pankso@62 | 51 local list="$1" |
pankso@62 | 52 IFS="|" |
pankso@62 | 53 cat $list | while read package version desc category |
pankso@62 | 54 do |
pankso@62 | 55 if [ "$short" ]; then |
pankso@62 | 56 echo -n "$(colorize "$package" 32)"; indent 28 " $version" |
pankso@62 | 57 else |
pankso@62 | 58 newline |
pankso@62 | 59 gettext "Package :"; colorize " $package" 32 |
pankso@62 | 60 gettext "Version :"; echo "$version" |
pankso@62 | 61 gettext "Short desc :"; echo "$desc" |
pankso@62 | 62 fi |
pankso@62 | 63 done && unset IFS |
pankso@62 | 64 } |
pankso@62 | 65 |
meshca@9 | 66 # Extract receipt from tazpkg |
meshca@9 | 67 # Parameters: result_dir package_file |
meshca@9 | 68 extract_receipt() { |
meshca@9 | 69 local dir="$1" |
meshca@9 | 70 local file="$2" |
pankso@26 | 71 cd "$dir" |
meshca@9 | 72 { cpio --quiet -i receipt > /dev/null 2>&1; } < $file |
pankso@26 | 73 cd - >/dev/null |
meshca@9 | 74 } |
meshca@9 | 75 |
pankso@60 | 76 # Extract files.list from tazpkg |
pankso@60 | 77 # Parameters: result_dir package_file |
pankso@60 | 78 extract_fileslist() { |
pankso@60 | 79 local dir="$1" |
pankso@60 | 80 local file="$2" |
pankso@60 | 81 cd "$dir" |
pankso@60 | 82 { cpio --quiet -i files.list > /dev/null 2>&1; } < $file |
pankso@60 | 83 cd - >/dev/null |
pankso@60 | 84 } |
pankso@60 | 85 |
pankso@5 | 86 # Used by: list |
pankso@5 | 87 count_installed() { |
pankso@18 | 88 local count=$(ls $installed | wc -l) |
pankso@60 | 89 gettext "Installed :"; echo " $count" |
pankso@5 | 90 } |
pankso@5 | 91 |
pankso@5 | 92 # Used by: list |
pankso@5 | 93 count_mirrored() { |
pankso@62 | 94 [ -f "$pkgsmd5" ] || return |
meshca@9 | 95 local count=$(cat $pkgsmd5 | wc -l) |
pankso@60 | 96 gettext "Mirrored :"; echo " $count" |
pankso@5 | 97 } |
meshca@9 | 98 |
pankso@63 | 99 # Check if package is on main or extra mirror. |
pankso@63 | 100 mirrored_pkg() { |
pankso@14 | 101 local name=$1 |
pankso@66 | 102 local find=$(grep "^$name |" $pkgsdesc $extradb/*/*.desc 2>/dev/null) |
pankso@66 | 103 [ -n "$find" ] |
meshca@11 | 104 } |
meshca@11 | 105 |
meshca@11 | 106 # Download a file trying all mirrors |
meshca@11 | 107 # Parameters: package/file |
pankso@65 | 108 # |
pankso@65 | 109 # We should do much better here, give priority to extra, then try |
pankso@65 | 110 # main mirror, then try others official mirrors. The case $file is |
pankso@65 | 111 # not needed since we use same URL for list or packages. |
pankso@65 | 112 # |
meshca@11 | 113 download() { |
pankso@65 | 114 local file=$1 |
meshca@11 | 115 local mirror="$(cat $mirrorurl)" |
pankso@65 | 116 [ "$quiet" ] && local quiet="-q" |
pankso@65 | 117 case "$file" in |
meshca@11 | 118 *.tazpkg) |
pankso@65 | 119 [ "$quiet" ] || echo "URL: ${mirror%/}/" |
pankso@65 | 120 gettext "Downloading:"; boldify " $file" |
pankso@65 | 121 wget $quiet -c ${mirror%/}/$file |
pankso@65 | 122 if [ ! -f "$file" ]; then |
pankso@65 | 123 gettext "ERROR: Missing package:"; boldify "$package" |
pankso@65 | 124 newline && exit 1 |
pankso@65 | 125 fi ;; |
pankso@65 | 126 ID|packages.*|files.list.lzma) |
pankso@65 | 127 echo "TODO" ;; |
meshca@11 | 128 esac |
meshca@11 | 129 } |
meshca@11 | 130 |
pankso@66 | 131 # Return the full package name, search in all packages.desc and break when |
pankso@66 | 132 # first occurance is found: Usage: full_package pkgname |
meshca@11 | 133 full_package() { |
pankso@66 | 134 for desc in $(find $extradb $pkgsdesc -name packages.desc); do |
pankso@66 | 135 local line="$(grep "^$1 |" $desc)" |
pankso@66 | 136 local db=$(dirname $desc) |
pankso@66 | 137 if grep -q "^$1 |" $desc; then |
pankso@66 | 138 IFS="|" |
pankso@66 | 139 echo $line | busybox awk '{print $1 "-" $2 ".tazpkg"}' |
pankso@66 | 140 unset IFS && break |
pankso@66 | 141 fi |
pankso@66 | 142 done |
meshca@11 | 143 } |
meshca@11 | 144 |
meshca@11 | 145 # Check if a package is already installed. |
pankso@27 | 146 # Usage: check_installed package |
pankso@27 | 147 check_installed() { |
pankso@14 | 148 local name="$1" |
pankso@18 | 149 if [ -d "$installed/$name" ]; then |
pankso@30 | 150 echo $(boldify "$name") $(gettext "package is already installed") |
pankso@55 | 151 [ "$forced" ] || rm -rf $tmpdir |
pankso@28 | 152 continue |
meshca@11 | 153 fi |
meshca@11 | 154 } |
meshca@11 | 155 |
meshca@11 | 156 # get an already installed package from packages.equiv TODO REDO! |
meshca@9 | 157 equivalent_pkg() { |
pankso@66 | 158 for i in $(grep -hs "^$1=" $pkgsequiv $extradb/*/*.equiv | sed "s/^$1=//") |
meshca@9 | 159 do |
meshca@9 | 160 if echo $i | fgrep -q : ; then |
meshca@9 | 161 # format 'alternative:newname' |
meshca@9 | 162 # if alternative is installed then substitute newname |
pankso@18 | 163 if [ -f $installed/${i%:*}/receipt ]; then |
meshca@9 | 164 # substitute package dependancy |
meshca@9 | 165 echo ${i#*:} |
meshca@9 | 166 return |
meshca@9 | 167 fi |
meshca@9 | 168 else |
meshca@9 | 169 # if alternative is installed then nothing to install |
pankso@18 | 170 if [ -f $installed/$i/receipt ]; then |
meshca@9 | 171 # substitute installed package |
meshca@9 | 172 echo $i |
meshca@9 | 173 return |
meshca@9 | 174 fi |
meshca@9 | 175 fi |
meshca@9 | 176 done |
meshca@9 | 177 # if not found in packages.equiv then no substitution |
meshca@9 | 178 echo $1 |
meshca@9 | 179 } |
meshca@9 | 180 |
meshca@9 | 181 # Check for missing deps listed in a receipt packages. |
meshca@9 | 182 # Parameters: package dependencies |
meshca@9 | 183 missing_deps() { |
meshca@9 | 184 local package="$1" |
meshca@9 | 185 shift 1 |
meshca@9 | 186 local depends="$@" |
pankso@10 | 187 |
meshca@9 | 188 local deps=0 |
meshca@9 | 189 local missing |
pankso@10 | 190 |
paul@12 | 191 # Calculate missing dependencies |
meshca@9 | 192 for pkgorg in $depends; do |
meshca@9 | 193 local pkg=$(equivalent_pkg $pkgorg) |
pankso@18 | 194 if [ ! -d "$installed/$pkg" ]; then |
pankso@30 | 195 gettext "Missing:"; echo " $pkg" |
meshca@9 | 196 deps=$(($deps+1)) |
pankso@18 | 197 elif [ ! -f "$installed/$pkg/receipt" ]; then |
pankso@56 | 198 gettext "WARNING: Dependency loop between:"; newline |
pankso@56 | 199 echo " $package --> $pkg" |
meshca@9 | 200 fi |
meshca@9 | 201 done |
pankso@14 | 202 |
pankso@53 | 203 gettext "Missing dependencies:"; echo " $(colorize "$deps" 34)" |
pankso@10 | 204 |
meshca@9 | 205 # Return true if missing deps |
meshca@9 | 206 [ "$deps" != "0" ] |
meshca@9 | 207 } |
meshca@11 | 208 |
meshca@11 | 209 grepesc() { |
meshca@11 | 210 sed 's/\[/\\[/g' |
meshca@11 | 211 } |
meshca@11 | 212 |
pankso@27 | 213 # Check for ELF file |
pankso@27 | 214 is_elf() { |
pankso@27 | 215 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] |
pankso@27 | 216 } |
pankso@66 | 217 |
pankso@66 | 218 # Exec functions directly for developement purpose. |
pankso@66 | 219 case $1 in |
pankso@66 | 220 *_*) func=$1 && shift && $func $@ ;; |
pankso@66 | 221 esac |