cookutils view modules/pkgdb @ rev 951
Minor bug fixes due to the change in the behavior of the dot command in Busybox-1.27.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu Jul 27 13:36:30 2017 +0300 (2017-07-27) |
parents | 79b65c3a4e40 |
children | a73e67901f49 |
line source
1 #!/bin/sh
2 #
3 # pkgdb - module of the SliTaz Cook
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
5 #
7 . /usr/lib/slitaz/libcook.sh
10 #
11 # Functions
12 #
14 dblog() { tee -a $LOGS/pkgdb.log; }
17 # Return size of file in human readible format
18 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
20 filesize() { busybox ls -lh "$1" | awk '{print $5 "B"}'; }
26 # Create suitable packages list for TazPkg and only for built packages
27 # as well as flavors files for TazLiTo. We don't need logs since we do it
28 # manually to ensure everything is fine before syncing the mirror.
30 # Find how much time was spent the last time (for web interface)
31 lastcooktime=$(sed '/Time:/!d; s|.*: *\([0-9]*\)s.*|\1|' $LOGS/pkgdb.log 2>/dev/null | sed '$!d')
32 [ -n "$lastcooktime" ] && echo "cook:pkgdb $lastcooktime $(date +%s)" >> $cooktime
33 while read cmd duration start; do
34 [ $(($start + $duration)) -lt $(date +%s) ] &&
35 echo "sed -i '/^$cmd $duration/d' $cooktime"
36 done < $cooktime | sh
38 rm $LOGS/pkgdb.log 2>/dev/null
40 case "$1" in
41 --flavors|--rmpkg) ;;
42 *)
43 [ -n "$1" ] && PKGS="$1"
44 if [ ! -d "$PKGS" ]; then
45 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
46 exit 1
47 fi ;;
48 esac
50 time=$(date +%s)
51 flavors="$SLITAZ/flavors"
52 live="$SLITAZ/live"
54 echo 'cook:pkgdb' > $command
55 _ 'Cook pkgdb: Creating all packages lists' | log
56 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
58 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
60 cd $PKGS
61 rm -f packages.* extra.list
62 touch packages.equiv
64 _n 'Creating file "%s"' 'packages.list' | dblog
65 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
66 echo " ($(filesize $PKGS/packages.list))" | dblog
68 _n 'Creating file "%s"' 'packages.md5' | dblog
69 md5sum *.tazpkg > $PKGS/packages.md5
70 echo " ($(filesize $PKGS/packages.md5))" | dblog
71 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of unnecessary packages
73 md5sum packages.md5 | cut -d' ' -f1 > ID
74 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
76 _n 'Creating file "%s"' 'descriptions.txt' | dblog
77 rm $PKGS/descriptions.txt 2>/dev/null
78 for i in $(ls $WOK | sort); do
79 [ -d "$WOK/$i/taz" ] || continue
81 for j in $(ls $WOK/$i/taz | sort); do
82 [ -e "$WOK/$i/taz/$j/description.txt" ] || continue
84 pkgname=$(. $WOK/$i/taz/$j/receipt; echo $PACKAGE)
85 echo "$pkgname"
86 sed 's|^$| |' "$WOK/$i/taz/$j/description.txt"
87 echo
88 done >> descriptions.txt
89 done
90 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
93 _ 'Creating lists from "%s"' "$WOK" | dblog
94 cd $WOK
95 rsumf=$(mktemp)
96 for i in *; do
97 [ -d "$WOK/$i/taz" ] || continue
99 for j in $(ls $WOK/$i/taz | sort); do
100 pack="$i/taz/$j"
101 [ -f "$WOK/$pack/receipt" ] || continue
102 unset_receipt
103 . ./$pack/receipt
105 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" -o \
106 -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
108 # packages.desc lets us search easily in DB
109 cat >> $PKGS/packages.desc <<EOT
110 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
111 EOT
113 # packages.txt used by tazpkg and tazpkg-web also to provide
114 # a human readable package list with version and description.
115 cat >> $PKGS/packages.txt <<EOT
116 $PACKAGE
117 $VERSION$EXTRAVERSION
118 $SHORT_DESC
119 $PACKED_SIZE ($UNPACKED_SIZE installed)
121 EOT
123 # packages.info combines TazPkg separate files
124 # and will substitute them all
125 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
126 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
128 #MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
129 cp $pack/md5sum $rsumf
130 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsumf
131 [ -e "$pack/description.txt" ] && md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsumf
132 rsum=$(md5sum $rsumf | awk '{print $1}')
134 cat >> $PKGS/packages.info <<EOT
135 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
136 EOT
138 # packages.equiv is used by tazpkg install to check depends.
139 for k in $PROVIDE; do
140 DEST=''
141 echo $k | fgrep -q : && DEST="${k#*:}:"
142 if grep -qs ^${k%:*}= $PKGS/packages.equiv; then
143 sed -i "s/^${k%:*}=/${k%:*}=$DEST$PACKAGE /" \
144 $PKGS/packages.equiv
145 else
146 echo "${k%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
147 fi
148 done
150 # files.list provides a list of all packages files.
151 cat $i/taz/$j/files.list | sed s/^/"$PACKAGE: \0"/ >> $PKGS/files.list
153 # list of unnecessary packages
154 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
155 else
156 # if receipt variable HOST_ARCH absent/empty or contains ARCH
157 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
158 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
159 fi
160 fi
161 done
162 done
163 rm $rsumf
166 # Display list size.
167 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
168 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
169 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
170 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
172 cd $PKGS
175 # Check for unnecessary packages
176 if [ -s "$PKGS/packages.toremove" ]; then
177 newline | dblog
178 case x$rmpkg in
179 x) _ 'Found unnecessary packages (use `cook pkgdb --rmpkg` to remove):' | dblog;;
180 *) _ 'Removing unnecessary packages:' | dblog;;
181 esac
182 while read pkgsum pkgfile; do
183 echo " - $pkgfile" | dblog
184 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
185 sed -i "/ $pkgfile/d" $PKGS/packages.md5
186 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
187 done < $PKGS/packages.toremove
188 newline | dblog
189 fi
190 rm $PKGS/packages.toremove
193 # files.list.lzma
194 _n 'Creating file "%s"' 'files.list.lzma' | dblog
195 touch files.list
196 # pkgs.slitaz.org strongly depends on list sorted by packages names
197 lzma e files.list files.list.lzma
198 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
200 # Pre-sorting filenames causes 10% smaller resulting lzma file
201 _n 'Creating file "%s"' 'files-list.lzma' | dblog
202 cat files.list | sort -k2 -o files.list.sorted
203 lzma e files.list.sorted files-list.lzma
204 rm -f files.list files.list.sorted
205 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
207 [ -e files.list.md5 ] && rm files.list.md5
208 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
210 # Make bundle to fast recharge
211 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
212 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
213 # Make sure to get "mirrors" file
214 until [ -e 'mirrors' ]; do
215 wget -q http://mirror1.slitaz.org/mirrors
216 echo -n '.' | dblog; sleep 5
217 done
218 # Make sure to get "extra.list" file
219 until [ -e 'extra.list' ]; do
220 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
221 echo -n '.' | dblog; sleep 5
222 done
223 busybox tar -chaf bundle.tar.lzma \
224 mirrors extra.list files-list.md5 packages.info descriptions.txt \
225 packages.desc packages.md5 packages.txt packages.list packages.equiv
226 rm ./mirrors
227 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
229 # Display some info.
230 separator | dblog
231 nb=$(ls $PKGS/*.tazpkg | wc -l)
232 time=$(($(date +%s) - $time))
233 # L10n: 's' is for seconds (cooking time)
234 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
237 # Create all flavors files at once. Do we really need code to monitor
238 # flavors changes? Let's just build them with packages lists before
239 # syncing the mirror.
240 [ "$1" != '--flavors' ] && rm $command && exit 1
242 if [ ! -d "$flavors" ]; then
243 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
244 rm $command
245 exit 1
246 fi
248 [ ! -d "$live" ] && mkdir -p $live
249 _ 'Creating flavors files in "%s"' "$live" | dblog
250 _ 'Cook pkgdb: Creating all flavors' | log
251 separator | dblog
253 _ 'Recharging lists to use latest packages...' | dblog
254 tazpkg recharge >/dev/null 2>/dev/null
256 # We need a custom tazlito config to set working dir to /home/slitaz.
257 if [ ! -f "$live/tazlito.conf" ]; then
258 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
259 cp /etc/tazlito/tazlito.conf $live
260 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
261 $live/tazlito.conf
262 fi
264 # Update Hg flavors repo and pack.
265 if [ -d "$flavors/.hg" ]; then
266 cd $flavors; hg pull -u
267 fi
269 cd $live
270 _ 'Starting to generate flavors...' | dblog
271 rm -f flavors.list *.flavor
272 for i in $flavors/*; do
273 fl=$(basename $i)
274 _ 'Packing flavor "%s"' "$fl" | dblog
275 tazlito pack-flavor $fl >/dev/null || exit 1
276 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
277 done
278 cp -f $live/*.flavor $live/flavors.list $PKGS
279 separator | dblog
280 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
281 separator | dblog
282 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
284 rm $command
287 exit 0