sup view sup @ rev 21

Small typo and up a bit of the french translation (to test i18n functions)
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 26 21:20:25 2017 +0100 (2017-02-26)
parents c0a780b534c2
children 361b8459a302
line source
1 #!/bin/sh
2 #
3 # SliTaz Users Package - Minimal cmdline tools - README for devel info
4 #
5 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
8 if [ -f "/usr/lib/slitaz/libsup.sh" ]; then
9 . /usr/lib/slitaz/libsup.sh
10 fi
11 # Devel mode
12 if [ -f "./libsup.sh" ]; then
13 . ./libsup.sh
14 fi
16 # Sanity check
17 if ! [ -d "/home/$(id -un)" ]; then
18 gettext "Not a valid user:"; colorize 31 " $(id -un)" && exit 1
19 fi
20 mkdir -p ${cache} ${installed}
22 #
23 # Functions
24 #
26 help() {
27 cat << EOT
29 $(boldify $(gettext "Usage:")) $(basename $0) [command|package] [package]
31 $(boldify $(gettext "Commands:"))
32 -c cook $(gettext "Cook a package from the wok")
33 -e extract $(gettext "Extract a package to current dir")
34 -i install $(gettext "Install a sup package")
35 -r remove $(gettext "Remove package files")
36 -l list $(gettext "List installed packages and your wok")
38 $(boldify $(gettext "Options:"))
39 --init cook $(gettext "Initialize sup cook environment")
40 --verbose all $(gettext "Display more output messages")
42 EOT
43 exit 0
44 }
46 cook_init() {
47 mkdir -p ${wok} ${cooked}
48 if [ ! -d "$supcook/wok" ]; then
49 ln -s ${wok} ${supcook}/wok
50 fi
51 }
53 # new_receipt "package"
54 new_receip() {
55 cat > receip << EOT
56 # SliTaz User Package receipt
58 PACKAGE="$1"
59 VERSION=""
60 SHORT_DESC=""
61 MAINTAINER=""
62 LICENSE=""
63 WEB_SITE=""
65 # Sup dependencies will be automatically downloaded but system wide
66 # deps must be manually installed by root.
67 SUP_DEPS=""
68 DEPENDS=""
70 # Here are the optional install rules (download, configure, etc)
71 sup_install() {
72 echo ""
73 }
75 EOT
76 }
78 #
79 # Commands
80 #
82 case "$1" in
84 -c|cook)
85 # Cook in $cache/cook amd mv pkg to a visible dir
86 pkg="$2"
87 receip="$wok/$pkg/receip"
88 cache="$cache/cook"
90 # Handle --init
91 if [ "$init" ]; then
92 gettext "Initializing sup cook environment..."
93 cook_init
94 status && exit 0
95 fi
97 # Sanity check
98 if [ ! "$pkg" ]; then
99 gettext "You must specify a package to cook:"
100 boldify " sup $1 [package]" && exit 1
101 fi
102 if [ ! -f "$receip" ]; then
103 gettext "Can't find receip in wok for:"
104 colorize 31 " $pkg" && exit 1
105 fi
107 newline
108 gettext "Building package:"; colorize 36 " $pkg"
109 separator
110 rm -rf ${cache} && mkdir -p ${cache} ${cooked}
112 # Check receip
113 [ "$verbose" ] && gettext "Checking receip variables..."
114 . ${receip}
115 for var in PACKAGE VERSION SHORT_DESC MAINTAINER LICENSE WEB_SITE
116 do
117 value="$(. $receip; eval echo \$$var)"
118 case "$var" in
119 PACKAGE|VERSION|SHORT_DESC|MAINTAINER|LICENSE)
120 if [ ! "$value" ]; then
121 gettext "Empty variable:"; colorize 31 " $var=\"\""
122 exit 1
123 fi ;;
124 WEB_SITE)
125 if [ ! "$value" ]; then
126 gettext "Empty variable:"; colorize 31 " $var=\"\""
127 gettext "You can use:"
128 boldify " http://scn.slitaz.org/?sup&pkg=$PACKAGE"
129 exit 1
130 fi ;;
131 esac
132 done
133 [ "$verbose" ] && status
135 # Set $PACKAGE-$VERSION.sup and copy pkg to cache
136 supfile="$PACKAGE-$VERSION.sup"
137 cp -rf ${wok}/${pkg} ${cache}/${supfile%.sup}
138 cd ${cache}/${supfile%.sup}
140 # Move to hidden dir: ~/.local and ~/.config
141 for dir in local config; do
142 mv files/${dir} files/.${dir}
143 done
145 # Add $build_date
146 echo "build_date=\"$(date "+%Y-%m-%d %H:%M")\"" >> ${receip}
148 gettext "Creating compressed archive..."
149 find files | cpio -o -H newc --quiet | lzma e files.lzma -si
150 rm -rf files
151 find . -print | cpio -o -H newc --quiet > ${cooked}/${supfile}
152 status
154 size="$(du -sh $cooked/$supfile | cut -d " " -f 1)"
155 echo "$(gettext 'Packages:') $(colorize 33 $supfile) ($size)"
156 sed -i "/^build_date=/"d ${receip}
157 rm -rf ${cache} && newline ;;
159 -e|extract)
160 # Extract package.sup to current dir
161 pkg="$2"
163 # Sanity check
164 if [ ! "$pkg" ]; then
165 gettext "Missing package file in argument:"
166 colorize 35 " sup $1 [package.sup]" && exit 1
167 fi
168 if [ ! -f "$pkg" ]; then
169 gettext "Can't find package file:"; colorize 35 " $pkg" && exit 1
170 fi
172 newline
173 gettext "Extract package:"; colorize 36 " $(basename $pkg)"
174 separator
176 extract_sup "$pkg"
178 echo "$(gettext 'Packages:') $(colorize 33 $pkg) ($size)"
179 newline ;;
181 -i|install)
182 # Download/extract run install() in $cache/install
183 pkg="$2"
185 if [ ! "$pkg" ]; then
186 gettext "Missing package name or file in argument:"
187 boldify " sup $1 [package] or [file.sup]" && exit 1
188 fi
190 # Sup pkg in current dir
191 if [ -f "$pkg" ]; then
192 install_sup "$pkg" && exit 0
193 fi
195 # Sup cooked from wok
196 if [ -f "$wok/$pkg/receip" ]; then
197 . $wok/$pkg/receip
198 if [ -f "$cooked/$PACKAGE-$VERSION.sup" ]; then
199 install_sup "$cooked/$PACKAGE-$VERSION.sup" && exit 0
200 fi
201 fi
203 # Sup on mirror
204 echo "TODO: check for package on mirror"
206 gettext "Can't find sup package:"; colorize 31 " $pkg" ;;
208 -r|remove)
209 # Remove a package
210 pkg="$2"
212 if [ ! "$pkg" ]; then
213 gettext "Missing package name in argument:"
214 boldify " sup $1 [package]" && exit 1
215 fi
217 if [ -d "$installed/$pkg" ]; then
218 remove_sup "$pkg"
219 else
220 gettext "Can't find installed package:"; colorize 31 " $pkg"
221 exit 1
222 fi ;;
224 -l|list)
225 installed_nb=$(ls ${installed} | wc -l)
226 newline
227 echo -n "$(colorize 36 $(gettext 'Installed sup packages:'))"
228 boldify " $installed_nb"
229 separator
230 for pkg in $(ls ${installed}); do
231 . ${wok}/${pkg}/receip
232 echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
233 done
234 if [ "$installed_nb" == 0 ]; then
235 gettext "No sup packages installed"; echo
236 fi
237 newline
238 if [ -d "$wok" ]; then
239 echo -n "$(colorize 35 $(gettext 'Sup packages in your wok:'))"
240 boldify " $(ls ${wok} | wc -l)"
241 separator
242 for pkg in $(ls ${wok}); do
243 . ${wok}/${pkg}/receip
244 echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
245 done
246 newline
247 fi ;;
249 ""|-h|help) help ;;
251 *)
252 # Display pkg info if installed
253 pkg="$1"
254 if [ -f "$installed/$pkg/receip" ]; then
255 . ${installed}/${pkg}/receip
256 newline
257 gettext "Installed package:"; colorize 36 " $PACKAGE $VERSION"
258 separator
259 echo "Short desc: $SHORT_DESC"
260 echo ""
261 boldify "$(gettext 'Installed files:') ($sup_size)"
262 cat ${installed}/${pkg}/files.list
263 newline
264 else
265 gettext "Can't find installed package:"; colorize 31 " $pkg"
266 fi ;;
268 esac && exit 0