slitaz-pizza view pizza-bot @ rev 91

pizza.cgi: notes should not be executable
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 28 09:30:48 2013 +0100 (2013-01-28)
parents 38d3a05db9e3
children 336b430315f8
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 a time 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"
24 # Log activities, we want first letter capitalized.
25 log() {
26 grep ^[A-Z] | \
27 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
28 }
30 # Clean exit.
31 quit() {
32 rm -f $lockfile
33 exit 0
34 }
36 # Create a XML feed for freshly built flavor.
37 gen_rss() {
38 pubdate=$(date "+%a, %d %b %Y %X")
39 cat > $feeds/slitaz-$ID.xml << EOT
40 <item>
41 <title>$FLAVOR $VERSION</title>
42 <link>${PIZZA_URL}?id=$ID</link>
43 <guid>slitaz-$ID</guid>
44 <pubDate>$pubdate</pubDate>
45 <description>$SHORT_DESC</description>
46 </item>
47 EOT
48 }
50 # Mail body.
51 mail_body() {
52 md5=$(cat $public/slitaz-$ID/$FLAVOR.md5 | awk '{print $1}')
53 cat << EOT
54 From: SliTaz Pizza <pizza@$MAIL_DOMAIN>
55 To: $MAINTAINER
56 Date: $(date '+%a, %d %b %Y %H:%M:%S %z')
57 Subject: Flavor ISO is built
58 Content-Type: text/plain; charset=utf-8
59 Content-Transfer-Encoding: 8bit
61 Hi,
63 Your custom SliTaz GNU/Linux system is ready to download! It will be
64 hosted for as long as we can but with absolutely no warranty in time.
66 Get $FLAVOR ISO and files at: ${PIZZA_URL}?id=$ID
68 ISO size: $ISO_SIZE
69 MD5 sum: $md5
71 If you would like a long time hosting service please get in touch via our
72 professional platform at http://slitaz.pro
74 Visit http://www.slitaz.org for latest news about the project and
75 get community support on SliTaz Forum http://forum.slitaz.org
77 Sent by the SliTaz Pizza Mailer
79 EOT
80 }
82 # Run as daemon by default.
83 case "$1" in
84 usage)
85 echo "Usage: $(basename $0) [lock|unlock]" ;;
86 lock)
87 echo $$ > $lockfile ;;
88 unlock)
89 rm -f $lockfile ;;
90 *)
91 [ -f "$lockfile" ] && echo "Pizza is locked" && exit 0
92 trap 'rm -f $command && exit 1' INT TERM
93 echo $$ > $lockfile
94 name=$(ls -rt $queue | head -n 1)
95 log="$public/$name/distro.log"
96 work="$pizza/flavors"
97 [ ! "$name" ] && echo "Empty build queue" && quit
98 . $queue/$name/receipt
100 [ -z "$ID" -o -z "$FLAVOR" ] && echo "$name not valid" && quit
102 [ -d /proc/1 ] || mount -t proc /proc /proc
103 #tazpkg setup-mirror /home/slitaz/packages
104 tazpkg recharge
106 echo "Build started for flavor: <a href='?id=$ID'>$ID</a> ($FLAVOR)" | log
107 echo -e "Build started : $(date '+%Y-%m-%d %H:%M')\n" | tee -a $log
109 rm -rf $work && mkdir -p $work && cd $work
110 mv $queue/$name $FLAVOR
111 chown -R root.root $FLAVOR
112 tazlito pack-flavor $FLAVOR | tee -a $log
113 tazlito get-flavor $FLAVOR | tee -a $log
114 mv $FLAVOR.flavor $public/$name
115 sed -i s"/^ISO_NAME=.*/ISO_NAME=\"$FLAVOR\"/" tazlito.conf
116 yes '' | tazlito gen-distro 2>&1 | tee -a $log
118 # Create an XML feed
119 gen_rss
121 # We want a public packages list md5sum file and move ISO so users
122 # can download it. Keep original pkgs list and build a complete one.
123 cp -f $FLAVOR/packages.list $public/$name
124 cd $pizza/distro
125 pkgsinst="$public/$name/installed.list"
126 rm -f $pkgsinst && touch $pkgsinst
127 for pkg in $(ls -1 rootfs/var/lib/tazpkg/installed)
128 do
129 . rootfs/var/lib/tazpkg/installed/$pkg/receipt
130 echo "$PACKAGE | $VERSION | $SHORT_DESC" >> $pkgsinst
131 done
132 echo "ISO_SIZE=\"$(du -sh $FLAVOR.iso | awk '{print $1}')\"" >> \
133 $public/$name/receipt
134 echo "ROOTFS_SIZE=\"$(du -sh rootfs | awk '{print $1}')\"" >> \
135 $public/$name/receipt
136 md5sum $FLAVOR.iso > $public/$name/$FLAVOR.md5
137 mv $FLAVOR.iso $public/$name
138 chown -R www.www $public/$name
140 # Send mail if enabled.
141 if [ "$MAIL_FROM" ]; then
142 . $public/$name/receipt
143 echo "Sending mail to: $MAINTAINER"
144 mail_body | /usr/bin/sendmail -f $MAIL_FROM $MAINTAINER
145 fi
147 # Notify Admin if enabled.
148 if [ "$MAIL_ADMIN" ]; then
149 echo "Sending mail to: $MAIL_ADMIN"
150 echo -e "From: SliTaz Pizza<noreply@slitaz.org>\nSubject: New build on Pizza\nNew flavor built on Pizza: ${PIZZA_URL}?id=$ID " \
151 | /usr/bin/sendmail -f $MAIL_FROM $MAIL_ADMIN
152 fi
154 # Count builds
155 count=$(cat $builds)
156 count=$(($count + 1))
157 echo "$count" > $builds
158 rm -f $lockfile ;;
159 esac
160 exit 0