tazinst view tazinst @ rev 115

tazint: restore grub_password_command
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 23 15:17:11 2021 +0000 (2021-10-23)
parents 9839929d4295
children ca5a7537bf0c
line source
1 #!/bin/sh
2 # tazinst - SliTaz GNU/Linux installer.
3 #
4 # So this is the SliTaz installer. The script starts with a
5 # few main variables, then all the functions and then the
6 # full sequence of functions.
7 #
8 # (C) 2007-2016 SliTaz - GNU General Public License v3.
9 #
10 # Authors : Christophe Lincoln <pankso@slitaz.org>
11 # Dominique Corbex <domcox@slitaz.org>
13 # Exit codes:
14 # 1: Parameters error
15 # 2: Install file error
16 # 3: Source error
17 # 4: Target error
18 # 5: Missing resource
19 # 6: SliTaz system to upgrade not found
20 # 7: Another instance is running
21 # 8: Internal error
22 # 9: User cancellation
25 # path
26 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
27 umask 0177
29 # read SliTaz conf
30 [ -r /etc/slitaz/slitaz.conf ] && . /etc/slitaz/slitaz.conf
32 # read Tazinst conf
33 [ -r /etc/slitaz/tazinst.conf ] && . /etc/slitaz/tazinst.conf
35 # version
36 readonly VERSION=3.95
38 # i18n
39 . /lib/libtaz.sh
40 export TEXTDOMAIN='tazinst'
43 # common kernels arguments
44 readonly KERNEL_ARGS="video=-32 quiet"
46 # files
47 readonly DEFAULT_INSTALL_FILE=./tazinst.rc
48 readonly SOURCE_ROOT=/media/source
49 readonly TARGET_ROOT=/mnt/target
50 readonly LOG=/var/log/tazinst.log
51 readonly LOCK=/run/tazinst.pid
52 MIRRORS="${MIRRORS:-$LOCALSTATE/mirrors}"
54 # settings
55 readonly SETTINGS="mode media source \
56 root_uuid root_format home_uuid home_format \
57 hostname root_pwd user_login user_pwd \
58 bootloader liveboot webboot winboot"
60 # modes (key:help)
61 readonly LST_MODE="
62 install:$(_ 'Fresh install on a HDD')
63 upgrade:$(_ 'Upgrade an existing system')"
65 # media (key:help)
66 readonly LST_MEDIA="
67 cdrom:$(_ 'LiveCD')
68 usb:$(_ 'LiveUSB')
69 iso:$(_ 'ISO image on a local drive')
70 web:$(_ 'ISO image on the Internet')"
72 # formats (key:help)
73 readonly LST_FORMAT="
74 btrfs:$(_ 'B-tree file system (Oracle)')
75 ext2:$(_ 'Second extended filesystem (Linux)')
76 ext3:$(_ 'Third extended filesystem (Linux)')
77 ext4:$(_ 'Fourth extended file system (Linux)')
78 jfs:$(_ 'Journaled File System (IBM)')
79 minix:$(_ 'File system of the MINIX operating system')
80 reiser4:$(_ 'Journaled computer file system (Namesys)')
81 xfs:$(_ 'Journaling file system (Silicon Graphics, Inc.)')"
83 # bootloaders (key:help)
84 readonly LST_BOOTLOADER="
85 auto:$(_ 'Automatic selection')
86 grub:$(_ 'GRUB legacy bootloader')
87 syslinux:$(_ 'Lightweight bootloader')"
89 # predefined iso (key:url:help)
90 SLITAZ_VERSION="${SLITAZ_VERSION:-cooking}"
91 [ "$SLITAZ_VERSION" = 'cooking' ] && SLITAZ_VERSION="$(($(date "+%y")-8)).0"
92 [ -n "$URL_ISO" ] && readonly LST_WEB="$URL_ISO" || readonly LST_WEB="
93 stable:iso/stable/slitaz-$SLITAZ_VERSION.iso \
94 :$(_ 'Stable release') $SLITAZ_VERSION
95 core:iso/stable/flavors/slitaz-$SLITAZ_VERSION-core.iso \
96 :$(_ 'Stable version without nested subsets')
97 base:iso/stable/flavors/slitaz-$SLITAZ_VERSION-base.iso \
98 :$(_ 'Stable text-only version (8.1MB)')
99 justx:iso/stable/flavors/slitaz-$SLITAZ_VERSION-justx.iso \
100 :$(_ 'Stable basic graphic version without graphic apps')
101 gtkonly:iso/stable/flavors/slitaz-$SLITAZ_VERSION-gtkonly.iso \
102 :$(_ 'Stable basic graphic version with only GTK')
103 cooking:iso/cooking/slitaz-cooking.iso \
104 :$(_ 'Development version for testing latest features')
105 rolling:iso/rolling/slitaz-rolling.iso \
106 :$(_ 'Bleeding edge development version updated every day')
107 "
110 #-------
111 # usage
112 #-------
114 # print a short help
115 usage()
116 {
117 _ 'SliTaz GNU/Linux Installer - Version: %s' "$VERSION"
118 newline; boldify "$(_ 'Usage:')"
119 echo -n ' '; _ '%s [command] <setting> <value> <file>' 'tazinst'
120 newline; boldify "$(_ 'Commands:')"
121 optlist "\
122 new $(_ 'Create a new install file.')
123 set $(_ 'Change value of a setting.')
124 unset $(_ 'Clear a setting.')
125 get $(_ 'Get the value of a setting.')
126 check $(_ 'Check settings.')
127 help $(_ 'Print a short help on settings')
128 list $(_ 'List system resources.')
129 execute $(_ 'Execute a SliTaz installation.')
130 log $(_ 'Display log file contents.')
131 clean $(_ 'Clean install and log files.')
132 version $(_ 'Print version and exit.')
133 usage $(_ 'Print this short usage.')
134 "
135 exit 0
136 }
138 usage_error()
139 {
140 local cmd="$1" script="$(basename $0)"
141 _ 'SliTaz GNU/Linux Installer - Version: %s' "$VERSION"
142 newline
143 _ "'%s': Unknown command!" "$cmd"
145 _ "Run: '%s' to get a list of available commands." "$script help"
146 exit 1
147 }
150 option_error()
151 {
152 local option="$1" list="$2"
153 _ 'SliTaz GNU/Linux Installer - Version: %s' "$VERSION"
154 newline
155 _ "'%s': Unknown option!" "$option"
157 _ 'Please select one of these options:'
158 printf " %s\n\n" "$list"
159 exit 1
160 }
162 #---------------------
163 # 1. settings section
164 #---------------------
166 #----------
167 # 1.1 file
168 #----------
170 # create a new install file
171 new_file()
172 {
173 local install_file=$1
174 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
175 if [ -e "$install_file" ]; then
176 _ 'Warning: file already exists.' 1>&2
177 exit 0
178 fi
179 [ -n "$install_file" ] && touch "$install_file"
180 if [ -w "$install_file" ]; then
181 write_file "$install_file"
182 else
183 _ 'Error: Cannot create file.' 1>&2
184 exit 2
185 fi
186 }
188 # fill up the install file
189 write_file()
190 {
191 local install_file="$1"
192 cat > "$install_file" <<EOT
193 # SliTaz GNU/Linux Installer - Version: $VERSION
194 #
195 # Install file.
196 #
198 # Mode of installation:
199 # install: Full install of SliTaz on a disk, all previous info will be erased
200 # upgrade: Upgrade an existing SliTaz installation to a new version
201 # run 'tazinst list mode' to have a full list.
202 MODE="$MODE"
204 # Media to install from:
205 # Options are cdrom usb iso web.
206 # run 'tazinst list media' to see available options on your system.
207 MEDIA="$MEDIA"
209 # Install source:
210 # it depends on the media used:
211 # usb: partition, run 'tazinst list uuid' to list your partitions
212 # iso: file.iso, ex: SOURCE=~/slitaz.5.0.iso
213 # web: url, ex: SOURCE=http://mirror.slitaz.org/../slitaz-cooking.iso
214 # web: iso names, ex: SOURCE=cooking
215 # run 'tazinst list <MEDIA>' to list source values. ex: tazinst list iso.
216 SOURCE="$SOURCE"
218 # root partition that SliTaz will be Installed on:
219 # Enter the UUID of the partition.
220 # run 'tazinst list uuid' to list your partitions
221 ROOT_UUID="$ROOT_UUID"
223 # Formatting the root partition:
224 # Let ROOT_FORMAT empty if you do not want to format the root partition.
225 # SliTaz uses ext2 ext3 ext4 by default but another filesystem can be
226 # installed if wanted, for this please adjust your /etc/fstab after
227 # installation.
228 # run 'tazinst list format' to list installed filesystems on your system.
229 ROOT_FORMAT="$ROOT_FORMAT"
231 # Home partition:
232 # On most GNU/Linux systems users personal files are stored in the directory
233 # /home. /home can be on another hard disk or on a separate partition.
234 # Leave HOME_UUID empty if you do not intend to use a specific partition for /home
235 # or enter the UUID of the partition to be used.
236 # run 'tazinst list uuid' to list your partitions.
237 HOME_UUID="$HOME_UUID"
239 # Formatting the /home partition (if /home is on a separate partition):
240 # Leave HOME_FORMAT empty if you do not want to format the /home partition.
241 # For options, see comments on 'Formatting the root partition' above.
242 HOME_FORMAT="$HOME_FORMAT"
244 # Hostname of the new system:
245 HOSTNAME="$HOSTNAME"
247 # root password:
248 # The root administrator privilege lets you manage and configure the full
249 # system. A root user can damage your system so you should always setup a
250 # strong password with special characters and/or numbers.
251 ROOT_PWD="$ROOT_PWD"
253 # Default user:
254 # The default user for the system will have his personal files stored
255 # in /home/<USER_LOGIN> (and will be automatically added to the audio group).
256 USER_LOGIN="$USER_LOGIN"
257 USER_PWD="$USER_PWD"
259 # Install bootloader:
260 # If you do not want to install a bootloader, leave this field empty.
261 # It's generally safe to set it up as 'auto'.
262 # Run 'tazinst list bootloader' to list all options.
263 BOOTLOADER="$BOOTLOADER"
265 # SliTaz live/rescue boot:
266 # If you do not want enable live boot, leave LIVEBOOT empty (LIVEBOOT="").
267 # You may let tazinst automatically find your rootfs file(s) by specifying auto
268 # (LIVEBOOT="auto").
269 LIVEBOOT="$LIVEBOOT"
271 # SliTaz Web boot:
272 # If you do not want enable Web boot, leave WEBBOOT empty (WEBBOOT="").
273 # You may let tazinst automatically find your pxe client by specifying auto
274 # (WEBBOOT="auto").
275 WEBBOOT="$WEBBOOT"
277 # Windows dual boot:
278 # If you do not want enable Dual boot, leave WINBOOT empty (WINBOOT="").
279 # You may let tazinst automatically find your win partition by specifying auto
280 # (WINBOOT="auto"), otherwise enter the UUID of the partition to be used.
281 # Run 'tazinst list winboot' to see the Windows partitions found by tazinst.
282 WINBOOT="$WINBOOT"
284 EOT
285 return "$?"
286 }
288 read_file()
289 {
290 local install_file="$1"
291 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
292 if ! [ -r "$install_file" ]; then
293 _ 'Error: Unable to read install file.' 1>&2
294 exit 2
295 fi
296 #
297 if ! CONTENTS="$(cat "$install_file")"; then
298 _ 'Error: Unable to read install file.' 1>&2
299 exit 2
300 fi
301 }
303 # read value of a setting
304 get_value()
305 {
306 local setting="$1"
307 printf "%s" "$CONTENTS" | /bin/busybox awk -v setting="$setting" 'BEGIN{
308 setting="^" toupper(setting) "="
309 }
310 {
311 if (match($0,setting)){
312 n=index($0,"=")
313 value=substr($0,n+1)
314 gsub(/[\t\s]*$/,"",value)
315 sub(/^"/,"",value)
316 sub(/"$/,"",value)
317 }
318 }
319 END{
320 print value
321 }'
322 }
324 # list of settings
325 get_settings()
326 {
327 local "mode=$(get_value mode)"
328 case "$mode" in
329 upgrade)
330 echo "mode media source root_uuid bootloader liveboot webboot winboot" ;;
331 *)
332 printf "%s\n" "$SETTINGS" ;;
333 esac
334 }
336 # get command
337 get()
338 {
339 local setting="$1"
340 [ -z "$setting" ] && setting="all"
341 # setting is valid: display value
342 if printf "%s" "$setting" | \
343 egrep -q "$(regex "$SETTINGS")"; then
344 get_value "$setting"
345 else
346 case "$setting" in
347 all)
348 for i in mode media source root_uuid root_format home_uuid home_format \
349 hostname root_pwd user_login user_pwd bootloader liveboot webboot winboot; do
350 printf "%-15s: %s\n" "$i" "$(get_value $i)"
351 done
352 ;;
353 settings)
354 get_settings
355 ;;
356 *)
357 option_error "$1" "$SETTINGS"
358 ;;
359 esac
360 fi
361 }
363 # set command
364 change()
365 {
366 local setting="$1" value="$2" install_file="$3"
367 # validate setting
368 if ! printf "%s" "$setting" | \
369 egrep -q "$(regex "$SETTINGS")"; then
370 _ "Error: '%s' unknown setting." "$setting" 1>&2
371 exit 1
372 fi
373 # and file
374 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
375 # write changes to file
376 if [ -w "$install_file" ]; then
377 printf "%s" "$CONTENTS" | \
378 /bin/busybox awk -v setting="$setting" -v value="$value" '
379 BEGIN{
380 set=0
381 }
382 {
383 if (match($0,"^" toupper(setting) "=")){
384 printf toupper(setting) "=\"" value "\"\n"
385 set++
386 }
387 else
388 printf $0 "\n"
389 }
390 END{
391 if (! set)
392 printf toupper(setting) "=\"" value "\"\n"
393 }' > "$install_file"
394 # check new value
395 read_file "$install_file"
396 check "$setting"
397 else
398 _ 'Error: Unable to write to install file.' 1>&2
399 exit 2
400 fi
401 }
403 #
404 load_settings()
405 {
406 MODE="$(get mode)"
407 local settings="$(get settings)"
408 MEDIA="$(get media)"
409 echo "source" | egrep -q "$(regex "$settings")" \
410 && SOURCE="$(get source)" \
411 || unset SOURCE
412 ROOT_UUID="$(get root_uuid)"
413 echo "root_format" | egrep -q "$(regex "$settings")" \
414 && ROOT_FORMAT="$(get root_format)" \
415 || unset ROOT_FORMAT
416 echo "home_uuid" | egrep -q "$(regex "$settings")" \
417 && HOME_UUID="$(get home_uuid)" \
418 || unset HOME_UUID
419 echo "home_format" | egrep -q "$(regex "$settings")" \
420 && HOME_FORMAT="$(get home_format)" \
421 || unset HOME_FORMAT
422 echo "hostname" | egrep -q "$(regex "$settings")" \
423 && HOSTNAME="$(get hostname)" \
424 || unset HOSTNAME
425 echo "root_pwd" | egrep -q "$(regex "$settings")" \
426 && ROOT_PWD="$(get root_pwd)" \
427 || unset ROOT_PWD
428 echo "user_login" | egrep -q "$(regex "$settings")" \
429 && USER_LOGIN="$(get user_login)" \
430 || unset USER_LOGIN
431 echo "user_pwd" | egrep -q "$(regex "$settings")" \
432 && USER_PWD="$(get user_pwd)" \
433 || unset USER_PWD
434 echo "bootloader" | egrep -q "$(regex "$settings")" \
435 && BOOTLOADER="$(get bootloader)" \
436 || unset BOOTLOADER
437 echo "liveboot" | egrep -q "$(regex "$settings")" \
438 && LIVEBOOT="$(get liveboot)" \
439 || unset LIVEBOOT
440 echo "webboot" | egrep -q "$(regex "$settings")" \
441 && WEBBOOT="$(get webboot)" \
442 || unset WEBBOOT
443 echo "winboot" | egrep -q "$(regex "$settings")" \
444 && WINBOOT="$(get winboot)" \
445 || unset WINBOOT
446 }
454 # clean command
455 clean()
456 {
457 # rm LOG
458 [ -r "$LOG" ] && rm -f "$LOG"
459 # rm temp files
460 rm -rf /tmp/tazinst
461 # rm install file
462 local install_file="$1"
463 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
464 _ 'Deleting install file: %s' "$install_file"
465 if ! [ -w "$install_file" ]; then
466 _ 'Error: Unable to delete install file.' 1>&2
467 exit 2
468 else
469 rm -f "$install_file"
470 fi
471 }
473 #-----------
474 # 1.2 check
475 #-----------
477 # exit if user is not root.
478 check_root()
479 {
480 if [ $(id -u) -ne 0 ]; then
481 _ "You must be the root user (system administrator) \
482 to install SliTaz, please use 'su' to get a root SHell and restart \
483 installation." 1>&2
484 exit 1
485 fi
486 }
488 # exit if another instance of tazinst is running
489 check_instance()
490 {
491 if [ -e "$LOCK" ]; then
492 _ 'Another instance of tazinst is running.' 1>&2
493 exit 7
494 else
495 printf "%s" "$$" > $LOCK
496 fi
497 }
499 # exit if the setting is not in a list of keywords
500 check_key()
501 {
502 local setting="$1" keylist="$2" keyword="$(get $1)" msg
503 if ! printf "%s" "$keyword" | \
504 egrep -q "$(regex "$keylist")"; then
505 msg="$setting=$keyword
506 $(_ "Error: '%s' Invalid keyword." "$keyword")
507 $(_ 'Select one of these options: %s.' "$keylist")
508 $(_ 'For more information, see tazinst Manual.')"
509 printf "%s\n" "$msg" 1>&2
510 exit 1
511 fi
512 }
514 # exit if the partition does not exist
515 check_uuid()
516 {
517 local setting="$1" value="$(get $1)" found=0 partition msg
518 for partition in $(list_uuid); do
519 [ "$partition" = "$value" ] && found="$(($found + 1))"
520 done
521 if [ "$found" != "1" ]; then
522 msg="$(gettext "$setting")=$value
523 $(_ 'Error: Partition not found.')
524 $(_ "To see available partitions, run '%s'." 'tazinst list uuid')"
525 printf "%s\n" "$msg" 1>&2
526 exit 1
527 fi
528 }
530 # exit if the source does not exist
531 check_source()
532 {
533 local media="$(get media)" source="$(get source)"
534 case $media in
535 usb)
536 check_uuid source ;;
537 iso)
538 if [ ! -r "$source" ]; then
539 _ 'Error: Source file not found.' 1>&2
540 exit 1
541 fi ;;
542 web)
543 local valid=0
544 # check full url (http://...)
545 local regexp="^(https?|ftp):\/\/([a-z0-9\-]+\.)?[a-z0-9\-]+\.\
546 [a-z0-9]{2,4}(\.[a-z0-9]{2,4})?(\/.*)?iso$"
547 printf "%s" "$source" | \
548 egrep -q "$regexp" && valid=$(($valid+1))
549 # check iso names (stable cooking...)
550 regexp="$(regex "$(list web)")"
551 printf "%s" "$source" | \
552 egrep -q "$regexp" && valid=$(($valid+1))
553 if [ "$valid" -le "0" ]; then
554 _ 'Error: invalid URL.' 1>&2
555 exit 1
556 fi
557 esac
558 }
560 # exit if a partition is selected more than once
561 check_uuid_mix()
562 {
563 local list all nodup
564 list="$(get root_uuid) $(get source) $(get home_uuid) $(get winboot)"
565 all="$(printf "%s" "$list" | wc -w)"
566 nodup="$(printf "%s" "$list" | /bin/busybox awk 'BEGIN{RS=" "}{print $0}' \
567 | sort | uniq | wc -w)"
568 if [ "$all" != "$nodup" ]; then
569 _ 'Error: multiple assignations for a disk.' 1>&2
570 exit 1
571 fi
572 }
575 # exit if a password is invalid
576 check_password()
577 {
578 local pass="$(get "$1")"
579 local invalid="^[A-Za-z0-9!@#$%^&*()_]{0,40}$"
580 local errcode=0
581 # too long
582 if [ "${#pass}" -ge 40 ]; then
583 _ 'Error: password too long.' 1>&2
584 exit 1
585 fi
586 # bad chars
587 if ! (printf "%s" "$pass" | egrep -q "$invalid"); then
588 _ 'Error: Unallowed characters in password.' 1>&2
590 exit 1
591 fi
592 # short pwd
593 [ "${#pass}" -le 4 ] && errcode=128
594 # empty pwd
595 [ -z "$pass" ] && errcode=129
596 case "$errcode" in
597 128)
598 _ 'Warning: short password!' 1>&2 ;;
599 129)
600 _ 'Warning: no password!' 1>&2 ;;
601 esac
602 return "$errcode"
603 }
605 # exit if a name is invalid
606 check_name()
607 {
608 local name="$1" value="$(get "$1")" msg
609 msg="$name=$value"
610 if [ "${#value}" -lt 2 ]; then
611 _ '%s Error: Too short.' "$msg" 1>&2
612 exit 1
613 fi
614 if [ "${#value}" -gt 32 ]; then
615 _ '%s Error: Too long.' "$msg" 1>&2
616 exit 1
617 fi
618 if printf "%s" "$value" | \
619 grep -q "[[:space:]\&\"\'\(\)\|\*\\#\`\+\:/;<>]"; then
620 _ '%s Error: Invalid chars.' "$msg" 1>&2
621 exit 1
622 fi
623 }
625 # check bootloader + winboot
626 check_boot_mix()
627 {
628 local bootloader=$(get bootloader)
629 local var name
630 [ -z "$bootloader" ] && while read var name; do
631 local value
632 eval value=\$$var
633 [ -z "$value" ] && continue
634 _ 'Error: %s set with no bootloader.' "$name" 1>&2
635 exit 1
636 done <<EOT
637 liveboot Rescue/live boot
638 webbot Web boot
639 winboot Dualboot
640 EOT
641 }
643 # exit if partition table is not in list
644 check_table()
645 {
646 local pt_list="gpt msdos"
647 # get root uuid
648 local uuid="$(get root_uuid)"
649 if [ "$(blkid | grep -c "$uuid")" = "1" ]; then
650 if ! printf "%s" "$(p_table $uuid)" | \
651 egrep -q "$(regex "$pt_list")"; then
652 _ 'Error: Unsupported Partition Table.' 1>&2
653 exit 1
654 fi
655 else
657 _ 'Error: No disk selected, cannot install any bootloader.' 1>&2
658 exit 1
659 fi
660 }
663 # check all settings()
664 check_all()
665 {
666 # check only settings we need
667 for key in $(get settings); do
668 case "$key" in
669 mode)
670 printf "%-15s: " "$key"
671 check_key $key "$(key "$LST_MODE")" && echo "ok" ;;
672 media)
673 printf "%-15s: " "$key"
674 check_key $key "$(key "$LST_MEDIA")" && echo "ok" ;;
675 source)
676 printf "%-15s: " "$key"
677 check_source && echo "ok" ;;
678 root_uuid)
679 printf "%-15s: " "$key"
680 check_uuid $key && echo "ok" ;;
681 root_format|home_format)
682 printf "%-15s: " "$key"
683 [ -n "$(get $key)" ] && \
684 { check_key $key "$(key "$LST_FORMAT")" && echo "ok"; } \
685 || echo "ok" ;;
686 home_uuid)
687 printf "%-15s: " "$key"
688 [ -n "$(get $key)" ] && \
689 { check_uuid $key && check_uuid_mix && echo "ok"; } \
690 || echo "ok" ;;
691 hostname|user_login)
692 printf "%-15s: " "$key"
693 check_name $key && echo "ok" ;;
694 root_pwd|user_pwd)
695 printf "%-15s: " "${key/pwd/password}"
696 check_password $key && echo "ok" ;;
697 bootloader)
698 printf "%-15s: " "$key"
699 [ -n "$(get $key)" ] \
700 && { check_key $key "$(list_bootloader)" \
701 && check_table && echo "ok" ; } \
702 || echo "ok" ;;
703 liveboot|webboot)
704 printf "%-15s: " "$key"
705 [ -n "$(get $key)" ] && { "$(get $key)" == "auto" ] \
706 && check_boot_mix && echo "ok"; } \
707 || echo "ok" ;;
708 winboot)
709 printf "%-15s: " "$key"
710 [ -n "$(get $key)" ] && [ "$(get $key)" != "auto" ] \
711 && { check_uuid $key && check_boot_mix && echo "ok"; } \
712 || echo "ok" ;;
713 esac
714 done
715 }
717 # check command
718 check()
719 {
720 local setting="$1"
721 case "$setting" in
722 mode)
723 check_key $setting "$(key "$LST_MODE")" ;;
724 media)
725 check_key $setting "$(key "$LST_MEDIA")" ;;
726 source)
727 check_source ;;
728 root_uuid)
729 check_uuid $setting
730 check_uuid_mix ;;
731 home_uuid)
732 [ -z "$(get $setting)" ] || check_uuid $setting
733 check_uuid_mix ;;
734 root_format)
735 [ -z "$(get $setting)" ] \
736 || check_key $setting "$(key "$LST_FORMAT")" ;;
737 home_format)
738 [ -z "$(get $setting)" ] \
739 || check_key $setting "$(key "$LST_FORMAT")" ;;
740 hostname|user_login)
741 check_name $setting ;;
742 root_pwd|user_pwd)
743 check_password $setting ;;
744 bootloader)
745 [ -z "$(get $setting)" ] \
746 || (check_key $setting "$(list_bootloader)" \
747 && check_table ; ) ;;
748 liveboot|webboot)
749 ([ -z "$(get $setting)" ] || [ "$(get $setting)" = "auto" ]) \
750 && check_boot_mix ;;
751 winboot)
752 ([ -z "$(get $setting)" ] || [ "$(get $setting)" = "auto" ]) \
753 || check_uuid $setting && check_boot_mix ;;
754 ""|all)
755 check_all ;;
756 *)
757 option_error "$setting" "$SETTINGS" ;;
758 esac
759 }
761 #----------
762 # 1.3 help
763 #----------
765 help_source()
766 {
768 _ 'The Source setting depends on the type of media:'
769 printf "%-12s%s\n" "cdrom" "$(help cdrom)"
770 printf "%-12s%s\n" "usb" "$(help usb)"
771 printf "%-12s%s\n" "iso" "$(help iso)"
772 printf "%-12s%s" "web" "$(_ 'Name or URL of the image on the web.')"
773 printf "%s\n" "$(_ 'Type: %s' 'tazinst help web')"
774 }
776 help_all()
777 {
778 _ 'List of settings:'
779 optlist "\
780 mode $(_ 'Mode of install')
781 media $(_ 'Media containing the SliTaz source files')
782 source $(_ 'Source file containing SliTaz')
783 root_uuid $(_ 'The name of the target partition')
784 root_format $(_ 'Format of the target partition')
785 home_uuid $(_ 'Separate home partition')
786 home_format $(_ 'Format of the root partition')
787 hostname $(_ 'Name of the system')
788 root_pwd $(_ 'Superuser password')
789 user_login $(_ 'First user name')
790 user_pwd $(_ 'First user password')
791 bootloader $(_ 'Install a bootloader')
792 liveboot $(_ 'Install a live/rescue boot (with root password)')
793 webboot $(_ 'Install a web boot (with root password)')
794 winboot $(_ 'Partition to dualboot Windows from')
795 "
796 }
798 # help command
799 help()
800 {
801 local setting="$1"
802 case "$setting" in
803 mode)
804 printf "%s" "$LST_MODE" | \
805 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
806 media)
807 printf "%s" "$LST_MEDIA" | \
808 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
809 source)
810 help_source ;;
811 cdrom)
812 _ 'CD. Automatically set' ;;
813 usb)
815 _ 'USB partition. For a list, type: %s' 'tazinst list usb' ;;
816 iso)
818 _ 'ISO file name. For a list, type: %s' 'tazinst list iso' ;;
819 web)
820 printf "%s" "$LST_WEB" | \
821 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $3}' ;;
822 root_format)
823 printf "%s" "$LST_FORMAT" | \
824 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
825 home_uuid|root_uuid)
826 /sbin/blkid -s TYPE -s LABEL | sort ;;
827 home_format)
828 printf "%s" "$LST_FORMAT" | \
829 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
830 hostname)
831 _ 'Name of the system' ;;
832 root_pwd)
833 _ 'Superuser password' ;;
834 user_login)
835 _ 'First user name' ;;
836 user_pwd)
837 _ 'First user password' ;;
838 bootloader)
839 printf "%s" "$LST_BOOTLOADER" | \
840 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n",$1,$2}' ;;
841 liveboot|webboot)
842 _ "Empty string, or 'auto'" ;;
843 winboot)
844 _ "Partition containing Windows, or 'auto'" ;;
845 ""|all)
846 help_all ;;
847 *)
848 option_error "$setting" "$SETTINGS" ;;
849 esac
850 }
852 #---------
853 # 2. list
854 #---------
856 list_media()
857 {
858 local key media
859 for key in $(key "$LST_MEDIA") ; do
860 case "$key" in
861 cdrom)
862 [ -e "/dev/cdrom" ] && media="cdrom" ;;
863 usb)
864 [ -e "/sys/bus/usb" ] && media="$media usb" ;;
865 web)
866 [ "$(ifconfig -a | grep -c Link)" -gt 2 ] \
867 && media="$media web" ;;
868 *)
869 media="$media $key"
870 esac
871 done
872 printf "%s\n" "$media" | sed 's/^\s//'
873 }
875 list_usb()
876 {
877 # List plugged USB disks
878 if [ -d /proc/scsi/usb-storage ]; then
879 for DEV in /sys/block/sd* ; do
880 if readlink $DEV | grep -q usb; then
881 DEV=$(basename $DEV)
882 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
883 blkid /dev/$DEV* | tr ' ' '\n' | /bin/busybox awk '
884 /^\/dev\// {
885 DEV=$1
886 gsub(/:/,"",DEV)
887 }
888 /^UUID/ {
889 UUID=$1
890 gsub(/"/,"",UUID)
891 printf "%s %s\n",UUID,DEV}'
892 fi
893 fi
894 done
895 fi
896 }
898 list_iso()
899 {
900 for i in /root/*.iso /home/*/*.iso /home/*/*/*.iso ; do
901 printf "%s" $i | grep -v "*"
902 done
903 }
905 list_format()
906 {
907 local fs
908 type mkfs.btrfs > /dev/null && fs="btrfs"
909 type mkfs.ext2 > /dev/null && fs="$fs ext2"
910 type mkfs.ext3 > /dev/null && fs="$fs ext3"
911 type mkfs.ext4 > /dev/null && fs="$fs ext4"
912 type mkfs.jfs > /dev/null && fs="$fs jfs"
913 type mkfs.minix > /dev/null && fs="$fs minix"
914 type mkfs.reiser4 > /dev/null && fs="$fs reiser4"
915 type mkfs.xfs > /dev/null && fs="$fs xfs"
916 printf "%s" "$fs" | sed 's/^\s//'
917 }
919 # list partitions
920 list_uuid()
921 {
922 # list all drives but cdroms
923 /sbin/blkid -o export| /bin/busybox awk '
924 BEGIN{FS="="}
925 /DEVNAME/{dev=$2, type="unknown", label=""}
926 /LABEL/{label=$2" "}
927 /TYPE/{type=$2}
928 /PARTUUID/{if (type != "iso9660"){
929 printf "%s %s(%s)\n", dev, label, type}}' | sort -k 2
930 }
932 list_partition_table()
933 {
934 /usr/sbin/parted -lms 2>&1 | \
935 /bin/busybox awk -F: '/^\/dev\//{printf "%s: %s\n", $1,$6}'
936 }
938 list_web()
939 {
940 local key="$1"
941 # print url of a given iso
942 if printf "%s" "$LST_WEB" | egrep -q "^$key:"; then
943 printf "%s" "$LST_WEB" | egrep "^$key:" | \
944 /bin/busybox awk -F: '{print $2}'
945 fi
946 # print all key
947 if [ -z "$key" ]; then
948 key "$LST_WEB"
949 fi
950 }
952 list_bootloader()
953 {
954 local btlr
955 type grub-install > /dev/null && btlr=" grub"
956 type syslinux > /dev/null && btlr="$btlr syslinux"
957 [ -n "$btlr" ] && printf "%s\n" "auto$btlr"
958 }
960 # list Windows partitions
961 list_winboot()
962 {
963 /usr/sbin/parted -lms 2>&1 | sed '/zram/,$d' | /bin/busybox awk '
964 BEGIN{
965 FS=":"
966 disknum=-1
967 found=0
968 winboot=""
969 printf "auto"
970 }
971 {
972 # Count disks
973 if (match($1,"^/dev")){
974 disknum++
975 part=0
976 disk=$1
977 dev=substr($1,6)
978 # get removable status
979 file="/sys/block/"dev"/removable"
980 "cat " file | getline removable
981 close("cat ")
982 }
983 # Count partitions
984 if (match($1,"[0-9][0-9]?")){
985 # List fixed drives only
986 if (removable==0){
987 part++
988 # Read partition Id
989 if (match($7,"boot")){
990 fs=$5
991 # Detect Windows Partition Type: ntfs vfat
992 WPT="ntfs|vfat"
993 if (fs ~ WPT){
994 found++
995 # record 1st Windows partition found
996 if (found==1){
997 printf(" %s%d",disk,part)
998 }
999 }
1004 END{printf "\n"}'
1007 # list command
1008 list()
1010 local ressource="$1"
1011 case "$ressource" in
1012 mode)
1013 printf "%s\n" "$(key "$LST_MODE")" ;;
1014 media)
1015 list_media ;;
1016 iso)
1017 list_iso ;;
1018 usb)
1019 list_usb ;;
1020 web)
1021 list_web "$2" ;;
1022 uuid)
1023 list_uuid ;;
1024 format)
1025 list_format ;;
1026 bootloader)
1027 list_bootloader ;;
1028 winboot)
1029 list_winboot ;;
1030 partition_table)
1031 list_partition_table ;;
1032 ""|all)
1033 printf "* mode:\n%s\n\n" "$(key "$LST_MODE")"
1034 printf "* media:\n%s\n\n" "$(list_media)"
1035 printf "* usb:\n%s\n\n" "$(list usb)"
1036 printf "* iso:\n%s\n\n" "$(list_iso)"
1037 printf "* web:\n%s\n\n" "$(list_web)"
1038 printf "* uuid:\n%s\n\n" "$(list_uuid)"
1039 printf "* format:\n%s\n\n" "$(list_format)"
1040 printf "* bootloader:\n%s\n\n" "$(list_bootloader)"
1041 printf "* partition_table:\n%s\n\n" "$(list_partition_table)"
1042 printf "* winboot:\n%s\n" "$(list_winboot)"
1043 ;;
1044 *)
1045 local options="mode media usb iso web uuid format bootloader \
1046 partition_table winboot"
1047 option_error "$1" "$options" ;;
1048 esac
1051 #----------
1052 # 3. tools
1053 #----------
1055 # list indexes from a list
1056 key()
1058 printf "%s" "$1" | /bin/busybox awk -F: 'BEGIN{
1059 other=-1
1061 !/^#|^$/{
1062 if(other){
1063 printf "%s", $1
1064 other++}
1065 else
1066 printf " %s", $1
1068 END{printf "\n"}'
1071 # convert a list of words to a regex
1072 regex()
1074 printf "%s" "^$1$" | sed s'/ /$|^/g'
1077 # print dev from uuid
1078 uuid2dev()
1080 local uuid="$1"
1081 if [ "${uuid%=*}" = "UUID" ]; then
1082 uuid="$(blkid | sed '/ UUID="'${uuid#*=}'"/!d;s|:.*||')"
1083 fi
1084 printf "%s" "$uuid"
1087 # print disk from uuid
1088 uuid2disk()
1090 printf "%s" "$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
1093 dev2uuid()
1095 local uuid="$1"
1096 if printf "%s" "$uuid" | grep -q dev; then
1097 printf "UUID=%s" "$(/sbin/blkid -p -i -o udev "$uuid" \
1098 | grep ID_FS_UUID= | cut -d '=' -f2)"
1099 else
1100 printf "%s" "$uuid"
1101 fi
1104 # print partition scheme from uuid
1105 p_table()
1107 local uuid="$1" device
1108 device="$(uuid2disk $uuid)"
1109 printf "%s" "$(/usr/sbin/parted -lms 2>&1 | grep "$device" | \
1110 cut -d':' -f6)"
1113 # print filesystem from uuid
1114 filesys()
1116 local uuid="$1"
1117 local fs="$(/sbin/blkid -s UUID -s TYPE | \
1118 grep "$(uuid2dev $uuid)" | cut -d' ' -f3)"
1119 fs="${fs#TYPE=\"}"
1120 fs="${fs%\"}"
1121 printf "%s" "$fs"
1124 # return removable status from uuid
1125 is_removable()
1127 local removable=1
1128 local disk="$(uuid2disk $1 | sed 's|/dev/||')"
1129 if [ "$disk" ]; then
1130 [ "$(cat /sys/block/"$disk"/removable 2> /dev/null)" -gt "0" ] \
1131 && removable=0
1132 fi
1133 return "$removable"
1136 randomize_mirrors()
1138 local list_mirrors
1139 if [ -r "$MIRRORS" ]; then
1140 # randomize list of mirrors
1141 list_mirrors="$(cat $MIRRORS | \
1142 /bin/busybox awk 'BEGIN {srand()}{
1143 printf "%05.0f %s \n",rand()*99999, $0;
1144 }' | sort -n | sed 's/^[0-9]* //' )"
1145 else
1146 log "$(_ 'No mirror list found, run %s.' 'tazpkg recharge')"
1147 list_mirrors="http://mirror.slitaz.org/"
1148 fi
1149 MIRRORS="$list_mirrors"
1152 # download a file
1153 dnl()
1155 local file="$1" mirror transfer=0 oldfile
1156 mkdir -p /tmp/tazinst
1157 for mirror in $MIRRORS; do
1158 log "$(_ 'Downloading: %s' "$mirror$file")"
1159 oldfile="$(printf "%s" $file | \
1160 /bin/busybox awk 'BEGIN{RS="/"}{text=$1}END{print text}')"
1161 [ -e "/tmp/tazinst/$oldfile" ] && rm -f "/tmp/tazinst/$oldfile"
1162 /bin/busybox wget $mirror$file -P /tmp/tazinst && transfer=1 && break
1163 done
1164 if [ "$transfer" -gt "0" ];then
1165 log "$(_ 'Download completed.')"
1166 else
1167 error 5 "(_ '%s: Download failed.' "$file")"
1168 fi
1171 # install pkg in current system
1172 need_package()
1174 local pkg="$1"
1175 if [ ! -d /var/lib/tazpkg/installed/$pkg ]; then
1176 log "$(_ 'Installing package %s to the current system.' "$pkg")"
1177 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1178 /usr/bin/tazpkg get-install "$pkg" || error 5 "$(_ 'Cannot install %s.' "$pkg")"
1179 fi
1182 # install pkg in target system
1183 add_pkg()
1185 local pkg="$1"
1186 log "$(_ 'Adding package %s to the target system...' "$pkg")"
1187 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1188 /usr/bin/tazpkg get "$pkg" >> "$LOG" 2>> "$LOG"
1189 yes "" | /usr/bin/tazpkg install $pkg.tazpkg \
1190 --root=$TARGET_ROOT >> "$LOG" 2>> "$LOG"
1191 rm -f $pkg.tazpkg
1194 #---------
1195 # 3.1 log
1196 #---------
1198 # start log
1199 log_open()
1201 _ '=== Tazinst: started on %s ===' "$(date "+%x %X")" > "$LOG"
1202 LOGGING="true"
1205 # print and log a comment
1206 log(){
1207 # for front-ends, sleep 1 if $1 is num
1208 printf "%s" "$1" | awk '{
1209 num=$1+0
1210 if(num>0 && num<=100)
1211 exit 0
1212 else
1213 exit 1
1214 }' && sleep 1
1215 # log
1216 printf "%s\n" "$1"
1217 [ -n "$LOGGING" ] && printf "%s\n" "$1" >> $LOG
1220 #--------------------
1221 # 3.2 error handling
1222 #--------------------
1224 # print an error msg & exit
1225 error()
1227 local error="$1" msg="$2" cancel="$(_ 'Process not completed')"
1228 _ 'Error: %s' "$msg" >&2; echo "$cancel" >&2
1229 if [ -n "$LOGGING" ]; then
1230 # 1st pattern
1231 echo "-x-x- " >> "$LOG"
1232 _ 'Error: %s' "$msg" >> "$LOG"; echo "$cancel" >> "$LOG"
1233 # 2nd pattern
1234 echo "x-x-x " >> "$LOG"
1235 _ '=== Tazinst error on %s ===' "$(date "+%x %X")" >> "$LOG"
1236 fi
1237 unset LOGGING
1238 umount_devices
1239 exit "$error"
1242 error8()
1244 error 8 "$(_ 'Internal error')"
1247 error9()
1249 error 9 "$(_ 'Cancelled by user')"
1252 #------------------
1253 # 4. disks section
1254 #------------------
1256 #------------
1257 # 4.1 source
1258 #------------
1260 # liveCD
1261 mount_cdrom()
1263 # set device name
1264 local drive="$(grep "drive name" < \
1265 /proc/sys/dev/cdrom/info | cut -f 3)"
1266 [ -n "$drive" ] || drive=cdrom
1267 local cdrom=/dev/$drive
1268 # mount cdrom
1269 if mount -t iso9660 "$cdrom" "$SOURCE_ROOT" 2>>"$LOG"; then
1270 log "$(_ 'Using files from %s.' "$cdrom")"
1271 else
1272 error 3 "$(_ '%s: Mount failed.' "$cdrom")"
1273 fi
1276 # liveUSB
1277 mount_usb()
1279 # /home is on LiveUSB
1280 if [ -d /home/boot ]; then
1281 log "$(_ 'Using files from USB device...')"
1282 ln -s /home/boot $SOURCE_ROOT/boot
1283 else
1284 # mount LiveUSB
1285 if mount "$SOURCE" "$SOURCE_ROOT" 2>>"$LOG"; then
1286 log "$(_ 'Using files from USB device %s.' "$SOURCE")"
1287 else
1288 error 3 "$(_ '%s: Failed to mount USB device.' "$SOURCE")"
1289 fi
1290 fi
1293 # ISO file on HDD
1294 mount_iso()
1296 # check integrity
1297 local md5file=$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')
1298 if [ -r "$md5file" ]; then
1299 local md5ref="$(cut -d' ' -f1 < "$md5file")"
1300 local md5calc="$(md5sum $SOURCE | cut -d' ' -f1)"
1301 if [ ! "$md5calc" = "$md5ref" ]; then
1302 log "md5sum iso=$md5ref md5sum tazinst=$md5calc"
1303 error 3 "$(_ 'md5sum error, file corrupted.')"
1304 fi
1305 else
1306 log "$(_ '%s: md5 file not found, cannot check integrity.' "$SOURCE")"
1307 fi
1308 # mount ISO
1309 if mount -o loop -t iso9660 "$SOURCE" \
1310 "$SOURCE_ROOT" 2>>"$LOG"; then
1311 log "$(_ 'Using files from ISO %s.' "$SOURCE")"
1312 else
1313 error 3 "$(_ '%s: Failed to mount ISO.' "$SOURCE")"
1314 fi
1317 # ISO file on the web
1318 mount_web()
1320 if (printf "%s" "$SOURCE" | egrep -q "$(regex "$(list web)")"); then
1321 SOURCE="$(list web $SOURCE)"
1322 fi
1323 dnl "$SOURCE"
1324 local md5file="$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')"
1325 dnl "$md5file"
1326 local webiso="$(printf "%s" $SOURCE | \
1327 /bin/busybox awk 'BEGIN{RS="/"}{out=$1} END{printf "%s",out}')"
1328 SOURCE="/tmp/tazinst/$webiso"
1329 mount_iso
1332 # set up source and check SliTaz' content
1333 mount_source()
1335 log "$(_ 'Creating mount point: %s...' "$SOURCE_ROOT")"
1336 mkdir -p "$SOURCE_ROOT"
1337 case "$MEDIA" in
1338 cdrom)
1339 mount_cdrom ;;
1340 usb)
1341 mount_usb ;;
1342 iso)
1343 mount_iso ;;
1344 web)
1345 mount_web ;;
1346 *)
1347 error8 ;;
1348 esac
1350 # exit if no rootfs.gz found.
1351 log "$(_ 'Checking installation media...')"
1352 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz -a \
1353 ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
1354 error 3 "$(_ 'Invalid source')"
1355 else
1356 log "$(_ 'Installation media checked ok')"
1357 fi
1360 #------------
1361 # 4.2 target
1362 #------------
1364 # format a partition
1365 format()
1367 local uuid="$1" fmt="$2" dest="$3" dev format
1368 log "$(_ 'Format %s (%s)' "$uuid" "$fmt")"
1369 format="mkfs.$fmt"
1370 if (printf "%s" "$uuid" | grep -q "UUID="); then
1371 # case UUID=
1372 dev="$(uuid2dev $uuid)"
1373 "$format" "$dev" >>"$LOG" 2>>"$LOG" || error 4 "$(_ 'Formatting has failed')"
1374 # uuid has changed
1375 case "$dest" in
1376 root_uuid)
1377 ROOT_UUID="$(/sbin/blkid -p "$dev" -o export | \
1378 grep ^UUID=)" ;;
1379 home_uuid)
1380 HOME_UUID="$(/sbin/blkid -p "$dev" -o export | \
1381 grep ^UUID=)" ;;
1382 esac
1383 else
1384 # case /dev/xxxx
1385 "$format" $uuid >>"$LOG" 2>>"$LOG" || error 4 "$(_ 'Formatting has failed')"
1386 fi
1389 # prepare partitions
1390 prepare_uuid()
1392 log "$(_ 'Preparing target partition...')"
1393 local uuid
1394 # target may be in use
1395 if mount | grep -q "$ROOT_UUID" ;then
1396 log "$(_ 'Partition is already mounted, unmounting.')"
1397 umount "$ROOT_UUID"
1398 fi
1399 mount | grep -q "$ROOT_UUID" && \
1400 error 4 "$ROOT_UUID: $(_ 'Partition is already in use.')"
1401 # Mount point can be already used.
1402 mount | grep -q "$TARGET_ROOT" && \
1403 umount "$TARGET_ROOT" 2>>"$LOG"
1405 # Formatting root partition
1406 case "$ROOT_FORMAT" in
1407 "")
1408 log "$(_ '%s: The partition will be cleaned...' "$ROOT_UUID")" ;;
1409 *)
1410 format "$ROOT_UUID" "$ROOT_FORMAT" root_uuid
1411 esac
1413 # Formatting /home
1414 if [ -n "$HOME_UUID" ]; then
1415 case "$HOME_FORMAT" in
1416 "")
1417 log "$(_ '%s: The partition will be kept...' "$HOME_UUID")" ;;
1418 *)
1419 format "$HOME_UUID" "$HOME_FORMAT" home_uuid
1420 esac
1421 fi
1423 log "$(_ 'Creating mount point: %s...' "$TARGET_ROOT")"
1424 mkdir -p "$TARGET_ROOT" >> "$LOG" || error8
1425 # Mount target.
1426 local mount_fs="$ROOT_FORMAT"
1427 [ -z "$mount_fs" ] && mount_fs="$(filesys $ROOT_UUID)"
1428 mount -t "$mount_fs" "$ROOT_UUID" \
1429 "$TARGET_ROOT" >>"$LOG" 2>>"$LOG"
1430 if [ $(mount | \
1431 grep -c "mnt/target") = "0" ]; then
1432 error 4 "$(_ '%s: Unable to mount partition' "$ROOT_UUID")"
1433 fi
1437 #------------
1438 # 4.3 umount
1439 #------------
1441 # copy log file, umount target and eject cdrom.
1442 umount_devices()
1444 # umount target
1445 if mount | grep -q "$TARGET_ROOT"; then
1446 log "$(_ 'Unmounting target partition: %s' "$ROOT_UUID")"
1447 umount -l "$TARGET_ROOT" 2>>$LOG
1448 fi
1450 # umount source
1451 if mount | grep -q "$SOURCE_ROOT"; then
1452 log "$(_ 'Unmounting: %s' "$SOURCE_ROOT")"
1453 umount -l "$SOURCE_ROOT"
1454 fi
1455 if [ -h $SOURCE_ROOT/boot ]; then
1456 log "$(_ 'Unlinking: %s' "$SOURCE_ROOT")"
1457 rm -f $SOURCE_ROOT/boot
1458 fi
1460 # eject cd
1461 if [ "$SOURCE" = "cdrom" ]; then
1462 _ 'Ejecting CD-ROM...'
1463 eject
1464 fi
1465 # remove lock file
1466 rm -f "$LOCK"
1469 end_of_install()
1471 log "$(_ 'Process completed. You can now restart (reboot) from your SliTaz GNU/Linux system.' |\
1472 fold -s)"
1473 _ '=== Tazinst ended on %s ===' "$(date "+%x %X")" >> "$LOG"
1474 unset LOGGING
1475 # saving log
1476 log "$(_ 'Copying log to %s' '/var/log/tazinst.log')"
1477 cp -a "$LOG" $TARGET_ROOT/var/log
1478 umount_devices
1482 #---------------
1483 # 5. bootloader
1484 #---------------
1486 #------------
1487 # 5.1 common
1488 #------------
1490 # selection
1491 bootloader()
1493 if [ "$BOOTLOADER" = "auto" ]; then
1494 # use syslinux, but if p_table=msdos take grub (if available)
1495 unset BOOTLOADER
1496 printf "%s" "$(list_bootloader)" | \
1497 grep -q "syslinux" && BOOTLOADER=syslinux
1498 if [ "$(p_table $ROOT_UUID)" = "msdos" ]; then
1499 printf "%s" "$(list_bootloader)" | \
1500 grep -q " grub" && BOOTLOADER=grub
1501 fi
1502 fi
1503 case "$BOOTLOADER" in
1504 grub)
1505 grub_config
1506 grub_install ;;
1507 syslinux)
1508 syslinux_config
1509 syslinux_install ;;
1510 *)
1511 syslinux_config
1512 log "$(_ 'No bootloader to install.')" ;;
1513 esac
1514 [ -d /sys/firmware/efi ] && efiboot_install
1517 # print disk num
1518 disknum()
1520 local disk="$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
1521 /usr/sbin/parted -lms 2>&1 | grep "^/dev" | \
1522 /bin/busybox awk -v PART="$disk:" '{if (match($0,PART)) print NR-1}'
1525 # print partition num
1526 partnum()
1528 printf "%s" "$(($(uuid2dev $1 | /bin/busybox sed 's|.*[^0-9]||')-1))"
1531 # print root device
1532 rootdev()
1534 local partition="$1"
1535 case "$(p_table $partition)" in
1536 msdos)
1537 # print device
1538 printf "%s" "$(uuid2dev $partition)" ;;
1539 gpt)
1540 # print PARTUUID (different from UUID)
1541 printf "%s" "PARTUUID="
1542 /sbin/blkid -p -i -o udev $(uuid2dev $partition) \
1543 | grep ENTRY_UUID | cut -d '=' -f2 ;;
1544 esac
1547 # add rootdelay for removable devices
1548 rootdelay()
1550 is_removable "$ROOT_UUID" && printf "%s" " rootdelay=9"
1553 # print winboot uuid
1554 winboot_uuid()
1556 if [ "$WINBOOT" = "auto" ]; then
1557 # get the first uuid if any
1558 [ $(list_winboot | wc -w) -gt 1 ] \
1559 && printf "%s" "$(list_winboot | cut -d' ' -f2)"
1560 else
1561 printf "%s" "$WINBOOT"
1562 fi
1566 #-----------
1567 # 5.1 grub1
1568 #-----------
1570 grub_password_command()
1572 grub --batch 2> /dev/null <<EOT | sed '/^Encrypted/!d;s|^Encrypted: |password --md5 |'
1573 md5crypt
1574 $ROOT_PWD
1575 EOT
1578 # create grub legacy conf
1579 grub_config()
1581 # backup an existing conf
1582 [ -e "$TARGET_ROOT/boot/grub/menu.lst" ] && \
1583 cp $TARGET_ROOT/boot/grub/menu.lst \
1584 $TARGET_ROOT/boot/grub/menu.bak
1585 # create the target GRUB configuration.
1586 mkdir -p $TARGET_ROOT/boot/grub || error8
1587 cat > $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1588 # /boot/grub/menu.lst: GRUB boot loader configuration.
1591 # By default, boot the first entry.
1592 default 0
1594 # Boot automatically after 8 secs.
1595 timeout 8
1597 # Graphical splash image.
1598 splashimage=/boot/grub/splash.xpm.gz
1600 # Root password is required for edition
1601 $(grub_password_command)
1603 # Change the colors.
1604 #color yellow/brown light-green/black
1606 # For booting SliTaz from : $ROOT_UUID
1608 title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1609 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1610 kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
1612 _EOF_
1614 if [ -n "$LIVEBOOT" ]; then
1615 local rootfs_files="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs*)"
1616 log "$(_ 'Enabling live/rescue boot with %s' "$rootfs_files")"
1617 for i in $rootfs_files; do
1618 [ -s $TARGET_ROOT/boot/$i ] &&
1619 mv $TARGET_ROOT/boot/$i $TARGET_ROOT/boot/$i.bak
1620 mv $TARGET_ROOT/boot/tazinst.$$/$i $TARGET_ROOT/boot/
1621 done
1622 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1623 # For booting SliTaz Live from : $ROOT_UUID
1625 title SliTaz GNU/Linux rescue $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1626 $(grub_password_command)
1627 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1628 kernel /boot/$KERNEL $(sed 's|.*gz ||' /proc/cmdline)
1629 initrd /boot/$ROOTFS
1631 _EOF_
1632 fi
1634 if [ -n "$WEBBOOT" -a -n "$IPXE" ]; then
1635 log "$(_ 'Enabling Webboot using %s' $IPXE)"
1636 mv -f $TARGET_ROOT/boot/tazinst.$$/$IPXE $TARGET_ROOT/boot/
1637 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1638 # For booting SliTaz Live from the web
1640 title SliTaz GNU/Linux web boot
1641 $(grub_password_command)
1642 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1643 kernel /boot/$IPXE
1645 _EOF_
1646 fi
1647 rm -rf $TARGET_ROOT/boot/tazinst.$$ 2> /dev/null
1649 local winpart="$(winboot_uuid)"
1650 if [ -n "$winpart" ]; then
1651 log "$(_ 'Enabling Windows dual-boot')"
1652 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1653 # For booting Windows :
1655 title Microsoft Windows
1656 rootnoverify (hd$(disknum $winpart),$(partnum $winpart))
1657 chainloader +1
1659 _EOF_
1660 fi
1662 # log
1663 printf "%s\n" "/boot/grub/menu.lst:" >> "$LOG"
1664 printf "%s\n" "--- menu.lst -------------" >> "$LOG"
1665 cat $TARGET_ROOT/boot/grub/menu.lst >> "$LOG"
1666 printf "%s\n\n" "--- menu.lst -------------" >> "$LOG"
1669 # GRUB info with disk name used for grub
1670 grub_install()
1672 # install grub
1673 local target_disk="$(uuid2disk $ROOT_UUID)"
1674 log "$(_ 'Installing GRUB on: %s' "$target_disk")"
1675 /usr/sbin/grub-install --version >> "$LOG" || error 5 "$(_ 'GRUB not found')"
1676 /usr/sbin/grub-install --no-floppy \
1677 --root-directory=$TARGET_ROOT $target_disk >>"$LOG" 2>>"$LOG"
1678 # set boot flag
1679 log "$(_ 'Setting the boot flag')"
1680 /usr/sbin/parted "$(uuid2disk $ROOT_UUID)" \
1681 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1682 # splash image
1683 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
1684 log "$(_ 'Copying splash image')"
1685 mkdir -p $TARGET_ROOT/boot/grub
1686 cp $SOURCE_ROOT/boot/grub/splash.xpm.gz \
1687 $TARGET_ROOT/boot/grub
1688 fi
1692 #--------------
1693 # 5.2 syslinux
1694 #--------------
1696 # create syslinux conf
1697 syslinux_config()
1699 local version="[$(cat $TARGET_ROOT/etc/slitaz-release)]"
1700 version="$version\(Kernel $KERNEL)"
1701 # backup an existing conf
1702 [ -e "$TARGET_ROOT/boot/syslinux/syslinux.cfg" ] && \
1703 cp $TARGET_ROOT/boot/syslinux/syslinux.cfg \
1704 $TARGET_ROOT/boot/syslinux/syslinux.bak
1705 # create the target syslinux configuration.
1706 mkdir -p $TARGET_ROOT/boot/syslinux || error8
1707 cat > $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1708 # use a boot menu
1709 UI vesamenu.c32
1711 # display the boot
1712 PROMPT 1
1714 # how long to pause at the boot
1715 TIMEOUT 50
1717 # default label
1718 DEFAULT slitaz
1720 # Menu settings
1721 MENU TITLE SliTaz GNU/Linux boot menu
1722 MENU BACKGROUND splash.jpg
1723 MENU WIDTH 78
1724 MENU MARGIN 6
1725 MENU ROW 10
1726 MENU VSHIFT 2
1727 MENU TIMEOUTROW 18
1728 MENU TABMSGROW 16
1729 MENU CMDLINEROW 16
1731 # Menu colors
1732 MENU COLOR border * #00000000 #00000000 none
1733 MENU COLOR title * #ffffffff #00000000 *
1734 MENU COLOR sel 0 #ffffffff #00000000 none
1735 MENU COLOR unsel 0 #50ffffff #00000000 none
1736 MENU COLOR help * #ffffffff #00000000 *
1737 MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
1738 MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
1739 MENU COLOR msg07 37;40 #90ffffff #a0000000 std
1740 MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
1742 # Labels
1743 LABEL slitaz
1744 MENU LABEL SliTaz GNU/Linux $version
1745 LINUX /boot/$KERNEL
1746 APPEND root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
1748 EOF
1749 if [ -n "$LIVEBOOT" ]; then
1750 local rootfs_files="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs*)"
1751 log "$(_ 'Enabling live/rescue boot with %s' "$rootfs_files")"
1752 for i in $rootfs_files; do
1753 [ -s $TARGET_ROOT/boot/$i ] &&
1754 mv $TARGET_ROOT/boot/$i $TARGET_ROOT/boot/$i.bak
1755 mv $TARGET_ROOT/boot/tazinst.$$/$i $TARGET_ROOT/boot/
1756 done
1757 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1758 LABEL live rescue
1759 MENU LABEL SliTaz GNU/Linux live/rescue $version
1760 LINUX /boot/$KERNEL
1761 INITRD /boot/$ROOTFS
1762 APPEND root=$(rootdev $ROOT_UUID) $(sed 's|.*gz ||' /proc/cmdline)
1764 EOF
1765 fi
1767 if [ -n "$WEBBOOT" -a -n "$IPXE" ]; then
1768 log "$(_ 'Enabling Webboot using %s' $IPXE)"
1769 mv -f $TARGET_ROOT/boot/tazinst.$$/$IPXE $TARGET_ROOT/boot/
1770 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1771 LABEL web zeb
1772 MENU LABEL SliTaz GNU/Linux web boot
1773 LINUX /boot/$IPXE
1775 EOF
1776 fi
1777 rm -rf $TARGET_ROOT/boot/tazinst.$$ 2> /dev/null
1779 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1780 LABEL cmdline
1781 MENU LABEL Command Line
1782 MENU QUIT
1784 EOF
1785 local winpart="$(winboot_uuid)"
1786 if [ -n "$winpart" ]; then
1787 log "$(_ 'Enabling Windows dual-boot')"
1788 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1789 LABEL windows
1790 MENU LABEL Windows
1791 COM32 chain.c32
1792 APPEND hd$(disknum $winpart) $(($(partnum $winpart)+1))
1794 EOF
1795 fi
1796 # log
1797 printf "%s\n" "/boot/syslinux/syslinux.cfg:" >> "$LOG"
1798 printf "%s\n" "--- syslinux.cfg -------------" >> "$LOG"
1799 cat $TARGET_ROOT/boot/syslinux/syslinux.cfg >> "$LOG"
1800 printf "%s\n\n" "--- syslinux.cfg -------------" >> "$LOG"
1803 # install syslinux
1804 syslinux_install()
1806 log "$(_ 'Installing Syslinux')"
1807 # needed tools
1808 local dir disk="$(uuid2disk $ROOT_UUID)"
1809 for dir in /home/boot/extlinux /home/boot/syslinux /boot/syslinux /boot/isolinux; do
1810 [ -d "$dir" ] && cp $dir/*.c32 $dir/*.sys "$TARGET_ROOT/boot/syslinux/"
1811 done
1812 cp /usr/share/boot/chain.c32 $TARGET_ROOT/boot/syslinux/chain.c32 2>> "$LOG"
1813 # install syslinux
1814 /bin/syslinux -version >> "$LOG" || error 5 "$(_ 'Syslinux not found')"
1815 /bin/extlinux --install $TARGET_ROOT/boot/syslinux >> "$LOG" 2>> "$LOG"
1816 case "$(p_table $ROOT_UUID)" in
1817 msdos)
1818 log "$(_ 'Setting the boot flag on')"
1819 /usr/sbin/parted "$disk" \
1820 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1821 [ -r /usr/share/boot/mbr.bin ] || error 5 "$(_ 'mbr.bin not found')"
1822 log "$(_ 'Installing MBR')"
1823 dd bs=440 count=1 conv=notrunc \
1824 if=/usr/share/boot/mbr.bin of=$disk >> "$LOG" ;;
1825 gpt)
1826 log "$(_ 'Setting the legacy_boot flag on')"
1827 # remove old boot flag
1828 local oldboot="$(parted $disk print \
1829 | grep boot | /bin/busybox awk '{print $1}')"
1830 /usr/sbin/parted "$disk" \
1831 set "$oldboot" legacy_boot off 2>> "$LOG"
1832 # set boot flag
1833 /usr/sbin/parted "$disk" \
1834 set "$(($(partnum $ROOT_UUID)+1))" legacy_boot on 2>> "$LOG"
1835 log "$(_ 'Installing GPTMBR')"
1836 [ -r /usr/share/boot/gptmbr.bin ] || error 5 "$(_ 'gptmbr.bin not found')"
1837 dd bs=440 conv=notrunc count=1 \
1838 if=/usr/share/boot/gptmbr.bin of=$disk >> "$LOG" ;;
1839 esac
1840 # splash image
1841 if [ -f "$SOURCE_ROOT/boot/isolinux/splash.jpg" ]; then
1842 log "$(_ 'Copying splash image')"
1843 cp -a $SOURCE_ROOT/boot/isolinux/splash.jpg \
1844 $TARGET_ROOT/boot/syslinux
1845 fi
1849 #-------------
1850 # 5.3 efiboot
1851 #-------------
1853 efiboot_install()
1855 local esp_fs_uuid mnt="/media/esp$$" efiboot="/EFI/SLITAZ"
1856 # We need efi stub support
1857 [ "$(strings $TARGET_ROOT/boot/$KERNEL | head | grep reloc)" ] || return
1858 # And the esp partition
1859 esp_fs_uuid="$(blkid | sed '/EFI system partition/!d;s|.* UUID="||;s|".*||;q')"
1860 [ "$esp_fs_uuid" ] || return
1861 # Copy SliTaz kernel and cmdline in esp partition
1862 mkdir $mnt &&
1863 mount "$(uuid2dev UUID=$esp_fs_uuid)" $mnt &&
1864 mkdir -p $mnt$efiboot 2> /dev/null
1865 if cp $TARGET_ROOT/boot/$KERNEL $mnt$efiboot/BZIMAGE.EFI; then
1866 log "$(_ 'Updating UEFI boot files')"
1867 echo "root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)" > $mnt$efiboot/linux.cmdline
1868 efibootmgr -v | grep -q SliTaz ||
1869 efibootmgr -c -d "$(uuid2disk UUID=$esp_fs_uuid)" -p "$(partnum UUID=$esp_fs_uuid)" \
1870 -L "SliTaz GNU/Linux" -l "${efiboot//\//\\}\\BZIMAGE.EFI"
1871 fi
1872 umount $mnt && rmdir $mnt
1875 #--------------------
1876 # 6. execute section
1877 #--------------------
1879 execute()
1881 local mode="$(get mode)" sighup=1 sigint=2 sigquit=3
1882 randomize_mirrors
1883 trap "error9" "$sighup" "$sigint" "$sigquit"
1884 case "$mode" in
1885 install)
1886 install ;;
1887 upgrade)
1888 upgrade ;;
1889 esac
1892 #-------------
1893 # 6.1 install
1894 #-------------
1896 # get a clean target device
1897 clean_target()
1899 if [ -z "$ROOT_FORMAT" ]; then
1900 # partition was not formatted
1901 log "$(_ 'Cleaning the root partition (%s)...' "$ROOT_UUID")"
1902 # keep /home in case of reinstall.
1903 local path="$(pwd)"
1904 cd "$TARGET_ROOT" || error8
1905 local dir
1906 for dir in *
1907 do
1908 case "$dir" in
1909 home)
1910 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")"
1911 mv home home.bak ;;
1912 lost+found)
1913 continue ;;
1914 *)
1915 log "$(_ 'removing target: %s' "$dir")"
1916 rm -rf "$dir" 2>>"$LOG" ;;
1917 esac
1918 done
1919 if [ ! -d lost+found ]; then
1920 mklost+found 2>>"$LOG"
1921 fi
1922 cd "$path" || error8
1923 fi
1926 # kernel is renamed to standard vmlinuz-$VERSION.
1927 install_kernel()
1929 KERNEL="vmlinuz-$(uname -r)"
1930 [ -d /$TARGET_ROOT/lib/modules/$(uname -r) ] ||
1931 log "$(_ 'Kernel name not found, falling back to: %s' "$(uname -r)")"
1932 mkdir -p $TARGET_ROOT/boot || error8
1933 for i in $SOURCE_ROOT/boot/bzImage* ; do
1934 cp $i $TARGET_ROOT/boot/${KERNEL%slitaz*}slitaz${i#*bzImage}
1935 done
1936 mkdir $TARGET_ROOT/boot/tazinst.$$
1937 for i in $(ls -r $SOURCE_ROOT/boot/rootfs?*.gz 2> /dev/null | sed q) \
1938 $SOURCE_ROOT/boot/rootfs.gz $SOURCE_ROOT/boot/*pxe* ; do
1939 cp $i $TARGET_ROOT/boot/tazinst.$$/
1940 done
1941 IPXE="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls *pxe* 2> /dev/null)"
1942 ROOTFS="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs.* 2> /dev/null)"
1943 [ -n "$ROOTFS" ] ||
1944 ROOTFS="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls -r rootfs?*.* | sed q)"
1945 log "$(_ 'install_kernel: %s' "$KERNEL")"
1948 # extract packed rootfs: squashfs or cromfs
1949 extract_loramfs()
1951 local i
1952 for i in $(/bin/busybox cpio -idvum 2> /dev/null); do
1953 case "$i" in
1954 rootfs*)
1955 need_package squashfs
1956 if ! unsquashfs $i ; then
1957 need_package cromfs
1958 unmkcromfs $i squashfs-root
1959 fi
1960 mv -f squashfs-root/* .
1961 rmdir squashfs-root
1962 rm -f $i
1963 esac
1964 done
1967 # this is a loram rootfs.gz, skip loram bootstrap and extract
1968 extract_first_loramfs()
1970 local path="$(pwd)"
1971 (zcat $1 || /usr/bin/unlzma < $1) | \
1972 /bin/busybox cpio -i extractfs.cpio 2> /dev/null &&
1973 ( cd / ; /bin/busybox cpio -id ) < extractfs.cpio && \
1974 rm -f extractfs.cpio
1975 ofs=$(/bin/busybox awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
1976 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
1977 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
1978 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | \
1979 extract_loramfs
1980 cd "$path" || error8
1983 # extract lzma'ed or gziped rootfs.
1984 extract_rootfs()
1986 local path="$(pwd)"
1987 local isloramfs
1988 cd "$TARGET_ROOT" || error8
1989 if [ -d "$1"/../fs/etc ]; then
1990 # this is a tazlitobox loram (cdrom)
1991 cp -a "$1"/../fs/. .
1992 else
1993 for i in $(ls "$1"/rootfs* | sort -r); do
1994 if [ ! -d etc ]; then
1995 if [ $( (zcat "$i" 2>/dev/null \
1996 || /usr/bin/lzma d "$i" -so) | \
1997 wc -c) -lt $(stat -c %s "$i") ]; then
1998 # this is a tazlitobox loram (ram)
1999 isloramfs="$i"
2000 extract_first_loramfs "$i"
2001 continue
2002 fi
2003 fi
2004 if [ -n "$isloramfs" ]; then
2005 extract_loramfs < "$i"
2006 continue
2007 fi
2008 ( zcat "$i" 2>/dev/null || /usr/bin/lzma d "$i" -so || \
2009 cat "$i" ) 2>>"$LOG" | /bin/busybox cpio -idu
2010 done 2>>"$LOG" > /dev/null
2011 fi
2012 $(which install) -m 644 /etc/keymap.conf /etc/locale.conf /etc/TZ /etc/network.conf etc
2013 cp -a /usr/lib/locale usr/lib/
2014 # unpack /usr (double check...)
2015 if ls etc/tazlito | grep -q ".extract"; then
2016 for i in etc/tazlito/*.extract; do
2017 [ -f "$i" ] && . "$i" /media/cdrom
2018 done
2019 fi
2020 cd "$pwd" || error8
2024 # pre configure freshly installed system (60 - 80%).
2025 pre_config_system()
2027 local path="$(pwd)"
2028 cd "$TARGET_ROOT" || error8
2029 # restore backup of existing /home if exists.
2030 # (created by prepare_target_dev)
2031 if [ -d home.bak ]; then
2032 log "$(_ 'Restoring directory: /home...')"
2033 rm -rf home
2034 mv home.bak home
2035 fi
2036 # add root device to CHECK_FS in rcS.conf to check filesystem
2037 # on each boot.
2038 log "$(_ 'Adding / partition and CHECK_FS to file %s...' '/etc/rcS.conf')"
2039 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$(dev2uuid $ROOT_UUID)\""# etc/rcS.conf
2040 # set hostname.
2041 log "$(_ 'Configuring host name: %s' "$HOSTNAME")"
2042 printf "%s\n" "$HOSTNAME" > etc/hostname
2043 printf "%s\n" "127.0.0.1 localhost $HOSTNAME tazpanel" > etc/hosts
2044 cd "$path" || error8
2047 # set root passwd and create user after rootfs extraction.
2048 users_settings()
2050 # create file
2051 cat > "$TARGET_ROOT/users.sh" << _EOF_
2052 #!/bin/sh
2053 umask 0022
2054 printf "root:%s" "$ROOT_PWD" | chpasswd -m
2055 adduser -D -H $USER_LOGIN
2057 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
2058 if ! grep \$grp /etc/group | grep -q $USER_LOGIN ; then
2059 grep -q \$grp /etc/group && addgroup $USER_LOGIN \$grp
2060 fi
2061 done
2063 printf "%s:%s" "$USER_LOGIN" "$USER_PWD" | chpasswd -m
2064 if [ ! -d /home/$USER_LOGIN ]; then
2065 cp -a /etc/skel /home/$USER_LOGIN
2066 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$USER_LOGIN
2067 mkdir -p /home/$USER_LOGIN/.config/slitaz
2068 cp -a /etc/slitaz/applications.conf /home/$USER_LOGIN/.config/slitaz
2069 # Set ownership
2070 if grep -q ^users: /etc/group; then
2071 chown -R $USER_LOGIN:users /home/$USER_LOGIN
2072 else
2073 chown -R $USER_LOGIN:$USER_LOGIN /home/$USER_LOGIN
2074 fi
2075 # Path for user desktop files.
2076 for i in /home/$USER_LOGIN/.local/share/applications/*.desktop
2077 do
2078 [ -e "$i" ] && sed -i s/"user_name"/"$USER_LOGIN"/g \$i
2079 done
2080 fi
2081 # Slim default user.
2082 if [ -f /etc/slim.conf ]; then
2083 sed -i s/"default_user .*"/"default_user $USER_LOGIN"/ \
2084 /etc/slim.conf
2085 fi
2086 _EOF_
2087 chmod o+x "$TARGET_ROOT/users.sh"
2088 chroot "$TARGET_ROOT" ./users.sh 2>>"$LOG" >> "$LOG"
2089 rm "$TARGET_ROOT/users.sh"
2090 umask 0177
2093 # /home can be on a separate partition. If default user exists in /home
2094 # we remove default file created by users_settings().
2095 home_config()
2097 if [ -n "$HOME_UUID" ]; then
2098 local path="$(pwd)" uuid
2099 cd "$TARGET_ROOT" || error8
2100 # detect fs
2101 local home_fs="$HOME_FORMAT"
2102 [ -z "$home_fs" ] && home_fs="$(filesys $HOME_UUID)"
2103 # manage /home
2104 log "$(_ 'Configuring partition to be used as /home: %s' "$HOME_UUID")"
2105 mv home/$USER_LOGIN tmp
2106 mount -t "$home_fs" "$HOME_UUID" home >> "$LOG" 2>> "$LOG"
2107 if [ -d $TARGET_ROOT/home/$USER_LOGIN ]; then
2108 rm -rf tmp/home/$USER_LOGIN
2109 else
2110 mv tmp/$USER_LOGIN home
2111 fi
2112 # write entry in fstab, force uuid
2113 uuid="$(dev2uuid "$HOME_UUID")"
2114 printf "%b\n" "$uuid /home $home_fs defaults \t0 \t2" >> etc/fstab
2115 umount home >> "$LOG" 2>> "$LOG"
2116 cd "$path" || error8
2117 fi
2120 install()
2122 log_open
2123 log "1 $(_ 'Installing SliTaz on: %s' "$(get root_uuid)")"
2124 log "5 $(_ 'Checking settings...')"
2125 check all >> "$LOG" 2>> "$LOG"
2126 load_settings
2128 log "10 $(_ 'Preparing source media...')"
2129 mount_source
2131 log "20 $(_ 'Preparing target disk...')"
2132 prepare_uuid
2134 log "30 $(_ 'Cleaning the root partition if necessary...')"
2135 clean_target
2137 log "40 $(_ 'Extracting the root system...')"
2138 extract_rootfs $SOURCE_ROOT/boot
2140 log "50 $(_ 'Installing the Kernel...')"
2141 install_kernel
2143 log "60 $(_ 'Preconfiguring the system...')"
2144 pre_config_system
2146 log "70 $(_ 'Configuring root and default user account...')"
2147 users_settings
2149 log "80 $(_ 'Configuring /home...')"
2150 home_config
2152 log "90 $(_ 'Checking bootloader installation...')"
2153 bootloader
2155 log "100 $(_ 'Files installation completed')"
2156 end_of_install
2160 #-------------
2161 # 6.2 upgrade
2162 #-------------
2164 # search for SliTaz
2165 check_release()
2167 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
2168 local release="$(cat $TARGET_ROOT/etc/slitaz-release)"
2169 log "$(_ 'Preparing upgrade of SliTaz release: %s' "$release")"
2170 else
2171 error 6 "$(_ "%s: This partition doesn't appear to contain a valid \
2172 SliTaz system, the file: %s doesn't exist." "$ROOT_UUID" '/etc/slitaz-release')"
2173 fi
2176 # backup packages list.
2177 backup_files()
2179 local path="$(pwd)"
2180 cd "$TARGET_ROOT" || error8
2181 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
2182 local dir
2183 for dir in *
2184 do
2185 case "$dir" in
2186 boot)
2187 rm -rf boot/vmlinuz-* ;;
2188 home)
2189 mv home home.bak
2190 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")" ;;
2191 etc)
2192 /bin/busybox tar czf etc.tar.gz etc
2193 mv etc etc.bak
2194 log "$(_ 'keeping /etc found on: %s' "$ROOT_UUID")" ;;
2195 var)
2196 if [ -d var/www ]; then
2197 mv var/www www.bak
2198 log "$(_ 'keeping /var/www found on: %s' "$ROOT_UUID")"
2199 fi
2200 rm -rf var 2>>"$LOG" ;;
2201 lost+found)
2202 continue ;;
2203 *)
2204 log "$(_ 'removing target: %s' "$dir")"
2205 rm -rf "$dir" 2>>"$LOG" ;;
2206 esac
2207 done
2208 if [ -d mklost+found ]; then
2209 mklost+found 2>>"$LOG"
2210 fi
2211 cd "$path" || error8
2214 # restore backups.
2215 restore_files()
2217 rm -rf $TARGET_ROOT/home
2218 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
2219 rm -rf $TARGET_ROOT/etc
2220 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
2221 if [ -d $TARGET_ROOT/www.bak ]; then
2222 rm -rf $TARGET_ROOT/var/www
2223 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
2224 fi
2225 log "$(_ 'backups restored: %s' "$(date)")"
2227 # /var/lib/slitaz-installer
2228 mkdir -p $TARGET_ROOT/var/lib/tazinst && \
2229 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst && \
2230 mv $TARGET_ROOT/home/packages-selection.list \
2231 $TARGET_ROOT/var/lib/tazinst \
2232 && log "$(_ 'backups saved in %s' '/var/lib/tazinst')"
2235 # upgrade added pkgs
2236 install_pkgs()
2238 # check if the pkg is on the mirror.
2239 log "$(_ 'Checking the availability of packages...')"
2240 touch packages-to-install.list
2241 packages=0
2242 diff="$(sort < packages-selection.diff)"
2243 for pkg in $diff
2244 do
2245 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
2246 packages="$(($packages+1))"
2247 printf "%s\n" "$pkg" >> packages-to-install.list
2248 fi
2249 done
2251 # install packages.
2252 log "$(_ 'Installing packages...')"
2253 if [ "$packages" = "0" ]; then
2254 log "$(_ 'packages to install: 0')"
2255 else
2256 # get-install all missing pkgs.
2257 while read pkg
2258 do
2259 log "$(_ 'Installing: %s...' "$pkg")"
2260 # get install package and answer yes in case of dependencies.
2261 pkgname="$(grep ^$pkg /var/lib/tazpkg/packages.list)"
2262 /usr/bin/tazpkg get "$pkg" >/dev/null 2>/dev/null
2263 yes "" | /usr/bin/tazpkg install $pkgname.tazpkg \
2264 --root=$TARGET_ROOT >/dev/null 2>/dev/null
2265 rm -f $pkgname.tazpkg
2266 done < packages-to-install.list
2267 fi
2268 log "$(_ 'Installation of packages complete...')"
2271 # search for added pkgs
2272 update_pkgs()
2274 local path="$(pwd)"
2275 cd $TARGET_ROOT/var/lib/tazinst || error8
2276 # LiveCD packages list.
2277 log "$(_ 'Creating package lists...')"
2278 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || error8
2279 log "$(_ '%s: done' 'packages-source.list')"
2280 # diff
2281 /bin/busybox diff packages-source.list packages-selection.list | \
2282 grep ^+[a-z] | sed s/^+// > packages-selection.diff
2283 log "$(_ '%s: done' 'packages-selection.diff')"
2284 # get mirror list.
2285 /usr/bin/tazpkg recharge >>$LOG 2>>$LOG
2286 if [ -f /var/lib/tazpkg/packages.list ]; then
2287 install_pkgs
2288 else
2289 touch packages-to-install.list
2290 longline "$(_ "The list of available packages on the mirror could not \
2291 be downloaded. No missing packages will be reinstalled now, but you can do so \
2292 later by looking at the following list:")"
2293 echo '/var/lib/tazinst/packages-selection.diff'
2294 fi
2295 cd "$path" || error8
2298 # upgrade command
2299 upgrade()
2301 log_open
2302 log "1 $(_ 'Upgrading SliTaz on: %s' "$(get root_uuid)")"
2303 log "5 $(_ 'Checking settings...')"
2304 check all >> "$LOG"
2305 load_settings
2307 log "10 $(_ 'Preparing source media...')"
2308 mount_source
2310 log "20 $(_ 'Preparing target disk...')"
2311 prepare_uuid
2313 log "30 $(_ 'Searching for %s...' '/etc/slitaz-release')"
2314 check_release
2316 log "40 $(_ 'Backup /etc, /home and the packages list...')"
2317 backup_files
2319 log "50 $(_ 'Extracting the root system...')"
2320 extract_rootfs $SOURCE_ROOT/boot
2322 log "60 $(_ 'Restoring configuration files...')"
2323 restore_files
2325 log "70 $(_ 'Installing the Kernel...')"
2326 install_kernel
2328 log "80 $(_ 'Upgrading added packages...')"
2329 update_pkgs
2331 log "90 $(_ 'Bootloader...')"
2332 bootloader
2334 log "100 $(_ 'Files installation completed')"
2335 end_of_install
2339 #--------------
2340 # tazinst main
2341 #--------------
2343 case $1 in
2344 new)
2345 new_file "$2" ;;
2346 set)
2347 [ -s "$4" ] || new_file "$4"
2348 read_file "$4"
2349 change "$2" "$3" "$4" ;;
2350 unset)
2351 read_file "$3"
2352 change "$2" "" "$3" "$4" ;;
2353 get)
2354 read_file "$3"
2355 get "$2" ;;
2356 check)
2357 read_file "$3"
2358 check "$2" ;;
2359 list)
2360 list "$2" "$3" ;;
2361 execute)
2362 check_root
2363 read_file "$2"
2364 execute "$2" ;;
2365 log)
2366 [ -r "$LOG" ] && cat "$LOG" ;;
2367 clean)
2368 clean "$2" ;;
2369 version)
2370 printf "%s\n" "$VERSION" ;;
2371 ""|usage)
2372 usage ;;
2373 help)
2374 help "$2" ;;
2375 *)
2376 usage_error "$1" ;;
2377 esac