tazinst view tazinst @ rev 112

tazinst,installer.cgi: add rescue boot
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 25 10:55:20 2021 +0000 (2021-02-25)
parents dbef8ca6dfa4
children 55a8e9fe5627
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 default passwords!)')
793 webboot $(_ 'Install a web boot (with default passwords!)')
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 # create grub legacy conf
1571 grub_config()
1573 # backup an existing conf
1574 [ -e "$TARGET_ROOT/boot/grub/menu.lst" ] && \
1575 cp $TARGET_ROOT/boot/grub/menu.lst \
1576 $TARGET_ROOT/boot/grub/menu.bak
1577 # create the target GRUB configuration.
1578 mkdir -p $TARGET_ROOT/boot/grub || error8
1579 cat > $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1580 # /boot/grub/menu.lst: GRUB boot loader configuration.
1583 # By default, boot the first entry.
1584 default 0
1586 # Boot automatically after 8 secs.
1587 timeout 8
1589 # Graphical splash image.
1590 splashimage=/boot/grub/splash.xpm.gz
1592 # Change the colors.
1593 #color yellow/brown light-green/black
1595 # For booting SliTaz from : $ROOT_UUID
1597 title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1598 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1599 kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
1601 _EOF_
1603 if [ -n "$LIVEBOOT" ]; then
1604 local rootfs_files="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs*)"
1605 log "$(_ 'Enabling live/rescue boot with %s' "$rootfs_files")"
1606 for i in $rootfs_files; do
1607 [ -s $TARGET_ROOT/boot/$i ] &&
1608 mv $TARGET_ROOT/boot/$i $TARGET_ROOT/boot/$i.bak
1609 mv $TARGET_ROOT/boot/tazinst.$$/$i $TARGET_ROOT/boot/
1610 done
1611 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1612 # For booting SliTaz Live from : $ROOT_UUID
1614 title SliTaz GNU/Linux rescue $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1615 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1616 kernel /boot/$KERNEL $(sed 's|.*gz ||' /proc/cmdline)
1617 initrd /boot/$ROOTFS
1619 _EOF_
1620 fi
1622 if [ -n "$WEBBOOT" -a -n "$IPXE" ]; then
1623 log "$(_ 'Enabling Webboot using %s' $IPXE)"
1624 mv -f $TARGET_ROOT/boot/tazinst.$$/$IPXE $TARGET_ROOT/boot/
1625 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1626 # For booting SliTaz Live from the web
1628 title SliTaz GNU/Linux web boot
1629 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1630 kernel /boot/$IPXE
1632 _EOF_
1633 fi
1634 rm -rf $TARGET_ROOT/boot/tazinst.$$ 2> /dev/null
1636 local winpart="$(winboot_uuid)"
1637 if [ -n "$winpart" ]; then
1638 log "$(_ 'Enabling Windows dual-boot')"
1639 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1640 # For booting Windows :
1642 title Microsoft Windows
1643 rootnoverify (hd$(disknum $winpart),$(partnum $winpart))
1644 chainloader +1
1646 _EOF_
1647 fi
1649 # log
1650 printf "%s\n" "/boot/grub/menu.lst:" >> "$LOG"
1651 printf "%s\n" "--- menu.lst -------------" >> "$LOG"
1652 cat $TARGET_ROOT/boot/grub/menu.lst >> "$LOG"
1653 printf "%s\n\n" "--- menu.lst -------------" >> "$LOG"
1656 # GRUB info with disk name used for grub
1657 grub_install()
1659 # install grub
1660 local target_disk="$(uuid2disk $ROOT_UUID)"
1661 log "$(_ 'Installing GRUB on: %s' "$target_disk")"
1662 /usr/sbin/grub-install --version >> "$LOG" || error 5 "$(_ 'GRUB not found')"
1663 /usr/sbin/grub-install --no-floppy \
1664 --root-directory=$TARGET_ROOT $target_disk >>"$LOG" 2>>"$LOG"
1665 # set boot flag
1666 log "$(_ 'Setting the boot flag')"
1667 /usr/sbin/parted "$(uuid2disk $ROOT_UUID)" \
1668 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1669 # splash image
1670 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
1671 log "$(_ 'Copying splash image')"
1672 mkdir -p $TARGET_ROOT/boot/grub
1673 cp $SOURCE_ROOT/boot/grub/splash.xpm.gz \
1674 $TARGET_ROOT/boot/grub
1675 fi
1679 #--------------
1680 # 5.2 syslinux
1681 #--------------
1683 # create syslinux conf
1684 syslinux_config()
1686 local version="[$(cat $TARGET_ROOT/etc/slitaz-release)]"
1687 version="$version\(Kernel $KERNEL)"
1688 # backup an existing conf
1689 [ -e "$TARGET_ROOT/boot/syslinux/syslinux.cfg" ] && \
1690 cp $TARGET_ROOT/boot/syslinux/syslinux.cfg \
1691 $TARGET_ROOT/boot/syslinux/syslinux.bak
1692 # create the target syslinux configuration.
1693 mkdir -p $TARGET_ROOT/boot/syslinux || error8
1694 cat > $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1695 # use a boot menu
1696 UI vesamenu.c32
1698 # display the boot
1699 PROMPT 1
1701 # how long to pause at the boot
1702 TIMEOUT 50
1704 # default label
1705 DEFAULT slitaz
1707 # Menu settings
1708 MENU TITLE SliTaz GNU/Linux boot menu
1709 MENU BACKGROUND splash.jpg
1710 MENU WIDTH 78
1711 MENU MARGIN 6
1712 MENU ROW 10
1713 MENU VSHIFT 2
1714 MENU TIMEOUTROW 18
1715 MENU TABMSGROW 16
1716 MENU CMDLINEROW 16
1718 # Menu colors
1719 MENU COLOR border * #00000000 #00000000 none
1720 MENU COLOR title * #ffffffff #00000000 *
1721 MENU COLOR sel 0 #ffffffff #00000000 none
1722 MENU COLOR unsel 0 #50ffffff #00000000 none
1723 MENU COLOR help * #ffffffff #00000000 *
1724 MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
1725 MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
1726 MENU COLOR msg07 37;40 #90ffffff #a0000000 std
1727 MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
1729 # Labels
1730 LABEL slitaz
1731 MENU LABEL SliTaz GNU/Linux $version
1732 LINUX /boot/$KERNEL
1733 APPEND root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
1735 EOF
1736 if [ -n "$LIVEBOOT" ]; then
1737 local rootfs_files="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs*)"
1738 log "$(_ 'Enabling live/rescue boot with %s' "$rootfs_files")"
1739 for i in $rootfs_files; do
1740 [ -s $TARGET_ROOT/boot/$i ] &&
1741 mv $TARGET_ROOT/boot/$i $TARGET_ROOT/boot/$i.bak
1742 mv $TARGET_ROOT/boot/tazinst.$$/$i $TARGET_ROOT/boot/
1743 done
1744 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1745 LABEL live rescue
1746 MENU LABEL SliTaz GNU/Linux live/rescue $version
1747 LINUX /boot/$KERNEL
1748 INITRD /boot/$ROOTFS
1749 APPEND root=$(rootdev $ROOT_UUID) $(sed 's|.*gz ||' /proc/cmdline)
1751 EOF
1752 fi
1754 if [ -n "$WEBBOOT" -a -n "$IPXE" ]; then
1755 log "$(_ 'Enabling Webboot using %s' $IPXE)"
1756 mv -f $TARGET_ROOT/boot/tazinst.$$/$IPXE $TARGET_ROOT/boot/
1757 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1758 LABEL web zeb
1759 MENU LABEL SliTaz GNU/Linux web boot
1760 LINUX /boot/$IPXE
1762 EOF
1763 fi
1764 rm -rf $TARGET_ROOT/boot/tazinst.$$ 2> /dev/null
1766 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1767 LABEL cmdline
1768 MENU LABEL Command Line
1769 MENU QUIT
1771 EOF
1772 local winpart="$(winboot_uuid)"
1773 if [ -n "$winpart" ]; then
1774 log "$(_ 'Enabling Windows dual-boot')"
1775 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1776 LABEL windows
1777 MENU LABEL Windows
1778 COM32 chain.c32
1779 APPEND hd$(disknum $winpart) $(($(partnum $winpart)+1))
1781 EOF
1782 fi
1783 # log
1784 printf "%s\n" "/boot/syslinux/syslinux.cfg:" >> "$LOG"
1785 printf "%s\n" "--- syslinux.cfg -------------" >> "$LOG"
1786 cat $TARGET_ROOT/boot/syslinux/syslinux.cfg >> "$LOG"
1787 printf "%s\n\n" "--- syslinux.cfg -------------" >> "$LOG"
1790 # install syslinux
1791 syslinux_install()
1793 log "$(_ 'Installing Syslinux')"
1794 # needed tools
1795 local dir disk="$(uuid2disk $ROOT_UUID)"
1796 for dir in /home/boot/extlinux /home/boot/syslinux /boot/syslinux /boot/isolinux; do
1797 [ -d "$dir" ] && cp $dir/*.c32 $dir/*.sys "$TARGET_ROOT/boot/syslinux/"
1798 done
1799 cp /usr/share/boot/chain.c32 $TARGET_ROOT/boot/syslinux/chain.c32 2>> "$LOG"
1800 # install syslinux
1801 /bin/syslinux -version >> "$LOG" || error 5 "$(_ 'Syslinux not found')"
1802 /bin/extlinux --install $TARGET_ROOT/boot/syslinux >> "$LOG" 2>> "$LOG"
1803 case "$(p_table $ROOT_UUID)" in
1804 msdos)
1805 log "$(_ 'Setting the boot flag on')"
1806 /usr/sbin/parted "$disk" \
1807 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1808 [ -r /usr/share/boot/mbr.bin ] || error 5 "$(_ 'mbr.bin not found')"
1809 log "$(_ 'Installing MBR')"
1810 dd bs=440 count=1 conv=notrunc \
1811 if=/usr/share/boot/mbr.bin of=$disk >> "$LOG" ;;
1812 gpt)
1813 log "$(_ 'Setting the legacy_boot flag on')"
1814 # remove old boot flag
1815 local oldboot="$(parted $disk print \
1816 | grep boot | /bin/busybox awk '{print $1}')"
1817 /usr/sbin/parted "$disk" \
1818 set "$oldboot" legacy_boot off 2>> "$LOG"
1819 # set boot flag
1820 /usr/sbin/parted "$disk" \
1821 set "$(($(partnum $ROOT_UUID)+1))" legacy_boot on 2>> "$LOG"
1822 log "$(_ 'Installing GPTMBR')"
1823 [ -r /usr/share/boot/gptmbr.bin ] || error 5 "$(_ 'gptmbr.bin not found')"
1824 dd bs=440 conv=notrunc count=1 \
1825 if=/usr/share/boot/gptmbr.bin of=$disk >> "$LOG" ;;
1826 esac
1827 # splash image
1828 if [ -f "$SOURCE_ROOT/boot/isolinux/splash.jpg" ]; then
1829 log "$(_ 'Copying splash image')"
1830 cp -a $SOURCE_ROOT/boot/isolinux/splash.jpg \
1831 $TARGET_ROOT/boot/syslinux
1832 fi
1836 #-------------
1837 # 5.3 efiboot
1838 #-------------
1840 efiboot_install()
1842 local esp_fs_uuid mnt="/media/esp$$" efiboot="/EFI/SLITAZ"
1843 # We need efi stub support
1844 [ "$(strings $TARGET_ROOT/boot/$KERNEL | head | grep reloc)" ] || return
1845 # And the esp partition
1846 esp_fs_uuid="$(blkid | sed '/EFI system partition/!d;s|.* UUID="||;s|".*||;q')"
1847 [ "$esp_fs_uuid" ] || return
1848 # Copy SliTaz kernel and cmdline in esp partition
1849 mkdir $mnt &&
1850 mount "$(uuid2dev UUID=$esp_fs_uuid)" $mnt &&
1851 mkdir -p $mnt$efiboot 2> /dev/null
1852 if cp $TARGET_ROOT/boot/$KERNEL $mnt$efiboot/BZIMAGE.EFI; then
1853 log "$(_ 'Updating UEFI boot files')"
1854 echo "root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)" > $mnt$efiboot/linux.cmdline
1855 efibootmgr -v | grep -q SliTaz ||
1856 efibootmgr -c -d "$(uuid2disk UUID=$esp_fs_uuid)" -p "$(partnum UUID=$esp_fs_uuid)" \
1857 -L "SliTaz GNU/Linux" -l "${efiboot//\//\\}\\BZIMAGE.EFI"
1858 fi
1859 umount $mnt && rmdir $mnt
1862 #--------------------
1863 # 6. execute section
1864 #--------------------
1866 execute()
1868 local mode="$(get mode)" sighup=1 sigint=2 sigquit=3
1869 randomize_mirrors
1870 trap "error9" "$sighup" "$sigint" "$sigquit"
1871 case "$mode" in
1872 install)
1873 install ;;
1874 upgrade)
1875 upgrade ;;
1876 esac
1879 #-------------
1880 # 6.1 install
1881 #-------------
1883 # get a clean target device
1884 clean_target()
1886 if [ -z "$ROOT_FORMAT" ]; then
1887 # partition was not formatted
1888 log "$(_ 'Cleaning the root partition (%s)...' "$ROOT_UUID")"
1889 # keep /home in case of reinstall.
1890 local path="$(pwd)"
1891 cd "$TARGET_ROOT" || error8
1892 local dir
1893 for dir in *
1894 do
1895 case "$dir" in
1896 home)
1897 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")"
1898 mv home home.bak ;;
1899 lost+found)
1900 continue ;;
1901 *)
1902 log "$(_ 'removing target: %s' "$dir")"
1903 rm -rf "$dir" 2>>"$LOG" ;;
1904 esac
1905 done
1906 if [ ! -d lost+found ]; then
1907 mklost+found 2>>"$LOG"
1908 fi
1909 cd "$path" || error8
1910 fi
1913 # kernel is renamed to standard vmlinuz-$VERSION.
1914 install_kernel()
1916 KERNEL="vmlinuz-$(uname -r)"
1917 [ -d /$TARGET_ROOT/lib/modules/$(uname -r) ] ||
1918 log "$(_ 'Kernel name not found, falling back to: %s' "$(uname -r)")"
1919 mkdir -p $TARGET_ROOT/boot || error8
1920 for i in $SOURCE_ROOT/boot/bzImage* ; do
1921 cp $i $TARGET_ROOT/boot/${KERNEL%slitaz*}slitaz${i#*bzImage}
1922 done
1923 mkdir $TARGET_ROOT/boot/tazinst.$$
1924 for i in $(ls -r $SOURCE_ROOT/boot/rootfs?*.gz 2> /dev/null | sed q) \
1925 $SOURCE_ROOT/boot/rootfs.gz $SOURCE_ROOT/boot/*pxe* ; do
1926 cp $i $TARGET_ROOT/boot/tazinst.$$/
1927 done
1928 IPXE="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls *pxe* 2> /dev/null)"
1929 ROOTFS="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs.* 2> /dev/null)"
1930 [ -n "$ROOTFS" ] ||
1931 ROOTFS="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls -r rootfs?*.* | sed q)"
1932 log "$(_ 'install_kernel: %s' "$KERNEL")"
1935 # extract packed rootfs: squashfs or cromfs
1936 extract_loramfs()
1938 local i
1939 for i in $(/bin/busybox cpio -idvum 2> /dev/null); do
1940 case "$i" in
1941 rootfs*)
1942 need_package squashfs
1943 if ! unsquashfs $i ; then
1944 need_package cromfs
1945 unmkcromfs $i squashfs-root
1946 fi
1947 mv -f squashfs-root/* .
1948 rmdir squashfs-root
1949 rm -f $i
1950 esac
1951 done
1954 # this is a loram rootfs.gz, skip loram bootstrap and extract
1955 extract_first_loramfs()
1957 local path="$(pwd)"
1958 (zcat $1 || /usr/bin/unlzma < $1) | \
1959 /bin/busybox cpio -i extractfs.cpio 2> /dev/null &&
1960 ( cd / ; /bin/busybox cpio -id ) < extractfs.cpio && \
1961 rm -f extractfs.cpio
1962 ofs=$(/bin/busybox awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
1963 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
1964 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
1965 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | \
1966 extract_loramfs
1967 cd "$path" || error8
1970 # extract lzma'ed or gziped rootfs.
1971 extract_rootfs()
1973 local path="$(pwd)"
1974 local isloramfs
1975 cd "$TARGET_ROOT" || error8
1976 if [ -d "$1"/../fs/etc ]; then
1977 # this is a tazlitobox loram (cdrom)
1978 cp -a "$1"/../fs/. .
1979 else
1980 for i in $(ls "$1"/rootfs* | sort -r); do
1981 if [ ! -d etc ]; then
1982 if [ $( (zcat "$i" 2>/dev/null \
1983 || /usr/bin/lzma d "$i" -so) | \
1984 wc -c) -lt $(stat -c %s "$i") ]; then
1985 # this is a tazlitobox loram (ram)
1986 isloramfs="$i"
1987 extract_first_loramfs "$i"
1988 continue
1989 fi
1990 fi
1991 if [ -n "$isloramfs" ]; then
1992 extract_loramfs < "$i"
1993 continue
1994 fi
1995 ( zcat "$i" 2>/dev/null || /usr/bin/lzma d "$i" -so || \
1996 cat "$i" ) 2>>"$LOG" | /bin/busybox cpio -idu
1997 done 2>>"$LOG" > /dev/null
1998 fi
1999 $(which install) -m 644 /etc/keymap.conf /etc/locale.conf /etc/TZ /etc/network.conf etc
2000 cp -a /usr/lib/locale usr/lib/
2001 # unpack /usr (double check...)
2002 if ls etc/tazlito | grep -q ".extract"; then
2003 for i in etc/tazlito/*.extract; do
2004 [ -f "$i" ] && . "$i" /media/cdrom
2005 done
2006 fi
2007 cd "$pwd" || error8
2011 # pre configure freshly installed system (60 - 80%).
2012 pre_config_system()
2014 local path="$(pwd)"
2015 cd "$TARGET_ROOT" || error8
2016 # restore backup of existing /home if exists.
2017 # (created by prepare_target_dev)
2018 if [ -d home.bak ]; then
2019 log "$(_ 'Restoring directory: /home...')"
2020 rm -rf home
2021 mv home.bak home
2022 fi
2023 # add root device to CHECK_FS in rcS.conf to check filesystem
2024 # on each boot.
2025 log "$(_ 'Adding / partition and CHECK_FS to file %s...' '/etc/rcS.conf')"
2026 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$(dev2uuid $ROOT_UUID)\""# etc/rcS.conf
2027 # set hostname.
2028 log "$(_ 'Configuring host name: %s' "$HOSTNAME")"
2029 printf "%s\n" "$HOSTNAME" > etc/hostname
2030 printf "%s\n" "127.0.0.1 localhost $HOSTNAME tazpanel" > etc/hosts
2031 cd "$path" || error8
2034 # set root passwd and create user after rootfs extraction.
2035 users_settings()
2037 # create file
2038 cat > "$TARGET_ROOT/users.sh" << _EOF_
2039 #!/bin/sh
2040 umask 0022
2041 printf "root:%s" "$ROOT_PWD" | chpasswd -m
2042 adduser -D -H $USER_LOGIN
2044 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
2045 if ! grep \$grp /etc/group | grep -q $USER_LOGIN ; then
2046 grep -q \$grp /etc/group && addgroup $USER_LOGIN \$grp
2047 fi
2048 done
2050 printf "%s:%s" "$USER_LOGIN" "$USER_PWD" | chpasswd -m
2051 if [ ! -d /home/$USER_LOGIN ]; then
2052 cp -a /etc/skel /home/$USER_LOGIN
2053 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$USER_LOGIN
2054 mkdir -p /home/$USER_LOGIN/.config/slitaz
2055 cp -a /etc/slitaz/applications.conf /home/$USER_LOGIN/.config/slitaz
2056 # Set ownership
2057 if grep -q ^users: /etc/group; then
2058 chown -R $USER_LOGIN:users /home/$USER_LOGIN
2059 else
2060 chown -R $USER_LOGIN:$USER_LOGIN /home/$USER_LOGIN
2061 fi
2062 # Path for user desktop files.
2063 for i in /home/$USER_LOGIN/.local/share/applications/*.desktop
2064 do
2065 [ -e "$i" ] && sed -i s/"user_name"/"$USER_LOGIN"/g \$i
2066 done
2067 fi
2068 # Slim default user.
2069 if [ -f /etc/slim.conf ]; then
2070 sed -i s/"default_user .*"/"default_user $USER_LOGIN"/ \
2071 /etc/slim.conf
2072 fi
2073 _EOF_
2074 chmod o+x "$TARGET_ROOT/users.sh"
2075 chroot "$TARGET_ROOT" ./users.sh 2>>"$LOG" >> "$LOG"
2076 rm "$TARGET_ROOT/users.sh"
2077 umask 0177
2080 # /home can be on a separate partition. If default user exists in /home
2081 # we remove default file created by users_settings().
2082 home_config()
2084 if [ -n "$HOME_UUID" ]; then
2085 local path="$(pwd)" uuid
2086 cd "$TARGET_ROOT" || error8
2087 # detect fs
2088 local home_fs="$HOME_FORMAT"
2089 [ -z "$home_fs" ] && home_fs="$(filesys $HOME_UUID)"
2090 # manage /home
2091 log "$(_ 'Configuring partition to be used as /home: %s' "$HOME_UUID")"
2092 mv home/$USER_LOGIN tmp
2093 mount -t "$home_fs" "$HOME_UUID" home >> "$LOG" 2>> "$LOG"
2094 if [ -d $TARGET_ROOT/home/$USER_LOGIN ]; then
2095 rm -rf tmp/home/$USER_LOGIN
2096 else
2097 mv tmp/$USER_LOGIN home
2098 fi
2099 # write entry in fstab, force uuid
2100 uuid="$(dev2uuid "$HOME_UUID")"
2101 printf "%b\n" "$uuid /home $home_fs defaults \t0 \t2" >> etc/fstab
2102 umount home >> "$LOG" 2>> "$LOG"
2103 cd "$path" || error8
2104 fi
2107 install()
2109 log_open
2110 log "1 $(_ 'Installing SliTaz on: %s' "$(get root_uuid)")"
2111 log "5 $(_ 'Checking settings...')"
2112 check all >> "$LOG" 2>> "$LOG"
2113 load_settings
2115 log "10 $(_ 'Preparing source media...')"
2116 mount_source
2118 log "20 $(_ 'Preparing target disk...')"
2119 prepare_uuid
2121 log "30 $(_ 'Cleaning the root partition if necessary...')"
2122 clean_target
2124 log "40 $(_ 'Extracting the root system...')"
2125 extract_rootfs $SOURCE_ROOT/boot
2127 log "50 $(_ 'Installing the Kernel...')"
2128 install_kernel
2130 log "60 $(_ 'Preconfiguring the system...')"
2131 pre_config_system
2133 log "70 $(_ 'Configuring root and default user account...')"
2134 users_settings
2136 log "80 $(_ 'Configuring /home...')"
2137 home_config
2139 log "90 $(_ 'Checking bootloader installation...')"
2140 bootloader
2142 log "100 $(_ 'Files installation completed')"
2143 end_of_install
2147 #-------------
2148 # 6.2 upgrade
2149 #-------------
2151 # search for SliTaz
2152 check_release()
2154 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
2155 local release="$(cat $TARGET_ROOT/etc/slitaz-release)"
2156 log "$(_ 'Preparing upgrade of SliTaz release: %s' "$release")"
2157 else
2158 error 6 "$(_ "%s: This partition doesn't appear to contain a valid \
2159 SliTaz system, the file: %s doesn't exist." "$ROOT_UUID" '/etc/slitaz-release')"
2160 fi
2163 # backup packages list.
2164 backup_files()
2166 local path="$(pwd)"
2167 cd "$TARGET_ROOT" || error8
2168 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
2169 local dir
2170 for dir in *
2171 do
2172 case "$dir" in
2173 boot)
2174 rm -rf boot/vmlinuz-* ;;
2175 home)
2176 mv home home.bak
2177 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")" ;;
2178 etc)
2179 /bin/busybox tar czf etc.tar.gz etc
2180 mv etc etc.bak
2181 log "$(_ 'keeping /etc found on: %s' "$ROOT_UUID")" ;;
2182 var)
2183 if [ -d var/www ]; then
2184 mv var/www www.bak
2185 log "$(_ 'keeping /var/www found on: %s' "$ROOT_UUID")"
2186 fi
2187 rm -rf var 2>>"$LOG" ;;
2188 lost+found)
2189 continue ;;
2190 *)
2191 log "$(_ 'removing target: %s' "$dir")"
2192 rm -rf "$dir" 2>>"$LOG" ;;
2193 esac
2194 done
2195 if [ -d mklost+found ]; then
2196 mklost+found 2>>"$LOG"
2197 fi
2198 cd "$path" || error8
2201 # restore backups.
2202 restore_files()
2204 rm -rf $TARGET_ROOT/home
2205 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
2206 rm -rf $TARGET_ROOT/etc
2207 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
2208 if [ -d $TARGET_ROOT/www.bak ]; then
2209 rm -rf $TARGET_ROOT/var/www
2210 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
2211 fi
2212 log "$(_ 'backups restored: %s' "$(date)")"
2214 # /var/lib/slitaz-installer
2215 mkdir -p $TARGET_ROOT/var/lib/tazinst && \
2216 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst && \
2217 mv $TARGET_ROOT/home/packages-selection.list \
2218 $TARGET_ROOT/var/lib/tazinst \
2219 && log "$(_ 'backups saved in %s' '/var/lib/tazinst')"
2222 # upgrade added pkgs
2223 install_pkgs()
2225 # check if the pkg is on the mirror.
2226 log "$(_ 'Checking the availability of packages...')"
2227 touch packages-to-install.list
2228 packages=0
2229 diff="$(sort < packages-selection.diff)"
2230 for pkg in $diff
2231 do
2232 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
2233 packages="$(($packages+1))"
2234 printf "%s\n" "$pkg" >> packages-to-install.list
2235 fi
2236 done
2238 # install packages.
2239 log "$(_ 'Installing packages...')"
2240 if [ "$packages" = "0" ]; then
2241 log "$(_ 'packages to install: 0')"
2242 else
2243 # get-install all missing pkgs.
2244 while read pkg
2245 do
2246 log "$(_ 'Installing: %s...' "$pkg")"
2247 # get install package and answer yes in case of dependencies.
2248 pkgname="$(grep ^$pkg /var/lib/tazpkg/packages.list)"
2249 /usr/bin/tazpkg get "$pkg" >/dev/null 2>/dev/null
2250 yes "" | /usr/bin/tazpkg install $pkgname.tazpkg \
2251 --root=$TARGET_ROOT >/dev/null 2>/dev/null
2252 rm -f $pkgname.tazpkg
2253 done < packages-to-install.list
2254 fi
2255 log "$(_ 'Installation of packages complete...')"
2258 # search for added pkgs
2259 update_pkgs()
2261 local path="$(pwd)"
2262 cd $TARGET_ROOT/var/lib/tazinst || error8
2263 # LiveCD packages list.
2264 log "$(_ 'Creating package lists...')"
2265 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || error8
2266 log "$(_ '%s: done' 'packages-source.list')"
2267 # diff
2268 /bin/busybox diff packages-source.list packages-selection.list | \
2269 grep ^+[a-z] | sed s/^+// > packages-selection.diff
2270 log "$(_ '%s: done' 'packages-selection.diff')"
2271 # get mirror list.
2272 /usr/bin/tazpkg recharge >>$LOG 2>>$LOG
2273 if [ -f /var/lib/tazpkg/packages.list ]; then
2274 install_pkgs
2275 else
2276 touch packages-to-install.list
2277 longline "$(_ "The list of available packages on the mirror could not \
2278 be downloaded. No missing packages will be reinstalled now, but you can do so \
2279 later by looking at the following list:")"
2280 echo '/var/lib/tazinst/packages-selection.diff'
2281 fi
2282 cd "$path" || error8
2285 # upgrade command
2286 upgrade()
2288 log_open
2289 log "1 $(_ 'Upgrading SliTaz on: %s' "$(get root_uuid)")"
2290 log "5 $(_ 'Checking settings...')"
2291 check all >> "$LOG"
2292 load_settings
2294 log "10 $(_ 'Preparing source media...')"
2295 mount_source
2297 log "20 $(_ 'Preparing target disk...')"
2298 prepare_uuid
2300 log "30 $(_ 'Searching for %s...' '/etc/slitaz-release')"
2301 check_release
2303 log "40 $(_ 'Backup /etc, /home and the packages list...')"
2304 backup_files
2306 log "50 $(_ 'Extracting the root system...')"
2307 extract_rootfs $SOURCE_ROOT/boot
2309 log "60 $(_ 'Restoring configuration files...')"
2310 restore_files
2312 log "70 $(_ 'Installing the Kernel...')"
2313 install_kernel
2315 log "80 $(_ 'Upgrading added packages...')"
2316 update_pkgs
2318 log "90 $(_ 'Bootloader...')"
2319 bootloader
2321 log "100 $(_ 'Files installation completed')"
2322 end_of_install
2326 #--------------
2327 # tazinst main
2328 #--------------
2330 case $1 in
2331 new)
2332 new_file "$2" ;;
2333 set)
2334 [ -s "$4" ] || new_file "$4"
2335 read_file "$4"
2336 change "$2" "$3" "$4" ;;
2337 unset)
2338 read_file "$3"
2339 change "$2" "" "$3" "$4" ;;
2340 get)
2341 read_file "$3"
2342 get "$2" ;;
2343 check)
2344 read_file "$3"
2345 check "$2" ;;
2346 list)
2347 list "$2" "$3" ;;
2348 execute)
2349 check_root
2350 read_file "$2"
2351 execute "$2" ;;
2352 log)
2353 [ -r "$LOG" ] && cat "$LOG" ;;
2354 clean)
2355 clean "$2" ;;
2356 version)
2357 printf "%s\n" "$VERSION" ;;
2358 ""|usage)
2359 usage ;;
2360 help)
2361 help "$2" ;;
2362 *)
2363 usage_error "$1" ;;
2364 esac