tazlito view tazlito-wiz @ rev 409
live.cgi: allow to choose only ISO images in file choosers
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Tue Dec 08 13:40:42 2015 +0200 (2015-12-08) |
parents | 6e2c8b742f47 |
children | e531b58ef2dc |
line source
1 #!/bin/sh
2 #
3 # Live system creation wizard in GTK using Yad.
4 #
5 # Copyright (C) 2012-2015 SliTaz GNU/Linux - GNU gpl v2
6 # Authors : Christophe Lincoln <pankso@slitaz.org>
7 #
9 default_icon="--image=slitaz-icon"
10 opts="--height=320 --width=600 --center --image-on-top --window-icon=slitaz-icon --title=LiveWizard"
11 rel=$(cat /etc/slitaz-release)
12 #[ "$rel" != "cooking" ] && rel=stable
13 live="/home/slitaz/$rel/live"
14 db='/var/lib/tazpkg'
15 list="$live/distro-packages.list"
16 distro="/home/slitaz/$rel/distro"
17 addfiles="$distro/addfiles"
20 # TazLito wizard is only for root.
22 if [ $(id -u) -ne 0 ]; then
23 exec tazbox su $0
24 exit 0
25 fi
28 # I18n
30 . /lib/libtaz.sh
31 export TEXTDOMAIN='tazlito'
34 # Sanity check.
36 mkdir -p $live && cd $live
37 #rm -rf *
40 #
41 # Functions
42 #
44 edit_list() {
45 cat $list | yad --list $opts --image='system-software-update' \
46 --text="<b>$(_ 'Edit the distro packages list')</b>" \
47 --no-headers --print-all --separator='' \
48 --editable --column=0:TEXT > "$live/list"
49 mv -f "$live/list" "$list"
50 }
53 # Start page GUI
55 start_main() {
56 yad --form $opts $default_icon \
57 --text="<b>$(_ 'SliTaz Live system creator wizard')</b>" \
58 --field="$(_ "Distro name:")" \
59 --field="$(_ "Based on:")":CB \
60 --button='gtk-help:4' \
61 --button="$(_ 'Write ISO')!iso-image-burn:3" \
62 --button="$(_ 'TazPanel Live'):2" \
63 --button='gtk-cancel:1' \
64 --button='gtk-go-forward:0' \
65 'custom' 'core!core64!gtkonly!justx!base'
66 }
69 # Start page handler
71 start() {
72 # Store box results
73 main=$(start_main)
75 # Deal with --button values
76 case $? in
77 1) exit 0;;
78 2) tazpanel live; exit 0;;
79 3) terminal -T 'write-iso' -e 'tazlito writeiso lzma'; exit 0;;
80 4) tazweb 'file:///usr/share/doc/tazlito/tazlito.html'; exit 0;;
81 *) continue;;
82 esac
84 # Deal with $main values
86 (
87 export output='raw'
88 # Numbers are moved the progressbar
89 echo '30'
90 # Lines started with '#' are displayed in the log
91 tazpkg recharge | sed 's|^.*|#&|'
92 name="$(echo $main | cut -d'|' -f1)"; name="${name:-custom}"
93 skel="$(echo $main | cut -d'|' -f2)"
94 echo "$skel" > $live/skel
95 echo '60'
96 tazlito get-flavor $skel | sed 's|^.*|#&|'
97 echo '90'
98 sed -i "s|^ISO_NAME=.*|ISO_NAME=\"$name\"|" tazlito.conf
99 sed -i "s|^VOLUM_NAME=.*|VOLUM_NAME=\"SliTaz $name\"|" tazlito.conf
100 ) | \
101 yad --progress $opts --image='system-software-update' \
102 --text="<b>$(_ 'Getting flavor file and packages list...')</b>" \
103 --enable-log="$(_ 'Log')" --log-expanded --button='gtk-go-forward:0'
105 }
108 # Packages page GUI
110 pkgs_main() {
111 pkgs=$(cat $list | wc -l)
112 skel=$(cat $live/skel)
113 text=$(_ 'Packages - The "$skel" has $pkgs packages')
114 yad --form $opts --image='application-x-tazpkg' \
115 --text="<b>$text</b>" --separator=' ' \
116 --field="$(_ 'Additional packages separated by space or by line:')\\n$(_ '(will be auto added to "Edit packages list")')":TXT \
117 --button="$(_ 'Edit packages list')!document-properties:2" \
118 --button='gtk-cancel:1' --button='gtk-go-forward:0'
119 }
122 # Packages page handler
124 pkgs() {
125 # Store box results
126 main=$(pkgs_main)
127 # Deal with --button values
128 case $? in
129 1) exit 0 ;;
130 2) add_to_list ; edit_list ;;
131 *) add_to_list ;;
132 esac
133 }
136 add_to_list() {
137 for pkg in $(echo $main | sed s'/\\n/ /'g); do
138 vers=$(grep -E "^$pkg \|" $db/packages.desc | awk '{print $3}')
139 [ -z $vers ] || \
140 (grep -v -q "^$pkg-$vers" $list && \
141 echo "$pkg-$vers" >> $list
142 )
143 unset vers
144 done
145 }
148 # Wallpaper page GUI
150 wallpaper_main() {
151 yad --form $opts --image='preferences-desktop-wallpaper' \
152 --text="<b>$(_ 'SliTaz desktop wallpaper')</b>" --separator='' \
153 --field="$(_ 'Wallpaper JPG image:')":FL \
154 --button='gtk-cancel:1' --button='gtk-go-forward:0'
155 }
158 # Wallpaper page handler
160 wallpaper() {
161 # Store box results
162 main=$(wallpaper_main)
163 # Deal with --button values
164 case $? in
165 1) exit 0 ;;
166 *) continue ;;
167 esac
168 if echo "$main" | fgrep -q .jpg; then
169 mkdir -p $addfiles/rootfs/usr/share/images
170 cp -f $main $addfiles/rootfs/usr/share/images
171 fi
172 }
175 # Last page GUI
177 gen_distro_main() {
178 (
179 _ "
180 Now it's time to generate the distro. Last chance to start over or stop. \
181 Creating a Live system uses quite a lot of resources and takes some time.
182 Note you can still add some files to the SliTaz root filesystem or on the CD-ROM."
183 echo
184 echo $addfiles
185 ) | yad --text-info $opts $default_icon \
186 --text="<b>$(_ 'Generate the distribution')</b>" --wrap --margins=20 \
187 --button='gtk-cancel:1' --button='gtk-go-forward:0'
188 }
191 # Last page handler
193 gen_distro() {
194 # Store box results
195 main=$(gen_distro_main)
197 # Deal with --button values
198 case $? in
199 1) exit 0 ;;
200 *)
201 export output='raw'
202 echo -e "\n" | tazlito gen-distro 2>&1 | yad \
203 --text-info $opts $default_icon --tail \
204 --text="<b>$(_ 'Building the Live system...')</b>" \
205 --button='gtk-go-forward:0'
206 ;;
207 esac
208 }
211 # Summary
213 summary() {
214 . tazlito.conf
215 iso_size=$(du -sh $distro/$ISO_NAME.iso | awk '{print $1}')
216 distro_size=$(du -sh $distro/rootfs | awk '{print $1}')
217 text="$(_ 'Live system summary')"
218 echo -e "\
219 $(_ 'Generated ISO') \n$distro/$ISO_NAME.iso
220 $(_ 'Image size') \n$iso_size
221 $(_ 'Uncompressed size') \n$distro_size" | \
222 yad --list $opts $default_icon --text="<b>$text</b>" \
223 --column="$(_ 'Information')":0 --column="$(_ 'Value')":1 \
224 --button="gtk-close":0
225 }
228 #
229 # Script commands
230 #
232 case "$1" in
233 usage)
234 echo "Usage: $(basename $0) [command]" ;;
235 *)
236 start
237 pkgs
238 wallpaper
239 gen_distro
240 summary ;;
241 esac
243 exit 0