slitaz-pizza view pizza-bot @ rev 53

Use get-install not -gi so we compatible 3.0
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 12 17:48:00 2012 +0200 (2012-04-12)
parents 41980f21c33e
children 8ef7eec5250e
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=$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 #tazpkg setup-mirror /home/slitaz/packages
100 tazpkg recharge
102 echo "Build started for flavor: <a href='?id=$ID'>$ID</a> ($FLAVOR)" | log
103 echo -e "Build started : $(date '+%Y-%m-%d %H:%M')\n" | tee -a $log
105 rm -rf $work && mkdir -p $work && cd $work
106 mv $queue/$name $FLAVOR
107 chown -R root.root $FLAVOR
108 tazlito pack-flavor $FLAVOR | tee -a $log
109 tazlito get-flavor $FLAVOR | tee -a $log
110 mv $FLAVOR.flavor $public/$name
111 sed -i s"/^ISO_NAME=.*/ISO_NAME=\"$FLAVOR\"/" tazlito.conf
112 yes '' | tazlito gen-distro 2>&1 | tee -a $log
114 # Create an XML feed
115 gen_rss
117 # We want a public packages list md5sum file and move ISO so users
118 # can download it. Keep original pkgs list and build a complete one.
119 cp -f $FLAVOR/packages.list $public/$name
120 cd $pizza/distro
121 pkgsinst="$public/$name/installed.list"
122 rm -f $pkgsinst && touch $pkgsinst
123 for pkg in $(ls -1 rootfs/var/lib/tazpkg/installed)
124 do
125 . rootfs/var/lib/tazpkg/installed/$pkg/receipt
126 echo "$PACKAGE | $VERSION | $SHORT_DESC" >> $pkgsinst
127 done
128 echo "ISO_SIZE=\"$(du -sh $FLAVOR.iso | awk '{print $1}')\"" >> \
129 $public/$name/receipt
130 echo "ROOTFS_SIZE=\"$(du -sh rootfs | awk '{print $1}')\"" >> \
131 $public/$name/receipt
132 md5sum $FLAVOR.iso > $public/$name/$FLAVOR.md5
133 mv $FLAVOR.iso $public/$name
134 chown -R www.www $public/$name
136 # Send mail if enabled.
137 if [ "$MAIL_DOMAIN" ]; then
138 . $public/$name/receipt
139 echo "Sending mail to: $MAINTAINER"
140 mail_body | /usr/sbin/sendmail $MAINTAINER
141 fi
143 # Count builds
144 count=$(cat $builds)
145 count=$(($count + 1))
146 echo "$count" > $builds
147 rm -f $lockfile ;;
148 esac
149 exit 0