slitaz-pizza view web/rootfs.cgi @ 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 8b324cb2c5e2
children a666d22cd751
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza CGI/web interface - Let's have a pizza :-)
4 # SliTaz rootfs step
5 #
7 . lib/libpizza
8 log="$tmpdir/slitaz-$id/distro.log"
10 # Internationalization: $(gettext "")
11 . /usr/bin/gettext.sh
12 TEXTDOMAIN='pizza'
13 export TEXTDOMAIN
15 # Handle rootfs.* file upload.
16 tarball_handler() {
17 echo "<pre>"
18 echo "File name : $tarball"
19 echo "File size : $size Bytes"
20 gettext "Moving rootfs tarball to slitaz-$id"
21 upload=$tmpdir/slitaz-$id/upload-$$
22 mkdir -p $upload && cd $upload
23 mv $tmpname "$upload/$tarball" && rm -rf $(dirname $tmpname)
24 chmod a+r $upload/$tarball
25 status
27 # Extract into the tmp upload dir.
28 gettext "Extracting archive for sanity checks..."
29 case "$tarball" in
30 *.tar.gz) tar xzf $tarball && status ;;
31 *.tar.bz2) tar xjf $tarball && status ;;
32 *.tar.lzma) tar xaf $tarball && status ;;
33 *) echo && error "Unsupported tarball format" && rm -rf $upload
34 esac
36 # Upload dir is removed if bad tarball so we stop here. Now be a bit
37 # restrictive using only rootfs as archive name and check FSH in root.
38 # Dont allow files in /dev /proc /sys /tmp /mnt
39 if [ -d "$upload/rootfs" ]; then
40 gettext "Checking Filesystem Standard..."
41 for i in $(ls $upload/rootfs)
42 do
43 case "$i" in
44 bin|boot|etc|home|init|lib|root|sbin|usr|var) continue ;;
45 *) echo "Bad FSH path for: $i" && rm -rf $upload ;;
46 esac
47 done && status
48 # Dont allow too big rootfs content.
49 size=$(du -s $upload/rootfs | awk '{print $1}')
50 gettext "Checking uploaded rootfs size..."
51 if [ "$size" -lt "$MAX_UPLOAD" ]; then
52 status
53 else
54 echo && error "Tarball is too big"
55 rm -rf $upload
56 fi
57 fi
59 # So now it time to move the addfile to flavor files.
60 if [ -d "$upload/rootfs" ]; then
61 echo "Additional rootfs: accepted" | tee -a $log
62 mkdir -p $tmpdir/slitaz-$id
63 mv $upload/rootfs $tmpdir/slitaz-$id
64 rm -rf $tmpdir/slitaz-$id/upload-*
65 fi
66 echo "</pre>"
67 rm -rf $upload
68 }
70 #
71 # Actions
72 #
74 case " $(FILE) " in
75 *\ wallpaper\ *)
76 id="$(POST id)"
77 tmpname="$(FILE wallpaper tmpname)"
78 wallpaper="$(FILE wallpaper name)"
79 size="$(FILE wallpaper size)"
80 if echo $wallpaper | fgrep -q .jpg; then
81 images=$tmpdir/slitaz-$id/rootfs/usr/share/images
82 mkdir -p $images
83 mv $tmpname $images/slitaz-background.jpg
84 chmod a+r $images/*.jpg
85 notify "$(gettext "Added image:") $wallpaper ($size Bytes)" "info"
86 else
87 notify "$(gettext "Unsupported image format")" "error"
88 fi ;;
89 *\ tarball\ *)
90 id="$(POST id)"
91 tmpname="$(FILE tarball tmpname)"
92 tarball="$(FILE tarball name)"
93 size="$(FILE tarball size)" ;;
94 *)
95 id="$(GET id)" ;;
96 esac
98 #
99 # Source receipt and display page with additional rootfs or file upload.
100 #
101 . $tmpdir/slitaz-$id/receipt
102 cat << EOT
103 <h2>Rootfs</h2>
104 <form method="post" action="rootfs.cgi" enctype="multipart/form-data">
106 <p>
107 SliTaz root filesystem modification can be done via an easy to use form,
108 a single tarball or by uploading files one by one in the wanted directory.
109 </p>
111 <h3>$(gettext "Easy customization")</h3>
113 $(gettext "Desktop Wallpaper"):
114 <input type="file" name="wallpaper" size="40" />
115 <input type="submit" value="Upload" />
117 <h3>$(gettext "Rootfs tarball")</h3>
118 <p>
119 The files in the rootfs archive must have the same directory structure
120 as any standard SliTaz or Linux system. For example if you wish to
121 have a custom boot configuration file, you will have: rootfs/etc/rcS.conf.
122 Accepted tarball formats are: <strong>tar.gz tar.bz2 tar.lzma</strong>
123 and the archived directory must be named rootfs with a valid file system
124 hierachy such as: /usr/bin /etc /var/www
125 </p>
127 Rootfs tarball:
128 <input type="file" name="tarball" size="40" />
129 <input type="hidden" name="id" value="$id" />
130 <input type="submit" value="Upload" />
131 </form>
133 $([ "$tarball" ] && tarball_handler)
135 <pre>
136 Uniq ID : $id
137 Flavor : $FLAVOR
138 Short desc : $SHORT_DESC
139 </pre>
140 <div class="next">
141 <form method="get" action="./">
142 <input type="hidden" name="id" value="$id" />
143 <input type="submit" name="gen" value="$(gettext "Continue")">
144 </form>
145 </div>
146 EOT
148 # HTML footer.
149 cat lib/footer.html
151 exit 0