sup view sup @ rev 19

Better help a source tree structure
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 26 19:20:31 2017 +0100 (2017-02-26)
parents 827dfe35cf35
children c0a780b534c2
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 -l list $(gettext "List installed packages and your wok")
37 $(boldify $(gettext "Options:"))
38 --init cook $(gettext "Initialize sup cook environment")
39 --verbose all $(gettext "Display more output messages")
41 EOT
42 exit 0
43 }
45 cook_init() {
46 mkdir -p ${wok} ${cooked}
47 if [ ! -d "$supcook/wok" ]; then
48 ln -s ${wok} ${supcook}/wok
49 fi
50 }
52 # new_receipt "package"
53 new_receip() {
54 cat > receip << EOT
55 # SliTaz User Package receipt
57 PACKAGE="$1"
58 VERSION=""
59 SHORT_DESC=""
60 MAINTAINER=""
61 LICENSE=""
62 WEB_SITE=""
64 # Sup dependencies will be automatically downloaded but system wide
65 # deps must be manually installed by root.
66 SUP_DEPS=""
67 DEPENDS=""
69 # Here are the optional install rules (download, configure, etc)
70 sup_install() {
71 echo ""
72 }
74 EOT
75 }
77 #
78 # Commands
79 #
81 case "$1" in
83 -c|cook)
84 # Cook in $cache/cook amd mv pkg to a visible dir
85 pkg="$2"
86 receip="$wok/$pkg/receip"
87 cache="$cache/cook"
89 # Handle --init
90 if [ "$init" ]; then
91 gettext "Initializing sup cook environment..."
92 cook_init
93 status && exit 0
94 fi
96 # Sanity check
97 if [ ! "$pkg" ]; then
98 gettext "You must specify a package to cook:"
99 boldify " sup cook [package]" && exit 1
100 fi
101 if [ ! -f "$receip" ]; then
102 gettext "Can't find receip in wok for:"
103 colorize 31 " $pkg" && exit 1
104 fi
106 newline
107 gettext "Building package:"; colorize 36 " $pkg"
108 separator
109 rm -rf ${cache} && mkdir -p ${cache} ${cooked}
111 # Check receip
112 [ "$verbose" ] && gettext "Checking receip variables..."
113 . ${receip}
114 for var in PACKAGE VERSION SHORT_DESC MAINTAINER LICENSE WEB_SITE
115 do
116 value="$(. $receip; eval echo \$$var)"
117 case "$var" in
118 PACKAGE|VERSION|SHORT_DESC|MAINTAINER|LICENSE)
119 if [ ! "$value" ]; then
120 gettext "Empty variable:"; colorize 31 " $var=\"\""
121 exit 1
122 fi ;;
123 WEB_SITE)
124 if [ ! "$value" ]; then
125 gettext "Empty variable:"; colorize 31 " $var=\"\""
126 gettext "You can use:"
127 boldify " http://scn.slitaz.org/?sup&pkg=$PACKAGE"
128 exit 1
129 fi ;;
130 esac
131 done
132 [ "$verbose" ] && status
134 # Set $PACKAGE-$VERSION.sup and copy pkg to cache
135 supfile="$PACKAGE-$VERSION.sup"
136 cp -rf ${wok}/${pkg} ${cache}/${supfile%.sup}
137 cd ${cache}/${supfile%.sup}
139 # Move to hidden dir: ~/.local and ~/.config
140 for dir in local config; do
141 mv files/${dir} files/.${dir}
142 done
144 # Add $build_date
145 echo "build_date=\"$(date "+%Y-%m-%d %H:%M")\"" >> ${receip}
147 gettext "Creating compressed archive..."
148 find files | cpio -o -H newc --quiet | lzma e files.lzma -si
149 rm -rf files
150 find . -print | cpio -o -H newc --quiet > ${cooked}/${supfile}
151 status
153 size="$(du -sh $cooked/$supfile | cut -d " " -f 1)"
154 echo "$(gettext 'Packages:') $(colorize 33 $supfile) ($size)"
155 sed -i "/^build_date=/"d ${receip}
156 rm -rf ${cache} && newline ;;
158 -e|extract)
159 # Extract package.sup to current dir
160 pkg="$2"
162 # Sanity check
163 if [ ! "$pkg" ]; then
164 gettext "Missing package in argument:"
165 colorize 35 " sup extract [package.sup]" && exit 1
166 fi
167 if [ ! -f "$pkg" ]; then
168 gettext "Can't find package file:"; colorize 35 " $pkg" && exit 1
169 fi
171 newline
172 gettext "Extract package:"; colorize 36 " $(basename $pkg)"
173 separator
175 extract_sup "$pkg"
177 echo "$(gettext 'Packages:') $(colorize 33 $pkg) ($size)"
178 newline ;;
180 -i|install)
181 # Download/extract run install() in $cache/install
182 pkg="$2"
184 if [ ! "$pkg" ]; then
185 gettext "Missing package in argument:"
186 boldify " sup install [name|pkg.sup]" && exit 1
187 fi
189 # Sup pkg in current dir
190 if [ -f "$pkg" ]; then
191 install_sup "$pkg" && exit 0
192 fi
194 # Sup cooked from wok
195 if [ -f "$wok/$pkg/receip" ]; then
196 . $wok/$pkg/receip
197 if [ -f "$cooked/$PACKAGE-$VERSION.sup" ]; then
198 install_sup "$cooked/$PACKAGE-$VERSION.sup" && exit 0
199 fi
200 fi
202 # Sup on mirror
203 echo "TODO: check for package on mirror"
205 gettext "Can't find sup package:"; colorize 31 " $pkg" ;;
207 -l|list)
208 installed_nb=$(ls ${installed} | wc -l)
209 newline
210 echo -n "$(colorize 36 $(gettext 'Installed sup packages:'))"
211 boldify " $installed_nb"
212 separator
213 for pkg in $(ls ${installed}); do
214 . ${wok}/${pkg}/receip
215 echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
216 done
217 if [ "$installed_nb" == 0 ]; then
218 gettext "No sup packages installed"; echo
219 fi
220 newline
221 if [ -d "$wok" ]; then
222 echo -n "$(colorize 35 $(gettext 'Sup packages in your wok:'))"
223 boldify " $(ls ${wok} | wc -l)"
224 separator
225 for pkg in $(ls ${wok}); do
226 . ${wok}/${pkg}/receip
227 echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
228 done
229 newline
230 fi ;;
232 ""|-h|help) help ;;
234 *)
235 # Display pkg info if installed
236 pkg="$1"
237 if [ -f "$installed/$pkg/receip" ]; then
238 . ${installed}/${pkg}/receip
239 newline
240 gettext "Installed package:"; colorize 36 " $PACKAGE $VERSION"
241 separator
242 echo "Short desc: $SHORT_DESC"
243 echo ""
244 boldify "Installed files size: $sup_size"
245 #
246 cat ${installed}/${pkg}/files.list
247 newline
248 else
249 gettext "Can't find installed package:"; colorize 31 " $pkg"
250 fi ;;
252 esac && exit 0