tazinst view slitaz-installer @ rev 2

Use UUIDs, boot delay on mobile disks, GPT support, boot flag, new slitaz-installer and web frontends
author Dominique Corbex <domcox@slitaz.org>
date Thu Feb 14 13:12:12 2013 +0100 (2013-02-14)
parents
children 5996df6fd4a7
line source
1 #!/bin/sh
2 #"
3 # slitaz-installer - A CLI frontend to tazinst, the
4 # SliTaz GNU/Linux installer
5 #
6 # (C) 2007-2013 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.90"
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's 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's \
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 a 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 "Ok")" \
326 --cancel-label "$(gettext "Cancel")" \
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 "Cancel")" \
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 "Ok")" \
380 --cancel-label "$(gettext "Cancel")" \
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 move back ;;
420 3) # no
421 return 3 ;;
422 255)# ESC pressed
423 move back ;;
424 esac
425 }
427 #--------------------
428 # sequencing section
429 #--------------------
431 # get list of settings
432 sequence()
433 {
434 SEQUENCE="$(tazinst get settings) summary"
435 MAX="$(echo "$SEQUENCE" | wc -w)"
436 }
438 # get the setting name corresponding to an index in the list of settings
439 key()
440 {
441 local index="$1" num=1 string
442 for string in $SEQUENCE; do
443 [ "$num" = "$index" ] && printf "$string"
444 num=$(($num + 1))
445 done
446 }
448 # move index in list of settings
449 move()
450 {
451 local way="$1"
452 case "$way" in
453 init)
454 INDEX=1
455 WAY="up" ;;
456 up)
457 INDEX=$(($INDEX+1))
458 WAY="up" ;;
459 back)
460 INDEX=$(($INDEX-1))
461 WAY="down" ;;
462 away)
463 # continue to move in the same way (move up or move back)
464 [ "$WAY" = "up" ] && INDEX=$(($INDEX+1)) || INDEX=$(($INDEX-1)) ;;
465 esac
466 }
468 source_menu()
469 {
470 media="$(tazinst get media)"
471 case "$media" in
472 cdrom)
473 tazinst unset source || exit 2
474 move away ;;
475 usb)
476 dialog_menu source "$(list_items usb)" ;;
477 iso)
478 dialog_menu source "$(list_items iso)" ;;
479 web)
480 dialog_menu source "$(list_items web)" ;;
481 *)
482 move away ;;
483 esac
484 }
486 #--------------
487 # main section
488 #--------------
490 check_tazinst && tazinst new
491 tazinst get mode || exit 1
492 sequence
493 move init
495 while [ "$INDEX" -le "$MAX" ]
496 do
497 OPTION="$(key $INDEX)"
498 case "$OPTION" in
499 "")
500 exit 0 ;;
501 mode)
502 dialog_menu mode "$(list_items mode)" && sequence ;;
503 media)
504 dialog_menu media "$(list_items media)" ;;
505 source)
506 source_menu ;;
507 root_uuid)
508 dialog_menu root_uuid "$(list_items root_uuid)" ;;
509 root_format)
510 dialog_yesno root_format && \
511 dialog_menu root_format "$(list_items root_format)" ;;
512 home_uuid)
513 dialog_yesno home_uuid && \
514 dialog_menu home_uuid "$(list_items home_uuid)" ;;
515 home_format)
516 if [ -n "$(tazinst get home_uuid)" ]; then
517 dialog_yesno home_format && \
518 dialog_menu home_format "$(list_items home_format)"
519 else
520 tazinst unset home_format
521 move away
522 fi ;;
523 hostname)
524 dialog_input hostname ;;
525 root_pwd)
526 dialog_input root_pwd ;;
527 user_login)
528 dialog_input user_login ;;
529 user_pwd)
530 dialog_input user_pwd ;;
531 bootloader)
532 dialog_yesno bootloader && \
533 { tazinst set bootloader "auto" && move up; } || \
534 { tazinst unset bootloader ;
535 tazinst unset winboot ; } ;;
536 winboot)
537 if [ -n "$(tazinst get bootloader)" ]; then
538 dialog_yesno winboot && \
539 { tazinst set winboot "auto" && move up; } || \
540 tazinst unset winboot
541 else
542 move away
543 fi ;;
544 summary)
545 summary ;;
546 *)
547 exit 1 ;;
548 esac
549 done
551 # execute process
552 tazinst execute | awk 'BEGIN{
553 printf "XXX\n0\n"
554 }
555 {
556 num=$1+0
557 if (num>=1){
558 printf "XXX\nXXX\n%s\n", num
559 printf "\n%s\n",substr($0,length($1)+2)
560 }
561 else
562 printf "%s\n",$0
563 }
564 END{
565 print "XXX"
566 }' | $DIALOG --title "Slitaz-Installer" --gauge "Installing.." 20 70 0
569 # end_of_install
570 if tazinst log | grep -q "x-x-" ; then
571 tazinst clean
572 $DIALOG --title " Installation complete " \
573 --backtitle "$BACKLIST" \
574 --yes-label "Exit" \
575 --no-label "Reboot" \
576 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
577 retval=$?
578 case $retval in
579 0)
580 exit 0 ;;
581 1)
582 reboot || reboot -f ;;
583 255)
584 echo -e "ESC pressed.\n" && exit 0 ;;
585 esac
586 else
587 $DIALOG --title " Process not completed " \
588 --backtitle "$BACKLIST" \
589 --clear --msgbox \
590 "$(tazinst log | awk '$1 == "-x-x-",$1 == "x-x-x"')" 18 70
591 retval=$?
592 case $retval in
593 0)
594 exit 0 ;;
595 255)
596 echo -e "ESC pressed.\n" && exit 0 ;;
597 esac
598 fi