spk view spk @ rev 19

add: spk and some improvments
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 15 14:20:23 2012 +0200 (2012-05-15)
parents
children 7d060800df61
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")
29 $(boldify $(gettext "Options:"))
30 --block $(gettext "TODO")
31 --root $(gettext "Set the root file system path")
32 --debug $(gettext "Display some usefull debug information")
34 $(boldify $(gettext "Examples:"))
35 $name package1 package2 packageN
36 $name package --block
38 EOT
39 exit 0
40 }
42 #
43 # Commands and exit
44 #
46 case "$1" in
47 ""|*usage|*help) usage ;;
48 info)
49 newline
50 boldify "Spk Info"
51 separator
52 gettext "Database :"; echo " $installed"
53 gettext "Mirror URL :"; echo " $(cat $mirrorurl)"
54 count_installed
55 count_mirrored
56 separator
57 newline && exit 0 ;;
58 activity)
59 newline
60 boldify "Spk Activity"
61 separator
62 cat $activity
63 separator && newline
64 exit 0 ;;
65 ls|add)
66 # Sort of helper on wrong commands or --option ? Or have better
67 # usage/help: spk help [command] ?
68 gettext "Did you mean ?"; echo " spk-$@"
69 exit 0 ;;
70 esac
72 #
73 # Handle packages: spk package1 ... packageN
74 #
76 [ "$debug" ] && echo "DEBUG: cmdline: $0 $@"
77 count=0
79 for pkg in $@
80 do
81 # Handle: --options
82 case " $@ " in
83 *\ --rm\ *)
84 spk-rm $pkg --count=$count
85 count=$(($count + 1))
86 continue ;;
87 esac
88 count=$(($count + 1))
89 # Installed ?
90 if [ -d "$installed/$pkg" ]; then
91 [ "$count" == 1 ] && newline
92 unset_receipt
93 . $installed/$pkg/receipt
94 boldify "$(gettext "Package") $pkg"
95 separator
96 gettext "Status : installed"; newline
97 receipt_info
98 separator && newline
99 continue
100 fi
101 # Mirrored ?
102 mirrored=$(grep "^$pkg |" $pkgsdesc)
103 if [ "$mirrored" ]; then
104 # Handle: --add
105 if [ "$add" ]; then
106 echo "TODO: test 'spk-add $pkg'"
107 else
108 [ "$count" == 1 ] && newline
109 boldify "$(gettext "Package") $pkg"
110 separator
111 gettext "Status : not installed"; echo ""
112 echo "$mirrored" | awk 'BEGIN { FS = "|" } ; { print \
113 "Version :" $2 "\n" \
114 "Short desc :" $3 "\n" \
115 "Category :" $4 }'
116 separator && newline
117 fi
118 continue
119 fi
120 # Skip options such as --confirm or unknow package
121 case "$pkg" in
122 --*) continue ;;
123 *) gettext "Unknow package"; echo ": $pkg"
124 esac
125 done
126 exit 0