spk view spk @ rev 67

libspk.sh and spk-add: better but not finished download function, spk: add option --get and command clean
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 18 19:23:52 2012 +0200 (2012-05-18)
parents 63fb720dc777
children d1790128faac
line source
1 #!/bin/sh
2 #
3 # Spk - The SliTaz Packages toolset. Read the README before adding or
4 # modifing any code in spk!
5 #
6 # Copyright (C) SliTaz GNU/Linux - BSD License
7 # Author: See AUTHORS files
8 #
9 #. /usr/lib/slitaz/libspk.sh
10 . lib/libspk.sh
12 #
13 # Functions
14 #
16 # Help and usage
17 usage() {
18 name=$(basename $0)
19 cat << EOT
21 $(boldify $(gettext "Usage:")) $name [packages|--options]
23 $(gettext "SliTaz Packages toolset")
25 $(boldify $(gettext "Commands:"))
26 info $(gettext "Display path, mirror and other stats")
27 activity $(gettext "Display packages activities")
28 clean $(gettext "Clean cache and temporary files")
30 $(boldify $(gettext "Options:"))
31 --add $(gettext "Install packages if mirrored")
32 --rm $(gettext "Remove installed packages")
33 --get $(gettext "Download packages specified on cmdline")
34 --block $(gettext "Add packages to the blocked list")
35 --unblock $(gettext "Remove packages from the blocked list")
36 --log $(gettext "Show package install and upgrade log")
37 --cache $(gettext "Used with --get to download in cache")
38 --forced $(gettext "Force packages reinstall or download")
39 --root= $(gettext "Set the root file system path")
40 --debug $(gettext "Display some usefull debug information")
42 $(boldify $(gettext "Examples:"))
43 $name package1 package2 packageN
44 $name package package2 --block
46 EOT
47 exit 0
48 }
50 #
51 # Commands and exit
52 #
54 case "$1" in
55 ""|*usage|*help) usage ;;
56 info)
57 cache="$(du -sh $CACHE_DIR | awk '{print $1 " " $2}')"
58 extra=$(ls $extradb | wc -l)
59 newline
60 boldify "Spk info"
61 separator
62 gettext "Architecture :"; echo " $SLITAZ_ARCH"
63 gettext "Database :"; echo " $installed"
64 gettext "Cache info :"; echo " $cache"
65 gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
66 gettext "Extra mirrors :"; echo " $extra"
67 count_installed
68 count_mirrored
69 separator
70 newline && exit 0 ;;
71 activity)
72 # --lines=NB
73 : ${lines=18}
74 newline
75 boldify "Spk Activity"
76 separator
77 cat $activity | tail -n $lines
78 separator && newline
79 exit 0 ;;
80 clean)
81 newline
82 boldify "Spk Clean"
83 separator
84 size=$(du -sh $CACHE_DIR | awk '{print $1}')
85 gettext "Cleaning cache:"; echo -n " $CACHE_DIR ($size)"
86 rm -rf $CACHE_DIR/* && status
87 gettext "Cleaning tmp :"; echo -n " $(dirname $tmpdir)"
88 rm -rf $(dirname $tmpdir) && status
89 separator && newline
90 exit 0 ;;
91 esac
93 #
94 # Handle packages: spk package1 ... packageN
95 #
97 #debug "cmdline: $@"
98 count=0
100 for pkg in $@
101 do
102 # Handle general: --options
103 case " $@ " in
104 *\ --get\ *)
105 # We want: package-version.tazpkg
106 package_full=$(full_package $pkg)
107 mirrored_pkg $pkg
108 [ "$mirrored" ] || continue
109 [ "$count" == 0 ] && newline
110 count=$(($count + 1))
111 download $package_full $mirror
112 unset mirrored mirror db
113 newline && continue ;;
114 esac
115 # Installed ?
116 if [ -d "$installed/$pkg" ]; then
117 # Handle: --options
118 case " $@ " in
119 *\ --block\ *)
120 check_root
121 [ -d "$installed/$pkg" ] || continue
122 if grep -qs ^${pkg}$ $blocked; then
123 echo -n "$(boldify "$pkg") "
124 gettext "is already blocked"; newline
125 else
126 gettext "Blocking package:"; echo -n " $pkg"
127 echo $pkg >> $blocked
128 log "Blocked package: $pkg" && status
129 fi && continue ;;
130 *\ --unblock\ *)
131 check_root
132 [ -d "$installed/$pkg" ] || continue
133 if grep -qs ^${pkg}$ $blocked; then
134 gettext "Unblocking package:"; echo -n " $pkg"
135 sed -i /"^${pkg}$"/d $blocked
136 log "Unblocked package: $pkg" && status
137 else
138 echo -n "$(boldify "$pkg") "
139 gettext "is not blocked"; newline
140 fi && continue ;;
141 *\ --rm\ *)
142 [ -d "$installed/$pkg" ] || continue
143 spk-rm $pkg --count=$count
144 count=$(($count + 1))
145 continue ;;
146 *\ --log\ *)
147 # Display packges log's
148 if [ -f "$logdir/$pkg/install.log" ]; then
149 count=$(($count + 1))
150 [ "$count" == "1" ] && newline
151 colorize "$(gettext "Install log for:"; echo " $pkg")" 36
152 separator
153 cat $logdir/$pkg/install.log
154 else
155 gettext "Any install log for:"; boldify " $pkg"
156 fi
157 if [ -f "$logdir/$pkg/up.log" ]; then
158 colorize "$(gettext "Upgrade log for:"; echo " $pkg")" 36
159 separator
160 cat $logdir/$pkg/up.log
161 else
162 colorize "$(gettext "Any upgrade log for:"; echo " $pkg")" 36
163 newline
164 fi && continue ;;
165 esac
166 count=$(($count + 1))
167 [ "$count" == 1 ] && newline
168 unset_receipt
169 . $installed/$pkg/receipt
170 boldify "$(gettext "Package") $pkg"
171 separator
172 gettext "Status :"; colorize " installed" 32
173 receipt_info
174 separator && newline
175 continue
176 fi
177 # Mirrored ?
178 mirrored_pkg $pkg
179 if [ "$mirrored" ]; then
180 # Handle mirrored: --options
181 case " $@ " in
182 *\ --add\ *)
183 spk-add $pkg --count=$count
184 count=$(($count + 1))
185 continue ;;
186 esac
187 count=$(($count + 1))
188 [ "$count" == 1 ] && newline
189 boldify "$(gettext "Package") $pkg"
190 separator
191 gettext "Status :"; colorize " not installed" 31
192 echo "$mirrored" | awk 'BEGIN { FS = "|" } ; { print \
193 "Version :" $2 "\n" \
194 "Short desc :" $3 "\n" \
195 "Category :" $4 }'
196 separator && newline
197 continue
198 fi
199 unset mirrored
200 # Skip options such as --confirm or unknow package
201 case "$pkg" in
202 --*) continue ;;
203 *) gettext "WARNING: Unknow package"; echo ": $pkg"
204 esac
205 done
206 exit 0