spk view spk @ rev 31

Tiny fixes and update Makefile
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 19:40:29 2012 +0200 (2012-05-15)
parents c067cf3860e1
children becb0314c7e1
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
11 #
12 # Functions
13 #
15 # Help and usage
16 usage() {
17 name=$(basename $0)
18 cat << EOT
20 $(boldify $(gettext "Usage:")) $name [packages|--options]
22 $(gettext "SliTaz Packages toolset")
24 $(boldify $(gettext "Commands:"))
25 info $(gettext "Display path, mirror and other stats")
26 activity $(gettext "Display packages activities")
28 $(boldify $(gettext "Options:"))
29 --add $(gettext "Install packages if mirrored")
30 --rm $(gettext "Remove installed packages")
31 --block $(gettext "Add packages to the blocked list")
32 --unblock $(gettext "Remove packages from the blocked list")
33 --root $(gettext "Set the root file system path")
34 --debug $(gettext "Display some usefull debug information")
36 $(boldify $(gettext "Examples:"))
37 $name package1 package2 packageN
38 $name package package2 --block
40 EOT
41 exit 0
42 }
44 #
45 # Commands and exit
46 #
48 case "$1" in
49 ""|*usage|*help) usage ;;
50 info)
51 newline
52 boldify "Spk Info"
53 separator
54 gettext "Database :"; echo " $installed"
55 gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
56 count_installed
57 count_mirrored
58 separator
59 newline && exit 0 ;;
60 activity)
61 newline
62 boldify "Spk Activity"
63 separator
64 cat $activity
65 separator && newline
66 exit 0 ;;
67 esac
69 #
70 # Handle packages: spk package1 ... packageN
71 #
73 [ "$debug" ] && echo "DEBUG: cmdline: $0 $@"
74 count=0
76 for pkg in $@
77 do
78 # Installed ?
79 if [ -d "$installed/$pkg" ]; then
80 # Handle: --options
81 case " $@ " in
82 *\ --block\ *)
83 check_root
84 [ -d "$installed/$pkg" ] || continue
85 if grep -qs ^${pkg}$ $blocked; then
86 echo -n "$(boldify "$pkg") "
87 gettext "is already blocked"; newline
88 else
89 gettext "Blocking package:"; echo -n " $pkg"
90 echo $pkg >> $blocked
91 log "Blocked package: $pkg" && status
92 fi
93 continue ;;
94 *\ --unblock\ *)
95 check_root
96 [ -d "$installed/$pkg" ] || continue
97 if grep -qs ^${pkg}$ $blocked; then
98 gettext "Unblocking package:"; echo -n " $pkg"
99 sed -i /"^${pkg}$"/d $blocked
100 log "Unblocked package: $pkg" && status
101 else
102 echo -n "$(boldify "$pkg") "
103 gettext "is not blocked"; newline
104 fi
105 continue ;;
106 *\ --rm\ *)
107 [ -d "$installed/$pkg" ] || continue
108 spk-rm $pkg --count=$count
109 count=$(($count + 1))
110 continue ;;
111 esac
112 count=$(($count + 1))
113 [ "$count" == 1 ] && newline
114 unset_receipt
115 . $installed/$pkg/receipt
116 boldify "$(gettext "Package") $pkg"
117 separator
118 gettext "Status :"; colorize " installed" 32
119 receipt_info
120 separator && newline
121 continue
122 fi
123 # Mirrored ?
124 mirrored=$(grep "^$pkg |" $pkgsdesc)
125 if [ "$mirrored" ]; then
126 # Handle: --options
127 case " $@ " in
128 *\ --add\ *)
129 echo "TODO: test 'spk-add $pkg'"
130 continue ;;
131 esac
132 count=$(($count + 1))
133 [ "$count" == 1 ] && newline
134 boldify "$(gettext "Package") $pkg"
135 separator
136 gettext "Status :"; colorize " not installed" 31
137 echo "$mirrored" | awk 'BEGIN { FS = "|" } ; { print \
138 "Version :" $2 "\n" \
139 "Short desc :" $3 "\n" \
140 "Category :" $4 }'
141 separator && newline
142 continue
143 fi
144 # Skip options such as --confirm or unknow package
145 case "$pkg" in
146 --*) continue ;;
147 *) gettext "WARNING: Unknow package"; echo ": $pkg"
148 esac
149 done
150 exit 0