spk view spk @ rev 124

spk:add
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Thu Jan 17 12:32:03 2013 +0100 (2013-01-17)
parents 4e691d670d5b
children ee5a53b16e51
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 VERSION=1.0
18 # Help and usage
19 usage() {
20 name=$(basename $0)
21 cat << EOT
23 $(boldify $(gettext "Usage:")) $name [packages|--options]
25 $(gettext "SliTaz Packages toolset v$VERSION")
27 $(boldify $(gettext "Commands:"))
28 info $(gettext "Display path, mirror and other stats")
29 activity $(gettext "Display packages activities")
30 clean $(gettext "Clean cache and temporary files")
32 $(boldify $(gettext "Options:"))
33 --add $(gettext "Install packages if mirrored")
34 --rm $(gettext "Remove installed packages")
35 --get $(gettext "Download packages specified on cmdline")
36 --block $(gettext "Add packages to the blocked list")
37 --unblock $(gettext "Remove packages from the blocked list")
38 --log $(gettext "Show package install and upgrade log")
39 --cache $(gettext "Used with --get to download in cache")
40 --forced $(gettext "Force packages reinstall or download")
41 --root= $(gettext "Set the root file system path")
42 --debug $(gettext "Display some useful debug information")
44 $(boldify $(gettext "Examples:"))
45 $name package1 package2 packageN
46 $name package package2 --block
48 EOT
49 exit 0
50 }
52 #
53 # Commands and exit
54 #
56 case "$1" in
57 ""|*usage|*help) usage ;;
58 info)
59 cache="$(du -sh $CACHE_DIR | awk '{print $1 " " $2}')"
60 extra=$(ls $extradb | wc -l)
61 newline
62 boldify "Spk info"
63 separator
64 gettext "Architecture :"; echo " $SLITAZ_ARCH"
65 gettext "Database :"; echo " $installed"
66 gettext "Cache info :"; echo " $cache"
67 gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
68 gettext "Extra mirrors :"; echo " $extra"
69 count_installed
70 count_mirrored
71 separator && newline
72 exit 0 ;;
73 activity)
74 # --lines=NB
75 : ${lines=18}
76 newline
77 boldify "Spk Activity"
78 separator
79 cat $activity | tail -n $lines
80 separator && newline
81 exit 0 ;;
82 clean)
83 newline
84 boldify "Spk Clean"
85 separator
86 size=$(du -sh $CACHE_DIR | awk '{print $1}')
87 gettext "Cleaning cache:"; echo -n " $CACHE_DIR ($size)"
88 rm -rf $CACHE_DIR/* && status
89 gettext "Cleaning tmp :"; echo -n " $(dirname $tmpdir)"
90 rm -rf $(dirname $tmpdir) && status
91 separator && newline
92 exit 0 ;;
93 esac
95 #
96 # Handle packages: spk package1 ... packageN
97 #
99 #debug "cmdline: $@"
100 count=0
102 for pkg in $@
103 do
104 # Handle general: --options
105 case " $@ " in
106 *\ --get\ *)
107 # We want: package-version.tazpkg
108 package_full=$(full_package $pkg)
109 mirrored_pkg $pkg
110 [ "$mirrored" ] || continue
111 [ "$count" == 0 ] && newline
112 count=$(($count + 1))
113 download $package_full $mirror
114 unset_mirrored
115 newline && continue ;;
116 esac
117 # Installed ?
118 if [ -d "$installed/$pkg" ]; then
119 # Handle: --options
120 case " $@ " in
121 *\ --block\ *)
122 check_root
123 [ -d "$installed/$pkg" ] || continue
124 if grep -qs ^${pkg}$ $blocked; then
125 echo $(boldify $pkg) $(gettext "is already blocked")
126 else
127 gettext "Blocking package:"; echo -n " $pkg"
128 echo $pkg >> $blocked
129 log "Blocked package: $pkg" && status
130 fi
131 continue ;;
132 *\ --unblock\ *)
133 check_root
134 [ -d "$installed/$pkg" ] || continue
135 if grep -qs ^${pkg}$ $blocked; then
136 gettext "Unblocking package:"; echo -n " $pkg"
137 sed -i /"^${pkg}$"/d $blocked
138 log "Unblocked package: $pkg" && status
139 else
140 echo $(boldify $pkg) $(gettext "is not blocked")
141 fi
142 continue ;;
143 *\ --rm\ *)
144 is_package_installed $pkg || continue
145 spk-rm $pkg --count=$count
146 count=$(($count + 1))
147 continue ;;
148 *\ --log\ *)
149 # Display package's log
150 if [ -f "$logdir/$pkg/install.log" ]; then
151 count=$(($count + 1))
152 [ "$count" == "1" ] && newline
153 colorize 36 $(gettext "Install log for:"; echo " $pkg")
154 separator
155 cat $logdir/$pkg/install.log
156 else
157 gettext "Any install log for:"; boldify " $pkg"
158 fi
159 if [ -f "$logdir/$pkg/up.log" ]; then
160 colorize 36 $(gettext "Upgrade log for:"; echo " $pkg")
161 separator
162 cat $logdir/$pkg/up.log
163 else
164 colorize 36 $(gettext "Any upgrade log for:"; echo " $pkg")
165 newline
166 fi
167 continue ;;
168 *\ --extract\ *)
169 newline
170 echo $(boldify $(gettext "Extracting:")) $pkg
171 separator ;;
172 *\ --forced\ *)
173 spk-add --forced $pkg --count=$count
174 count=$(($count + 1))
175 continue ;;
176 esac
177 count=$(($count + 1))
178 [ "$count" == 1 ] && newline
179 unset_receipt
180 source_receipt $installed/$pkg/receipt
181 boldify $(gettext "Package") $pkg
182 separator
183 gettext "Status :"; colorize 32 " installed"
184 receipt_info
185 separator && newline
186 continue
187 fi
188 # Mirrored ?
189 mirrored_pkg $pkg
190 if [ "$mirrored" ]; then
191 # Handle mirrored: --options
192 case " $@ " in
193 *\ --add\ *)
194 spk-add $pkg --count=$count
195 count=$(($count + 1))
196 continue ;;
197 esac
198 count=$(($count + 1))
199 [ "$count" == 1 ] && newline
200 boldify $(gettext "Package") $pkg
201 separator
202 gettext "Status :"; colorize 31 " not installed"
203 gettext "Version :"; echo "$mirrored" | cut -d '|' -f 2
204 gettext "Short desc :"; echo "$mirrored" | cut -d '|' -f 3
205 gettext "Category :"; echo "$mirrored" | cut -d '|' -f 4
206 separator && newline
207 continue
208 fi
209 unset mirrored
210 # Skip options such as --confirm or unknown package
211 case "$pkg" in
212 --*) continue ;;
213 *) gettext "WARNING: Unknown package"; echo ": $pkg"
214 esac
215 done
216 exit 0