tazinst view tazinst @ rev 2

Use UUIDs, boot delay on mobile disks, GPT support, boot flag, new slitaz-installer and web frontends
author Dominique Corbex <domcox@slitaz.org>
date Thu Feb 14 13:12:12 2013 +0100 (2013-02-14)
parents ced519734730
children cc9e582d5abc
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-2013 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 ressource
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.90
37 BANNER="Tazinst - SliTaz GNU/Linux Installer - $(gettext "Version") $VERSION"
39 # i18n
40 . /usr/bin/gettext.sh
41 TEXTDOMAIN='tazinst'
42 export TEXTDOMAIN
44 # files
45 readonly DEFAULT_INSTALL_FILE=./tazinst.rc
46 readonly SOURCE_ROOT=/media/source
47 readonly TARGET_ROOT=/mnt/target
48 readonly LOG=/var/log/tazinst.log
49 readonly LOCK=/run/tazinst.pid
50 MIRRORS="${MIRRORS:-$LOCALSTATE/mirrors}"
52 # settings
53 readonly SETTINGS="mode media source \
54 root_uuid root_format home_uuid home_format \
55 hostname root_pwd user_login user_pwd \
56 bootloader winboot"
58 # modes (key:help)
59 readonly LST_MODE="
60 install:$(gettext "Fresh install on a HDD")
61 upgrade:$(gettext "Upgrade an existing system")"
63 # medias (key:help)
64 readonly LST_MEDIA="
65 cdrom:$(gettext "LiveCD")
66 usb:$(gettext "LiveUSB")
67 iso:$(gettext "ISO image on a local drive")
68 web:$(gettext "ISO image on the Internet")"
70 # formats (key:help)
71 readonly LST_FORMAT="
72 btrfs:B-tree file system (Oracle)
73 ext2:Second extended filesystem (Linux)
74 ext3:Third extended filesystem (Linux)
75 ext4:Fourth extended file system (Linux)
76 jfs:Journaled File System (IBM)
77 minix:File system of the MINIX operating system
78 reiser4:Journaled computer file system (Namesys)
79 xfs:journaling file system (Silicon Graphics, Inc.)"
81 # bootloaders (key:help)
82 readonly LST_BOOTLOADER="
83 auto:$(gettext "Automatic selection")
84 grub:$(gettext "Grub legacy bootoader")
85 syslinux:$(gettext "Lightweight bootloader")"
87 # predefined iso (key:url:help)
88 SLITAZ_VERSION="${SLITAZ_VERSION:-cooking}"
89 [ "$SLITAZ_VERSION" = "cooking" ] && SLITAZ_VERSION="$(($(date "+%y")-8)).0"
90 [ -n "$URL_ISO" ] && readonly LST_WEB="$URL_ISO" || readonly LST_WEB="
91 stable:iso/stable/slitaz-$SLITAZ_VERSION.iso \
92 :$(gettext "Stable release") $SLITAZ_VERSION
93 core:iso/stable/flavors/slitaz-$SLITAZ_VERSION-core.iso \
94 :$(gettext "Stable version without nested subsets")
95 base:iso/stable/flavors/slitaz-$SLITAZ_VERSION-base.iso \
96 :$(gettext "Stable text-only version (8.1MB)")
97 justx:iso/stable/flavors/slitaz-$SLITAZ_VERSION-justx.iso \
98 :$(gettext "Stable basic graphic version without graphic apps")
99 gtkonly:iso/stable/flavors/slitaz-$SLITAZ_VERSION-gtkonly.iso \
100 :$(gettext "Stable basic graphic version with only Gtk")
101 cooking:iso/cooking/slitaz-cooking.iso \
102 :$(gettext "Development version for testing latest features")
103 rolling:iso/rolling/slitaz-rolling.iso \
104 :$(gettext "Bleeding edge development version updated every day")
105 "
108 #-------
109 # usage
110 #-------
112 # print a short help
113 usage()
114 {
115 printf "\n$BANNER\n\n"
116 printf "\033[1m$(gettext "Usage"):\033[0m $(gettext "tazinst [command] \
117 <setting> <value> <file>")
119 \033[1m$(gettext "Commands"): \033[0m
120 new $(gettext "Create a new install file.")
121 set $(gettext "Change value of a setting.")
122 unset $(gettext "Clear a setting.")
123 get $(gettext "Get the value of a setting.")
124 check $(gettext "Check settings.")
125 help $(gettext "Print a short help on settings")
126 list $(gettext "List system ressources.")
127 execute $(gettext "Execute a SliTaz installation.")
128 log $(gettext "Display log file contents.")
129 clean $(gettext "Clean install and log files.")
130 version $(gettext "Print version and exit.")
131 usage $(gettext "Print this short usage.")
132 "
133 exit 0
134 }
136 usage_error()
137 {
138 local command="$1"
139 printf "\n$BANNER\n\n"
140 if [ -z "$command" ]; then
141 printf "$(gettext "Error: Missing parameter.")\n"
142 else
143 printf "\033[1m$command\033[0m: $(gettext "Unknown command.")\n"
144 fi
145 local script_name=$(printf "$0" | /bin/busybox awk 'BEGIN{RS="/"}
146 {cmd=$command}END{print cmd}')
147 printf "$(gettext "Run"): '$script_name help' $(gettext "to get a list \
148 of available commands").\n\n"
149 }
151 option_error()
152 {
153 local option="$1" list="$2"
154 printf "\n$BANNER\n\n'$option': Unknown setting!\n
155 Please select one of these options: $list\n\n"
156 }
158 #---------------------
159 # 1. settings section
160 #---------------------
162 #----------
163 # 1.1 file
164 #----------
166 # create a new install file
167 new_file()
168 {
169 local install_file=$1
170 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
171 if [ -e "$install_file" ]; then
172 printf "$(gettext "Warning: file exists already.")\n" 1>&2
173 exit 0
174 fi
175 [ -n "$install_file" ] && touch "$install_file"
176 if [ -w "$install_file" ]; then
177 write_file "$install_file"
178 else
179 printf "$(gettext "Error: Can't create file.")\n" 1>&2
180 exit 2
181 fi
182 }
184 # fill up the install file
185 write_file()
186 {
187 local install_file="$1"
188 cat > "$install_file" << EOT
189 # $BANNER
190 #
191 # SliTaz Installer setup file.
192 #
194 # Mode of installation:
195 # install: Full install of SliTaz on a disk, all previous info will be erased
196 # upgrade: Upgrade an existing SliTaz installation to a new version
197 # run 'tazinst list mode' to have a full list.
198 MODE="$MODE"
200 # Media to install from:
201 # Options are cdrom usb iso web.
202 # run 'tazinst list media' to see available options on your system.
203 MEDIA="$MEDIA"
205 # Install source:
206 # it depends on the media used:
207 # usb: partition, run 'tazinst list uuid' to list your partitions
208 # iso: file.iso, ex: SOURCE=~/slitaz.5.0.iso
209 # web: url, ex: SOURCE=http://mirror.slitaz.org/../slitaz-cooking.iso
210 # web: iso names, ex: SOURCE=cooking
211 # run 'tazinst list <MEDIA>' to list source values. ex: tazinst list iso.
212 SOURCE="$SOURCE"
214 # root partition that SliTaz will be Installed on:
215 # Enter the UUID of the partition.
216 # run 'tazinst list uuid' to list your partitions
217 ROOT_UUID="$ROOT_UUID"
219 # Formatting the root partition:
220 # Let ROOT_FORMAT empty if you do not want to format the root partition.
221 # SliTaz uses ext2 ext3 ext4 by default but another filesystem can be
222 # installed if wanted, for this please adjust your /etc/fstab after
223 # installation.
224 # run 'tazinst list format' to list installed filesystems on your system.
225 ROOT_FORMAT="$ROOT_FORMAT"
227 # Home partition:
228 # On most GNU/Linux systems users personal files are stored in the directory
229 # /home. /home can be on another hard disk or on a separate partition.
230 # Let HOME_UUID empty if you do not intend to use a specific partition for /home
231 # or enter the UUID of the partition to be used.
232 # run 'tazinst list uuid' to list your partitions.
233 HOME_UUID="$HOME_UUID"
235 # Formatting the /home partition (if /home is on a separate partition):
236 # Let HOME_FORMAT empty if you don not want to format the /home partition.
237 # For options, see comments on 'Formatting the root partition' above.
238 HOME_FORMAT="$HOME_FORMAT"
240 # Hostname of the new system:
241 HOSTNAME="$HOSTNAME"
243 # root password:
244 # The root administrator privilege lets you manage and configure the full
245 # system. A root user can damage your system so you should always setup a
246 # strong password with special characters and/or numbers.
247 ROOT_PWD="$ROOT_PWD"
249 # Default user:
250 # The default user for the system will have his personal files stored
251 # in /home/<USER_LOGIN> (and will be automatically added to the audio group).
252 USER_LOGIN="$USER_LOGIN"
253 USER_PWD="$USER_PWD"
255 # Install bootloader:
256 # If you do not want to install a bootloader, let this field empty.
257 # It's generally safe to set it up as 'auto'.
258 # Run 'tazinst list bootloader' to list all options.
259 BOOTLOADER="$BOOTLOADER"
261 # Windows dual boot:
262 # If you do not want enable Dual boot, let WINBOOT empty (WINBOOT="").
263 # You may let tazinst automatically find your win partition by specifying auto
264 # (WINBOOT="auto"), otherwise enter the UUID of the partition to be used.
265 # Run 'tazinst list winboot' to see the Windows partitions found by tazinst.
266 WINBOOT="$WINBOOT"
268 EOT
269 return "$?"
270 }
272 read_file()
273 {
274 local install_file="$1"
275 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
276 if ! [ -r "$install_file" ]; then
277 printf "$(gettext "Error: Unable to read install file")\n" 1>&2
278 exit 2
279 fi
280 #
281 if ! CONTENTS="$(cat "$install_file")"; then
282 printf "$(gettext "Error: Unable to read install file")\n" 1>&2
283 exit 2
284 fi
285 }
287 # read value of a setting
288 get_value()
289 {
290 local setting="$1"
291 printf "%s" "$CONTENTS" | /bin/busybox awk -v setting="$setting" 'BEGIN{
292 setting="^" toupper(setting) "="
293 }
294 {
295 if (match($0,setting)){
296 n=index($0,"=")
297 value=substr($0,n+1)
298 gsub(/[\t\s]*$/,"",value)
299 sub(/^"/,"",value)
300 sub(/"$/,"",value)
301 }
302 }
303 END{
304 print value
305 }'
306 }
308 # list of settings
309 get_settings()
310 {
311 local "mode=$(get_value mode)"
312 case "$mode" in
313 upgrade)
314 echo "mode media source root_uuid bootloader winboot" ;;
315 *)
316 echo "$SETTINGS" ;;
317 esac
318 }
320 # get command
321 get()
322 {
323 local setting="$1"
324 [ -z "$setting" ] && setting="all"
325 # setting is valid: display value
326 if printf "%s" "$setting" | \
327 egrep -q "$(regex "$SETTINGS")"; then
328 get_value "$setting"
329 else
330 if [ "$setting" = "all" ]; then
331 printf "%-15s: %s\n" "mode" "$(get_value mode)"
332 printf "%-15s: %s\n" "media" "$(get_value media)"
333 printf "%-15s: %s\n" "source" "$(get_value source)"
334 printf "%-15s: %s\n" "root_uuid" "$(get_value root_uuid)"
335 printf "%-15s: %s\n" "root_format" "$(get_value root_format)"
336 printf "%-15s: %s\n" "home_uuid" "$(get_value home_uuid)"
337 printf "%-15s: %s\n" "home_format" "$(get_value home_format)"
338 printf "%-15s: %s\n" "hostname" "$(get_value hostname)"
339 printf "%-15s: %s\n" "root_pwd" "$(get_value root_pwd)"
340 printf "%-15s: %s\n" "user_login" "$(get_value user_login)"
341 printf "%-15s: %s\n" "user_pwd" "$(get_value user_pwd)"
342 printf "%-15s: %s\n" "bootloader" "$(get_value bootloader)"
343 printf "%-15s: %s\n" "winboot" "$(get_value winboot)"
344 elif [ "$setting" = "settings" ]; then
345 get_settings
346 else
347 option_error "$1" "$SETTINGS"
348 fi
349 fi
350 }
352 # set command
353 change()
354 {
355 local setting="$1" value="$2" install_file="$3"
356 # validate setting
357 if ! printf "%s" "$setting" | \
358 egrep -q "$(regex "$SETTINGS")"; then
359 printf "$(gettext "Error: '$setting' unknown setting.")\n" 1>&2
360 exit 1
361 fi
362 # and file
363 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
364 # write changes to file
365 if [ -w "$install_file" ]; then
366 printf "%s" "$CONTENTS" | \
367 /bin/busybox awk -v setting="$setting" -v value="$value" '
368 BEGIN{
369 set=0
370 }
371 {
372 if (match($0,"^" toupper(setting) "=")){
373 printf toupper(setting) "=\"" value "\"\n"
374 set++
375 }
376 else
377 printf $0 "\n"
378 }
379 END{
380 if (! set)
381 printf toupper(setting) "=\"" value "\"\n"
382 }' > "$install_file"
383 # check new value
384 read_file "$install_file"
385 check "$setting"
386 else
387 printf "$(gettext "Error: Unable to write to install file.")\n" 1>&2
388 exit 2
389 fi
390 }
392 #
393 load_settings()
394 {
395 MODE="$(get mode)"
396 local settings="$(get settings)"
397 MEDIA="$(get media)"
398 printf "source" | egrep -q "$(regex "$settings")" \
399 && SOURCE="$(get source)" \
400 || unset SOURCE
401 ROOT_UUID="$(get root_uuid)"
402 printf "root_format" | egrep -q "$(regex "$settings")" \
403 && ROOT_FORMAT="$(get root_format)" \
404 || unset ROOT_FORMAT
405 printf "home_uuid" | egrep -q "$(regex "$settings")" \
406 && HOME_UUID="$(get home_uuid)" \
407 || unset HOME_UUID
408 printf "home_format" | egrep -q "$(regex "$settings")" \
409 && HOME_FORMAT="$(get home_format)" \
410 || unset HOME_FORMAT
411 printf "hostname" | egrep -q "$(regex "$settings")" \
412 && HOSTNAME="$(get hostname)" \
413 || unset HOSTNAME
414 printf "root_pwd" | egrep -q "$(regex "$settings")" \
415 && ROOT_PWD="$(get root_pwd)" \
416 || unset ROOT_PWD
417 printf "user_login" | egrep -q "$(regex "$settings")" \
418 && USER_LOGIN="$(get user_login)" \
419 || unset USER_LOGIN
420 printf "user_pwd" | egrep -q "$(regex "$settings")" \
421 && USER_PWD="$(get user_pwd)" \
422 || unset USER_PWD
423 printf "bootloader" | egrep -q "$(regex "$settings")" \
424 && BOOTLOADER="$(get bootloader)" \
425 || unset BOOTLOADER
426 printf "winboot" | egrep -q "$(regex "$settings")" \
427 && WINBOOT="$(get winboot)" \
428 || unset WINBOOT
429 }
431 # clean command
432 clean()
433 {
434 # rm LOG
435 [ -r "$LOG" ] && rm -f "$LOG"
436 # rm temp files
437 rm -rf /tmp/tazinst
438 # rm install file
439 local install_file="$1"
440 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
441 echo "$(gettext "Deleting install file:") $install_file"
442 if ! [ -w "$install_file" ]; then
443 printf "$(gettext "Error: Unable to delete install file")\n" 1>&2
444 exit 2
445 else
446 rm -f "$install_file"
447 fi
448 }
450 #-----------
451 # 1.2 check
452 #-----------
454 # exit if user is not root.
455 check_root()
456 {
457 if test $(id -u) != 0 ; then
458 printf "$(gettext "You must be the root user (system administrator) \
459 to install SliTaz, please use 'su' to get a root SHell and restart \
460 installation.")\n" 1>&2
461 exit 1
462 fi
463 }
465 # exit if another instance of tazinst is running
466 check_instance()
467 {
468 if [ -e "$LOCK" ]; then
469 printf "$(gettext "Another instance of tazinst is running.")\n" 1>&2
470 exit 7
471 else
472 printf "$$" > $LOCK
473 fi
474 }
476 # exit if the setting is not in a list of keywords
477 check_key()
478 {
479 local setting="$1" keylist="$2" keyword="$(get $1)"
480 if ! printf "%s" "$keyword" | \
481 egrep -q "$(regex "$keylist")"; then
482 printf "$setting=$keyword
483 $(gettext "Error:") '$keyword' $(gettext "Invalid keyword.")
484 $(gettext "Select one of these options:") $keylist
485 $(gettext "For more information, see tazinst Manual.")\n" 1>&2
486 exit 1
487 fi
488 }
490 # exit if the partition do not exists
491 check_uuid()
492 {
493 local setting="$1" value="$(get $1)" found=0 partition
494 for partition in $(list_uuid); do
495 [ "$partition" == "$value" ] && found="$(($found + 1))"
496 done
497 if [ "$found" != "1" ]; then
498 printf "$(gettext "$setting")=$value
499 $(gettext "Error: Partition not found")
500 $(gettext "To see available partitions, run") 'tazinst list uuid'.\n" 1>&2
501 exit 1
502 fi
503 }
505 # exit if the source do not exists
506 check_source()
507 {
508 local media="$(get media)" source="$(get source)"
509 case $media in
510 usb)
511 check_uuid source ;;
512 iso)
513 if [ ! -r "$source" ]; then
514 printf "$(gettext "Error: Source file not found")\n" 1>&2
515 exit 1
516 fi ;;
517 web)
518 local valid=0
519 # check full url (http://...)
520 local regexp="^(https?|ftp):\/\/([a-z0-9\-]+\.)?[a-z0-9\-]+\.\
521 [a-z0-9]{2,4}(\.[a-z0-9]{2,4})?(\/.*)?iso$"
522 printf "%s" "$source" | \
523 egrep -q "$regexp" && valid=$(($valid+1))
524 # check iso names (stable cooking...)
525 regexp="$(regex "$(list web)")"
526 printf "%s" "$source" | \
527 egrep -q "$regexp" && valid=$(($valid+1))
528 if [ "$valid" -le "0" ]; then
529 printf "$(gettext "Error: invalid URL").\n" 1>&2
530 exit 1
531 fi
532 esac
533 }
535 # exit if a partition is selected more than once
536 check_uuid_mix()
537 {
538 local list all nodup
539 list="$(get root_uuid) $(get source) $(get home_uuid) $(get winboot)"
540 all="$(echo $list | wc -w)"
541 nodup="$(echo $list | /bin/busybox awk 'BEGIN{RS=" "}{print $0}' | \
542 sort | uniq | wc -w)"
543 if [ "$all" != "$nodup" ]; then
544 printf "$(gettext "Error: multiple assignations for a disk. Please \
545 check your settings.")\n"
546 exit 1
547 fi
548 }
550 # exit if a password is invalid
551 check_password()
552 {
553 local pass="$(get "$1")"
554 local invalid="^[A-Za-z0-9!@#$%^&*()_]{0,40}$"
555 local errcode=0
556 # too long
557 if [ "${#pass}" -ge 40 ]; then
558 printf "$(gettext "Error: To long password")\n" 1>&2
559 exit 1
560 fi
561 # bad chars
562 if ! (echo "$pass" | egrep -q "$invalid"); then
563 printf "$(gettext "Error: Unallowed characters in password.")\n" 1>&2
564 exit 1
565 fi
566 # short pwd
567 [ "${#pass}" -le 4 ] && errcode=128
568 # empty pwd
569 [ -z "$pass" ] && errcode=129
570 case "$errcode" in
571 128)
572 printf "$(gettext "Warning: short password!")\n" 1>&2 ;;
573 129)
574 printf "$(gettext "Warning: no password!")\n" 1>&2 ;;
575 esac
576 return "$errcode"
577 }
579 # exit if a name is invalid
580 check_name()
581 {
582 local name="$1" value="$(get "$1")"
583 if [ "${#value}" -lt 2 ]; then
584 printf "$name=$value\n$(gettext "Error: Too short.")\n" 1>&2
585 exit 1
586 fi
587 if [ "${#value}" -gt 32 ]; then
588 printf "$name=$value\n$(gettext "Error: Too long.")\n" 1>&2
589 exit 1
590 fi
591 if printf "$value" | \
592 grep -q "[[:space:]\&\"\'\(\)\|\*\\#\`\+\:/;<>]"; then
593 printf "$name='$value'\n$(gettext "Error: Invalid chars.")\n" 1>&2
594 exit 1
595 fi
596 }
598 # check bootloader + winboot
599 check_boot_mix()
600 {
601 local bootloader=$(get bootloader)
602 local winboot=$(get winboot)
603 if [ -z "$bootloader" ] && [ -n "$winboot" ]; then
604 printf "$(gettext "Error: Dualboot set with no bootloader.")\n" 1>&2
605 exit 1
606 fi
607 }
609 # exit if partition table is not in list
610 check_table()
611 {
612 local pt_list="gpt msdos"
613 # get root uuid
614 local uuid="$(get root_uuid)"
615 if [ "$(/sbin/blkid | grep -c "$uuid")" == "1" ]; then
616 if ! printf "$(p_table $uuid)" | \
617 egrep -q "$(regex "$pt_list")"; then
618 printf "$(gettext "Error: Unsupported Partition Table")\n" 1>&2
619 exit 1
620 fi
621 else
622 printf "$(gettext "Error: No disk selected, can't install any \
623 bootloader.")\n" 1>&2
624 exit 1
625 fi
626 }
629 # check all settings()
630 check_all()
631 {
632 # check only settings we need
633 for key in $(get settings); do
634 case "$key" in
635 mode)
636 printf "%-15s: " "mode"
637 check_key mode "$(key "$LST_MODE")" && echo "ok" ;;
638 media)
639 printf "%-15s: " "media"
640 check_key media "$(key "$LST_MEDIA")" && echo "ok" ;;
641 source)
642 printf "%-15s: " "source"
643 check_source && echo "ok" ;;
644 root_uuid)
645 printf "%-15s: " "root_uuid"
646 check_uuid root_uuid && echo "ok" ;;
647 root_format)
648 printf "%-15s: " "root_format"
649 [ -n "$(get root_format)" ] && \
650 { check_key root_format "$(key "$LST_FORMAT")" && echo "ok"; } \
651 || echo "ok" ;;
652 home_uuid)
653 printf "%-15s: " "home_uuid"
654 [ -n "$(get home_uuid)" ] && \
655 { check_uuid home_uuid && check_uuid_mix && echo "ok"; } \
656 || echo "ok" ;;
657 home_format)
658 printf "%-15s: " "home_format"
659 [ -n "$(get home_format)" ] && \
660 { check_key home_format "$(key "$LST_FORMAT")" && echo "ok"; } \
661 || echo "ok" ;;
662 hostname)
663 printf "%-15s: " "hostname"
664 check_name hostname && echo "ok" ;;
665 root_pwd)
666 printf "%-15s: " "root_password"
667 check_password root_pwd && echo "ok" ;;
668 user_login)
669 printf "%-15s: " "user_login"
670 check_name user_login && echo "ok" ;;
671 user_pwd)
672 printf "%-15s: " "user_password"
673 check_password user_pwd && echo "ok" ;;
674 bootloader)
675 printf "%-15s: " "bootloader"
676 [ -n "$(get bootloader)" ] \
677 && { check_key bootloader "$(list_bootloader)" \
678 && check_table && echo "ok" ; } \
679 || echo "ok" ;;
680 winboot)
681 printf "%-15s: " "winboot"
682 [ -n "$(get winboot)" ] && [ "$(get winboot)" != "auto" ] \
683 && { check_uuid winboot && check_boot_mix && echo "ok"; } \
684 || echo "ok" ;;
685 esac
686 done
687 }
689 # check command
690 check()
691 {
692 local setting="$1"
693 case "$setting" in
694 mode)
695 check_key mode "$(key "$LST_MODE")" ;;
696 media)
697 check_key media "$(key "$LST_MEDIA")" ;;
698 source)
699 check_source ;;
700 root_uuid)
701 check_uuid root_uuid
702 check_uuid_mix ;;
703 home_uuid)
704 [ -z "$(get home_uuid)" ] || check_uuid home_uuid
705 check_uuid_mix ;;
706 root_format)
707 [ -z "$(get root_format)" ] \
708 || check_key root_format "$(key "$LST_FORMAT")" ;;
709 home_format)
710 [ -z "$(get home_format)" ] \
711 || check_key home_format "$(key "$LST_FORMAT")" ;;
712 hostname)
713 check_name hostname ;;
714 root_pwd)
715 check_password root_pwd ;;
716 user_login)
717 check_name user_login ;;
718 user_pwd)
719 check_password user_pwd ;;
720 bootloader)
721 [ -z "$(get bootloader)" ] \
722 || (check_key bootloader "$(list_bootloader)" \
723 && check_table ; ) ;;
724 winboot)
725 ([ -z "$(get winboot)" ] || [ "$(get winboot)" = "auto" ]) \
726 || check_uuid winboot && check_boot_mix ;;
727 ""|all)
728 check_all ;;
729 *)
730 option_error "$setting" "$SETTINGS" ;;
731 esac
732 }
734 #----------
735 # 1.3 help
736 #----------
738 help_source()
739 {
740 printf "$(gettext "The Source setting depends on the type of media:")\n"
741 printf "%-12s%s\n" "cdrom" "$(help cdrom)"
742 printf "%-12s%s\n" "usb" "$(help usb)"
743 printf "%-12s%s\n" "iso" "$(help iso)"
744 printf "%-12s%s\n" "web" "$(gettext "Name or URL of the image on the web. \
745 Type: tazinst help web")"
746 }
748 help_all()
749 {
750 local text="mode:$(gettext "Mode of install")
751 media:$(gettext "Media containing the SliTaz source files")
752 source:$(gettext "Source file containing SliTaz")
753 root_uuid:$(gettext "The name of the target partition")
754 root_format:$(gettext "Format of the target partition")
755 home_uuid:$(gettext "Separate home partition")
756 home_format:$(gettext "Format of the root partition")
757 hostname:$(gettext "Name of the system")
758 root_pwd:$(gettext "Superuser password")
759 user_login:$(gettext "First user name")
760 user_pwd:$(gettext "First user password")
761 bootloader:$(gettext "Install a bootloader")
762 winboot:$(gettext "Partition to duaboot Windows from")"
763 printf "$(gettext "List of settings:")\n"
764 printf "$text" | /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}'
765 }
767 # help command
768 help()
769 {
770 local setting="$1"
771 case "$setting" in
772 mode)
773 echo "$LST_MODE" | \
774 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
775 media)
776 echo "$LST_MEDIA" | \
777 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
778 source)
779 help_source ;;
780 cdrom)
781 echo "$(gettext "Automatically set")" ;;
782 usb)
783 echo "$(gettext "USB partition. For a list, type: tazinst list usb")" ;;
784 iso)
785 echo "$(gettext "ISO file name. For a list, type: tazinst list iso")" ;;
786 web)
787 echo "$LST_WEB" | \
788 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $3}' ;;
789 root_uuid)
790 /sbin/blkid -s TYPE -s LABEL | sort ;;
791 root_format)
792 echo "$LST_FORMAT" | \
793 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
794 home_uuid)
795 /sbin/blkid -s TYPE -s LABEL | sort ;;
796 home_format)
797 echo "$LST_FORMAT" | \
798 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
799 hostname)
800 echo "$(gettext "Name of the system")" ;;
801 root_pwd)
802 echo "$(gettext "Superuser password")" ;;
803 user_login)
804 echo "$(gettext "First user name")" ;;
805 user_pwd)
806 echo "$(gettext "First user password")" ;;
807 bootloader)
808 printf "$LST_BOOTLOADER" | \
809 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n",$1,$2}' ;;
810 winboot)
811 echo "$(gettext "Partition containing Windows, or 'auto'")" ;;
812 ""|all)
813 help_all ;;
814 *)
815 option_error "$setting" "$SETTINGS" ;;
816 esac
817 }
819 #---------
820 # 2. list
821 #---------
823 list_media()
824 {
825 local key media
826 for key in $(key "$LST_MEDIA") ; do
827 case "$key" in
828 cdrom)
829 [ -e "/dev/cdrom" ] && media="cdrom" ;;
830 usb)
831 [ -e "/sys/bus/usb" ] && media="$media usb" ;;
832 web)
833 [ "$(ifconfig -a | grep -c Link)" -gt 2 ] \
834 && media="$media web" ;;
835 *)
836 media="$media $key"
837 esac
838 done
839 echo "$media" | sed 's/^\s//'
840 }
842 list_usb()
843 {
844 # List plugged USB disks
845 if [ -d /proc/scsi/usb-storage ]; then
846 for DEV in /sys/block/sd* ; do
847 if readlink $DEV | grep -q usb; then
848 DEV=$(basename $DEV)
849 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
850 /sbin/blkid /dev/$DEV* | /bin/busybox awk 'BEGIN{RS=" "}
851 /^\/dev\// {
852 DEV=$1
853 gsub(/:/,"",DEV)
854 }
855 /UUID/ {
856 UUID=$1
857 gsub(/"/,"",UUID)
858 printf "%s %s\n",UUID,DEV}'
859 fi
860 fi
861 done
862 fi
863 }
865 list_iso()
866 {
867 for i in /root/*.iso /home/*/*.iso /home/*/*/*.iso ; do
868 echo $i | grep -v "*"
869 done
870 }
872 list_format()
873 {
874 local fs
875 type mkfs.btrfs > /dev/null && fs="btrfs"
876 type mkfs.ext2 > /dev/null && fs="$fs ext2"
877 type mkfs.ext3 > /dev/null && fs="$fs ext3"
878 type mkfs.ext4 > /dev/null && fs="$fs ext4"
879 type mkfs.jfs > /dev/null && fs="$fs jfs"
880 type mkfs.minix > /dev/null && fs="$fs minix"
881 type mkfs.reiser4 > /dev/null && fs="$fs reiser4"
882 type mkfs.xfs > /dev/null && fs="$fs xfs"
883 echo "$fs" | sed 's/^\s//'
884 }
886 # list partitions
887 list_uuid()
888 {
889 /sbin/blkid | sort | /bin/busybox awk '
890 /UUID/ {
891 UUID=substr($0,index($0,"UUID="))
892 UUID=substr(UUID,1,index(UUID,"\" "))
893 gsub(/"/,"",UUID)
894 DEV=substr($1,1,index($1,":")-1)
895 printf "%s %s\n", UUID, DEV
896 }'
897 }
899 list_partition_table()
900 {
901 /usr/sbin/parted -lm | \
902 /bin/busybox awk -F: '/^\/dev\//{printf "%s: %s\n", $1,$6}'
903 }
905 list_web()
906 {
907 local key="$1"
908 # print url of a given iso
909 if printf "$LST_WEB" | egrep -q "^$key:"; then
910 printf "$LST_WEB" | egrep "^$key:" | \
911 /bin/busybox awk -F: '{print $2}'
912 fi
913 # print all key
914 if [ -z "$key" ]; then
915 key "$LST_WEB"
916 fi
917 }
919 list_bootloader()
920 {
921 local btlr
922 type grub-install > /dev/null && btlr=" grub"
923 type syslinux > /dev/null && btlr="$btlr syslinux"
924 [ -n "$btlr" ] && printf "auto$btlr\n"
925 }
927 # list Windows partitions
928 list_winboot()
929 {
930 /usr/sbin/parted -lm | /bin/busybox awk '
931 BEGIN{
932 FS=":"
933 disknum=-1
934 found=0
935 winboot=""
936 printf "auto"
937 }
938 {
939 # Count disks
940 if (match($1,"^/dev")){
941 disknum++
942 part=0
943 disk=substr($1,1,8)
944 dev=substr($1,6,3)
945 # get removable status
946 file="/sys/block/"dev"/removable"
947 "cat " file | getline removable
948 close("cat ")
949 }
950 # Count partitions
951 if (match($1,"[0-9][0-9]?")){
952 # List fixed drives only
953 if (removable==0){
954 part++
955 # Read partition Id
956 if (match($7,"boot")){
957 fs=$5
958 # Detect Windows Partition Type: ntfs vfat
959 WPT="ntfs|vfat"
960 if (fs ~ WPT){
961 found++
962 # record 1st Windows partition found
963 if (found==1){
964 printf(" %s%d",disk,part)
965 }
966 }
967 }
968 }
969 }
970 }
971 END{printf "\n"}'
972 }
974 # list commmand
975 list()
976 {
977 local ressource="$1"
978 case "$ressource" in
979 mode)
980 echo "$(key "$LST_MODE")" ;;
981 media)
982 list_media ;;
983 iso)
984 list_iso ;;
985 usb)
986 list_usb ;;
987 web)
988 list_web "$2" ;;
989 uuid)
990 list_uuid ;;
991 format)
992 list_format ;;
993 bootloader)
994 list_bootloader ;;
995 winboot)
996 list_winboot ;;
997 partition_table)
998 list_partition_table ;;
999 ""|all)
1000 printf "* mode:\n$(key "$LST_MODE")\n\n"
1001 printf "* media:\n$(list_media)\n\n"
1002 printf "* usb:\n$(list usb)\n\n"
1003 printf "* iso:\n$(list_iso)\n\n"
1004 printf "* web:\n$(list_web)\n\n"
1005 printf "* format:\n$(list_format)\n\n"
1006 printf "* bootloader:\n$(list_bootloader)\n\n"
1007 printf "* partition_table:\n$(list_partition_table)\n\n"
1008 printf "* winboot:\n$(list_winboot)\n"
1009 ;;
1010 *)
1011 local options="mode media usb iso web uuid format bootloader \
1012 partition_table winboot"
1013 option_error "$1" "$options" ;;
1014 esac
1017 #----------
1018 # 3. tools
1019 #----------
1021 # list indexes from a list
1022 key()
1024 printf "$1" | /bin/busybox awk -F: 'BEGIN{
1025 other=-1
1027 !/^#|^$/{
1028 if(other){
1029 printf "%s", $1
1030 other++}
1031 else
1032 printf " %s", $1
1034 END{printf "\n"}'
1037 # convert a list of words to a regex
1038 regex()
1040 printf "^$1$" | sed s'/ /$|^/g'
1043 # print dev from uuid
1044 uuid2dev()
1046 local uuid="$1" id
1047 if [ "$(echo $uuid | cut -d '=' -f1)" = "UUID" ]; then
1048 id="$(echo $uuid | cut -d'=' -f2)"
1049 printf "$(/sbin/blkid -U $id)"
1050 else
1051 printf "$uuid"
1052 fi
1055 # print disk from uuid
1056 uuid2disk()
1058 local uuid="$1"
1059 printf "$(uuid2dev $uuid | /bin/busybox awk '{print substr($0,1,8)}')"
1062 dev2uuid()
1064 local uuid="$1"
1065 if printf "$uuid" | grep -q dev; then
1066 printf "UUID=$(/sbin/blkid -p -i -o udev "$uuid" \
1067 | grep ID_FS_UUID= | cut -d '=' -f2)"
1068 else
1069 printf "$uuid"
1070 fi
1073 # print partition scheme from uuid
1074 p_table()
1076 local uuid="$1" device
1077 device="$(uuid2disk $uuid)"
1078 printf "$(/usr/sbin/parted -lm | grep "$device" | \
1079 cut -d':' -f6)"
1082 # print filesystem from uuid
1083 filesys()
1085 local uuid="$1"
1086 local fs="$(/sbin/blkid -s UUID -s TYPE | \
1087 grep "$(uuid2dev $uuid)" | cut -d' ' -f3)"
1088 fs="${fs#TYPE=\"}"
1089 fs="${fs%\"}"
1090 printf "$fs"
1093 # return removable status from uuid
1094 is_removable()
1096 local uuid="$1" removable=1
1097 local disk="$(uuid2disk $uuid | /bin/busybox awk '{print substr($0,6,3)}')"
1098 if [ "$(echo $disk | wc -w)" -eq "1" ]; then
1099 [ "$(cat /sys/block/"$disk"/removable)" -gt "0" ] \
1100 && removable=0
1101 fi
1102 return "$removable"
1105 randomize_mirrors()
1107 local list_mirrors
1108 if [ -r "$MIRRORS" ]; then
1109 # randomize list of mirrors
1110 list_mirrors="$(cat $MIRRORS | \
1111 /bin/busybox awk 'BEGIN {srand()}{
1112 printf "%05.0f %s \n",rand()*99999, $0;
1113 }' | sort -n | sed 's/^[0-9]* //' )"
1114 else
1115 log "$(gettext "No mirror list found, run tazpkg recharge.")"
1116 list_mirrors="http://mirror.slitaz.org/"
1117 fi
1118 MIRRORS="$list_mirrors"
1121 # download a file
1122 dnl()
1124 local file="$1" mirror transfer=0 oldfile
1125 mkdir -p /tmp/tazinst
1126 for mirror in $MIRRORS; do
1127 log "$(gettext "Downloading:") $mirror$file"
1128 oldfile="$(printf $file | \
1129 /bin/busybox awk 'BEGIN{RS="/"}{text=$1}END{print text}')"
1130 [ -e "/tmp/tazinst/$oldfile" ] && rm -f "/tmp/tazinst/$oldfile"
1131 /bin/busybox wget $mirror$file -P /tmp/tazinst && transfer=1 && break
1132 done
1133 if [ "$transfer" -gt "0" ];then
1134 log "$(gettext "Download completed.")"
1135 else
1136 error 5 "$file: $(gettext "Download failed.")"
1137 fi
1140 # install pkg in current system
1141 need_package()
1143 local pkg="$1"
1144 if [ ! -d /var/lib/tazpkg/installed/$pkg ]; then
1145 log "$(gettext "Installing package to the current system:") $pkg"
1146 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1147 /usr/bin/tazpkg get-install "$pkg" || error 5 "Cannot install $pkg"
1148 fi
1151 # install pkg in target system
1152 add_pkg()
1154 local pkg="$1"
1155 log "$(gettext "Adding package to the target system:") $pkg..."
1156 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1157 /usr/bin/tazpkg get "$pkg" >> "$LOG" 2>> "$LOG"
1158 yes "" | /usr/bin/tazpkg install $pkg.tazpkg \
1159 --root=$TARGET_ROOT >> "$LOG" 2>> "$LOG"
1160 rm -f $pkg.tazpkg
1163 #---------
1164 # 3.1 log
1165 #---------
1167 # start log
1168 log_open()
1170 printf "=== Tazinst: start on $(date "+%x %X") ===\n" > "$LOG"
1171 LOGGING="true"
1174 # print and log a comment
1175 log(){
1176 # for front-ends, sleep 1 if $1 is num
1177 printf "$1" | awk '{
1178 num=$1+0
1179 if(num>0 && num<=100)
1180 exit 0
1181 else
1182 exit 1
1183 }' && sleep 1
1184 # log
1185 printf "$1\n"
1186 [ -n "$LOGGING" ] && printf "$1\n" >> $LOG
1189 #--------------------
1190 # 3.2 error handling
1191 #--------------------
1193 # print an error msg & exit
1194 error()
1196 local error="$1" msg="$2" cancel="$(gettext "Process not completed")"
1197 printf "$(gettext "Error"): $msg\n$cancel\n" 1>&2
1198 if [ -n "$LOGGING" ]; then
1199 # 1st pattern
1200 printf "-x-x- \n" >> "$LOG"
1201 printf "$(gettext "Error") $error: $msg\n$cancel\n" >> "$LOG"
1202 # 2nd pattern
1203 printf "x-x-x \n" >> "$LOG"
1204 printf "=== Tazinst error on $(date "+%x %X") ===\n" >> "$LOG"
1205 fi
1206 unset LOGGING
1207 umount_devices
1208 exit "$error"
1211 error8()
1213 error 8 "$(gettext "Internal error")"
1216 error9()
1218 error 9 "$(gettext "Cancelled by user")"
1221 #------------------
1222 # 4. disks section
1223 #------------------
1225 #------------
1226 # 4.1 source
1227 #------------
1229 # liveCD
1230 mount_cdrom()
1232 # set device name
1233 local drive="$(cat /proc/sys/dev/cdrom/info | \
1234 grep "drive name" | cut -f 3)"
1235 [ -n "$drive" ] || drive=cdrom
1236 local cdrom=/dev/$drive
1237 # mount cdrom
1238 if mount -t iso9660 "$cdrom" "$SOURCE_ROOT" 2>>"$LOG"; then
1239 log "$(gettext "Using files from") $cdrom."
1240 else
1241 error 3 "$cdrom: $(gettext "Mount failed")."
1242 fi
1245 # liveUSB
1246 mount_usb()
1248 # /home is on LiveUSB
1249 if [ -d /home/boot ]; then
1250 log "$(gettext "Using files from USB device...")"
1251 ln -s /home/boot $SOURCE_ROOT/boot
1252 else
1253 # mount LiveUSB
1254 if mount "$SOURCE" "$SOURCE_ROOT" 2>>"$LOG"; then
1255 log "$(gettext "Using files from USB device") $SOURCE."
1256 else
1257 error 3 "$SOURCE: $(gettext "Failed to mount USB device")."
1258 fi
1259 fi
1262 # ISO file on HDD
1263 mount_iso()
1265 # check integrity
1266 local md5file=$(echo $SOURCE | sed 's/.iso$/.md5/')
1267 if [ -r "$md5file" ]; then
1268 local md5ref="$(cat "$md5file" | cut -d' ' -f1)"
1269 local md5calc="$(md5sum $SOURCE | cut -d' ' -f1)"
1270 if [ ! "$md5calc" = "$md5ref" ]; then
1271 log "md5sum iso=$md5ref md5sum tazinst=$md5calc"
1272 error 3 "$(gettext "md5sum error, file corrupted.")"
1273 fi
1274 else
1275 log "$SOURCE: $(gettext "md5 file not found, can't check integrity.")"
1276 fi
1277 # mount ISO
1278 if mount -o loop -t iso9660 "$SOURCE" \
1279 "$SOURCE_ROOT" 2>>"$LOG"; then
1280 log "$(gettext "Using files from ISO") $SOURCE."
1281 else
1282 error 3 "$SOURCE: $(gettext "Failed to mount ISO.")"
1283 fi
1286 # ISO file on the web
1287 mount_web()
1289 if (echo "$SOURCE" | egrep -q "$(regex "$(list web)")"); then
1290 SOURCE="$(list web $SOURCE)"
1291 fi
1292 dnl "$SOURCE"
1293 local md5file="$(echo $SOURCE | sed 's/.iso$/.md5/')"
1294 dnl "$md5file"
1295 local webiso="$(echo $SOURCE | /bin/busybox awk 'BEGIN{RS="/"}{out=$1}
1296 END{printf"%s",out}')"
1297 SOURCE="/tmp/tazinst/$webiso"
1298 mount_iso
1301 # set up source and check Slitaz' content
1302 mount_source()
1304 log "$(gettext "Creating mount point:") $SOURCE_ROOT..."
1305 mkdir -p "$SOURCE_ROOT"
1306 case "$MEDIA" in
1307 cdrom)
1308 mount_cdrom ;;
1309 usb)
1310 mount_usb ;;
1311 iso)
1312 mount_iso ;;
1313 web)
1314 mount_web ;;
1315 *)
1316 error8 ;;
1317 esac
1319 # exit if no rootfs.gz found.
1320 log "$(gettext "Checking installation media...")"
1321 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz -a \
1322 ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
1323 error 3 $(gettext "Invalid source")
1324 else
1325 log "$(gettext "Installation media checked ok")"
1326 fi
1329 #------------
1330 # 4.2 target
1331 #------------
1333 # format a partition
1334 format()
1336 local uuid="$1" fmt="$2" dest="$3" dev format
1337 log "$(gettext "Format") $uuid ($fmt)"
1338 format="mkfs.$fmt"
1339 if (printf "$uuid" | grep -q "UUID="); then
1340 # case UUID=
1341 dev="$(uuid2dev $uuid)"
1342 "$format" "$dev" >>"$LOG" 2>>"$LOG" || error 4 "Formatting has failed"
1343 # uuid has changed
1344 case "$dest" in
1345 root_uuid)
1346 ROOT_UUID="$(/sbin/blkid -p "$dev" -o export | \
1347 grep ^UUID=)" ;;
1348 home_uuid)
1349 HOME_UUID="$(/sbin/blkid -p "$dev" -o export | \
1350 grep ^UUID=)" ;;
1351 esac
1352 else
1353 # case /dev/xxxx
1354 "$format" $uuid >>"$LOG" 2>>"$LOG" || error 4 "Formatting has failed"
1355 fi
1358 # prepare partitions
1359 prepare_uuid()
1361 log "$(gettext "Preparing target partition...")"
1362 local uuid
1363 # target may be in use
1364 mount | grep -q "$ROOT_UUID" && \
1365 error 4 "$ROOT_UUID: $(gettext "Partition is already in use.")"
1366 # Mount point can be already used.
1367 mount | grep -q "$TARGET_ROOT" && \
1368 umount "$TARGET_ROOT" 2>>"$LOG"
1370 # Formatting root partition
1371 case "$ROOT_FORMAT" in
1372 "")
1373 log "$ROOT_UUID: $(gettext "The partition will be cleaned...")" ;;
1374 *)
1375 format "$ROOT_UUID" "$ROOT_FORMAT" root_uuid
1376 esac
1378 # Formatting /home
1379 if [ -n "$HOME_UUID" ]; then
1380 case "$HOME_FORMAT" in
1381 "")
1382 log "$HOME_UUID $(gettext "The partition will be kept...")" ;;
1383 *)
1384 format "$HOME_UUID" "$HOME_FORMAT" home_uuid
1385 esac
1386 fi
1388 log "$(gettext "Creating mount point:") $TARGET_ROOT"
1389 mkdir -p "$TARGET_ROOT" >> "$LOG" || error8
1390 # Mount target.
1391 local mount_fs="$ROOT_FORMAT"
1392 [ -z "$mount_fs" ] && mount_fs="$(filesys $ROOT_UUID)"
1393 mount -t "$mount_fs" "$ROOT_UUID" \
1394 "$TARGET_ROOT" >>"$LOG" 2>>"$LOG"
1395 if [ $(mount | \
1396 grep -c "mnt/target") == "0" ]; then
1397 error 4 "$ROOT_UUID: $(gettext "Unable to mount partition")"
1398 fi
1402 #------------
1403 # 4.3 umount
1404 #------------
1406 # copy log file, umount target and eject cdrom.
1407 umount_devices()
1409 # umount target
1410 if mount | grep -q "$TARGET_ROOT"; then
1411 log "$(gettext "Unmounting target partition:") $ROOT_UUID"
1412 umount -l "$TARGET_ROOT" 2>>$LOG
1413 fi
1415 # umount source
1416 if mount | grep -q "$SOURCE_ROOT"; then
1417 log "$(gettext "Unmounting:") $SOURCE_ROOT"
1418 umount -l "$SOURCE_ROOT"
1419 fi
1420 if [ -h $SOURCE_ROOT/boot ]; then
1421 log "$(gettext "Unlinking:") $SOURCE_ROOT"
1422 rm -f $SOURCE_ROOT/boot
1423 fi
1425 # eject cd
1426 if [ "$SOURCE" == "cdrom" ]; then
1427 gettext "Ejecting cdrom..."
1428 eject
1429 fi
1430 # remove lock file
1431 rm -f "$LOCK"
1434 end_of_install()
1436 log "\n$(gettext "Process completed. You can now restart (reboot)")"
1437 log "$(gettext "from your SliTaz GNU/Linux system.")"
1438 printf "=== Tazinst end on $(date "+%x %X") ===\n" >> "$LOG"
1439 unset LOGGING
1440 # saving log
1441 log "$(gettext "Copying log to /var/log/tazinst.log")"
1442 cp -a "$LOG" $TARGET_ROOT/var/log
1443 umount_devices
1447 #---------------
1448 # 5. bootloader
1449 #---------------
1451 #------------
1452 # 5.1 common
1453 #------------
1455 # selection
1456 bootloader()
1458 if [ "$BOOTLOADER" == "auto" ]; then
1459 # use syslinux, but if p_table=msdos take grub (if available)
1460 unset BOOTLOADER
1461 printf "$(list_bootloader)" | \
1462 grep -q "syslinux" && BOOTLOADER=syslinux
1463 if [ "$(p_table $ROOT_UUID)" == "msdos" ]; then
1464 printf "$(list_bootloader)" | \
1465 grep -q " grub" && BOOTLOADER=grub
1466 fi
1467 fi
1468 case "$BOOTLOADER" in
1469 grub)
1470 grub_config
1471 grub_install ;;
1472 syslinux)
1473 syslinux_config
1474 syslinux_install ;;
1475 *)
1476 syslinux_config
1477 log "$(gettext "No bootloader to install.")" ;;
1478 esac
1481 # print disk num
1482 disknum()
1484 local partition="$(uuid2dev $1)"
1485 partition="${partition%[0-9]}"
1486 /usr/sbin/parted -lm | grep "^/dev" | \
1487 /bin/busybox awk -v PART="$partition" '{if (match($0,PART)) print NR-1}'
1490 # print partition num
1491 partnum()
1493 local partition="$(uuid2dev $1)"
1494 printf "$((${partition#/dev/[h-s]d[a-z]}-1))\n"
1497 # print root device
1498 rootdev()
1500 local partition="$1"
1501 case "$(p_table $partition)" in
1502 msdos)
1503 # print device
1504 printf "$(uuid2dev $partition)" ;;
1505 gpt)
1506 # print PARTUUID (different from UUID)
1507 printf "PARTUUID="
1508 /sbin/blkid -p -i -o udev $(uuid2dev $partition) \
1509 | grep ENTRY_UUID | cut -d '=' -f2 ;;
1510 esac
1513 # add rootdelay for removable devices
1514 rootdelay()
1516 is_removable "$ROOT_UUID" && printf "rootdelay=9"
1519 # print winboot uuid
1520 winboot_uuid()
1522 if [ "$WINBOOT" = "auto" ]; then
1523 # get the first uuid if any
1524 [ $(list_winboot | wc -w) -gt 1 ] \
1525 && printf "$(list_winboot | cut -d' ' -f2)"
1526 else
1527 printf "$WINBOOT"
1528 fi
1532 #-----------
1533 # 5.1 grub1
1534 #-----------
1536 # create grub legacy conf
1537 grub_config()
1539 # backup an existing conf
1540 [ -e "$TARGET_ROOT/boot/grub/menu.lst" ] && \
1541 cp $TARGET_ROOT/boot/grub/menu.lst \
1542 $TARGET_ROOT/boot/grub/menu.bak
1543 # create the target GRUB configuration.
1544 mkdir -p $TARGET_ROOT/boot/grub || error8
1545 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
1546 # /boot/grub/menu.lst: GRUB boot loader configuration.
1549 # By default, boot the first entry.
1550 default 0
1552 # Boot automatically after 8 secs.
1553 timeout 8
1555 # Graphical splash image.
1556 splashimage=/boot/grub/splash.xpm.gz
1558 # Change the colors.
1559 #color yellow/brown light-green/black
1561 # For booting SliTaz from : $ROOT_UUID
1563 title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1564 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1565 kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) quiet $(rootdelay)
1567 _EOF_
1569 local winpart="$(winboot_uuid)"
1570 if [ -n "$winpart" ]; then
1571 log "$(gettext "Enabling Windows dual-boot")"
1572 cat >> $TARGET_ROOT/boot/grub/menu.lst << _EOF_
1573 # For booting Windows :
1575 title Microsoft Windows
1576 rootnoverify (hd$(disknum $winpart),$(partnum $winpart))
1577 chainloader +1
1579 _EOF_
1580 fi
1582 # log
1583 printf "/boot/grub/menu.lst:\n" >> "$LOG"
1584 printf "--- menu.lst -------------\n" >> "$LOG"
1585 cat $TARGET_ROOT/boot/grub/menu.lst >> "$LOG"
1586 printf "--- menu.lst -------------\n\n" >> "$LOG"
1589 # GRUB info with disk name used for grub
1590 grub_install()
1592 # install grub
1593 local target_disk="$(uuid2disk $ROOT_UUID)"
1594 log "$(gettext "Installing grub on:") $target_disk"
1595 /usr/sbin/grub-install --version >> "$LOG" || error 5 "grub not found"
1596 /usr/sbin/grub-install --no-floppy \
1597 --root-directory=$TARGET_ROOT $target_disk >>"$LOG" 2>>"$LOG"
1598 # set boot flag
1599 log "$(gettext "Setting the boot flag")"
1600 /usr/sbin/parted "$(uuid2disk $ROOT_UUID)" \
1601 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1602 # splash image
1603 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
1604 log "$(gettext "Copying splash image")"
1605 mkdir -p $TARGET_ROOT/boot/grub
1606 cp $SOURCE_ROOT/boot/grub/splash.xpm.gz \
1607 $TARGET_ROOT/boot/grub
1608 fi
1612 #--------------
1613 # 5.2 syslinux
1614 #--------------
1616 # create syslinux conf
1617 syslinux_config()
1619 local version="[$(cat $TARGET_ROOT/etc/slitaz-release)]"
1620 version="$version\(Kernel $KERNEL)"
1621 # backup an existing conf
1622 [ -e "$TARGET_ROOT/boot/syslinux/syslinux.cfg" ] && \
1623 cp $TARGET_ROOT/boot/syslinux/syslinux.cfg \
1624 $TARGET_ROOT/boot/syslinux/syslinux.bak
1625 # create the target syslinux configuration.
1626 mkdir -p $TARGET_ROOT/boot/syslinux || error8
1627 cat > $TARGET_ROOT/boot/syslinux/syslinux.cfg << EOF
1628 # use a boot menu
1629 UI vesamenu.c32
1631 # display the boot
1632 PROMPT 1
1634 # how long to pause at the boot
1635 TIMEOUT 50
1637 # default label
1638 DEFAULT slitaz
1640 # Menu settings
1641 MENU TITLE SliTaz GNU/Linux boot menu
1642 MENU BACKGROUND splash.jpg
1643 MENU WIDTH 78
1644 MENU MARGIN 6
1645 MENU ROW 10
1646 MENU VSHIFT 2
1647 MENU TIMEOUTROW 18
1648 MENU TABMSGROW 16
1649 MENU CMDLINEROW 16
1651 # Menu colors
1652 MENU COLOR border * #00000000 #00000000 none
1653 MENU COLOR title * #ffffffff #00000000 *
1654 MENU COLOR sel 0 #ffffffff #00000000 none
1655 MENU COLOR unsel 0 #50ffffff #00000000 none
1656 MENU COLOR help * #ffffffff #00000000 *
1657 MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
1658 MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
1659 MENU COLOR msg07 37;40 #90ffffff #a0000000 std
1660 MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
1662 # Labels
1663 LABEL slitaz
1664 MENU LABEL SliTaz GNU/Linux $version
1665 LINUX /boot/$KERNEL
1666 APPEND root=$(rootdev $ROOT_UUID) quiet $(rootdelay)
1668 LABEL cmdline
1669 MENU LABEL Command Line
1670 MENU QUIT
1672 EOF
1673 local winpart="$(winboot_uuid)"
1674 if [ -n "$winpart" ]; then
1675 log "$(gettext "Enabling Windows dual-boot")"
1676 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg << EOF
1677 LABEL windows
1678 MENU LABEL Windows
1679 COM32 chain.c32
1680 APPEND hd$(disknum $winpart) $(($(partnum $winpart)+1))
1682 EOF
1683 fi
1684 # log
1685 printf "/boot/syslinux/syslinux.cfg:\n" >> "$LOG"
1686 printf "--- syslinux.cfg -------------\n" >> "$LOG"
1687 cat $TARGET_ROOT/boot/syslinux/syslinux.cfg >> "$LOG"
1688 printf "--- syslinux.cfg -------------\n\n" >> "$LOG"
1691 # install syslinux
1692 syslinux_install()
1694 log "$(gettext "Installing syslinux")"
1695 # needed tools
1696 local dir disk="$(uuid2disk $ROOT_UUID)"
1697 for dir in /home/boot/extlinux /home/boot/syslinux /boot/syslinux; do
1698 [ -d "$dir" ] && cp $dir/*.c32 "$TARGET_ROOT/boot/syslinux/"
1699 [ -d "$dir" ] && cp $dir/*.sys "$TARGET_ROOT/boot/syslinux/"
1700 done
1701 /usr/bin/lzma d /usr/share/boot/chain.c32.lzma \
1702 $TARGET_ROOT/boot/syslinux/chain.c32 2>> "$LOG"
1703 # install syslinux
1704 /bin/syslinux -version >> "$LOG" || error 5 "syslinux not found"
1705 /bin/extlinux --install $TARGET_ROOT/boot/syslinux >> "$LOG" 2>> "$LOG"
1706 case "$(p_table $ROOT_UUID)" in
1707 msdos)
1708 log "$(gettext "Setting the boot flag on")"
1709 /usr/sbin/parted "$disk" \
1710 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1711 [ -r /usr/share/boot/mbr.bin ] || error 5 "mbr.bin not found"
1712 log "$(gettext "Installing mbr")"
1713 dd bs=440 count=1 conv=notrunc \
1714 if=/usr/share/boot/mbr.bin of=$disk >> "$LOG" ;;
1715 gpt)
1716 log "$(gettext "Setting the legacy_boot flag on")"
1717 # remove old boot flag
1718 local oldboot="$(parted $disk print \
1719 | grep boot | /bin/busybox awk '{print $1}')"
1720 /usr/sbin/parted "$disk" \
1721 set "$oldboot" legacy_boot off 2>> "$LOG"
1722 # set boot flag
1723 /usr/sbin/parted "$disk" \
1724 set "$(($(partnum $ROOT_UUID)+1))" legacy_boot on 2>> "$LOG"
1725 log "$(gettext "Installing gptmbr")"
1726 [ -r /usr/share/boot/gptmbr.bin ] || error 5 "gptmbr.bin not found"
1727 dd bs=440 conv=notrunc count=1 \
1728 if=/usr/share/boot/gptmbr.bin of=$disk >> "$LOG" ;;
1729 esac
1730 # splash image
1731 if [ -f "$SOURCE_ROOT/boot/isolinux/splash.jpg" ]; then
1732 log "$(gettext "Copying splash image")"
1733 cp -a $SOURCE_ROOT/boot/isolinux/splash.jpg \
1734 $TARGET_ROOT/boot/syslinux
1735 fi
1739 #--------------------
1740 # 6. execute section
1741 #--------------------
1743 execute()
1745 local mode="$(get mode)" sighup=1 sigint=2 sigquit=3
1746 randomize_mirrors
1747 trap "error9" "$sighup" "$sigint" "$sigquit"
1748 case "$mode" in
1749 install)
1750 install ;;
1751 upgrade)
1752 upgrade ;;
1753 esac
1756 #-------------
1757 # 6.1 install
1758 #-------------
1760 # get a clean target device
1761 clean_target()
1763 if [ -z "$ROOT_FORMAT" ]; then
1764 # partition was not formatted
1765 log "$(gettext "Cleaning the root partition") ($ROOT_UUID)..."
1766 # keep /home in case of reinstall.
1767 local path="$(pwd)"
1768 cd "$TARGET_ROOT" || error8
1769 local dir
1770 for dir in *
1771 do
1772 case "$dir" in
1773 home)
1774 log "$(gettext "keeping /home found on:") $ROOT_UUID"
1775 mv home home.bak ;;
1776 lost+found)
1777 continue ;;
1778 *)
1779 log "$(gettext "removing target:") $dir"
1780 rm -rf "$dir" 2>>"$LOG" ;;
1781 esac
1782 done
1783 if [ ! -d lost+found ]; then
1784 mklost+found 2>>"$LOG"
1785 fi
1786 cd "$path" || error8
1787 fi
1790 # kernel is renamed to standard vmlinuz-$VERSION.
1791 install_kernel()
1793 if [ -d /$TARGET_ROOT/lib/modules ]; then
1794 KERNEL=$(ls /$TARGET_ROOT/lib/modules | tail -1)
1795 KERNEL="vmlinuz-$KERNEL"
1796 else
1797 KERNEL="vmlinuz-$(uname -r)"
1798 log "$(gettext "Kernel name not found, falling back to:") $(uname -r)"
1799 fi
1800 mkdir -p $TARGET_ROOT/boot || error8
1801 cp $SOURCE_ROOT/boot/bzImage $TARGET_ROOT/boot/$KERNEL
1802 log "$(gettext "install_kernel:") $KERNEL"
1805 # extract packed rootfs: squashfs or cromfs
1806 extract_loramfs()
1808 local i
1809 for i in $(/bin/busybox cpio -idvum 2> /dev/null); do
1810 case "$i" in
1811 rootfs*)
1812 need_package squashfs
1813 if ! unsquashfs $i ; then
1814 need_package cromfs
1815 unmkcromfs $i squashfs-root
1816 fi
1817 mv -f squashfs-root/* .
1818 rmdir squashfs-root
1819 rm -f $i
1820 esac
1821 done
1824 # this is a loram rootfs.gz, skip loram bootstrap and extract
1825 extract_first_loramfs()
1827 local path="$(pwd)"
1828 (zcat $1 || /usr/bin/unlzma -c $1) | \
1829 /bin/busybox cpio -i extractfs.cpio 2> /dev/null &&
1830 ( cd / ; /bin/busybox cpio -id ) < extractfs.cpio && \
1831 rm -f extractfs.cpio
1832 ofs=$(/bin/busybox awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
1833 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
1834 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
1835 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | \
1836 extract_loramfs
1837 cd "$path" || error8
1840 # extract lzma'ed or gziped rootfs.
1841 extract_rootfs()
1843 local path="$(pwd)"
1844 local isloramfs
1845 cd "$TARGET_ROOT" || error8
1846 if [ -d "$1"/../fs/etc ]; then
1847 # this is a tazlitobox loram (cdrom)
1848 cp -a "$1"/../fs/. .
1849 else
1850 for i in $(ls "$1"/rootfs* | sort -r); do
1851 if [ ! -d etc ]; then
1852 if [ $( (zcat "$i" 2>/dev/null \
1853 || /usr/bin/lzma d "$i" -so) | \
1854 wc -c) -lt $(stat -c %s "$i") ]; then
1855 # this is a tazlitobox loram (ram)
1856 isloramfs="$i"
1857 extract_first_loramfs "$i"
1858 continue
1859 fi
1860 fi
1861 if [ -n "$isloramfs" ]; then
1862 extract_loramfs < "$i"
1863 continue
1864 fi
1865 ( zcat "$i" 2>/dev/null || /usr/bin/lzma d "$i" -so || \
1866 cat "$i" ) 2>>"$LOG" | /bin/busybox cpio -idu
1867 done 2>>"$LOG" > /dev/null
1868 fi
1869 cp /etc/keymap.conf etc
1870 # unpack /usr (double check...)
1871 if ls etc/tazlito | grep -q ".extract"; then
1872 for i in etc/tazlito/*.extract; do
1873 [ -f "$i" ] && . "$i" /media/cdrom
1874 done
1875 fi
1876 cd "$pwd" || error8
1880 # pre configure freshly installed system (60 - 80%).
1881 pre_config_system()
1883 local path="$(pwd)"
1884 cd "$TARGET_ROOT" || error8
1885 # restore backup of existing /home if exists.
1886 # (created by prepare_target_dev)
1887 if [ -d home.bak ]; then
1888 log "$(gettext "Restoring directory: /home...")"
1889 rm -rf home
1890 mv home.bak home
1891 fi
1892 # add root device to CHECK_FS in rcS.conf to check filesystem
1893 # on each boot.
1894 log "$(gettext "Adding / partition and CHECK_FS to file /etc/rcS.conf...")"
1895 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$ROOT_UUID\""# etc/rcS.conf
1896 # set hostname.
1897 log "$(gettext "Configuring host name:") $HOSTNAME"
1898 printf "$HOSTNAME\n" > etc/hostname
1899 printf "127.0.0.1 localhost $HOSTNAME tazpanel\n" > etc/hosts
1900 cd "$path" || error8
1903 # set root passwd and create user after rootfs extraction.
1904 users_settings()
1906 # create file
1907 cat > "$TARGET_ROOT/users.sh" << _EOF_
1908 #!/bin/sh
1909 umask 0022
1910 echo "root:$ROOT_PWD" | chpasswd -m
1911 adduser -D -H $USER_LOGIN
1913 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
1914 if ! grep \$grp /etc/group | grep -q $USER_LOGIN ; then
1915 grep -q \$grp /etc/group && addgroup $USER_LOGIN \$grp
1916 fi
1917 done
1919 echo "$USER_LOGIN:$USER_PWD" | chpasswd -m
1920 if [ ! -d /home/$USER_LOGIN ]; then
1921 cp -a /etc/skel /home/$USER_LOGIN
1922 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$USER_LOGIN
1923 mkdir -p /home/$USER_LOGIN/.config/slitaz
1924 cp -a /etc/slitaz/applications.conf /home/$USER_LOGIN/.config/slitaz
1925 # Set ownership
1926 if grep -q ^users: /etc/group; then
1927 chown -R $USER_LOGIN:users /home/$USER_LOGIN
1928 else
1929 chown -R $USER_LOGIN:$USER_LOGIN /home/$USER_LOGIN
1930 fi
1931 # Path for user desktop files.
1932 for i in /home/$USER_LOGIN/.local/share/applications/*.desktop
1933 do
1934 [ -e "$i" ] && sed -i s/"user_name"/"$USER_LOGIN"/g \$i
1935 done
1936 fi
1937 # Slim default user.
1938 if [ -f /etc/slim.conf ]; then
1939 sed -i s/"default_user .*"/"default_user $USER_LOGIN"/ \
1940 /etc/slim.conf
1941 fi
1942 _EOF_
1943 chmod o+x "$TARGET_ROOT/users.sh"
1944 chroot "$TARGET_ROOT" ./users.sh 2>>"$LOG" >> "$LOG"
1945 rm "$TARGET_ROOT/users.sh"
1946 umask 0177
1949 # /home can be on a separate partition. If default user exists in /home
1950 # we remove default file created by users_settings().
1951 home_config()
1953 if [ -n "$HOME_UUID" ]; then
1954 local path="$(pwd)" uuid
1955 cd "$TARGET_ROOT" || error8
1956 # detect fs
1957 local home_fs="$HOME_FORMAT"
1958 [ -z "$home_fs" ] && home_fs="$(filesys $HOME_UUID)"
1959 # manage /home
1960 log "$(gettext "Configuring partition to be used as /home:") $HOME_UUID"
1961 mv home/$USER_LOGIN tmp
1962 mount -t "$home_fs" "$HOME_UUID" home >> "$LOG" 2>> "$LOG"
1963 if [ -d $TARGET_ROOT/home/$USER_LOGIN ]; then
1964 rm -rf tmp/home/$USER_LOGIN
1965 else
1966 mv tmp/$USER_LOGIN home
1967 fi
1968 # write entry in fstab, force uuid
1969 uuid="$(dev2uuid "$HOME_UUID")"
1970 printf "$uuid /home $home_fs defaults \t0 \t2\n" >> etc/fstab
1971 umount home >> "$LOG" 2>> "$LOG"
1972 cd "$path" || error8
1973 fi
1976 install()
1978 log_open
1979 log "1 $(gettext "Installing SliTaz on:") $(get root_uuid)"
1980 log "5 $(gettext "Checking settings")..."
1981 check all >> "$LOG" 2>> "$LOG"
1982 load_settings
1984 log "10 $(gettext "Preparing source media")..."
1985 mount_source
1987 log "20 $(gettext "Preparing target disk")..."
1988 prepare_uuid
1990 log "30 $(gettext "Cleaning the root partition if necessary")..."
1991 clean_target
1993 log "40 $(gettext "Extracting the root system")..."
1994 extract_rootfs $SOURCE_ROOT/boot
1996 log "50 $(gettext "Installing the kernel")..."
1997 install_kernel
1999 log "60 $(gettext "Preconfiguring the system")..."
2000 pre_config_system
2002 log "70 $(gettext "Configuring root and default user account")..."
2003 users_settings
2005 log "80 $(gettext "Configuring /home")..."
2006 home_config
2008 log "90 $(gettext "Checking bootloader installation...")"
2009 bootloader
2011 log "100 $(gettext "Files installation completed")"
2012 end_of_install
2016 #-------------
2017 # 6.2 upgrade
2018 #-------------
2020 # search for SliTaz
2021 check_release()
2023 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
2024 local release="$(cat $TARGET_ROOT/etc/slitaz-release)"
2025 log "$(gettext "Preparing upgrade of SliTaz release:") $release"
2026 else
2027 error 6 "$ROOT_UUID: $(gettext "This partition doesn't appear to \
2028 contain a valid SliTaz system, the file: /etc/slitaz-release doesn't exist.")"
2029 fi
2032 # backup packages list.
2033 backup_files()
2035 local path="$(pwd)"
2036 cd "$TARGET_ROOT" || error8
2037 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
2038 local dir
2039 for dir in *
2040 do
2041 case "$dir" in
2042 boot)
2043 rm -rf boot/vmlinuz-* ;;
2044 home)
2045 mv home home.bak
2046 log "$(gettext "keeping /home found on:") $ROOT_UUID" ;;
2047 etc)
2048 /bin/busybox tar czf etc.tar.gz etc
2049 mv etc etc.bak
2050 log "$(gettext "keeping /etc found on:") $ROOT_UUID" ;;
2051 var)
2052 if [ -d var/www ]; then
2053 mv var/www www.bak
2054 log "$(gettext "keeping /var/www found on:") $ROOT_UUID"
2055 fi
2056 rm -rf var 2>>"$LOG" ;;
2057 lost+found)
2058 continue ;;
2059 *)
2060 log "$(gettext "removing target: $dir")"
2061 rm -rf "$dir" 2>>"$LOG" ;;
2062 esac
2063 done
2064 if [ -d mklost+found ]; then
2065 mklost+found 2>>"$LOG"
2066 fi
2067 cd "$path" || error8
2070 # restore backups.
2071 restore_files()
2073 rm -rf $TARGET_ROOT/home
2074 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
2075 rm -rf $TARGET_ROOT/etc
2076 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
2077 if [ -d $TARGET_ROOT/www.bak ]; then
2078 rm -rf $TARGET_ROOT/var/www
2079 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
2080 fi
2081 log "$(gettext "backups restored:") $(date)"
2083 # /var/lib/slitaz-installer
2084 mkdir -p $TARGET_ROOT/var/lib/tazinst && \
2085 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst && \
2086 mv $TARGET_ROOT/home/packages-selection.list \
2087 $TARGET_ROOT/var/lib/tazinst \
2088 && log "$(gettext "backups saved in /var/lib/tazinst")"
2091 # upgrade added pkgs
2092 install_pkgs()
2094 # check if the pkg is on the mirror.
2095 log "$(gettext "Checking the availability of packages...")"
2096 touch packages-to-install.list
2097 packages=0
2098 diff="$(cat packages-selection.diff | sort)"
2099 for pkg in $diff
2100 do
2101 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
2102 packages="$(($packages+1))"
2103 echo "$pkg" >> packages-to-install.list
2104 fi
2105 done
2107 # install packages.
2108 log "$(gettext "Installing packages...")"
2109 if [ "$packages" == "0" ]; then
2110 log "$(gettext "packages to install: 0")"
2111 else
2112 # get-install all missing pkgs.
2113 for pkg in $(cat packages-to-install.list)
2114 do
2115 log "$(gettext "Installing:") $pkg..."
2116 # get install package and answer yes in case of dependencies.
2117 pkgname="$(grep ^$pkg /var/lib/tazpkg/packages.list)"
2118 /usr/bin/tazpkg get "$pkg" >/dev/null 2>/dev/null
2119 yes "" | /usr/bin/tazpkg install $pkgname.tazpkg \
2120 --root=$TARGET_ROOT >/dev/null 2>/dev/null
2121 rm -f $pkgname.tazpkg
2122 done
2123 fi
2124 log "$(gettext "Installation of packages complete...")"
2127 # search for added pkgs
2128 update_pkgs()
2130 local path="$(pwd)"
2131 cd $TARGET_ROOT/var/lib/tazinst || error8
2132 # LiveCD packages list.
2133 log "$(gettext "Creating package lists...")"
2134 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || error8
2135 log "$(gettext "packages-source.list: done")"
2136 # diff
2137 /bin/busybox diff packages-source.list packages-selection.list | \
2138 grep ^+[a-z] | sed s/^+// > packages-selection.diff
2139 log "$(gettext "packages-selection.diff: done")"
2140 # get mirror list.
2141 /usr/bin/tazpkg recharge >>$LOG 2>>$LOG
2142 if [ -f /var/lib/tazpkg/packages.list ]; then
2143 install_pkgs
2144 else
2145 touch packages-to-install.list
2146 printf "$(gettext "The list of available packages on the mirror could \
2147 not be downloaded. No missing packages will be reinstalled now, but you can do \
2148 so later by looking at the following list:
2149 /var/lib/tazinst/packages-selection.diff")"
2150 fi
2151 cd "$path" || error8
2154 # upgrade command
2155 upgrade()
2157 log_open
2158 log "1 $(gettext "Upgrading SliTaz on:") $(get root_uuid)"
2159 log "5 $(gettext "Checking settings")..."
2160 check all >> "$LOG"
2161 load_settings
2163 log "10 $(gettext "Preparing source media")..."
2164 mount_source
2166 log "20 $(gettext "Preparing target disk")..."
2167 prepare_uuid
2169 log "30 $(gettext "Searching for /etc/slitaz-release")..."
2170 check_release
2172 log "40 $(gettext "Backup /etc, /home and the packages list")..."
2173 backup_files
2175 log "50 $(gettext "Extracting the root system")..."
2176 extract_rootfs $SOURCE_ROOT/boot
2178 log "60 $(gettext "Restoring configuration files")..."
2179 restore_files
2181 log "70 $(gettext "Installing the kernel")..."
2182 install_kernel
2184 log "80 $(gettext "Upgrading added packages")..."
2185 update_pkgs
2187 log "90 $(gettext "Bootloader")..."
2188 bootloader
2190 log "100 $(gettext "Files installation completed")"
2191 end_of_install
2195 #--------------
2196 # tazinst main
2197 #--------------
2199 case $1 in
2200 new)
2201 new_file "$2" ;;
2202 set)
2203 read_file "$4"
2204 change "$2" "$3" "$4" ;;
2205 unset)
2206 read_file "$3"
2207 change "$2" "" "$3" "$4" ;;
2208 get)
2209 read_file "$3"
2210 get "$2" ;;
2211 check)
2212 read_file "$3"
2213 check "$2" ;;
2214 list)
2215 list "$2" "$3" ;;
2216 execute)
2217 check_root
2218 read_file "$2"
2219 execute "$2" ;;
2220 log)
2221 [ -r "$LOG" ] && cat "$LOG" ;;
2222 clean)
2223 clean "$2" ;;
2224 version)
2225 echo "$VERSION" ;;
2226 ""|usage)
2227 usage ;;
2228 help)
2229 help "$2" ;;
2230 *)
2231 usage_error ;;
2232 esac