slitaz-pizza view pizza @ 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 ebafde6ecb03
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza host cmdline utility - Create environment, chroot, clean.
4 # Backup and purge should be done via cron jobs.
5 #
7 [ -f "/etc/slitaz/pizza.conf" ] && . /etc/slitaz/pizza.conf
8 [ -f "pizza.conf" ] && . ./pizza.conf
10 # Pizza DB files.
11 chroot="$PIZZA/chroot"
12 pkgs="${chroot}$SLITAZ/packages"
13 cache="${chroot}$SLITAZ/cache"
14 queue="${chroot}$SLITAZ/queue"
15 tmp="${chroot}$SLITAZ/tmp"
16 feeds="${chroot}$SLITAZ/xml"
17 activity="$cache/activity"
18 builds="$cache/builds"
19 public="$VHOST/public"
20 bindpub="${chroot}$SLITAZ/public"
22 #
23 # Functions
24 #
26 usage() {
27 cat << EOT
29 $(echo -e "\033[1mUsage:\033[0m") pizza [command]
31 $(echo -e "\033[1mCommands:\033[0m")
32 usage Display this short usage.
33 setup Setup Pizza build environment.
34 up-files Update chroot and web files from datadir.
35 exec Execute a command in chroot.
36 chroot Chroot in Pizza environment.
37 start Start Pizza bot and mount packages.
38 stop Stop Pizza and unmount packages.
39 get-lists Get latest skel packages list from Hg.
40 sync-pkgs Sync packages from SliTaz mirror.
41 purge Purge Pizza tmp directory.
42 clean Complete chroot clean-up.
44 EOT
45 }
47 # Status function.
48 status() {
49 if [ $? = 0 ]; then
50 echo " OK"
51 else
52 echo " Failed"
53 fi
54 }
56 # Get latest skel packages list
57 get_pkgs_lists() {
58 cd $cache
59 for skel in base justx gtkonly core
60 do
61 echo -n "Getting $skel packages list... "
62 wget -O packages.$skel \
63 $HG/raw-file/tip/$skel/packages.list 2>/dev/null
64 echo "Done"
65 done
66 }
68 # The Bot is chrooted and can't access main pizza.conf
69 bot_config()
70 {
71 config=$chroot/etc/slitaz/pizza-bot.conf
72 echo '# Pizza Bot configuration.' > $config
73 grep ^PIZZA_URL /etc/slitaz/pizza.conf >> $config
74 grep ^MAIL_DOMAIN /etc/slitaz/pizza.conf >> $config
75 grep ^MAIL_SERVER /etc/slitaz/pizza.conf >> $config
76 }
78 #
79 # Commands
80 #
82 case "$1" in
83 setup)
84 # Setup build host.
85 crontabs="$chroot/var/spool/cron/crontabs"
86 if [ -d "$chroot/proc" ]; then
87 echo "Chroot already exists: $chroot" && exit 0
88 fi
89 echo ""
90 echo "Setting up Pizza environment..."
91 mkdir -p $crontabs $cache $pkgs $tmp $queue $bindpub $feeds
92 touch $activity $builds
93 chmod 0777 $tmp $queue $cache
94 chmod 0666 $activity
95 for pkg in slitaz-base-files busybox tazlito tazpkg postfix \
96 shared-mime-info
97 do
98 echo "Installing package: $pkg"
99 tazpkg -gi $pkg --root=$chroot >/dev/null
100 done
102 # Files
103 echo -n "Creating needed files..."
104 cp -f /etc/resolv.conf $chroot/etc
105 mkdir -p $chroot/etc/init.d
106 bot_config
107 # No more needed when slitaz-base-files have rc.functions
108 cp -f /etc/init.d/rc.functions $chroot/etc/init.d
109 echo '# Check pizza queue every 5 mins' > $crontabs/root
110 echo '*/20 * * * * /usr/bin/pizza-bot' >> $crontabs/root
111 status
113 # We want Tazlito to build ISO's in /home/slitaz
114 echo -n "Updating Tazlito default configuration..."
115 sed -i s'/^WORK_DIR=.*/WORK_DIR="\/home\/slitaz"/' \
116 $chroot/etc/tazlito/tazlito.conf
117 status
119 echo -n "Installing Pizza Bot..."
120 cp -a $DATA/pizza-bot $chroot/usr/bin
121 status
122 cd $cache && get_pkgs_lists
124 # Web interface and public dir
125 echo -n "Installing the web interface..."
126 mkdir -p $public && chmod 0777 $public
127 cp -a $DATA/web/* $VHOST
128 status
129 echo "Pizza chroot : $chroot"
130 echo "Vhost path : $VHOST"
131 echo ""
132 echo "To start Pizza Bot: $(basename $0) start"
133 echo "" ;;
134 up-files)
135 # Update files in chroot when pizza is updated on host.
136 echo -n "Updating chroot and virtual host..."
137 cp -a $DATA/web/* $VHOST
138 cp -a $DATA/pizza-bot $chroot/usr/bin
139 bot_config
140 status ;;
141 exec)
142 # Execute a command in chroot.
143 [ "$2" ] || exit 0
144 chroot $chroot $2 ;;
145 chroot)
146 # Chroot in Pizza environment.
147 echo -e "\nChrooting to: $chroot\n"
148 chroot $chroot /bin/sh --login
149 echo -e "\nExiting Pizza chroot...\n" ;;
150 start)
151 # Mount and start Pizza
152 if ! mount | fgrep -q "pizza/chroot"; then
153 gettext -e "Mounting packages and public...\n"
154 mount -o bind $SLITAZ/$SLITAZ_VERSION/packages $pkgs
155 mount -o bind $public $bindpub
156 fi
157 chroot $chroot /etc/init.d/crond start
158 [ "$MAIL_DOMAIN" ] && chroot $chroot /etc/init.d/postfix start ;;
159 stop)
160 # unmount and stop Pizza
161 if mount | fgrep -q "pizza/chroot"; then
162 gettext -e "Unmounting packages and public...\n"
163 umount $pkgs
164 umount $bindpub
165 fi
166 chroot $chroot /etc/init.d/crond stop
167 [ "$MAIL_DOMAIN" ] && chroot $chroot /etc/init.d/postfix stop ;;
168 get-lists)
169 get_pkgs_lists ;;
170 sync-pkgs)
171 echo "Syncing all $SLITAZ_VERSION packages..."
172 rsync -azH --delete rsync://mirror.slitaz.org/slitaz-$SLITAZ_VERSION/
173 $SLITAZ/$SLITAZ_VERSION/packages/ ;;
174 backup)
175 echo "Creating Pizza backup..."
176 bak="pizza-$(date "+%Y%m%d")"
177 dir="$PIZZA/backups/$bak"
178 mkdir -p $dir && cd $PIZZA/backups
179 cp -a $cache $dir
180 cp -a $chroot/home/slitaz/xml $dir
181 for flavor in $(ls $public)
182 do
183 if [ -f "$public/$flavor/receipt" ]; then
184 mkdir -p $dir/public/$flavor
185 . $public/$flavor/receipt
186 cp -f $public/$flavor/$FLAVOR.flavor \
187 $dir/public/$flavor 2>/dev/null
188 fi
189 done
190 tar cf $bak.tar $bak && rm -rf $bak
191 lzma e $bak.tar $bak.tar.lzma
192 du -sh $bak.tar.lzma ;;
193 purge)
194 # Remove tmp file older than 24 hours and ISO older than 15 days.
195 # TODO: Improve and use configs from pizza.conf
196 echo "Purging tmp files..."
197 find $tmp -mtime +1 | xargs rm -f
198 echo "Purging ISO's..."
199 find $public -mtime +15 | xargs rm -f ;;
200 clean)
201 # Clean all chroot.
202 echo -e "\nCleaning: $chroot"
203 cd $chroot || exit 1
204 for i in *
205 do
206 [ "$i" == "home" ] || rm -rf $i
207 done && echo "" ;;
208 *)
209 usage ;;
210 esac
211 exit 0