tazinst view slitaz-installer @ rev 116

tazinst: typo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 09 15:11:39 2021 +0000 (2021-11-09)
parents e6d15a13acca
children
line source
1 #!/bin/sh
2 #
3 # slitaz-installer - A CLI frontend to tazinst, the
4 # SliTaz GNU/Linux installer
5 #
6 # (C) 2007-2016 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.96"
17 #--------------
18 # msgs section
19 #--------------
20 . /lib/libtaz.sh
21 # info msgs
23 MODE_MSG="\n$(_ 'Welcome to the slitaz-installer.')\n
24 \Z2$(_ 'Which type of installation do you want to start?')\Zn\n"
26 MEDIA_MSG="\n$(_ 'SliTaz can be installed from different media.')\n
27 \Z2$(_ 'Select a media from the following list:')\Zn\n"
29 SOURCE_USB_MSG="\n$(_ 'You have selected the option to install SliTaz from a USB Key.')\n
30 \Z2$(_ 'Enter the partition where SliTaz Live is located:')\Zn\n"
32 SOURCE_ISO_MSG="\n$(_ "You have selected the option to install SliTaz \
33 from an ISO file located on a local disk.")\n
34 \Z2$(_ 'Please, select a file below:')\Zn\n"
36 SOURCE_WEB_MSG="\n$(_ 'You have selected the option to install SliTaz from the web.')\n
37 \\Z2$(_ 'Please, select a version:')\Zn\n"
39 SOURCE_DEF_MSG="\n$(_ 'Select the source:')\n"
41 ROOT_UUID_DEFAULT_MSG="\n$(_ 'Drive selection')\n
42 \Z2$(_ 'Please specify the partition where to install SliTaz:')\Zn\n"
44 ROOT_UUID_UPGRADE_MSG="$(_ "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 CD-ROM.")
49 $(_ 'You will need an active internet connection before upgrading.')
50 \Z2$(_ 'Partition containing the system to upgrade:')\Zn\n"
52 ROOT_FORMAT_MSG="\n$(_ "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. Unless you know what you are doing, it is safe to use ext2, \
55 ext3 or ext4.")\n
56 \Z2$(_ 'To format this partition, please select a filesystem below:')\Zn\n"
58 HOME_UUID_MSG="\n$(_ 'Separate /home partition')\n
59 \Z2$(_ 'Please, select the partition to use:')\Zn\n"
61 HOSTNAME_MSG="\n$(_ "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
64 \Z2$(_ 'Enter a hostname:')\Zn\n)"
66 ROOT_PWD_MSG="\n$(_ "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.")\n
69 \Z2$(_ 'Enter the password for root:')\Zn\n"
71 USER_LOGIN_MSG="\n$(_ "The default user for the system will have their \
72 personal files stored in /home/*user* (and will be automatically added to the \
73 audio group)")\n
74 \Z2$(_ 'Enter the name of the first user:')\Zn\n"
76 USER_PWD_MSG="\n$(_ 'The password for default user.')
77 $(_ "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$(_ 'Enter the password for the default user:')\Zn\n"
81 END_OF_INSTALL_MSG="\n$(_ "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$(_ "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 \Z2$(_ 'Do you wish to format the partition?')\Zn)"
93 ASK_HOME_UUID="\n$(_ "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 \Z2$(_ 'Do you want to use a separate Home partition?')\Zn)"
98 ASK_HOME_FORMAT="\n$(_ "/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.")
101 $(_ 'Warning! formating a partition will destroy all current data.')\n
102 \Z2$(_ 'Do you wish to format the /home partition?')\Zn)"
104 ASK_BOOTLOADER="\n$(_ "You have now the option to install a \
105 bootloader which is capable of booting almost any kind of operating system.")\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
109 \Z2$(_ 'Install a bootloader?')\Zn\n"
111 ASK_WINBOOT="\n$(_ "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 \Z2$(_ 'Install a dual-boot with Windows?')\n"
116 ASK_SUMMARY="$(_ "Installation settings summary and last chance to \
117 cancel or restart all installation steps.")\n
118 \Z2$(_ 'Go and install SliTaz?')\Zn\n\n"
120 EMPTY_MENU_MSG="\n$(_ '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 _ 'Error 2:'
132 _ "The lightweight SliTaz HDD installer '%s' is missing." 'tazinst'
133 _ 'Check permissions, or reinstall the %s package.' 'slitaz-installer'
134 newline; 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 _ 'Error 2:'
141 _ 'The lightweight SliTaz HDD installer tazinst (%s) is not at the required version (%s).' \
142 "$version" "$TAZINST_REQUIRED_VERSION"
143 _ 'Use %s in an xterm or reinstall the %s package.' 'tazinst' 'slitaz-installer'
144 newline; 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 if [ "$mode" = 'upgrade' ]; then printf "$ROOT_UUID_UPGRADE_MSG";
176 else printf "$ROOT_UUID_DEFAULT_MSG"; fi ;;
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$(_ 'Mode: %s')" \
269 "$(tazinst help mode | grep "$mode")" ;;
270 media)
271 printf "\n$(_ 'From media: %s')" "$(tazinst get media)" ;;
272 source)
273 local source="$(tazinst get source)"
274 [ -n "$source" ] && printf " ($source)" ;;
275 root_uuid)
276 printf "\n$(_ 'To the disk: %s')" "$(tazinst get root_uuid)" ;;
277 root_format)
278 local root_format="$(tazinst get root_format)"
279 if [ -n "$root_format" ];
280 then printf " $(_ '(Formatting as %s)' "$root_format")";
281 else printf " $(_ '(No formatting)')"; fi ;;
282 home_uuid)
283 local home_uuid="$(tazinst get home_uuid)"
284 if [ -n "$home_uuid" ];
285 then printf "\n$(_ 'Separate /home is: %s' "$home_uuid")";
286 else printf "\n$(_ 'No separate /home partition')"; fi ;;
287 home_format)
288 local home_format="$(tazinst get home_format)"
289 if [ -n "$home_uuid" ]; then if [ -n "$home_format" ];
290 then printf " $(_ '(Formatting as %s)' "$home_format")";
291 else printf " $(_ '(No /home formatting)')"; fi; fi ;;
292 hostname)
293 printf "\n$(_ 'Hostname: %s' "$(tazinst get hostname)")" ;;
294 user_login)
295 printf "\n$(_ 'User login: %s' "$(tazinst get user_login)")" ;;
296 bootloader)
297 local bootloader="$(tazinst get bootloader)"
298 if [ -n "$bootloader" ];
299 then printf "\n$(_ 'Bootloader: installed')";
300 else printf "\n$(_ 'No bootloader installed')"; fi ;;
301 winboot)
302 local winboot="$(tazinst get winboot)"
303 if [ -n "$winboot" ];
304 then printf "$(_ ", with Windows dual-boot")";
305 else printf "$(_ ", no dual-boot")"; fi ;;
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 %s' "$option") " \
323 --backtitle "$BACKLIST" \
324 --default-item "$(tazinst get "$option")" \
325 --ok-label "$(_ 'Next')" \
326 --cancel-label "$(_ '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 %s' "$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 %s' "$option") " \
351 --backtitle "$BACKLIST" \
352 --ok-label "$(_ 'Yes')" \
353 --cancel-label "$(_ 'Back')" \
354 --extra-button --extra-label "$(_ '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 %s' "$option") " \
379 --ok-label "$(_ 'Next')" \
380 --cancel-label "$(_ '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 %s' "$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 "$(_ 'Yes')" \
412 --no-label "$(_ '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 _ '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 _ 'ESC pressed.'; newline; 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 _ 'ESC pressed.'; newline; exit 0 ;;
598 esac
599 fi