tazinst view tazinst @ rev 109

Tazinst: fix iso already mounted error (thanks ben)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 16 10:57:25 2021 +0000 (2021-01-16)
parents 292c3fdb9769
children 5de73d81809b
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 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 # Windows dual boot:
266 # If you do not want enable Dual boot, leave WINBOOT empty (WINBOOT="").
267 # You may let tazinst automatically find your win partition by specifying auto
268 # (WINBOOT="auto"), otherwise enter the UUID of the partition to be used.
269 # Run 'tazinst list winboot' to see the Windows partitions found by tazinst.
270 WINBOOT="$WINBOOT"
272 EOT
273 return "$?"
274 }
276 read_file()
277 {
278 local install_file="$1"
279 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
280 if ! [ -r "$install_file" ]; then
281 _ 'Error: Unable to read install file.' 1>&2
282 exit 2
283 fi
284 #
285 if ! CONTENTS="$(cat "$install_file")"; then
286 _ 'Error: Unable to read install file.' 1>&2
287 exit 2
288 fi
289 }
291 # read value of a setting
292 get_value()
293 {
294 local setting="$1"
295 printf "%s" "$CONTENTS" | /bin/busybox awk -v setting="$setting" 'BEGIN{
296 setting="^" toupper(setting) "="
297 }
298 {
299 if (match($0,setting)){
300 n=index($0,"=")
301 value=substr($0,n+1)
302 gsub(/[\t\s]*$/,"",value)
303 sub(/^"/,"",value)
304 sub(/"$/,"",value)
305 }
306 }
307 END{
308 print value
309 }'
310 }
312 # list of settings
313 get_settings()
314 {
315 local "mode=$(get_value mode)"
316 case "$mode" in
317 upgrade)
318 echo "mode media source root_uuid bootloader winboot" ;;
319 *)
320 printf "%s\n" "$SETTINGS" ;;
321 esac
322 }
324 # get command
325 get()
326 {
327 local setting="$1"
328 [ -z "$setting" ] && setting="all"
329 # setting is valid: display value
330 if printf "%s" "$setting" | \
331 egrep -q "$(regex "$SETTINGS")"; then
332 get_value "$setting"
333 else
334 case "$setting" in
335 all)
336 for i in mode media source root_uuid root_format home_uuid home_format \
337 hostname root_pwd user_login user_pwd bootloader winboot; do
338 printf "%-15s: %s\n" "$i" "$(get_value $i)"
339 done
340 ;;
341 settings)
342 get_settings
343 ;;
344 *)
345 option_error "$1" "$SETTINGS"
346 ;;
347 esac
348 fi
349 }
351 # set command
352 change()
353 {
354 local setting="$1" value="$2" install_file="$3"
355 # validate setting
356 if ! printf "%s" "$setting" | \
357 egrep -q "$(regex "$SETTINGS")"; then
358 _ "Error: '%s' unknown setting." "$setting" 1>&2
359 exit 1
360 fi
361 # and file
362 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
363 # write changes to file
364 if [ -w "$install_file" ]; then
365 printf "%s" "$CONTENTS" | \
366 /bin/busybox awk -v setting="$setting" -v value="$value" '
367 BEGIN{
368 set=0
369 }
370 {
371 if (match($0,"^" toupper(setting) "=")){
372 printf toupper(setting) "=\"" value "\"\n"
373 set++
374 }
375 else
376 printf $0 "\n"
377 }
378 END{
379 if (! set)
380 printf toupper(setting) "=\"" value "\"\n"
381 }' > "$install_file"
382 # check new value
383 read_file "$install_file"
384 check "$setting"
385 else
386 _ 'Error: Unable to write to install file.' 1>&2
387 exit 2
388 fi
389 }
391 #
392 load_settings()
393 {
394 MODE="$(get mode)"
395 local settings="$(get settings)"
396 MEDIA="$(get media)"
397 echo "source" | egrep -q "$(regex "$settings")" \
398 && SOURCE="$(get source)" \
399 || unset SOURCE
400 ROOT_UUID="$(get root_uuid)"
401 echo "root_format" | egrep -q "$(regex "$settings")" \
402 && ROOT_FORMAT="$(get root_format)" \
403 || unset ROOT_FORMAT
404 echo "home_uuid" | egrep -q "$(regex "$settings")" \
405 && HOME_UUID="$(get home_uuid)" \
406 || unset HOME_UUID
407 echo "home_format" | egrep -q "$(regex "$settings")" \
408 && HOME_FORMAT="$(get home_format)" \
409 || unset HOME_FORMAT
410 echo "hostname" | egrep -q "$(regex "$settings")" \
411 && HOSTNAME="$(get hostname)" \
412 || unset HOSTNAME
413 echo "root_pwd" | egrep -q "$(regex "$settings")" \
414 && ROOT_PWD="$(get root_pwd)" \
415 || unset ROOT_PWD
416 echo "user_login" | egrep -q "$(regex "$settings")" \
417 && USER_LOGIN="$(get user_login)" \
418 || unset USER_LOGIN
419 echo "user_pwd" | egrep -q "$(regex "$settings")" \
420 && USER_PWD="$(get user_pwd)" \
421 || unset USER_PWD
422 echo "bootloader" | egrep -q "$(regex "$settings")" \
423 && BOOTLOADER="$(get bootloader)" \
424 || unset BOOTLOADER
425 echo "winboot" | egrep -q "$(regex "$settings")" \
426 && WINBOOT="$(get winboot)" \
427 || unset WINBOOT
428 }
436 # clean command
437 clean()
438 {
439 # rm LOG
440 [ -r "$LOG" ] && rm -f "$LOG"
441 # rm temp files
442 rm -rf /tmp/tazinst
443 # rm install file
444 local install_file="$1"
445 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
446 _ 'Deleting install file: %s' "$install_file"
447 if ! [ -w "$install_file" ]; then
448 _ 'Error: Unable to delete install file.' 1>&2
449 exit 2
450 else
451 rm -f "$install_file"
452 fi
453 }
455 #-----------
456 # 1.2 check
457 #-----------
459 # exit if user is not root.
460 check_root()
461 {
462 if [ $(id -u) -ne 0 ]; then
463 _ "You must be the root user (system administrator) \
464 to install SliTaz, please use 'su' to get a root SHell and restart \
465 installation." 1>&2
466 exit 1
467 fi
468 }
470 # exit if another instance of tazinst is running
471 check_instance()
472 {
473 if [ -e "$LOCK" ]; then
474 _ 'Another instance of tazinst is running.' 1>&2
475 exit 7
476 else
477 printf "%s" "$$" > $LOCK
478 fi
479 }
481 # exit if the setting is not in a list of keywords
482 check_key()
483 {
484 local setting="$1" keylist="$2" keyword="$(get $1)" msg
485 if ! printf "%s" "$keyword" | \
486 egrep -q "$(regex "$keylist")"; then
487 msg="$setting=$keyword
488 $(_ "Error: '%s' Invalid keyword." "$keyword")
489 $(_ 'Select one of these options: %s.' "$keylist")
490 $(_ 'For more information, see tazinst Manual.')"
491 printf "%s\n" "$msg" 1>&2
492 exit 1
493 fi
494 }
496 # exit if the partition does not exist
497 check_uuid()
498 {
499 local setting="$1" value="$(get $1)" found=0 partition msg
500 for partition in $(list_uuid); do
501 [ "$partition" = "$value" ] && found="$(($found + 1))"
502 done
503 if [ "$found" != "1" ]; then
504 msg="$(gettext "$setting")=$value
505 $(_ 'Error: Partition not found.')
506 $(_ "To see available partitions, run '%s'." 'tazinst list uuid')"
507 printf "%s\n" "$msg" 1>&2
508 exit 1
509 fi
510 }
512 # exit if the source does not exist
513 check_source()
514 {
515 local media="$(get media)" source="$(get source)"
516 case $media in
517 usb)
518 check_uuid source ;;
519 iso)
520 if [ ! -r "$source" ]; then
521 _ 'Error: Source file not found.' 1>&2
522 exit 1
523 fi ;;
524 web)
525 local valid=0
526 # check full url (http://...)
527 local regexp="^(https?|ftp):\/\/([a-z0-9\-]+\.)?[a-z0-9\-]+\.\
528 [a-z0-9]{2,4}(\.[a-z0-9]{2,4})?(\/.*)?iso$"
529 printf "%s" "$source" | \
530 egrep -q "$regexp" && valid=$(($valid+1))
531 # check iso names (stable cooking...)
532 regexp="$(regex "$(list web)")"
533 printf "%s" "$source" | \
534 egrep -q "$regexp" && valid=$(($valid+1))
535 if [ "$valid" -le "0" ]; then
536 _ 'Error: invalid URL.' 1>&2
537 exit 1
538 fi
539 esac
540 }
542 # exit if a partition is selected more than once
543 check_uuid_mix()
544 {
545 local list all nodup
546 list="$(get root_uuid) $(get source) $(get home_uuid) $(get winboot)"
547 all="$(printf "%s" "$list" | wc -w)"
548 nodup="$(printf "%s" "$list" | /bin/busybox awk 'BEGIN{RS=" "}{print $0}' \
549 | sort | uniq | wc -w)"
550 if [ "$all" != "$nodup" ]; then
551 _ 'Error: multiple assignations for a disk.' 1>&2
552 exit 1
553 fi
554 }
557 # exit if a password is invalid
558 check_password()
559 {
560 local pass="$(get "$1")"
561 local invalid="^[A-Za-z0-9!@#$%^&*()_]{0,40}$"
562 local errcode=0
563 # too long
564 if [ "${#pass}" -ge 40 ]; then
565 _ 'Error: password too long.' 1>&2
566 exit 1
567 fi
568 # bad chars
569 if ! (printf "%s" "$pass" | egrep -q "$invalid"); then
570 _ 'Error: Unallowed characters in password.' 1>&2
572 exit 1
573 fi
574 # short pwd
575 [ "${#pass}" -le 4 ] && errcode=128
576 # empty pwd
577 [ -z "$pass" ] && errcode=129
578 case "$errcode" in
579 128)
580 _ 'Warning: short password!' 1>&2 ;;
581 129)
582 _ 'Warning: no password!' 1>&2 ;;
583 esac
584 return "$errcode"
585 }
587 # exit if a name is invalid
588 check_name()
589 {
590 local name="$1" value="$(get "$1")" msg
591 msg="$name=$value"
592 if [ "${#value}" -lt 2 ]; then
593 _ '%s Error: Too short.' "$msg" 1>&2
594 exit 1
595 fi
596 if [ "${#value}" -gt 32 ]; then
597 _ '%s Error: Too long.' "$msg" 1>&2
598 exit 1
599 fi
600 if printf "%s" "$value" | \
601 grep -q "[[:space:]\&\"\'\(\)\|\*\\#\`\+\:/;<>]"; then
602 _ '%s Error: Invalid chars.' "$msg" 1>&2
603 exit 1
604 fi
605 }
607 # check bootloader + winboot
608 check_boot_mix()
609 {
610 local bootloader=$(get bootloader)
611 local winboot=$(get winboot)
612 if [ -z "$bootloader" ] && [ -n "$winboot" ]; then
614 _ 'Error: Dualboot set with no bootloader.' 1>&2
615 exit 1
616 fi
617 }
619 # exit if partition table is not in list
620 check_table()
621 {
622 local pt_list="gpt msdos"
623 # get root uuid
624 local uuid="$(get root_uuid)"
625 if [ "$(blkid | grep -c "$uuid")" = "1" ]; then
626 if ! printf "%s" "$(p_table $uuid)" | \
627 egrep -q "$(regex "$pt_list")"; then
628 _ 'Error: Unsupported Partition Table.' 1>&2
629 exit 1
630 fi
631 else
633 _ 'Error: No disk selected, cannot install any bootloader.' 1>&2
634 exit 1
635 fi
636 }
639 # check all settings()
640 check_all()
641 {
642 # check only settings we need
643 for key in $(get settings); do
644 case "$key" in
645 mode)
646 printf "%-15s: " "mode"
647 check_key mode "$(key "$LST_MODE")" && echo "ok" ;;
648 media)
649 printf "%-15s: " "media"
650 check_key media "$(key "$LST_MEDIA")" && echo "ok" ;;
651 source)
652 printf "%-15s: " "source"
653 check_source && echo "ok" ;;
654 root_uuid)
655 printf "%-15s: " "root_uuid"
656 check_uuid root_uuid && echo "ok" ;;
657 root_format)
658 printf "%-15s: " "root_format"
659 [ -n "$(get root_format)" ] && \
660 { check_key root_format "$(key "$LST_FORMAT")" && echo "ok"; } \
661 || echo "ok" ;;
662 home_uuid)
663 printf "%-15s: " "home_uuid"
664 [ -n "$(get home_uuid)" ] && \
665 { check_uuid home_uuid && check_uuid_mix && echo "ok"; } \
666 || echo "ok" ;;
667 home_format)
668 printf "%-15s: " "home_format"
669 [ -n "$(get home_format)" ] && \
670 { check_key home_format "$(key "$LST_FORMAT")" && echo "ok"; } \
671 || echo "ok" ;;
672 hostname)
673 printf "%-15s: " "hostname"
674 check_name hostname && echo "ok" ;;
675 root_pwd)
676 printf "%-15s: " "root_password"
677 check_password root_pwd && echo "ok" ;;
678 user_login)
679 printf "%-15s: " "user_login"
680 check_name user_login && echo "ok" ;;
681 user_pwd)
682 printf "%-15s: " "user_password"
683 check_password user_pwd && echo "ok" ;;
684 bootloader)
685 printf "%-15s: " "bootloader"
686 [ -n "$(get bootloader)" ] \
687 && { check_key bootloader "$(list_bootloader)" \
688 && check_table && echo "ok" ; } \
689 || echo "ok" ;;
690 winboot)
691 printf "%-15s: " "winboot"
692 [ -n "$(get winboot)" ] && [ "$(get winboot)" != "auto" ] \
693 && { check_uuid winboot && check_boot_mix && echo "ok"; } \
694 || echo "ok" ;;
695 esac
696 done
697 }
699 # check command
700 check()
701 {
702 local setting="$1"
703 case "$setting" in
704 mode)
705 check_key mode "$(key "$LST_MODE")" ;;
706 media)
707 check_key media "$(key "$LST_MEDIA")" ;;
708 source)
709 check_source ;;
710 root_uuid)
711 check_uuid root_uuid
712 check_uuid_mix ;;
713 home_uuid)
714 [ -z "$(get home_uuid)" ] || check_uuid home_uuid
715 check_uuid_mix ;;
716 root_format)
717 [ -z "$(get root_format)" ] \
718 || check_key root_format "$(key "$LST_FORMAT")" ;;
719 home_format)
720 [ -z "$(get home_format)" ] \
721 || check_key home_format "$(key "$LST_FORMAT")" ;;
722 hostname)
723 check_name hostname ;;
724 root_pwd)
725 check_password root_pwd ;;
726 user_login)
727 check_name user_login ;;
728 user_pwd)
729 check_password user_pwd ;;
730 bootloader)
731 [ -z "$(get bootloader)" ] \
732 || (check_key bootloader "$(list_bootloader)" \
733 && check_table ; ) ;;
734 winboot)
735 ([ -z "$(get winboot)" ] || [ "$(get winboot)" = "auto" ]) \
736 || check_uuid winboot && check_boot_mix ;;
737 ""|all)
738 check_all ;;
739 *)
740 option_error "$setting" "$SETTINGS" ;;
741 esac
742 }
744 #----------
745 # 1.3 help
746 #----------
748 help_source()
749 {
751 _ 'The Source setting depends on the type of media:'
752 printf "%-12s%s\n" "cdrom" "$(help cdrom)"
753 printf "%-12s%s\n" "usb" "$(help usb)"
754 printf "%-12s%s\n" "iso" "$(help iso)"
755 printf "%-12s%s" "web" "$(_ 'Name or URL of the image on the web.')"
756 printf "%s\n" "$(_ 'Type: %s' 'tazinst help web')"
757 }
759 help_all()
760 {
761 _ 'List of settings:'
762 optlist "\
763 mode $(_ 'Mode of install')
764 media $(_ 'Media containing the SliTaz source files')
765 source $(_ 'Source file containing SliTaz')
766 root_uuid $(_ 'The name of the target partition')
767 root_format $(_ 'Format of the target partition')
768 home_uuid $(_ 'Separate home partition')
769 home_format $(_ 'Format of the root partition')
770 hostname $(_ 'Name of the system')
771 root_pwd $(_ 'Superuser password')
772 user_login $(_ 'First user name')
773 user_pwd $(_ 'First user password')
774 bootloader $(_ 'Install a bootloader')
775 winboot $(_ 'Partition to dualboot Windows from')
776 "
777 }
779 # help command
780 help()
781 {
782 local setting="$1"
783 case "$setting" in
784 mode)
785 printf "%s" "$LST_MODE" | \
786 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
787 media)
788 printf "%s" "$LST_MEDIA" | \
789 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
790 source)
791 help_source ;;
792 cdrom)
793 _ 'CD. Automatically set' ;;
794 usb)
796 _ 'USB partition. For a list, type: %s' 'tazinst list usb' ;;
797 iso)
799 _ 'ISO file name. For a list, type: %s' 'tazinst list iso' ;;
800 web)
801 printf "%s" "$LST_WEB" | \
802 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $3}' ;;
803 root_format)
804 printf "%s" "$LST_FORMAT" | \
805 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
806 home_uuid|root_uuid)
807 /sbin/blkid -s TYPE -s LABEL | sort ;;
808 home_format)
809 printf "%s" "$LST_FORMAT" | \
810 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
811 hostname)
812 _ 'Name of the system' ;;
813 root_pwd)
814 _ 'Superuser password' ;;
815 user_login)
816 _ 'First user name' ;;
817 user_pwd)
818 _ 'First user password' ;;
819 bootloader)
820 printf "%s" "$LST_BOOTLOADER" | \
821 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n",$1,$2}' ;;
822 winboot)
823 _ "Partition containing Windows, or 'auto'" ;;
824 ""|all)
825 help_all ;;
826 *)
827 option_error "$setting" "$SETTINGS" ;;
828 esac
829 }
831 #---------
832 # 2. list
833 #---------
835 list_media()
836 {
837 local key media
838 for key in $(key "$LST_MEDIA") ; do
839 case "$key" in
840 cdrom)
841 [ -e "/dev/cdrom" ] && media="cdrom" ;;
842 usb)
843 [ -e "/sys/bus/usb" ] && media="$media usb" ;;
844 web)
845 [ "$(ifconfig -a | grep -c Link)" -gt 2 ] \
846 && media="$media web" ;;
847 *)
848 media="$media $key"
849 esac
850 done
851 printf "%s\n" "$media" | sed 's/^\s//'
852 }
854 list_usb()
855 {
856 # List plugged USB disks
857 if [ -d /proc/scsi/usb-storage ]; then
858 for DEV in /sys/block/sd* ; do
859 if readlink $DEV | grep -q usb; then
860 DEV=$(basename $DEV)
861 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
862 blkid /dev/$DEV* | tr ' ' '\n' | /bin/busybox awk '
863 /^\/dev\// {
864 DEV=$1
865 gsub(/:/,"",DEV)
866 }
867 /^UUID/ {
868 UUID=$1
869 gsub(/"/,"",UUID)
870 printf "%s %s\n",UUID,DEV}'
871 fi
872 fi
873 done
874 fi
875 }
877 list_iso()
878 {
879 for i in /root/*.iso /home/*/*.iso /home/*/*/*.iso ; do
880 printf "%s" $i | grep -v "*"
881 done
882 }
884 list_format()
885 {
886 local fs
887 type mkfs.btrfs > /dev/null && fs="btrfs"
888 type mkfs.ext2 > /dev/null && fs="$fs ext2"
889 type mkfs.ext3 > /dev/null && fs="$fs ext3"
890 type mkfs.ext4 > /dev/null && fs="$fs ext4"
891 type mkfs.jfs > /dev/null && fs="$fs jfs"
892 type mkfs.minix > /dev/null && fs="$fs minix"
893 type mkfs.reiser4 > /dev/null && fs="$fs reiser4"
894 type mkfs.xfs > /dev/null && fs="$fs xfs"
895 printf "%s" "$fs" | sed 's/^\s//'
896 }
898 # list partitions
899 list_uuid()
900 {
901 # list all drives but cdroms
902 /sbin/blkid -o export| /bin/busybox awk '
903 BEGIN{FS="="}
904 /DEVNAME/{dev=$2, type="unknown", label=""}
905 /LABEL/{label=$2" "}
906 /TYPE/{type=$2}
907 /PARTUUID/{if (type != "iso9660"){
908 printf "%s %s(%s)\n", dev, label, type}}' | sort -k 2
909 }
911 list_partition_table()
912 {
913 /usr/sbin/parted -lms 2>&1 | \
914 /bin/busybox awk -F: '/^\/dev\//{printf "%s: %s\n", $1,$6}'
915 }
917 list_web()
918 {
919 local key="$1"
920 # print url of a given iso
921 if printf "%s" "$LST_WEB" | egrep -q "^$key:"; then
922 printf "%s" "$LST_WEB" | egrep "^$key:" | \
923 /bin/busybox awk -F: '{print $2}'
924 fi
925 # print all key
926 if [ -z "$key" ]; then
927 key "$LST_WEB"
928 fi
929 }
931 list_bootloader()
932 {
933 local btlr
934 type grub-install > /dev/null && btlr=" grub"
935 type syslinux > /dev/null && btlr="$btlr syslinux"
936 [ -n "$btlr" ] && printf "%s\n" "auto$btlr"
937 }
939 # list Windows partitions
940 list_winboot()
941 {
942 /usr/sbin/parted -lms 2>&1 | sed '/zram/,$d' | /bin/busybox awk '
943 BEGIN{
944 FS=":"
945 disknum=-1
946 found=0
947 winboot=""
948 printf "auto"
949 }
950 {
951 # Count disks
952 if (match($1,"^/dev")){
953 disknum++
954 part=0
955 disk=$1
956 dev=substr($1,6)
957 # get removable status
958 file="/sys/block/"dev"/removable"
959 "cat " file | getline removable
960 close("cat ")
961 }
962 # Count partitions
963 if (match($1,"[0-9][0-9]?")){
964 # List fixed drives only
965 if (removable==0){
966 part++
967 # Read partition Id
968 if (match($7,"boot")){
969 fs=$5
970 # Detect Windows Partition Type: ntfs vfat
971 WPT="ntfs|vfat"
972 if (fs ~ WPT){
973 found++
974 # record 1st Windows partition found
975 if (found==1){
976 printf(" %s%d",disk,part)
977 }
978 }
979 }
980 }
981 }
982 }
983 END{printf "\n"}'
984 }
986 # list command
987 list()
988 {
989 local ressource="$1"
990 case "$ressource" in
991 mode)
992 printf "%s\n" "$(key "$LST_MODE")" ;;
993 media)
994 list_media ;;
995 iso)
996 list_iso ;;
997 usb)
998 list_usb ;;
999 web)
1000 list_web "$2" ;;
1001 uuid)
1002 list_uuid ;;
1003 format)
1004 list_format ;;
1005 bootloader)
1006 list_bootloader ;;
1007 winboot)
1008 list_winboot ;;
1009 partition_table)
1010 list_partition_table ;;
1011 ""|all)
1012 printf "* mode:\n%s\n\n" "$(key "$LST_MODE")"
1013 printf "* media:\n%s\n\n" "$(list_media)"
1014 printf "* usb:\n%s\n\n" "$(list usb)"
1015 printf "* iso:\n%s\n\n" "$(list_iso)"
1016 printf "* web:\n%s\n\n" "$(list_web)"
1017 printf "* uuid:\n%s\n\n" "$(list_uuid)"
1018 printf "* format:\n%s\n\n" "$(list_format)"
1019 printf "* bootloader:\n%s\n\n" "$(list_bootloader)"
1020 printf "* partition_table:\n%s\n\n" "$(list_partition_table)"
1021 printf "* winboot:\n%s\n" "$(list_winboot)"
1022 ;;
1023 *)
1024 local options="mode media usb iso web uuid format bootloader \
1025 partition_table winboot"
1026 option_error "$1" "$options" ;;
1027 esac
1030 #----------
1031 # 3. tools
1032 #----------
1034 # list indexes from a list
1035 key()
1037 printf "%s" "$1" | /bin/busybox awk -F: 'BEGIN{
1038 other=-1
1040 !/^#|^$/{
1041 if(other){
1042 printf "%s", $1
1043 other++}
1044 else
1045 printf " %s", $1
1047 END{printf "\n"}'
1050 # convert a list of words to a regex
1051 regex()
1053 printf "%s" "^$1$" | sed s'/ /$|^/g'
1056 # print dev from uuid
1057 uuid2dev()
1059 local uuid="$1"
1060 if [ "${uuid%=*}" = "UUID" ]; then
1061 uuid="$(blkid | sed '/ UUID="'${uuid#*=}'"/!d;s|:.*||')"
1062 fi
1063 printf "%s" "$uuid"
1066 # print disk from uuid
1067 uuid2disk()
1069 printf "%s" "$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
1072 dev2uuid()
1074 local uuid="$1"
1075 if printf "%s" "$uuid" | grep -q dev; then
1076 printf "UUID=%s" "$(/sbin/blkid -p -i -o udev "$uuid" \
1077 | grep ID_FS_UUID= | cut -d '=' -f2)"
1078 else
1079 printf "%s" "$uuid"
1080 fi
1083 # print partition scheme from uuid
1084 p_table()
1086 local uuid="$1" device
1087 device="$(uuid2disk $uuid)"
1088 printf "%s" "$(/usr/sbin/parted -lms 2>&1 | grep "$device" | \
1089 cut -d':' -f6)"
1092 # print filesystem from uuid
1093 filesys()
1095 local uuid="$1"
1096 local fs="$(/sbin/blkid -s UUID -s TYPE | \
1097 grep "$(uuid2dev $uuid)" | cut -d' ' -f3)"
1098 fs="${fs#TYPE=\"}"
1099 fs="${fs%\"}"
1100 printf "%s" "$fs"
1103 # return removable status from uuid
1104 is_removable()
1106 local removable=1
1107 local disk="$(uuid2disk $1 | sed 's|/dev/||')"
1108 if [ "$disk" ]; then
1109 [ "$(cat /sys/block/"$disk"/removable 2> /dev/null)" -gt "0" ] \
1110 && removable=0
1111 fi
1112 return "$removable"
1115 randomize_mirrors()
1117 local list_mirrors
1118 if [ -r "$MIRRORS" ]; then
1119 # randomize list of mirrors
1120 list_mirrors="$(cat $MIRRORS | \
1121 /bin/busybox awk 'BEGIN {srand()}{
1122 printf "%05.0f %s \n",rand()*99999, $0;
1123 }' | sort -n | sed 's/^[0-9]* //' )"
1124 else
1125 log "$(_ 'No mirror list found, run %s.' 'tazpkg recharge')"
1126 list_mirrors="http://mirror.slitaz.org/"
1127 fi
1128 MIRRORS="$list_mirrors"
1131 # download a file
1132 dnl()
1134 local file="$1" mirror transfer=0 oldfile
1135 mkdir -p /tmp/tazinst
1136 for mirror in $MIRRORS; do
1137 log "$(_ 'Downloading: %s' "$mirror$file")"
1138 oldfile="$(printf "%s" $file | \
1139 /bin/busybox awk 'BEGIN{RS="/"}{text=$1}END{print text}')"
1140 [ -e "/tmp/tazinst/$oldfile" ] && rm -f "/tmp/tazinst/$oldfile"
1141 /bin/busybox wget $mirror$file -P /tmp/tazinst && transfer=1 && break
1142 done
1143 if [ "$transfer" -gt "0" ];then
1144 log "$(_ 'Download completed.')"
1145 else
1146 error 5 "(_ '%s: Download failed.' "$file")"
1147 fi
1150 # install pkg in current system
1151 need_package()
1153 local pkg="$1"
1154 if [ ! -d /var/lib/tazpkg/installed/$pkg ]; then
1155 log "$(_ 'Installing package %s to the current system.' "$pkg")"
1156 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1157 /usr/bin/tazpkg get-install "$pkg" || error 5 "$(_ 'Cannot install %s.' "$pkg")"
1158 fi
1161 # install pkg in target system
1162 add_pkg()
1164 local pkg="$1"
1165 log "$(_ 'Adding package %s to the target system...' "$pkg")"
1166 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1167 /usr/bin/tazpkg get "$pkg" >> "$LOG" 2>> "$LOG"
1168 yes "" | /usr/bin/tazpkg install $pkg.tazpkg \
1169 --root=$TARGET_ROOT >> "$LOG" 2>> "$LOG"
1170 rm -f $pkg.tazpkg
1173 #---------
1174 # 3.1 log
1175 #---------
1177 # start log
1178 log_open()
1180 _ '=== Tazinst: started on %s ===' "$(date "+%x %X")" > "$LOG"
1181 LOGGING="true"
1184 # print and log a comment
1185 log(){
1186 # for front-ends, sleep 1 if $1 is num
1187 printf "%s" "$1" | awk '{
1188 num=$1+0
1189 if(num>0 && num<=100)
1190 exit 0
1191 else
1192 exit 1
1193 }' && sleep 1
1194 # log
1195 printf "%s\n" "$1"
1196 [ -n "$LOGGING" ] && printf "%s\n" "$1" >> $LOG
1199 #--------------------
1200 # 3.2 error handling
1201 #--------------------
1203 # print an error msg & exit
1204 error()
1206 local error="$1" msg="$2" cancel="$(_ 'Process not completed')"
1207 _ 'Error: %s' "$msg" >&2; echo "$cancel" >&2
1208 if [ -n "$LOGGING" ]; then
1209 # 1st pattern
1210 echo "-x-x- " >> "$LOG"
1211 _ 'Error: %s' "$msg" >> "$LOG"; echo "$cancel" >> "$LOG"
1212 # 2nd pattern
1213 echo "x-x-x " >> "$LOG"
1214 _ '=== Tazinst error on %s ===' "$(date "+%x %X")" >> "$LOG"
1215 fi
1216 unset LOGGING
1217 umount_devices
1218 exit "$error"
1221 error8()
1223 error 8 "$(_ 'Internal error')"
1226 error9()
1228 error 9 "$(_ 'Cancelled by user')"
1231 #------------------
1232 # 4. disks section
1233 #------------------
1235 #------------
1236 # 4.1 source
1237 #------------
1239 # liveCD
1240 mount_cdrom()
1242 # set device name
1243 local drive="$(grep "drive name" < \
1244 /proc/sys/dev/cdrom/info | cut -f 3)"
1245 [ -n "$drive" ] || drive=cdrom
1246 local cdrom=/dev/$drive
1247 # mount cdrom
1248 if mount -t iso9660 "$cdrom" "$SOURCE_ROOT" 2>>"$LOG"; then
1249 log "$(_ 'Using files from %s.' "$cdrom")"
1250 else
1251 error 3 "$(_ '%s: Mount failed.' "$cdrom")"
1252 fi
1255 # liveUSB
1256 mount_usb()
1258 # /home is on LiveUSB
1259 if [ -d /home/boot ]; then
1260 log "$(_ 'Using files from USB device...')"
1261 ln -s /home/boot $SOURCE_ROOT/boot
1262 else
1263 # mount LiveUSB
1264 if mount "$SOURCE" "$SOURCE_ROOT" 2>>"$LOG"; then
1265 log "$(_ 'Using files from USB device %s.' "$SOURCE")"
1266 else
1267 error 3 "$(_ '%s: Failed to mount USB device.' "$SOURCE")"
1268 fi
1269 fi
1272 # ISO file on HDD
1273 mount_iso()
1275 # check integrity
1276 local md5file=$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')
1277 if [ -r "$md5file" ]; then
1278 local md5ref="$(cut -d' ' -f1 < "$md5file")"
1279 local md5calc="$(md5sum $SOURCE | cut -d' ' -f1)"
1280 if [ ! "$md5calc" = "$md5ref" ]; then
1281 log "md5sum iso=$md5ref md5sum tazinst=$md5calc"
1282 error 3 "$(_ 'md5sum error, file corrupted.')"
1283 fi
1284 else
1285 log "$(_ '%s: md5 file not found, cannot check integrity.' "$SOURCE")"
1286 fi
1287 # mount ISO
1288 if mount -o loop -t iso9660 "$SOURCE" \
1289 "$SOURCE_ROOT" 2>>"$LOG"; then
1290 log "$(_ 'Using files from ISO %s.' "$SOURCE")"
1291 else
1292 error 3 "$(_ '%s: Failed to mount ISO.' "$SOURCE")"
1293 fi
1296 # ISO file on the web
1297 mount_web()
1299 if (printf "%s" "$SOURCE" | egrep -q "$(regex "$(list web)")"); then
1300 SOURCE="$(list web $SOURCE)"
1301 fi
1302 dnl "$SOURCE"
1303 local md5file="$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')"
1304 dnl "$md5file"
1305 local webiso="$(printf "%s" $SOURCE | \
1306 /bin/busybox awk 'BEGIN{RS="/"}{out=$1} END{printf "%s",out}')"
1307 SOURCE="/tmp/tazinst/$webiso"
1308 mount_iso
1311 # set up source and check SliTaz' content
1312 mount_source()
1314 log "$(_ 'Creating mount point: %s...' "$SOURCE_ROOT")"
1315 mkdir -p "$SOURCE_ROOT"
1316 case "$MEDIA" in
1317 cdrom)
1318 mount_cdrom ;;
1319 usb)
1320 mount_usb ;;
1321 iso)
1322 mount_iso ;;
1323 web)
1324 mount_web ;;
1325 *)
1326 error8 ;;
1327 esac
1329 # exit if no rootfs.gz found.
1330 log "$(_ 'Checking installation media...')"
1331 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz -a \
1332 ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
1333 error 3 "$(_ 'Invalid source')"
1334 else
1335 log "$(_ 'Installation media checked ok')"
1336 fi
1339 #------------
1340 # 4.2 target
1341 #------------
1343 # format a partition
1344 format()
1346 local uuid="$1" fmt="$2" dest="$3" dev format
1347 log "$(_ 'Format %s (%s)' "$uuid" "$fmt")"
1348 format="mkfs.$fmt"
1349 if (printf "%s" "$uuid" | grep -q "UUID="); then
1350 # case UUID=
1351 dev="$(uuid2dev $uuid)"
1352 "$format" "$dev" >>"$LOG" 2>>"$LOG" || error 4 "$(_ 'Formatting has failed')"
1353 # uuid has changed
1354 case "$dest" in
1355 root_uuid)
1356 ROOT_UUID="$(/sbin/blkid -p "$dev" -o export | \
1357 grep ^UUID=)" ;;
1358 home_uuid)
1359 HOME_UUID="$(/sbin/blkid -p "$dev" -o export | \
1360 grep ^UUID=)" ;;
1361 esac
1362 else
1363 # case /dev/xxxx
1364 "$format" $uuid >>"$LOG" 2>>"$LOG" || error 4 "$(_ 'Formatting has failed')"
1365 fi
1368 # prepare partitions
1369 prepare_uuid()
1371 log "$(_ 'Preparing target partition...')"
1372 local uuid
1373 # target may be in use
1374 if mount | grep -q "$ROOT_UUID" ;then
1375 log "$(_ 'Partition is already mounted, unmounting.')"
1376 umount "$ROOT_UUID"
1377 fi
1378 mount | grep -q "$ROOT_UUID" && \
1379 error 4 "$ROOT_UUID: $(_ 'Partition is already in use.')"
1380 # Mount point can be already used.
1381 mount | grep -q "$TARGET_ROOT" && \
1382 umount "$TARGET_ROOT" 2>>"$LOG"
1384 # Formatting root partition
1385 case "$ROOT_FORMAT" in
1386 "")
1387 log "$(_ '%s: The partition will be cleaned...' "$ROOT_UUID")" ;;
1388 *)
1389 format "$ROOT_UUID" "$ROOT_FORMAT" root_uuid
1390 esac
1392 # Formatting /home
1393 if [ -n "$HOME_UUID" ]; then
1394 case "$HOME_FORMAT" in
1395 "")
1396 log "$(_ '%s: The partition will be kept...' "$HOME_UUID")" ;;
1397 *)
1398 format "$HOME_UUID" "$HOME_FORMAT" home_uuid
1399 esac
1400 fi
1402 log "$(_ 'Creating mount point: %s...' "$TARGET_ROOT")"
1403 mkdir -p "$TARGET_ROOT" >> "$LOG" || error8
1404 # Mount target.
1405 local mount_fs="$ROOT_FORMAT"
1406 [ -z "$mount_fs" ] && mount_fs="$(filesys $ROOT_UUID)"
1407 mount -t "$mount_fs" "$ROOT_UUID" \
1408 "$TARGET_ROOT" >>"$LOG" 2>>"$LOG"
1409 if [ $(mount | \
1410 grep -c "mnt/target") = "0" ]; then
1411 error 4 "$(_ '%s: Unable to mount partition' "$ROOT_UUID")"
1412 fi
1416 #------------
1417 # 4.3 umount
1418 #------------
1420 # copy log file, umount target and eject cdrom.
1421 umount_devices()
1423 # umount target
1424 if mount | grep -q "$TARGET_ROOT"; then
1425 log "$(_ 'Unmounting target partition: %s' "$ROOT_UUID")"
1426 umount -l "$TARGET_ROOT" 2>>$LOG
1427 fi
1429 # umount source
1430 if mount | grep -q "$SOURCE_ROOT"; then
1431 log "$(_ 'Unmounting: %s' "$SOURCE_ROOT")"
1432 umount -l "$SOURCE_ROOT"
1433 fi
1434 if [ -h $SOURCE_ROOT/boot ]; then
1435 log "$(_ 'Unlinking: %s' "$SOURCE_ROOT")"
1436 rm -f $SOURCE_ROOT/boot
1437 fi
1439 # eject cd
1440 if [ "$SOURCE" = "cdrom" ]; then
1441 _ 'Ejecting CD-ROM...'
1442 eject
1443 fi
1444 # remove lock file
1445 rm -f "$LOCK"
1448 end_of_install()
1450 log "$(_ 'Process completed. You can now restart (reboot) from your SliTaz GNU/Linux system.' |\
1451 fold -s)"
1452 _ '=== Tazinst ended on %s ===' "$(date "+%x %X")" >> "$LOG"
1453 unset LOGGING
1454 # saving log
1455 log "$(_ 'Copying log to %s' '/var/log/tazinst.log')"
1456 cp -a "$LOG" $TARGET_ROOT/var/log
1457 umount_devices
1461 #---------------
1462 # 5. bootloader
1463 #---------------
1465 #------------
1466 # 5.1 common
1467 #------------
1469 # selection
1470 bootloader()
1472 if [ "$BOOTLOADER" = "auto" ]; then
1473 # use syslinux, but if p_table=msdos take grub (if available)
1474 unset BOOTLOADER
1475 printf "%s" "$(list_bootloader)" | \
1476 grep -q "syslinux" && BOOTLOADER=syslinux
1477 if [ "$(p_table $ROOT_UUID)" = "msdos" ]; then
1478 printf "%s" "$(list_bootloader)" | \
1479 grep -q " grub" && BOOTLOADER=grub
1480 fi
1481 fi
1482 case "$BOOTLOADER" in
1483 grub)
1484 grub_config
1485 grub_install ;;
1486 syslinux)
1487 syslinux_config
1488 syslinux_install ;;
1489 *)
1490 syslinux_config
1491 log "$(_ 'No bootloader to install.')" ;;
1492 esac
1493 [ -d /sys/firmware/efi ] && efiboot_install
1496 # print disk num
1497 disknum()
1499 local disk="$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
1500 /usr/sbin/parted -lms 2>&1 | grep "^/dev" | \
1501 /bin/busybox awk -v PART="$disk:" '{if (match($0,PART)) print NR-1}'
1504 # print partition num
1505 partnum()
1507 printf "%s" "$(($(uuid2dev $1 | /bin/busybox sed 's|.*[^0-9]||')-1))"
1510 # print root device
1511 rootdev()
1513 local partition="$1"
1514 case "$(p_table $partition)" in
1515 msdos)
1516 # print device
1517 printf "%s" "$(uuid2dev $partition)" ;;
1518 gpt)
1519 # print PARTUUID (different from UUID)
1520 printf "%s" "PARTUUID="
1521 /sbin/blkid -p -i -o udev $(uuid2dev $partition) \
1522 | grep ENTRY_UUID | cut -d '=' -f2 ;;
1523 esac
1526 # add rootdelay for removable devices
1527 rootdelay()
1529 is_removable "$ROOT_UUID" && printf "%s" " rootdelay=9"
1532 # print winboot uuid
1533 winboot_uuid()
1535 if [ "$WINBOOT" = "auto" ]; then
1536 # get the first uuid if any
1537 [ $(list_winboot | wc -w) -gt 1 ] \
1538 && printf "%s" "$(list_winboot | cut -d' ' -f2)"
1539 else
1540 printf "%s" "$WINBOOT"
1541 fi
1545 #-----------
1546 # 5.1 grub1
1547 #-----------
1549 # create grub legacy conf
1550 grub_config()
1552 # backup an existing conf
1553 [ -e "$TARGET_ROOT/boot/grub/menu.lst" ] && \
1554 cp $TARGET_ROOT/boot/grub/menu.lst \
1555 $TARGET_ROOT/boot/grub/menu.bak
1556 # create the target GRUB configuration.
1557 mkdir -p $TARGET_ROOT/boot/grub || error8
1558 cat > $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1559 # /boot/grub/menu.lst: GRUB boot loader configuration.
1562 # By default, boot the first entry.
1563 default 0
1565 # Boot automatically after 8 secs.
1566 timeout 8
1568 # Graphical splash image.
1569 splashimage=/boot/grub/splash.xpm.gz
1571 # Change the colors.
1572 #color yellow/brown light-green/black
1574 # For booting SliTaz from : $ROOT_UUID
1576 title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1577 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1578 kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
1580 _EOF_
1582 local winpart="$(winboot_uuid)"
1583 if [ -n "$winpart" ]; then
1584 log "$(_ 'Enabling Windows dual-boot')"
1585 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
1586 # For booting Windows :
1588 title Microsoft Windows
1589 rootnoverify (hd$(disknum $winpart),$(partnum $winpart))
1590 chainloader +1
1592 _EOF_
1593 fi
1595 # log
1596 printf "%s\n" "/boot/grub/menu.lst:" >> "$LOG"
1597 printf "%s\n" "--- menu.lst -------------" >> "$LOG"
1598 cat $TARGET_ROOT/boot/grub/menu.lst >> "$LOG"
1599 printf "%s\n\n" "--- menu.lst -------------" >> "$LOG"
1602 # GRUB info with disk name used for grub
1603 grub_install()
1605 # install grub
1606 local target_disk="$(uuid2disk $ROOT_UUID)"
1607 log "$(_ 'Installing GRUB on: %s' "$target_disk")"
1608 /usr/sbin/grub-install --version >> "$LOG" || error 5 "$(_ 'GRUB not found')"
1609 /usr/sbin/grub-install --no-floppy \
1610 --root-directory=$TARGET_ROOT $target_disk >>"$LOG" 2>>"$LOG"
1611 # set boot flag
1612 log "$(_ 'Setting the boot flag')"
1613 /usr/sbin/parted "$(uuid2disk $ROOT_UUID)" \
1614 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1615 # splash image
1616 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
1617 log "$(_ 'Copying splash image')"
1618 mkdir -p $TARGET_ROOT/boot/grub
1619 cp $SOURCE_ROOT/boot/grub/splash.xpm.gz \
1620 $TARGET_ROOT/boot/grub
1621 fi
1625 #--------------
1626 # 5.2 syslinux
1627 #--------------
1629 # create syslinux conf
1630 syslinux_config()
1632 local version="[$(cat $TARGET_ROOT/etc/slitaz-release)]"
1633 version="$version\(Kernel $KERNEL)"
1634 # backup an existing conf
1635 [ -e "$TARGET_ROOT/boot/syslinux/syslinux.cfg" ] && \
1636 cp $TARGET_ROOT/boot/syslinux/syslinux.cfg \
1637 $TARGET_ROOT/boot/syslinux/syslinux.bak
1638 # create the target syslinux configuration.
1639 mkdir -p $TARGET_ROOT/boot/syslinux || error8
1640 cat > $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1641 # use a boot menu
1642 UI vesamenu.c32
1644 # display the boot
1645 PROMPT 1
1647 # how long to pause at the boot
1648 TIMEOUT 50
1650 # default label
1651 DEFAULT slitaz
1653 # Menu settings
1654 MENU TITLE SliTaz GNU/Linux boot menu
1655 MENU BACKGROUND splash.jpg
1656 MENU WIDTH 78
1657 MENU MARGIN 6
1658 MENU ROW 10
1659 MENU VSHIFT 2
1660 MENU TIMEOUTROW 18
1661 MENU TABMSGROW 16
1662 MENU CMDLINEROW 16
1664 # Menu colors
1665 MENU COLOR border * #00000000 #00000000 none
1666 MENU COLOR title * #ffffffff #00000000 *
1667 MENU COLOR sel 0 #ffffffff #00000000 none
1668 MENU COLOR unsel 0 #50ffffff #00000000 none
1669 MENU COLOR help * #ffffffff #00000000 *
1670 MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
1671 MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
1672 MENU COLOR msg07 37;40 #90ffffff #a0000000 std
1673 MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
1675 # Labels
1676 LABEL slitaz
1677 MENU LABEL SliTaz GNU/Linux $version
1678 LINUX /boot/$KERNEL
1679 APPEND root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
1681 LABEL cmdline
1682 MENU LABEL Command Line
1683 MENU QUIT
1685 EOF
1686 local winpart="$(winboot_uuid)"
1687 if [ -n "$winpart" ]; then
1688 log "$(_ 'Enabling Windows dual-boot')"
1689 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
1690 LABEL windows
1691 MENU LABEL Windows
1692 COM32 chain.c32
1693 APPEND hd$(disknum $winpart) $(($(partnum $winpart)+1))
1695 EOF
1696 fi
1697 # log
1698 printf "%s\n" "/boot/syslinux/syslinux.cfg:" >> "$LOG"
1699 printf "%s\n" "--- syslinux.cfg -------------" >> "$LOG"
1700 cat $TARGET_ROOT/boot/syslinux/syslinux.cfg >> "$LOG"
1701 printf "%s\n\n" "--- syslinux.cfg -------------" >> "$LOG"
1704 # install syslinux
1705 syslinux_install()
1707 log "$(_ 'Installing Syslinux')"
1708 # needed tools
1709 local dir disk="$(uuid2disk $ROOT_UUID)"
1710 for dir in /home/boot/extlinux /home/boot/syslinux /boot/syslinux /boot/isolinux; do
1711 [ -d "$dir" ] && cp $dir/*.c32 $dir/*.sys "$TARGET_ROOT/boot/syslinux/"
1712 done
1713 cp /usr/share/boot/chain.c32 $TARGET_ROOT/boot/syslinux/chain.c32 2>> "$LOG"
1714 # install syslinux
1715 /bin/syslinux -version >> "$LOG" || error 5 "$(_ 'Syslinux not found')"
1716 /bin/extlinux --install $TARGET_ROOT/boot/syslinux >> "$LOG" 2>> "$LOG"
1717 case "$(p_table $ROOT_UUID)" in
1718 msdos)
1719 log "$(_ 'Setting the boot flag on')"
1720 /usr/sbin/parted "$disk" \
1721 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1722 [ -r /usr/share/boot/mbr.bin ] || error 5 "$(_ 'mbr.bin not found')"
1723 log "$(_ 'Installing MBR')"
1724 dd bs=440 count=1 conv=notrunc \
1725 if=/usr/share/boot/mbr.bin of=$disk >> "$LOG" ;;
1726 gpt)
1727 log "$(_ 'Setting the legacy_boot flag on')"
1728 # remove old boot flag
1729 local oldboot="$(parted $disk print \
1730 | grep boot | /bin/busybox awk '{print $1}')"
1731 /usr/sbin/parted "$disk" \
1732 set "$oldboot" legacy_boot off 2>> "$LOG"
1733 # set boot flag
1734 /usr/sbin/parted "$disk" \
1735 set "$(($(partnum $ROOT_UUID)+1))" legacy_boot on 2>> "$LOG"
1736 log "$(_ 'Installing GPTMBR')"
1737 [ -r /usr/share/boot/gptmbr.bin ] || error 5 "$(_ 'gptmbr.bin not found')"
1738 dd bs=440 conv=notrunc count=1 \
1739 if=/usr/share/boot/gptmbr.bin of=$disk >> "$LOG" ;;
1740 esac
1741 # splash image
1742 if [ -f "$SOURCE_ROOT/boot/isolinux/splash.jpg" ]; then
1743 log "$(_ 'Copying splash image')"
1744 cp -a $SOURCE_ROOT/boot/isolinux/splash.jpg \
1745 $TARGET_ROOT/boot/syslinux
1746 fi
1750 #-------------
1751 # 5.3 efiboot
1752 #-------------
1754 efiboot_install()
1756 local esp_fs_uuid mnt="/media/esp$$" efiboot="/EFI/SLITAZ"
1757 # We need efi stub support
1758 [ "$(strings $TARGET_ROOT/boot/$KERNEL | head | grep reloc)" ] || return
1759 # And the esp partition
1760 esp_fs_uuid="$(blkid | sed '/EFI system partition/!d;s|.* UUID="||;s|".*||;q')"
1761 [ "$esp_fs_uuid" ] || return
1762 # Copy SliTaz kernel and cmdline in esp partition
1763 mkdir $mnt &&
1764 mount "$(uuid2dev UUID=$esp_fs_uuid)" $mnt &&
1765 mkdir -p $mnt$efiboot 2> /dev/null
1766 if cp $TARGET_ROOT/boot/$KERNEL $mnt$efiboot/BZIMAGE.EFI; then
1767 log "$(_ 'Updating UEFI boot files')"
1768 echo "root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)" > $mnt$efiboot/linux.cmdline
1769 efibootmgr -v | grep -q SliTaz ||
1770 efibootmgr -c -d "$(uuid2disk UUID=$esp_fs_uuid)" -p "$(partnum UUID=$esp_fs_uuid)" \
1771 -L "SliTaz GNU/Linux" -l "${efiboot//\//\\}\\BZIMAGE.EFI"
1772 fi
1773 umount $mnt && rmdir $mnt
1776 #--------------------
1777 # 6. execute section
1778 #--------------------
1780 execute()
1782 local mode="$(get mode)" sighup=1 sigint=2 sigquit=3
1783 randomize_mirrors
1784 trap "error9" "$sighup" "$sigint" "$sigquit"
1785 case "$mode" in
1786 install)
1787 install ;;
1788 upgrade)
1789 upgrade ;;
1790 esac
1793 #-------------
1794 # 6.1 install
1795 #-------------
1797 # get a clean target device
1798 clean_target()
1800 if [ -z "$ROOT_FORMAT" ]; then
1801 # partition was not formatted
1802 log "$(_ 'Cleaning the root partition (%s)...' "$ROOT_UUID")"
1803 # keep /home in case of reinstall.
1804 local path="$(pwd)"
1805 cd "$TARGET_ROOT" || error8
1806 local dir
1807 for dir in *
1808 do
1809 case "$dir" in
1810 home)
1811 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")"
1812 mv home home.bak ;;
1813 lost+found)
1814 continue ;;
1815 *)
1816 log "$(_ 'removing target: %s' "$dir")"
1817 rm -rf "$dir" 2>>"$LOG" ;;
1818 esac
1819 done
1820 if [ ! -d lost+found ]; then
1821 mklost+found 2>>"$LOG"
1822 fi
1823 cd "$path" || error8
1824 fi
1827 # kernel is renamed to standard vmlinuz-$VERSION.
1828 install_kernel()
1830 KERNEL="vmlinuz-$(uname -r)"
1831 [ -d /$TARGET_ROOT/lib/modules/$(uname -r) ] ||
1832 log "$(_ 'Kernel name not found, falling back to: %s' "$(uname -r)")"
1833 mkdir -p $TARGET_ROOT/boot || error8
1834 for i in $SOURCE_ROOT/boot/bzImage* ; do
1835 cp $i $TARGET_ROOT/boot/${KERNEL%slitaz*}slitaz${i#*bzImage}
1836 done
1837 log "$(_ 'install_kernel: %s' "$KERNEL")"
1840 # extract packed rootfs: squashfs or cromfs
1841 extract_loramfs()
1843 local i
1844 for i in $(/bin/busybox cpio -idvum 2> /dev/null); do
1845 case "$i" in
1846 rootfs*)
1847 need_package squashfs
1848 if ! unsquashfs $i ; then
1849 need_package cromfs
1850 unmkcromfs $i squashfs-root
1851 fi
1852 mv -f squashfs-root/* .
1853 rmdir squashfs-root
1854 rm -f $i
1855 esac
1856 done
1859 # this is a loram rootfs.gz, skip loram bootstrap and extract
1860 extract_first_loramfs()
1862 local path="$(pwd)"
1863 (zcat $1 || /usr/bin/unlzma < $1) | \
1864 /bin/busybox cpio -i extractfs.cpio 2> /dev/null &&
1865 ( cd / ; /bin/busybox cpio -id ) < extractfs.cpio && \
1866 rm -f extractfs.cpio
1867 ofs=$(/bin/busybox awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
1868 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
1869 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
1870 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | \
1871 extract_loramfs
1872 cd "$path" || error8
1875 # extract lzma'ed or gziped rootfs.
1876 extract_rootfs()
1878 local path="$(pwd)"
1879 local isloramfs
1880 cd "$TARGET_ROOT" || error8
1881 if [ -d "$1"/../fs/etc ]; then
1882 # this is a tazlitobox loram (cdrom)
1883 cp -a "$1"/../fs/. .
1884 else
1885 for i in $(ls "$1"/rootfs* | sort -r); do
1886 if [ ! -d etc ]; then
1887 if [ $( (zcat "$i" 2>/dev/null \
1888 || /usr/bin/lzma d "$i" -so) | \
1889 wc -c) -lt $(stat -c %s "$i") ]; then
1890 # this is a tazlitobox loram (ram)
1891 isloramfs="$i"
1892 extract_first_loramfs "$i"
1893 continue
1894 fi
1895 fi
1896 if [ -n "$isloramfs" ]; then
1897 extract_loramfs < "$i"
1898 continue
1899 fi
1900 ( zcat "$i" 2>/dev/null || /usr/bin/lzma d "$i" -so || \
1901 cat "$i" ) 2>>"$LOG" | /bin/busybox cpio -idu
1902 done 2>>"$LOG" > /dev/null
1903 fi
1904 /usr/sbin/install -m 644 /etc/keymap.conf /etc/locale.conf /etc/TZ /etc/network.conf etc
1905 # unpack /usr (double check...)
1906 if ls etc/tazlito | grep -q ".extract"; then
1907 for i in etc/tazlito/*.extract; do
1908 [ -f "$i" ] && . "$i" /media/cdrom
1909 done
1910 fi
1911 cd "$pwd" || error8
1915 # pre configure freshly installed system (60 - 80%).
1916 pre_config_system()
1918 local path="$(pwd)"
1919 cd "$TARGET_ROOT" || error8
1920 # restore backup of existing /home if exists.
1921 # (created by prepare_target_dev)
1922 if [ -d home.bak ]; then
1923 log "$(_ 'Restoring directory: /home...')"
1924 rm -rf home
1925 mv home.bak home
1926 fi
1927 # add root device to CHECK_FS in rcS.conf to check filesystem
1928 # on each boot.
1929 log "$(_ 'Adding / partition and CHECK_FS to file %s...' '/etc/rcS.conf')"
1930 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$(dev2uuid $ROOT_UUID)\""# etc/rcS.conf
1931 # set hostname.
1932 log "$(_ 'Configuring host name: %s' "$HOSTNAME")"
1933 printf "%s\n" "$HOSTNAME" > etc/hostname
1934 printf "%s\n" "127.0.0.1 localhost $HOSTNAME tazpanel" > etc/hosts
1935 cd "$path" || error8
1938 # set root passwd and create user after rootfs extraction.
1939 users_settings()
1941 # create file
1942 cat > "$TARGET_ROOT/users.sh" << _EOF_
1943 #!/bin/sh
1944 umask 0022
1945 printf "root:%s" "$ROOT_PWD" | chpasswd -m
1946 adduser -D -H $USER_LOGIN
1948 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
1949 if ! grep \$grp /etc/group | grep -q $USER_LOGIN ; then
1950 grep -q \$grp /etc/group && addgroup $USER_LOGIN \$grp
1951 fi
1952 done
1954 printf "%s:%s" "$USER_LOGIN" "$USER_PWD" | chpasswd -m
1955 if [ ! -d /home/$USER_LOGIN ]; then
1956 cp -a /etc/skel /home/$USER_LOGIN
1957 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$USER_LOGIN
1958 mkdir -p /home/$USER_LOGIN/.config/slitaz
1959 cp -a /etc/slitaz/applications.conf /home/$USER_LOGIN/.config/slitaz
1960 # Set ownership
1961 if grep -q ^users: /etc/group; then
1962 chown -R $USER_LOGIN:users /home/$USER_LOGIN
1963 else
1964 chown -R $USER_LOGIN:$USER_LOGIN /home/$USER_LOGIN
1965 fi
1966 # Path for user desktop files.
1967 for i in /home/$USER_LOGIN/.local/share/applications/*.desktop
1968 do
1969 [ -e "$i" ] && sed -i s/"user_name"/"$USER_LOGIN"/g \$i
1970 done
1971 fi
1972 # Slim default user.
1973 if [ -f /etc/slim.conf ]; then
1974 sed -i s/"default_user .*"/"default_user $USER_LOGIN"/ \
1975 /etc/slim.conf
1976 fi
1977 _EOF_
1978 chmod o+x "$TARGET_ROOT/users.sh"
1979 chroot "$TARGET_ROOT" ./users.sh 2>>"$LOG" >> "$LOG"
1980 rm "$TARGET_ROOT/users.sh"
1981 umask 0177
1984 # /home can be on a separate partition. If default user exists in /home
1985 # we remove default file created by users_settings().
1986 home_config()
1988 if [ -n "$HOME_UUID" ]; then
1989 local path="$(pwd)" uuid
1990 cd "$TARGET_ROOT" || error8
1991 # detect fs
1992 local home_fs="$HOME_FORMAT"
1993 [ -z "$home_fs" ] && home_fs="$(filesys $HOME_UUID)"
1994 # manage /home
1995 log "$(_ 'Configuring partition to be used as /home: %s' "$HOME_UUID")"
1996 mv home/$USER_LOGIN tmp
1997 mount -t "$home_fs" "$HOME_UUID" home >> "$LOG" 2>> "$LOG"
1998 if [ -d $TARGET_ROOT/home/$USER_LOGIN ]; then
1999 rm -rf tmp/home/$USER_LOGIN
2000 else
2001 mv tmp/$USER_LOGIN home
2002 fi
2003 # write entry in fstab, force uuid
2004 uuid="$(dev2uuid "$HOME_UUID")"
2005 printf "%b\n" "$uuid /home $home_fs defaults \t0 \t2" >> etc/fstab
2006 umount home >> "$LOG" 2>> "$LOG"
2007 cd "$path" || error8
2008 fi
2011 install()
2013 log_open
2014 log "1 $(_ 'Installing SliTaz on: %s' "$(get root_uuid)")"
2015 log "5 $(_ 'Checking settings...')"
2016 check all >> "$LOG" 2>> "$LOG"
2017 load_settings
2019 log "10 $(_ 'Preparing source media...')"
2020 mount_source
2022 log "20 $(_ 'Preparing target disk...')"
2023 prepare_uuid
2025 log "30 $(_ 'Cleaning the root partition if necessary...')"
2026 clean_target
2028 log "40 $(_ 'Extracting the root system...')"
2029 extract_rootfs $SOURCE_ROOT/boot
2031 log "50 $(_ 'Installing the Kernel...')"
2032 install_kernel
2034 log "60 $(_ 'Preconfiguring the system...')"
2035 pre_config_system
2037 log "70 $(_ 'Configuring root and default user account...')"
2038 users_settings
2040 log "80 $(_ 'Configuring /home...')"
2041 home_config
2043 log "90 $(_ 'Checking bootloader installation...')"
2044 bootloader
2046 log "100 $(_ 'Files installation completed')"
2047 end_of_install
2051 #-------------
2052 # 6.2 upgrade
2053 #-------------
2055 # search for SliTaz
2056 check_release()
2058 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
2059 local release="$(cat $TARGET_ROOT/etc/slitaz-release)"
2060 log "$(_ 'Preparing upgrade of SliTaz release: %s' "$release")"
2061 else
2062 error 6 "$(_ "%s: This partition doesn't appear to contain a valid \
2063 SliTaz system, the file: %s doesn't exist." "$ROOT_UUID" '/etc/slitaz-release')"
2064 fi
2067 # backup packages list.
2068 backup_files()
2070 local path="$(pwd)"
2071 cd "$TARGET_ROOT" || error8
2072 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
2073 local dir
2074 for dir in *
2075 do
2076 case "$dir" in
2077 boot)
2078 rm -rf boot/vmlinuz-* ;;
2079 home)
2080 mv home home.bak
2081 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")" ;;
2082 etc)
2083 /bin/busybox tar czf etc.tar.gz etc
2084 mv etc etc.bak
2085 log "$(_ 'keeping /etc found on: %s' "$ROOT_UUID")" ;;
2086 var)
2087 if [ -d var/www ]; then
2088 mv var/www www.bak
2089 log "$(_ 'keeping /var/www found on: %s' "$ROOT_UUID")"
2090 fi
2091 rm -rf var 2>>"$LOG" ;;
2092 lost+found)
2093 continue ;;
2094 *)
2095 log "$(_ 'removing target: %s' "$dir")"
2096 rm -rf "$dir" 2>>"$LOG" ;;
2097 esac
2098 done
2099 if [ -d mklost+found ]; then
2100 mklost+found 2>>"$LOG"
2101 fi
2102 cd "$path" || error8
2105 # restore backups.
2106 restore_files()
2108 rm -rf $TARGET_ROOT/home
2109 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
2110 rm -rf $TARGET_ROOT/etc
2111 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
2112 if [ -d $TARGET_ROOT/www.bak ]; then
2113 rm -rf $TARGET_ROOT/var/www
2114 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
2115 fi
2116 log "$(_ 'backups restored: %s' "$(date)")"
2118 # /var/lib/slitaz-installer
2119 mkdir -p $TARGET_ROOT/var/lib/tazinst && \
2120 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst && \
2121 mv $TARGET_ROOT/home/packages-selection.list \
2122 $TARGET_ROOT/var/lib/tazinst \
2123 && log "$(_ 'backups saved in %s' '/var/lib/tazinst')"
2126 # upgrade added pkgs
2127 install_pkgs()
2129 # check if the pkg is on the mirror.
2130 log "$(_ 'Checking the availability of packages...')"
2131 touch packages-to-install.list
2132 packages=0
2133 diff="$(sort < packages-selection.diff)"
2134 for pkg in $diff
2135 do
2136 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
2137 packages="$(($packages+1))"
2138 printf "%s\n" "$pkg" >> packages-to-install.list
2139 fi
2140 done
2142 # install packages.
2143 log "$(_ 'Installing packages...')"
2144 if [ "$packages" = "0" ]; then
2145 log "$(_ 'packages to install: 0')"
2146 else
2147 # get-install all missing pkgs.
2148 while read pkg
2149 do
2150 log "$(_ 'Installing: %s...' "$pkg")"
2151 # get install package and answer yes in case of dependencies.
2152 pkgname="$(grep ^$pkg /var/lib/tazpkg/packages.list)"
2153 /usr/bin/tazpkg get "$pkg" >/dev/null 2>/dev/null
2154 yes "" | /usr/bin/tazpkg install $pkgname.tazpkg \
2155 --root=$TARGET_ROOT >/dev/null 2>/dev/null
2156 rm -f $pkgname.tazpkg
2157 done < packages-to-install.list
2158 fi
2159 log "$(_ 'Installation of packages complete...')"
2162 # search for added pkgs
2163 update_pkgs()
2165 local path="$(pwd)"
2166 cd $TARGET_ROOT/var/lib/tazinst || error8
2167 # LiveCD packages list.
2168 log "$(_ 'Creating package lists...')"
2169 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || error8
2170 log "$(_ '%s: done' 'packages-source.list')"
2171 # diff
2172 /bin/busybox diff packages-source.list packages-selection.list | \
2173 grep ^+[a-z] | sed s/^+// > packages-selection.diff
2174 log "$(_ '%s: done' 'packages-selection.diff')"
2175 # get mirror list.
2176 /usr/bin/tazpkg recharge >>$LOG 2>>$LOG
2177 if [ -f /var/lib/tazpkg/packages.list ]; then
2178 install_pkgs
2179 else
2180 touch packages-to-install.list
2181 longline "$(_ "The list of available packages on the mirror could not \
2182 be downloaded. No missing packages will be reinstalled now, but you can do so \
2183 later by looking at the following list:")"
2184 echo '/var/lib/tazinst/packages-selection.diff'
2185 fi
2186 cd "$path" || error8
2189 # upgrade command
2190 upgrade()
2192 log_open
2193 log "1 $(_ 'Upgrading SliTaz on: %s' "$(get root_uuid)")"
2194 log "5 $(_ 'Checking settings...')"
2195 check all >> "$LOG"
2196 load_settings
2198 log "10 $(_ 'Preparing source media...')"
2199 mount_source
2201 log "20 $(_ 'Preparing target disk...')"
2202 prepare_uuid
2204 log "30 $(_ 'Searching for %s...' '/etc/slitaz-release')"
2205 check_release
2207 log "40 $(_ 'Backup /etc, /home and the packages list...')"
2208 backup_files
2210 log "50 $(_ 'Extracting the root system...')"
2211 extract_rootfs $SOURCE_ROOT/boot
2213 log "60 $(_ 'Restoring configuration files...')"
2214 restore_files
2216 log "70 $(_ 'Installing the Kernel...')"
2217 install_kernel
2219 log "80 $(_ 'Upgrading added packages...')"
2220 update_pkgs
2222 log "90 $(_ 'Bootloader...')"
2223 bootloader
2225 log "100 $(_ 'Files installation completed')"
2226 end_of_install
2230 #--------------
2231 # tazinst main
2232 #--------------
2234 case $1 in
2235 new)
2236 new_file "$2" ;;
2237 set)
2238 [ -s "$4" ] || new_file "$4"
2239 read_file "$4"
2240 change "$2" "$3" "$4" ;;
2241 unset)
2242 read_file "$3"
2243 change "$2" "" "$3" "$4" ;;
2244 get)
2245 read_file "$3"
2246 get "$2" ;;
2247 check)
2248 read_file "$3"
2249 check "$2" ;;
2250 list)
2251 list "$2" "$3" ;;
2252 execute)
2253 check_root
2254 read_file "$2"
2255 execute "$2" ;;
2256 log)
2257 [ -r "$LOG" ] && cat "$LOG" ;;
2258 clean)
2259 clean "$2" ;;
2260 version)
2261 printf "%s\n" "$VERSION" ;;
2262 ""|usage)
2263 usage ;;
2264 help)
2265 help "$2" ;;
2266 *)
2267 usage_error "$1" ;;
2268 esac