spk view spk @ rev 108

spk: Add --forced support. Someone must have forgot this.
author Christopher Rogers <slaxemulator@gmail.com>
date Tue Jun 05 16:57:50 2012 +0000 (2012-06-05)
parents 8bcd11c1cc91
children a3e324588d24
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 useful 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 && newline
70 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
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 $(boldify $pkg) $(gettext "is already blocked")
124 else
125 gettext "Blocking package:"; echo -n " $pkg"
126 echo $pkg >> $blocked
127 log "Blocked package: $pkg" && status
128 fi
129 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 $(boldify $pkg) $(gettext "is not blocked")
139 fi
140 continue ;;
141 *\ --rm\ *)
142 is_package_installed $pkg || continue
143 spk-rm $pkg --count=$count
144 count=$(($count + 1))
145 continue ;;
146 *\ --log\ *)
147 # Display package's log
148 if [ -f "$logdir/$pkg/install.log" ]; then
149 count=$(($count + 1))
150 [ "$count" == "1" ] && newline
151 colorize 36 $(gettext "Install log for:"; echo " $pkg")
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 36 $(gettext "Upgrade log for:"; echo " $pkg")
159 separator
160 cat $logdir/$pkg/up.log
161 else
162 colorize 36 $(gettext "Any upgrade log for:"; echo " $pkg")
163 newline
164 fi
165 continue ;;
166 *\ --extract\ *)
167 newline
168 echo $(boldify $(gettext "Extracting:")) $pkg
169 separator ;;
170 *\ --forced\ *)
171 spk-add --forced $pkg --count=$count
172 count=$(($count + 1))
173 continue ;;
174 esac
175 count=$(($count + 1))
176 [ "$count" == 1 ] && newline
177 unset_receipt
178 source_receipt $installed/$pkg/receipt
179 boldify $(gettext "Package") $pkg
180 separator
181 gettext "Status :"; colorize 32 " installed"
182 receipt_info
183 separator && newline
184 continue
185 fi
186 # Mirrored ?
187 mirrored_pkg $pkg
188 if [ "$mirrored" ]; then
189 # Handle mirrored: --options
190 case " $@ " in
191 *\ --add\ *)
192 spk-add $pkg --count=$count
193 count=$(($count + 1))
194 continue ;;
195 esac
196 count=$(($count + 1))
197 [ "$count" == 1 ] && newline
198 boldify $(gettext "Package") $pkg
199 separator
200 gettext "Status :"; colorize 31 " not installed"
201 gettext "Version :"; echo "$mirrored" | cut -d '|' -f 2
202 gettext "Short desc :"; echo "$mirrored" | cut -d '|' -f 3
203 gettext "Category :"; echo "$mirrored" | cut -d '|' -f 4
204 separator && newline
205 continue
206 fi
207 unset mirrored
208 # Skip options such as --confirm or unknown package
209 case "$pkg" in
210 --*) continue ;;
211 *) gettext "WARNING: Unknown package"; echo ": $pkg"
212 esac
213 done
214 exit 0