tazlito view tazlito-wiz @ rev 454

dot command may not search current directory first
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 23 13:52:41 2017 +0200 (24 months ago)
parents d7d87b67adeb
children 7c8e4ca19511
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 --field="":LBL --field=" ":LBL \
61 --field="$(_ "*.flavor file (optional):")":SFL \
62 --button='gtk-help:4' \
63 --button="$(_ 'Write ISO')!iso-image-burn:3" \
64 --button="$(_ 'TazPanel Live'):2" \
65 --button='gtk-cancel:1' \
66 --button='gtk-go-forward:0' \
67 'custom' 'core!core64!gtkonly!justx!base'
68 }
71 # Start page handler
73 start() {
74 # Store box results
75 main=$(start_main)
77 # Deal with --button values
78 case $? in
79 1) exit 0;;
80 2) tazpanel live; exit 0;;
81 3) terminal -T 'write-iso' -e 'tazlito writeiso lzma'; exit 0;;
82 4) tazweb 'file:///usr/share/doc/tazlito/tazlito.html'; exit 0;;
83 *) continue;;
84 esac
86 # Deal with $main values
88 (
89 export output='raw'
90 # Numbers are moved the progressbar
91 echo '30'
92 # Lines started with '#' are displayed in the log
93 tazpkg recharge | sed 's|^.*|#&|'
94 name="$(echo $main | cut -d'|' -f1)"; name="${name:-custom}"
95 skel="$(echo $main | cut -d'|' -f2)"
96 flvf="$(echo $main | cut -d'|' -f5)"
97 if [ ${flvf/*./} == flavor ]; then
98 cp -a $flvf $live ; skel=$(basename $flvf)
99 fi
100 echo "$skel" > $live/skel
101 echo '60'
102 tazlito get-flavor $skel | sed 's|^.*|#&|'
103 echo '90'
104 sed -i "s|^ISO_NAME=.*|ISO_NAME=\"$name\"|" tazlito.conf
105 sed -i "s|^VOLUM_NAME=.*|VOLUM_NAME=\"SliTaz $name\"|" tazlito.conf
106 ) | \
107 yad --progress $opts --image='system-software-update' \
108 --text="<b>$(_ 'Getting flavor file and packages list...')</b>" \
109 --enable-log="$(_ 'Log')" --log-expanded --button='gtk-go-forward:0'
111 }
114 # Packages page GUI
116 pkgs_main() {
117 pkgs=$(cat $list | wc -l)
118 skel=$(cat $live/skel)
119 text=$(_p 'Packages - The "%s" has %d package' 'Packages - The "%s" has %d packages' "$pkgs" "$skel" "$pkgs")
120 yad --form $opts --image='application-x-tazpkg' \
121 --text="<b>$text</b>" --separator=' ' \
122 --field="$(_ 'Additional packages separated by space or by line:')\\n$(_ '(will be auto added to "Edit packages list")')":TXT \
123 --button="$(_ 'Edit packages list')!document-properties:2" \
124 --button='gtk-cancel:1' --button='gtk-go-forward:0'
125 }
128 # Packages page handler
130 pkgs() {
131 # Store box results
132 main=$(pkgs_main)
133 # Deal with --button values
134 case $? in
135 1) exit 0 ;;
136 2) add_to_list ; edit_list ;;
137 *) add_to_list ;;
138 esac
139 }
142 add_to_list() {
143 for pkg in $(echo $main | sed s'/\\n/ /'g); do
144 vers=$(grep -E "^$pkg \|" $db/packages.desc | awk '{print $3}')
145 [ -z $vers ] || \
146 (grep -v -q "^$pkg-$vers" $list && \
147 echo "$pkg-$vers" >> $list
148 )
149 unset vers
150 done
151 }
154 # Wallpaper page GUI
156 wallpaper_main() {
157 yad --form $opts --image='preferences-desktop-wallpaper' \
158 --text="<b>$(_ 'SliTaz desktop wallpaper')</b>" --separator='' \
159 --field="$(_ 'Wallpaper JPG image:')":FL \
160 --button='gtk-cancel:1' --button='gtk-go-forward:0'
161 }
164 # Wallpaper page handler
166 wallpaper() {
167 # Store box results
168 main=$(wallpaper_main)
169 # Deal with --button values
170 case $? in
171 1) exit 0 ;;
172 *) continue ;;
173 esac
174 if echo "$main" | fgrep -q .jpg; then
175 mkdir -p $addfiles/rootfs/usr/share/images
176 cp -f $main $addfiles/rootfs/usr/share/images
177 fi
178 }
181 # Last page GUI
183 gen_distro_main() {
184 (
185 _ "
186 Now it's time to generate the distro. Last chance to start over or stop. \
187 Creating a Live system uses quite a lot of resources and takes some time.
188 Note you can still add some files to the SliTaz root filesystem or on the CD-ROM."
189 echo
190 echo $addfiles
191 ) | yad --text-info $opts $default_icon \
192 --text="<b>$(_ 'Generate the distribution')</b>" --wrap --margins=20 \
193 --button='gtk-cancel:1' --button='gtk-go-forward:0'
194 }
197 # Last page handler
199 gen_distro() {
200 # Store box results
201 main=$(gen_distro_main)
203 # Deal with --button values
204 case $? in
205 1) exit 0 ;;
206 *)
207 export output='raw'
208 echo -e "\n" | tazlito gen-distro 2>&1 | yad \
209 --text-info $opts $default_icon --tail \
210 --text="<b>$(_ 'Building the Live system...')</b>" \
211 --button='gtk-go-forward:0'
212 ;;
213 esac
214 }
217 # Summary
219 summary() {
220 . ./tazlito.conf
221 iso_size=$(du -sh $distro/$ISO_NAME.iso | awk '{print $1}')
222 distro_size=$(du -sh $distro/rootfs | awk '{print $1}')
223 text="$(_ 'Live system summary')"
224 echo -e "\
225 $(_ 'Generated ISO') \n$distro/$ISO_NAME.iso
226 $(_ 'Image size') \n$iso_size
227 $(_ 'Uncompressed size') \n$distro_size" | \
228 yad --list $opts $default_icon --text="<b>$text</b>" \
229 --column="$(_ 'Information')":0 --column="$(_ 'Value')":1 \
230 --button="gtk-close":0
231 }
234 #
235 # Script commands
236 #
238 case "$1" in
239 usage)
240 echo "Usage: $(basename $0) [command]" ;;
241 *)
242 start
243 pkgs
244 wallpaper
245 gen_distro
246 summary ;;
247 esac
249 exit 0