spk view spk @ rev 140

spk: add reconf command
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 05 05:01:56 2014 +0200 (2014-04-05)
parents 365a7811faf7
children 1ab690b993b4
line source
1 #!/bin/sh
2 #
3 # Spk - The SliTaz Packages toolset. Read the README before adding or
4 # modifying 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.3
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")
31 reconf $(gettext "Reconfigure an installed packages")
33 $(boldify $(gettext "Options:"))
34 --add $(gettext "Install packages if mirrored")
35 --rm $(gettext "Remove installed packages")
36 --get $(gettext "Download packages specified on cmdline")
37 --block $(gettext "Add packages to the blocked list")
38 --unblock $(gettext "Remove packages from the blocked list")
39 --log $(gettext "Show package install and upgrade log")
40 --cache $(gettext "Used with --get to download in cache")
41 --forced $(gettext "Force packages reinstall or download")
42 --root= $(gettext "Set the root file system path")
43 --debug $(gettext "Display some useful debug information")
45 $(boldify $(gettext "Examples:"))
46 $name package1 package2 packageN
47 $name package package2 --block
49 EOT
50 exit 0
51 }
53 #
54 # Commands and exit
55 #
57 case "$1" in
58 ""|*usage|*help) usage ;;
59 info)
60 cache="$(du -sh $CACHE_DIR | awk '{print $1 " " $2}')"
61 extra=$(ls $extradb | wc -l)
62 newline
63 boldify "Spk info"
64 separator
65 gettext "Architecture :"; echo " $SLITAZ_ARCH"
66 gettext "Database :"; echo " $installed"
67 gettext "Cache info :"; echo " $cache"
68 gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
69 gettext "Extra mirrors :"; echo " $extra"
70 count_installed
71 count_mirrored
72 separator && newline
73 exit 0 ;;
74 activity)
75 # --lines=NB
76 : ${lines=18}
77 newline
78 boldify "Spk Activity"
79 separator
80 cat $activity | tail -n $lines
81 separator && newline
82 exit 0 ;;
83 clean)
84 newline
85 boldify "Spk Clean"
86 separator
87 size=$(du -sh $CACHE_DIR | awk '{print $1}')
88 gettext "Cleaning cache:"; echo -n " $CACHE_DIR ($size)"
89 rm -rf $CACHE_DIR/* && status
90 gettext "Cleaning tmp :"; echo -n " $(dirname $tmpdir)"
91 rm -rf $(dirname $tmpdir) && status
92 separator && newline
93 exit 0 ;;
94 reconf|reconfigure)
95 packages="$@"
96 [ "$all" ] && packages=$(ls $installed)
97 for pkg in ${packages}
98 do
99 receipt="$installed/$pkg/receipt"
100 [ ! -f "$receipt" ] && continue
101 if grep -q ^post_install ${receipt}; then
102 gettext "Configuring packages:"; echo " $pkg"
103 . ${receipt}
104 post_install
105 fi
106 done && exit 0 ;;
107 esac
109 #
110 # Handle packages: spk package1 ... packageN
111 #
113 #debug "cmdline: $@"
114 count=0
116 for pkg in $@
117 do
118 # Handle general: --options
119 case " $@ " in
120 *\ --get\ *)
121 # We want: package-version.tazpkg
122 package_full=$(full_package $pkg)
123 mirrored_pkg $pkg
124 [ "$mirrored" ] || continue
125 [ "$count" == 0 ] && newline
126 count=$(($count + 1))
127 download $package_full $mirror
128 unset_mirrored
129 if [ ! "$cache" ]; then
130 gettext "Moving package to current directory..."
131 mv -f "$CACHE_DIR/$package_full" .
132 status
133 fi
134 newline && continue ;;
135 esac
136 # Installed ?
137 if [ -d "$installed/$pkg" ]; then
138 # Handle: --options
139 case " $@ " in
140 *\ --block\ *)
141 check_root
142 [ -d "$installed/$pkg" ] || continue
143 if grep -qs ^${pkg}$ $blocked; then
144 echo $(boldify $pkg) $(gettext "is already blocked")
145 else
146 gettext "Blocking package:"; echo -n " $pkg"
147 echo $pkg >> $blocked
148 log "Blocked package: $pkg" && status
149 fi
150 continue ;;
151 *\ --unblock\ *)
152 check_root
153 [ -d "$installed/$pkg" ] || continue
154 if grep -qs ^${pkg}$ $blocked; then
155 gettext "Unblocking package:"; echo -n " $pkg"
156 sed -i /"^${pkg}$"/d $blocked
157 log "Unblocked package: $pkg" && status
158 else
159 echo $(boldify $pkg) $(gettext "is not blocked")
160 fi
161 continue ;;
162 *\ --rm\ *)
163 is_package_installed $pkg || continue
164 spk-rm $pkg --count=$count
165 count=$(($count + 1))
166 continue ;;
167 *\ --log\ *)
168 # Display package's log
169 if [ -f "$logdir/$pkg/install.log" ]; then
170 count=$(($count + 1))
171 [ "$count" == "1" ] && newline
172 colorize 36 $(gettext "Install log for:"; echo " $pkg")
173 separator
174 cat $logdir/$pkg/install.log
175 else
176 gettext "Any install log for:"; boldify " $pkg"
177 fi
178 if [ -f "$logdir/$pkg/up.log" ]; then
179 colorize 36 $(gettext "Upgrade log for:"; echo " $pkg")
180 separator
181 cat $logdir/$pkg/up.log
182 else
183 colorize 36 $(gettext "Any upgrade log for:"; echo " $pkg")
184 newline
185 fi
186 continue ;;
187 *\ --extract\ *)
188 newline
189 echo $(boldify $(gettext "Extracting:")) $pkg
190 separator ;;
191 *\ --forced\ *)
192 spk-add --forced $pkg --count=$count
193 count=$(($count + 1))
194 continue ;;
195 esac
196 count=$(($count + 1))
197 [ "$count" == 1 ] && newline
198 unset_receipt
199 source_receipt $installed/$pkg/receipt
200 boldify $(gettext "Package") $pkg
201 separator
202 gettext "Status :"; colorize 32 " installed"
203 receipt_info
204 separator && newline
205 continue
206 fi
207 # Mirrored ?
208 mirrored_pkg $pkg
209 if [ "$mirrored" ]; then
210 # Handle mirrored: --options
211 case " $@ " in
212 *\ --add\ *)
213 spk-add $pkg --count=$count
214 count=$(($count + 1))
215 continue ;;
216 esac
217 count=$(($count + 1))
218 [ "$count" == 1 ] && newline
219 boldify $(gettext "Package") $pkg
220 separator
221 gettext "Status :"; colorize 31 " not installed"
222 gettext "Version :"; echo "$mirrored" | cut -d '|' -f 2
223 gettext "Short desc :"; echo "$mirrored" | cut -d '|' -f 3
224 gettext "Category :"; echo "$mirrored" | cut -d '|' -f 4
225 separator && newline
226 continue
227 fi
228 unset mirrored
229 # Skip options such as --confirm or unknown package
230 case "$pkg" in
231 --*) continue ;;
232 *) gettext "WARNING: Unknown package"; echo ": $pkg"
233 esac
234 done
235 exit 0