tazinst view tazinst @ rev 16

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