tazinst view slitaz-installer @ rev 31

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sat Feb 22 21:13:33 2014 +0000 (2014-02-22)
parents df9c8e8bab7f
children 0df59f69c90c
line source
1 #!/bin/sh
2 #
3 # slitaz-installer - A CLI frontend to tazinst, the
4 # SliTaz GNU/Linux installer
5 #
6 # (C) 2007-2014 SliTaz - GNU General Public License v3.
7 #
8 # Authors : Christophe Lincoln <pankso@slitaz.org>
9 # Dominique Corbex <domcox@slitaz.org>
10 #
12 TAZINST_REQUIRED_VERSION="2.98"
13 BACKLIST="SliTaz GNU/Linux installer"
14 DIALOG=dialog
15 VERSION="3.95"
17 #--------------
18 # msgs section
19 #--------------
21 # info msgs
23 MODE_MSG="\n$(gettext "Welcome to the slitaz-installer").\n
24 \Z2$(gettext "Which type of installation do you want to start?")\Zn\n"
26 MEDIA_MSG="\n$(gettext "SliTaz can be installed from different media.")\n\n\
27 \Z2$(gettext "Select a media from the following list:")\Zn\n"
29 SOURCE_USB_MSG="\n$(gettext "You have selected the option to install SliTaz \
30 from an USB Key")\n\n\
31 \Z2$(gettext "Enter the partition where SliTaz Live is located:"):\Zn\n"
33 SOURCE_ISO_MSG="\n$(gettext "You have selected the option to install SliTaz \
34 from an ISO file located on a local disk.")\n\n\
35 \Z2$(gettext "Please, select a file below:")\Zn\n"
37 SOURCE_WEB_MSG="\n$(gettext "You have selected the option to install SliTaz \
38 from the web")\n\n\\Z2$(gettext "Please, select a version:")\Zn\n"
40 SOURCE_DEF_MSG="\n$(gettext "Select the source"):\n"
42 ROOT_UUID_DEFAULT_MSG="$(gettext "\nDrive selection")\n\n\Z2$(gettext "Please specify the partition where to install SliTaz:")\Zn\n"
44 ROOT_UUID_UPGRADE_MSG="$(gettext "The installer will upgrade the existing \
45 SliTaz system by saving all configuration files and the list of installed \
46 packages. Then, it will clean the partition and install the new version \
47 of SliTaz, restore the configuration files and reinstall any packages which \
48 are not present on the cdrom.
49 You will need an active internet connection before upgrading.")\n \
50 \Z2$(gettext "Partition containing the system to upgrade:")\Zn\n"
52 ROOT_FORMAT_MSG="\n$(gettext "Only the filesystems actually installed on your \
53 system are listed. If you intend to use another filesystem, you have to \
54 install it before. \
55 Unless you know what you are doing, it is safe to use ext2, ext3 or ext4.\n\n\
56 \Z2To format this partition, please select a filesystem below:")\Zn\n"
58 HOME_UUID_MSG="\n$(gettext "Separate /home partition")\n\n\
59 \Z2$(gettext "Please, select the partition to use:")\Zn\n"
61 HOSTNAME_MSG="\n$(gettext "Hostname configuration allows you to specify the \
62 machine name. The hostname is used internally to identify the host on the \
63 network. This value can be changed after the system is installed.\n\n\
64 \Z2Enter a hostname:\Zn\n")"
66 ROOT_PWD_MSG="\n$(gettext "The root administrator privilege lets you manage \
67 and configure the full system. A root user can damage your system so you \
68 should always setup a strong password with special characters and/or numbers.\
69 ")\n\n\
70 \Z2$(gettext "Enter the password for root:")\Zn\n"
72 USER_LOGIN_MSG="\n$(gettext "The default user for the system will have their \
73 personal files stored in /home/*user* (and will be automatically added to the \
74 audio group)")\n\n\Z2$(gettext "Enter the name of the first user:")\Zn\n"
76 USER_PWD_MSG="\n$(gettext "The password for default user").
77 $(gettext "It may be a security risk if too weak and should always be strong \
78 if you use a SSH connection through the web.")\n
79 \Z2$(gettext "Enter the password for the default user:")\Zn\n"
81 END_OF_INSTALL_MSG="\n$(gettext "Installation is now finished, you can exit \
82 the installer or reboot on your new SliTaz GNU/Linux operating system")."
85 # questions msgs
87 ASK_ROOT_FORMAT="\n$(gettext "The next step lets you format the target \
88 partition. Choose between robust, stable and/or journaled filesystem. If the \
89 partition is already formated you can skip this stage, if not just accept.\n
90 Warning! formating a partition will destroy all current data.\n
91 \Z2Do you wish to format the partition ?\Zn")"
93 ASK_HOME_UUID="\n$(gettext "On most GNU/Linux systems users personal \
94 files are stored in the directory /home. Home can be on a separate partition \
95 or another hard disk.\n
96 \Z2DO you want to use a separate Home partition ?\Zn")"
98 ASK_HOME_FORMAT="\n$(gettext "/home will be installed on a separate partition. \
99 The next step lets you format the /home partition. If the partition \
100 is already formated you can skip this stage, if not just accept. Warning \
101 formating a partition will destroy all current data.\n
102 \Z2Do you wish to format the /home partition ?\Zn")"
104 ASK_BOOTLOADER="\n$(gettext "You have now the option to install a \
105 bootloader which is capable of booting almost any kind of operating system.\n\n\
106 If you want to use an existing bootloader installation, skip this step \
107 and configure your bootloader to boot SliTaz (refer to your bootloader \
108 documentation on how to do this)").\n\n\
109 \Z2$(gettext "Install a bootloader?")\Zn\n"
111 ASK_WINBOOT="\n$(gettext "Do you want to implement a dual-boot with \
112 Windows? At start-up, you will be asked whether you want to boot into \
113 Windows or SliTaz GNU/Linux.\n
114 \Z2Install a dual-boot with Windows ?")\n"
116 ASK_SUMMARY="$(gettext "Installation settings summary and last chance to \
117 cancel or restart all installation steps.")\n
118 \Z2Go and install SliTaz?\Zn\n\n"
120 EMPTY_MENU_MSG="\n$(gettext "Sorry, no device, nor file found or available.")"
122 #---------------"
123 # check section
124 #---------------
126 check_tazinst()
127 {
128 local version
129 # search for tazinst
130 if ! [ -x /usr/sbin/tazinst ] ; then
131 printf "$(gettext "Error 2: ")
132 $(gettext "The lightweight SliTaz HDD installer 'tazinst' is missing.
133 Check permissions, or reinstall the slitaz-tools package.")\n"
134 exit 2
135 fi
136 # check version
137 version=$(tazinst version | tr -d '[:alpha:]')
138 if ! (echo "$version" | awk -v req="$TAZINST_REQUIRED_VERSION" '
139 {ver=$0+0}{ if (ver < req) exit 1}') ; then
140 printf "$(gettext "Error 2: ")
141 $(gettext "The lightweight SliTaz HDD installer tazinst ($version) is not
142 at the required version ($TAZINST_REQUIRED_VERSION), use tazinst in an xterm or
143 reinstall the slitaz-tools package.")\n"
144 exit 2
145 fi
146 }
148 #----------------
149 # dialog section
150 #----------------
152 # select msgs to display
153 msg()
154 {
155 local option="$1"
156 case "$option" in
157 mode)
158 printf "$MODE_MSG" ;;
159 media)
160 printf "$MEDIA_MSG" ;;
161 source)
162 local media="$(tazinst get media)"
163 case "$media" in
164 usb)
165 printf "$SOURCE_USB_MSG" ;;
166 iso)
167 printf "$SOURCE_ISO_MSG" ;;
168 web)
169 printf "$SOURCE_WEB_MSG" ;;
170 *)
171 printf "$SOURCE_DEF_MSG" ;;
172 esac ;;
173 root_uuid)
174 local mode="$(tazinst get mode)"
175 [ "$mode" = "upgrade" ] && printf "$ROOT_UUID_UPGRADE_MSG" \
176 || printf "$ROOT_UUID_DEFAULT_MSG" ;;
177 root_format|home_format)
178 printf "$ROOT_FORMAT_MSG" ;;
179 home_uuid)
180 printf "$HOME_UUID_MSG" ;;
181 hostname)
182 printf "$HOSTNAME_MSG" ;;
183 root_pwd)
184 printf "$ROOT_PWD_MSG" ;;
185 user_login)
186 printf "$USER_LOGIN_MSG" ;;
187 user_pwd)
188 printf "$USER_PWD_MSG" ;;
189 esac
190 }
192 # select questions to ask
193 ask()
194 {
195 local option="$1"
196 case "$option" in
197 root_format)
198 printf "$ASK_ROOT_FORMAT" ;;
199 home_uuid)
200 printf "$ASK_HOME_UUID" ;;
201 home_format)
202 printf "$ASK_HOME_FORMAT" ;;
203 bootloader)
204 printf "$ASK_BOOTLOADER" ;;
205 winboot)
206 printf "$ASK_WINBOOT" ;;
207 summary)
208 printf "$ASK_SUMMARY"
210 esac
211 }
213 # make text dialog compatible
214 text2dlg()
215 {
216 printf "$@" | awk '
217 {
218 num=split($0,list)
219 printf "%s ",$1
220 for (x=2; x<=num; x++){
221 if (x!=num)
222 printf "%s ", list[x]
223 else
224 printf "%s\n", list[x]
225 }
226 }'
227 }
229 # menu items msgs
230 list_items()
231 {
232 local data ref
233 case "$1" in
234 mode)
235 text2dlg "$(tazinst help mode)" ;;
236 media)
237 text2dlg "$(tazinst help media)" ;;
238 usb)
239 tazinst list usb ;;
240 iso)
241 tazinst list iso | awk '{print $0, " "}' ;;
242 web)
243 text2dlg "$(tazinst help web)" ;;
244 root_uuid)
245 tazinst list uuid ;;
246 root_format)
247 for i in $(tazinst list format); do
248 text2dlg "$(tazinst help root_format | grep $i)"
249 done ;;
250 home_uuid)
251 tazinst list uuid ;;
252 home_format)
253 for i in $(tazinst list format); do
254 text2dlg "$(tazinst help home_format | grep $i)"
255 done ;;
256 bootloader)
257 text2dlg "$(tazinst help bootloader)" ;;
258 esac
259 }
261 summary_list()
262 {
263 local option
264 for option in $SEQUENCE; do
265 case "$option" in
266 mode)
267 local mode="$(tazinst get mode)"
268 printf "\n\n$(gettext "Mode"): "
269 printf "$(tazinst help mode | grep "$mode")" ;;
270 media)
271 printf "\n$(gettext "From media"): $(tazinst get media)" ;;
272 source)
273 local source="$(tazinst get source)"
274 [ -n "$source" ] && printf " ($source)" ;;
275 root_uuid)
276 printf "\n$(gettext "To the disk"): $(tazinst get root_uuid)" ;;
277 root_format)
278 local root_format="$(tazinst get root_format)"
279 [ -n "$root_format" ] \
280 && printf " $(gettext "(Formatting as"): $root_format)" \
281 || printf " $(gettext "(No formatting)")" ;;
282 home_uuid)
283 local home_uuid="$(tazinst get home_uuid)"
284 [ -n "$home_uuid" ] \
285 && printf "\n$(gettext "Separate /home is"): $home_uuid" \
286 || printf "\n$(gettext "No separate /home partition")" ;;
287 home_format)
288 local home_format="$(tazinst get home_format)"
289 [ -n "$home_uuid" ] && ([ -n "$home_format" ] \
290 && printf " $(gettext "(Formatting as"): $home_format)" \
291 || printf " $(gettext "(No /home formatting)")";) ;;
292 hostname)
293 printf "\nHostname: $(tazinst get hostname)" ;;
294 user_login)
295 printf "\n$(gettext "User login"): $(tazinst get user_login)" ;;
296 bootloader)
297 local bootloader="$(tazinst get bootloader)"
298 [ -n "$bootloader" ] \
299 && printf "\n$(gettext "Bootloader: installed")" \
300 || printf "\n$(gettext "No bootloader installed")" ;;
301 winboot)
302 local winboot="$(tazinst get winboot)"
303 [ -n "$winboot" ] \
304 && printf "$(gettext ", with Windows dual-boot")" \
305 || printf "$(gettext ", no dual-boot")" ;;
306 esac
307 done
308 }
310 dialog_menu()
311 {
312 local option="$1" items="$2" sighup=1 sigint=2 sigquit=3
313 if [ -z "$items" ]; then
314 "$DIALOG" \
315 --title " Select $option " --clear \
316 --msgbox "$EMPTY_MENU_MSG" 10 41
317 fi
318 tempfile="$(mktemp)"
319 trap "rm -f $tempfile ; exit 1" $sighup $sigint $sigquit
320 "$DIALOG" \
321 --clear --colors \
322 --title " Select $option " \
323 --backtitle "$BACKLIST" \
324 --default-item "$(tazinst get "$option")" \
325 --ok-label "$(gettext "Next")" \
326 --cancel-label "$(gettext "Back")" \
327 --menu "$(msg $option)" 18 70 6 $items 2> "$tempfile"
328 retval="$?"
329 choice=$(cat "$tempfile")
330 rm -f "$tempfile"
331 case "$retval" in
332 0)
333 # a '$choice' was selected
334 tazinst set "$option" "$choice" && move up || \
335 "$DIALOG" \
336 --title " Select $option " --clear \
337 --msgbox "\n$(tazinst check "$option" 2>&1)" 10 41 ;;
338 1|255)
339 # voluntary exit or ESC pressed
340 move back ;;
341 esac
342 return "$retval"
343 }
345 dialog_yesno()
346 {
347 local option="$1"
348 "$DIALOG" \
349 --clear --colors \
350 --title " Select $option " \
351 --backtitle "$BACKLIST" \
352 --ok-label "$(gettext "Yes")" \
353 --cancel-label "$(gettext "Back")" \
354 --extra-button --extra-label "$(gettext "No")" \
355 --yesno "$(ask $option)" 18 70
356 retval="$?"
357 case "$retval" in
358 # 0: yes
359 1) # cancel
360 move back ;;
361 3) # no
362 tazinst unset "$option"
363 move up ;;
364 255)# ESC pressed
365 move back ;;
366 esac
367 return "$retval"
368 }
370 dialog_input()
371 {
372 local option="$1" sighup=1 sigint=2 sigquit=3
373 local value="$(tazinst get "$option")"
374 tempfile="$(mktemp)"
375 trap "rm -f $tempfile; exit 1" $sighup $sigint $sigquit
376 $DIALOG \
377 --clear --colors \
378 --title " Select $option " \
379 --ok-label "$(gettext "Next")" \
380 --cancel-label "$(gettext "Back")" \
381 --inputbox "$(msg $option)" 16 51 "$value" 2> "$tempfile"
382 retval="$?"
383 choice="$(cat $tempfile)"
384 rm -f "$tempfile"
385 case "$retval" in
386 0) # new value
387 tazinst set "$option" "$choice"
388 retcode=$?
389 [ "$retcode" -gt "0" ] && \
390 "$DIALOG" \
391 --title " Select $option " --clear \
392 --msgbox "\n$(tazinst check "$option" 2>&1)" 10 41
393 # continue if no error (0) or only warning (>127)
394 [ "$retcode" -le "0" ] && move up
395 [ "$retcode" -gt "127" ] && move up ;;
396 1) # cancel pressed."
397 move back ;;
398 255)# ESC pressed
399 move back ;;
400 esac
401 return "$retval"
402 }
404 # tiny summary and last chance to cancel or restart
405 summary()
406 {
407 "$DIALOG" \
408 --clear --colors \
409 --title " Summary " \
410 --backtitle "$BACKLIST" \
411 --yes-label "$(gettext "Yes")" \
412 --no-label "$(gettext "No")" \
413 --yesno "$(ask summary)$(summary_list)" 18 70
414 retval="$?"
415 case "$retval" in
416 0) # yes
417 move up ;;
418 1) # Cancel
419 gettext "Slitaz install cancelled."; echo
420 exit 1 ;;
421 3) # no
422 return 3 ;;
423 255)# ESC pressed
424 move back ;;
425 esac
426 }
428 #--------------------
429 # sequencing section
430 #--------------------
432 # get list of settings
433 sequence()
434 {
435 SEQUENCE="$(tazinst get settings) summary"
436 MAX="$(echo "$SEQUENCE" | wc -w)"
437 }
439 # get the setting name corresponding to an index in the list of settings
440 key()
441 {
442 local index="$1" num=1 string
443 for string in $SEQUENCE; do
444 [ "$num" = "$index" ] && printf "$string"
445 num=$(($num + 1))
446 done
447 }
449 # move index in list of settings
450 move()
451 {
452 local way="$1"
453 case "$way" in
454 init)
455 INDEX=1
456 WAY="up" ;;
457 up)
458 INDEX=$(($INDEX+1))
459 WAY="up" ;;
460 back)
461 INDEX=$(($INDEX-1))
462 WAY="down" ;;
463 away)
464 # continue to move in the same way (move up or move back)
465 [ "$WAY" = "up" ] && INDEX=$(($INDEX+1)) || INDEX=$(($INDEX-1)) ;;
466 esac
467 }
469 source_menu()
470 {
471 media="$(tazinst get media)"
472 case "$media" in
473 cdrom)
474 tazinst unset source || exit 2
475 move away ;;
476 usb)
477 dialog_menu source "$(list_items usb)" ;;
478 iso)
479 dialog_menu source "$(list_items iso)" ;;
480 web)
481 dialog_menu source "$(list_items web)" ;;
482 *)
483 move away ;;
484 esac
485 }
487 #--------------
488 # main section
489 #--------------
491 check_tazinst && tazinst new
492 tazinst get mode || exit 1
493 sequence
494 move init
496 while [ "$INDEX" -le "$MAX" ]
497 do
498 OPTION="$(key $INDEX)"
499 case "$OPTION" in
500 "")
501 exit 0 ;;
502 mode)
503 dialog_menu mode "$(list_items mode)" && sequence ;;
504 media)
505 dialog_menu media "$(list_items media)" ;;
506 source)
507 source_menu ;;
508 root_uuid)
509 dialog_menu root_uuid "$(list_items root_uuid)" ;;
510 root_format)
511 dialog_yesno root_format && \
512 dialog_menu root_format "$(list_items root_format)" ;;
513 home_uuid)
514 dialog_yesno home_uuid && \
515 dialog_menu home_uuid "$(list_items home_uuid)" ;;
516 home_format)
517 if [ -n "$(tazinst get home_uuid)" ]; then
518 dialog_yesno home_format && \
519 dialog_menu home_format "$(list_items home_format)"
520 else
521 tazinst unset home_format
522 move away
523 fi ;;
524 hostname)
525 dialog_input hostname ;;
526 root_pwd)
527 dialog_input root_pwd ;;
528 user_login)
529 dialog_input user_login ;;
530 user_pwd)
531 dialog_input user_pwd ;;
532 bootloader)
533 dialog_yesno bootloader && \
534 { tazinst set bootloader "auto" && move up; } || \
535 { tazinst unset bootloader ;
536 tazinst unset winboot ; } ;;
537 winboot)
538 if [ -n "$(tazinst get bootloader)" ]; then
539 dialog_yesno winboot && \
540 { tazinst set winboot "auto" && move up; } || \
541 tazinst unset winboot
542 else
543 move away
544 fi ;;
545 summary)
546 summary ;;
547 *)
548 exit 1 ;;
549 esac
550 done
552 # execute process
553 tazinst execute | awk 'BEGIN{
554 printf "XXX\n0\n"
555 }
556 {
557 num=$1+0
558 if (num>=1){
559 printf "XXX\nXXX\n%s\n", num
560 printf "\n%s\n",substr($0,length($1)+2)
561 }
562 else
563 printf "%s\n",$0
564 }
565 END{
566 print "XXX"
567 }' | $DIALOG --title "Slitaz-Installer" --gauge "Installing.." 20 70 0
570 # end_of_install
571 if tazinst log | grep -q "x-x-" ; then
572 tazinst clean
573 $DIALOG --title " Installation complete " \
574 --backtitle "$BACKLIST" \
575 --yes-label "Exit" \
576 --no-label "Reboot" \
577 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
578 retval=$?
579 case $retval in
580 0)
581 exit 0 ;;
582 1)
583 reboot || reboot -f ;;
584 255)
585 echo -e "ESC pressed.\n" && exit 0 ;;
586 esac
587 else
588 $DIALOG --title " Process not completed " \
589 --backtitle "$BACKLIST" \
590 --clear --msgbox \
591 "$(tazinst log | awk '$1 == "-x-x-",$1 == "x-x-x"')" 18 70
592 retval=$?
593 case $retval in
594 0)
595 exit 0 ;;
596 255)
597 echo -e "ESC pressed.\n" && exit 0 ;;
598 esac
599 fi