slitaz-pizza view pizza-bot @ rev 14

Add Gravatar support to flavor status page
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 26 13:05:04 2012 +0200 (2012-03-26)
parents a5164f0bb461
children 41980f21c33e
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza chroot cmdline utility. This tool is designed to be run
4 # by cron and automatically build flavors in the queue. We build one ISO
5 # at once so we don't use too many resources.
6 #
7 # Copyright (C) 2012 SliTaz GNU/Linux - GNU gpl v2
8 # Authors : Christophe Lincoln <pankso@slitaz.org>
9 #
11 . /etc/slitaz/pizza-bot.conf
13 # Pizza DB files.
14 pizza="/home/slitaz"
15 cache="$pizza/cache"
16 queue="$pizza/queue"
17 activity="$cache/activity"
18 public="$pizza/public"
19 builds="$cache/builds"
20 lockfile="/var/lock/pizza.lock"
21 feeds="$pizza/xml"
23 # Log activities, we want first letter capitalized.
24 log() {
25 grep ^[A-Z] | \
26 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
27 }
29 # Clean exit.
30 quit() {
31 rm -f $lockfile
32 exit 0
33 }
35 # Create a XML feed for freshly built flavor.
36 gen_rss() {
37 pubdate=$(date "+%a, %d %b %Y %X")
38 cat > $feeds/slitaz-$ID.xml << EOT
39 <item>
40 <title>$FLAVOR $VERSION</title>
41 <link>${PIZZA_URL}?id=$ID</link>
42 <guid>slitaz-$ID</guid>
43 <pubDate>$pubdate</pubDate>
44 <description>$SHORT_DESC</description>
45 </item>
46 EOT
47 }
49 # Mail body.
50 mail_body() {
51 md5=$(cat $public/slitaz-$ID/$FLAVOR.md5 | awk '{print $1}')
52 cat << EOT
53 From: SliTaz Pizza <pizza@$MAIL_DOMAIN>
54 To: $MAINTAINER
55 Date: $(date '+%a, %d %b %Y %H:%M:%S %z')
56 Subject: Flavor ISO is built
57 Content-Type: text/plain; charset=utf-8
58 Content-Transfer-Encoding: 8bit
60 Hi,
62 Your custom SliTaz GNU/Linux system is ready to download! It will be
63 hosted as long as we can but with absolutely no warranty in time.
65 Get $FLAVOR ISO and files at: ${PIZZA_URL}?id=slitaz-$ID
67 ISO size: $ISO_SIZE
68 MD5 sum: $md5
70 If you wish a long time hosting service please get in touch via our
71 professional platform at http://slitaz.pro
73 Visit http://www.slitaz.org for latest news about the project and
74 get community support on SliTaz Forum http://forum.slitaz.org
76 Sent by the SliTaz Pizza Mailer
78 EOT
79 }
81 # Run as daemon by default.
82 case "$1" in
83 usage)
84 echo "Usage: $(basename $0) [lock|unlock]" ;;
85 lock)
86 echo $$ > $lockfile ;;
87 unlock)
88 rm -f $lockfile ;;
89 *)
90 [ -f "$lockfile" ] && echo "Pizza is locked" && exit 0
91 trap 'rm -f $command && exit 1' INT TERM
92 echo $$ > $lockfile
93 name=$(ls -rt $queue | head -n 1)
94 log="$public/$name/distro.log"
95 work="$pizza/flavors"
96 [ ! "$name" ] && echo "Empty build queue" && quit
97 . $queue/$name/receipt
99 echo "Build started for flavor: <a href='?id=$ID'>$ID</a> ($FLAVOR)" | log
100 echo -e "Build started : $(date '+%Y-%m-%d %H:%M')\n" | tee -a $log
102 rm -rf $work && mkdir -p $work && cd $work
103 mv $queue/$name $FLAVOR
104 chown -R root.root $FLAVOR
105 tazlito pack-flavor $FLAVOR | tee -a $log
106 tazlito get-flavor $FLAVOR | tee -a $log
107 mv $FLAVOR.flavor $public/$name
108 sed -i s"/^ISO_NAME=.*/ISO_NAME=\"$FLAVOR\"/" tazlito.conf
109 yes '' | tazlito gen-distro 2>&1 | tee -a $log
111 # Create an XML feed
112 gen_rss
114 # We want a public packages list md5sum file and move ISO so users
115 # can download it. Keep original pkgs list and build a complete one.
116 cp -f $FLAVOR/packages.list $public/$name
117 cd $pizza/distro
118 pkgsinst="$public/$name/installed.list"
119 rm -f $pkgsinst && touch $pkgsinst
120 for pkg in $(ls -1 rootfs/var/lib/tazpkg/installed)
121 do
122 . rootfs/var/lib/tazpkg/installed/$pkg/receipt
123 echo "$PACKAGE | $VERSION | $SHORT_DESC" >> $pkgsinst
124 done
125 echo "ISO_SIZE=\"$(du -sh $FLAVOR.iso | awk '{print $1}')\"" >> \
126 $public/$name/receipt
127 echo "ROOTFS_SIZE=\"$(du -sh rootfs | awk '{print $1}')\"" >> \
128 $public/$name/receipt
129 md5sum $FLAVOR.iso > $public/$name/$FLAVOR.md5
130 mv $FLAVOR.iso $public/$name
131 chown -R www.www $public/$name
133 # Send mail if enabled.
134 if [ "$MAIL_DOMAIN" ]; then
135 . $public/$name/receipt
136 echo "Sending mail to: $MAINTAINER"
137 mail_body | /usr/sbin/sendmail $MAINTAINER
138 fi
140 # Count builds
141 count=$(cat $builds)
142 count=$(($count + 1))
143 echo "$count" > $builds
144 rm -f $lockfile ;;
145 esac
146 exit 0