sup view sup @ rev 37

Add run command, small fixes, getting ready for initial release
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 28 20:35:45 2017 +0100 (2017-02-28)
parents f63ac3e0e9da
children d58ceb6b8fe9
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 #
9 # Get system wide libsup.sh or development version if working in Hg folder
10 if [ -f "/usr/lib/slitaz/libsup.sh" ]; then
11 . /usr/lib/slitaz/libsup.sh
12 fi
13 if [ -f "./libsup.sh" ]; then
14 . ./libsup.sh
15 fi
17 # Sanity check
18 if ! [ -d "/home/$(id -un)" ]; then
19 gettext "Not a valid user:"; colorize 31 " $(id -un)" && exit 1
20 fi
21 mkdir -p ${cache} ${installed}
23 #
24 # Functions
25 #
27 help() {
28 cat << EOT
30 $(boldify $(gettext "Usage:")) $(basename $0) [command|package] [package]
32 $(boldify $(gettext "Commands:"))
33 -c cook $(gettext "Cook a package from the wok")
34 -r run $(gettext "Run sup_install without installing")
35 -e extract $(gettext "Extract a package to current dir")
36 -i install $(gettext "Install a new package")
37 -u update $(gettext "Update installed package")
38 -r remove $(gettext "Remove package files")
39 -n new $(gettext "Create a new SUP package :-)")
40 -l list $(gettext "List installed packages in your wok")
42 $(boldify $(gettext "Options:"))
43 --install update $(gettext "Install all updates from mirror")
44 --force update $(gettext "Force recharging packages database")
45 --init cook $(gettext "Initialize sup cook environment")
46 --verbose all $(gettext "Display more output messages")
48 $(colorize 33 README) /usr/share/sup/README
49 $(colorize 33 Documentation) http://scn.slitaz.org/?d=en/sup
51 EOT
52 exit 0
53 }
55 cook_init() {
56 mkdir -p ${wok} ${cooked}
57 if [ ! -d "$supcook/wok" ]; then
58 ln -s ${wok} ${supcook}/wok
59 fi
60 }
62 # check_pkg_arg "command"
63 check_pkg_arg() {
64 if [ ! "$pkg" ]; then
65 gettext "Missing package name or file path:"
66 boldify " sup $1 [package|file.sup]" && exit 1
67 fi
68 }
70 # new_receip "package"
71 new_receip() {
72 cat > ${wok}/${1}/receip << EOT
73 # SliTaz User Package receip
75 PACKAGE="$1"
76 VERSION=""
77 SHORT_DESC=""
78 MAINTAINER=""
79 LICENSE=""
80 WEB_SITE=""
82 # Sup dependencies will be automatically downloaded but system wide
83 # deps must be manually installed by root.
84 SUP_DEPS=""
85 DEPENDS=""
87 # Here are the optional install rules (download, configure, etc)
88 sup_install() {
89 echo ""
90 }
92 EOT
93 }
95 #
96 # Commands
97 #
99 case "$1" in
101 -c|cook)
102 # Cook in $cache/cook and mv pkg to a visible dir
103 pkg="$2"
104 receip="$wok/$pkg/receip"
105 cache="$cache/cook"
107 # Handle --init
108 if [ "$init" ]; then
109 gettext "Initializing sup cook environment..."
110 cook_init; status; exit 0
111 fi
113 # Sanity check
114 check_pkg_arg "$1"
115 if [ ! -f "$receip" ]; then
116 gettext "Can't find receip in wok for:"; colorize 31 " $pkg"; exit 1
117 fi
119 newline
120 echo -n "$(colorize 33 $(gettext 'Building package:'))"
121 colorize 35 " $pkg"
122 separator
123 rm -rf ${cache} && mkdir -p ${cache} ${cooked}
125 # Check receip
126 [ "$verbose" ] && gettext "Checking receip variables..."
127 . ${receip}
128 for var in PACKAGE VERSION SHORT_DESC MAINTAINER LICENSE WEB_SITE
129 do
130 value="$(. $receip; eval echo \$$var)"
131 case "$var" in
132 PACKAGE|VERSION|SHORT_DESC|MAINTAINER|LICENSE)
133 if [ ! "$value" ]; then
134 gettext "Empty variable:"; colorize 31 " $var=\"\""
135 exit 1
136 fi ;;
137 WEB_SITE)
138 if [ ! "$value" ]; then
139 gettext "Empty variable:"; colorize 31 " $var=\"\""
140 gettext "You can use:"
141 boldify " http://scn.slitaz.org/?sup&pkg=$PACKAGE"
142 exit 1
143 fi ;;
144 esac
145 done
146 [ "$verbose" ] && status
148 # Set $PACKAGE-$VERSION.sup and copy pkg to cache
149 supfile="$PACKAGE-$VERSION.sup"
150 cp -rf ${wok}/${pkg} ${cache}/${supfile%.sup}
151 cd ${cache}/${supfile%.sup}
153 # Move to hidden dir: ~/.local ~/.config ~./icons
154 for dir in local config icons; do
155 [ -d "files/${dir}" ] && mv files/${dir} files/.${dir}
156 done
158 # Add $build_date
159 sed -i "/^build_date=/"d receip
160 echo "build_date=\"$(date "+%Y-%m-%d %H:%M")\"" >> receip
162 gettext "Creating compressed archive..."
163 find files | cpio -o -H newc --quiet | lzma e files.lzma -si
164 rm -rf files
165 find . -print | cpio -o -H newc --quiet > ${cooked}/${supfile}
166 status
168 size="$(du -sh $cooked/$supfile | cut -d " " -f 1)"
169 echo "$(gettext 'Packages:') $(colorize 035 $supfile) ($size)"
170 rm -rf ${cache} && newline ;;
172 -r|run)
173 # Run sup_install() without any installation to help package creation
174 pkg="$2"
175 receip="$wok/$pkg/receip"
176 work="$supcook/sup_install"
178 # Sanity check
179 check_pkg_arg "$1"
180 if [ ! -f "$receip" ]; then
181 gettext "Can't find receip in wok for:"; colorize 31 " $pkg"; exit 1
182 fi
184 newline
185 echo "$(colorize 33 $(gettext 'Running') sup_install\(\):) $(colorize 35 $pkg)"
186 separator
187 mkdir -p ${work} && cd ${work}
188 . ${wok}/${pkg}/receip
189 sup_install
190 separator
191 gettext "Working folder:"; echo " $work"
192 newline ;;
194 -n|new)
195 pkg="$2"
196 if [ ! "$pkg" ]; then
197 newline
198 gettext "New package name:"; echo -n " "; read pkg
199 fi
200 newline
201 [ ! "$pkg" ] && exit 0
202 [ ! -d "$wok" ] && cook_init
203 if [ -d "$wok/$pkg" ]; then
204 gettext "Package already exists in wok:"; colorize 35 " $pkg"
205 newline && exit 0
206 fi
207 gettext "Creating new package files and tree..."
208 mkdir -p ${wok}/${pkg}/files
209 new_receip "$pkg"; status
210 gettext "Executing your favorite editor..."
211 editor ${wok}/${pkg}/receip; status
212 gettext "To cook your package:"; colorize 33 " sup cook $pkg"
213 newline ;;
215 -e|extract)
216 # Extract package.sup to current dir
217 pkg="$2"
219 # Sanity check
220 check_pkg_arg "$1"
221 if [ ! -f "$pkg" ]; then
222 gettext "Can't find package file:"; colorize 31 " $pkg" && exit 1
223 fi
225 newline
226 echo -n "$(colorize 33 $(gettext 'Extract package:'))"
227 colorize 36 " $(basename $pkg)"
228 separator
230 extract_sup "$pkg"
232 echo "$(gettext 'Packages:') $(colorize 036 $pkg) ($size)"
233 newline ;;
235 -i|install)
236 # Download/extract run install() in $cache/install
237 pkg="$2"
238 check_pkg_arg "$1"
240 # Sup pkg in current dir
241 if [ -f "$pkg" ]; then
242 install_sup "$pkg" && exit 0
243 fi
245 # Sup cooked from wok
246 if [ -f "$wok/$pkg/receip" ]; then
247 . $wok/$pkg/receip
248 if [ -f "$cooked/$PACKAGE-$VERSION.sup" ]; then
249 install_sup "$cooked/$PACKAGE-$VERSION.sup" && exit 0
250 fi
251 fi
253 # Sup on mirror
254 [ ! -f "${pkgsdb}" ] && sup -u
256 if sqlite3 ${pkgsdb} "SELECT name FROM pkgs WHERE name = '$pkg'" >/dev/null
257 then
258 vers=$(sqlite3 ${pkgsdb} "SELECT version FROM pkgs WHERE name = '$pkg'")
259 mkdir -p ${cache}/wget && cd ${cache}/wget
260 # Download
261 newline
262 download "$pkg" "${mirror}/${pkg}-${vers}.sup"
263 install_sup "${pkg}-${vers}.sup"
264 rm -rf ${cache}/wget && exit 0
265 fi
266 gettext "Can't find sup package:"; colorize 31 " $pkg" ;;
268 -u|update)
269 # Update packages
270 online=""
271 newline
272 colorize 33 $(gettext "SUP Update")
273 separator
275 # Skip HTTP/1.1 404 Not Found: 2>/dev/null
276 if ! wget -q -T 5 --spider ${mirror}/packages.sql 2>/dev/null; then
277 gettext "Mirror is unreachable"; newline
278 else
279 online=0
280 fi
282 # Newer packages.sql ?
283 gettext "Checking packages.sql..."
284 db_sum=$(wget -q "${server}?sup=dbsum" -O -)
285 if echo "$db_sum $pkgsdb" | md5sum -s -c -; then
286 indent $(($(tty_size) - 13)) "[ $(colorize 036 synced) ]"
287 else
288 [ "$online" ] && rm -f ${pkgsdb}
289 indent $(($(tty_size) - 13)) "[ $(colorize 035 update) ]"
290 fi
292 # --force
293 [ "$force" ] && rm -f ${pkgsdb}
295 # No packages.sql: get latest!
296 if [ ! -f "$pkgsdb" ] && [ "$online" ]; then
298 download "db" "${mirror}/packages.sql" "${supdb}"
300 timestamp=$(sqlite3 ${pkgsdb} 'SELECT timestamp FROM info' \
301 | awk '{printf $1 " " $2}')
302 gettext "Database timestamp:"
303 indent $(($(tty_size) - 23)) "[ $(colorize 30 $timestamp) ]"
304 fi
306 # Scan installed packages
307 count="$(ls $installed | wc -l)"
308 char="$(echo $count | wc -L)"
309 in=$((7 + ${char}))
311 gettext "Installed packages:"
312 indent $(($(tty_size) - ${in})) "[ $(colorize 033 $count) ]"
313 cat << EOT
315 $(boldify $(gettext "Package") $(indent 30 $(gettext "Version")) \
316 $(indent 60 $(gettext "Status")))
317 $(separator "-")
318 EOT
319 for pkg in $(ls $installed)
320 do
321 . ${installed}/${pkg}/receip
322 db_sum=$(sqlite3 ${pkgsdb} \
323 "SELECT md5sum FROM pkgs WHERE name = '$pkg'")
325 # MD5sum not matching: new version our new build ?
326 if [ "$md5_sum" != "$db_sum" ]; then
327 vers=$(sqlite3 ${pkgsdb} \
328 "SELECT version FROM pkgs WHERE name = '$pkg'")
329 if [ "$VERSION" != "$vers" ]; then
330 status="$(colorize 032 $(gettext "update"))"
331 else
332 status="$(colorize 035 $(gettext "rebuilt"))"
333 fi
334 echo "$pkg $(indent 30 $VERSION) $(indent 60 $status)"
335 echo "$pkg" >> ${cache}/updates
336 fi
337 done
339 if [ -f "$cache/updates" ]; then
340 count=$(cat $cache/updates | wc -l)
341 separator "-"
342 gettext "Available updates:"; colorize 32 " $count"
343 newline
344 # --install
345 if [ "$install" ]; then
346 for pkg in $(cat $cache/updates); do
347 sup -i ${pkg}
348 done
349 fi
350 else
351 gettext "Packages are up-to-date"; echo
352 newline
353 fi
354 rm -f ${cache}/updates ;;
356 -r|remove)
357 # Remove a package
358 pkg="$2"
359 check_pkg_arg "$1"
360 if [ -d "$installed/$pkg" ]; then
361 remove_sup "$pkg"
362 else
363 gettext "Can't find installed package:"; colorize 31 " $pkg"
364 exit 1
365 fi ;;
367 -l|list)
368 installed_nb=$(ls ${installed} | wc -l)
369 newline
370 echo -n "$(colorize 36 $(gettext 'Installed sup packages:'))"
371 boldify " $installed_nb"
372 separator
373 for pkg in $(ls ${installed}); do
374 . ${installed}/${pkg}/receip
375 echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
376 done
377 if [ "$installed_nb" == 0 ]; then
378 gettext "No sup packages installed"; echo
379 fi
380 newline
381 if [ -d "$wok" ]; then
382 echo -n "$(colorize 35 $(gettext 'Sup packages in your wok:'))"
383 boldify " $(ls ${wok} | wc -l)"
384 separator
385 for pkg in $(ls ${wok}); do
386 . ${wok}/${pkg}/receip
387 echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
388 done
389 newline
390 fi ;;
392 ""|-h|help) help ;;
394 *)
395 # Display pkg info if installed
396 pkg="$1"
397 if [ -f "$installed/$pkg/receip" ]; then
398 . ${installed}/${pkg}/receip
399 newline
400 gettext "Installed package:"; colorize 36 " $PACKAGE $VERSION"
401 separator
402 echo "Short desc: $SHORT_DESC"
403 echo ""
404 boldify "$(gettext 'Installed files:') ($sup_size)"
405 cat ${installed}/${pkg}/files.list
406 newline
407 else
408 gettext "Can't find installed package:"; colorize 31 " $pkg"
409 fi ;;
411 esac && exit 0