tazinst view tazinst @ rev 17

Copyright 2014
author Dominique Corbex <domcox@slitaz.org>
date Fri Jan 03 17:57:31 2014 +0100 (2014-01-03)
parents 80e88d4d4629
children eba42025e5c1
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-2014 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 "* uuid:\n%s\n\n" "$(list_uuid)"
1017 printf "* format:\n%s\n\n" "$(list_format)"
1018 printf "* bootloader:\n%s\n\n" "$(list_bootloader)"
1019 printf "* partition_table:\n%s\n\n" "$(list_partition_table)"
1020 printf "* winboot:\n%s\n" "$(list_winboot)"
1021 ;;
1022 *)
1023 local options="mode media usb iso web uuid format bootloader \
1024 partition_table winboot"
1025 option_error "$1" "$options" ;;
1026 esac
1029 #----------
1030 # 3. tools
1031 #----------
1033 # list indexes from a list
1034 key()
1036 printf "%s" "$1" | /bin/busybox awk -F: 'BEGIN{
1037 other=-1
1039 !/^#|^$/{
1040 if(other){
1041 printf "%s", $1
1042 other++}
1043 else
1044 printf " %s", $1
1046 END{printf "\n"}'
1049 # convert a list of words to a regex
1050 regex()
1052 printf "%s" "^$1$" | sed s'/ /$|^/g'
1055 # print dev from uuid
1056 uuid2dev()
1058 local uuid="$1" id
1059 if [ "$(printf "%s" $uuid | cut -d '=' -f1)" = "UUID" ]; then
1060 id="$(printf "%s" $uuid | cut -d'=' -f2)"
1061 printf "$(/sbin/blkid -U $id)"
1062 else
1063 printf "%s" "$uuid"
1064 fi
1067 # print disk from uuid
1068 uuid2disk()
1070 local uuid="$1"
1071 printf "%s" "$(uuid2dev $uuid | /bin/busybox awk '{print substr($0,1,8)}')"
1074 dev2uuid()
1076 local uuid="$1"
1077 if printf "%s" "$uuid" | grep -q dev; then
1078 printf "UUID=%s" "$(/sbin/blkid -p -i -o udev "$uuid" \
1079 | grep ID_FS_UUID= | cut -d '=' -f2)"
1080 else
1081 printf "%s" "$uuid"
1082 fi
1085 # print partition scheme from uuid
1086 p_table()
1088 local uuid="$1" device
1089 device="$(uuid2disk $uuid)"
1090 printf "%s" "$(/usr/sbin/parted -lm | grep "$device" | \
1091 cut -d':' -f6)"
1094 # print filesystem from uuid
1095 filesys()
1097 local uuid="$1"
1098 local fs="$(/sbin/blkid -s UUID -s TYPE | \
1099 grep "$(uuid2dev $uuid)" | cut -d' ' -f3)"
1100 fs="${fs#TYPE=\"}"
1101 fs="${fs%\"}"
1102 printf "%s" "$fs"
1105 # return removable status from uuid
1106 is_removable()
1108 local uuid="$1" removable=1
1109 local disk="$(uuid2disk $uuid | /bin/busybox awk '{print substr($0,6,3)}')"
1110 if [ "$(printf "%s" $disk | wc -w)" -eq "1" ]; then
1111 [ "$(cat /sys/block/"$disk"/removable)" -gt "0" ] \
1112 && removable=0
1113 fi
1114 return "$removable"
1117 randomize_mirrors()
1119 local list_mirrors
1120 if [ -r "$MIRRORS" ]; then
1121 # randomize list of mirrors
1122 list_mirrors="$(cat $MIRRORS | \
1123 /bin/busybox awk 'BEGIN {srand()}{
1124 printf "%05.0f %s \n",rand()*99999, $0;
1125 }' | sort -n | sed 's/^[0-9]* //' )"
1126 else
1127 log "$(gettext "No mirror list found, run tazpkg recharge.")"
1128 list_mirrors="http://mirror.slitaz.org/"
1129 fi
1130 MIRRORS="$list_mirrors"
1133 # download a file
1134 dnl()
1136 local file="$1" mirror transfer=0 oldfile
1137 mkdir -p /tmp/tazinst
1138 for mirror in $MIRRORS; do
1139 log "$(gettext "Downloading:") $mirror$file"
1140 oldfile="$(printf "%s" $file | \
1141 /bin/busybox awk 'BEGIN{RS="/"}{text=$1}END{print text}')"
1142 [ -e "/tmp/tazinst/$oldfile" ] && rm -f "/tmp/tazinst/$oldfile"
1143 /bin/busybox wget $mirror$file -P /tmp/tazinst && transfer=1 && break
1144 done
1145 if [ "$transfer" -gt "0" ];then
1146 log "$(gettext "Download completed.")"
1147 else
1148 error 5 "$file: $(gettext "Download failed.")"
1149 fi
1152 # install pkg in current system
1153 need_package()
1155 local pkg="$1"
1156 if [ ! -d /var/lib/tazpkg/installed/$pkg ]; then
1157 log "$(gettext "Installing package to the current system:") $pkg"
1158 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1159 /usr/bin/tazpkg get-install "$pkg" || error 5 "Cannot install $pkg"
1160 fi
1163 # install pkg in target system
1164 add_pkg()
1166 local pkg="$1"
1167 log "$(gettext "Adding package to the target system:") $pkg..."
1168 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
1169 /usr/bin/tazpkg get "$pkg" >> "$LOG" 2>> "$LOG"
1170 yes "" | /usr/bin/tazpkg install $pkg.tazpkg \
1171 --root=$TARGET_ROOT >> "$LOG" 2>> "$LOG"
1172 rm -f $pkg.tazpkg
1175 #---------
1176 # 3.1 log
1177 #---------
1179 # start log
1180 log_open()
1182 printf "%s\n" "=== Tazinst: started on $(date "+%x %X") ===" > "$LOG"
1183 LOGGING="true"
1186 # print and log a comment
1187 log(){
1188 # for front-ends, sleep 1 if $1 is num
1189 printf "%s" "$1" | awk '{
1190 num=$1+0
1191 if(num>0 && num<=100)
1192 exit 0
1193 else
1194 exit 1
1195 }' && sleep 1
1196 # log
1197 printf "%s\n" "$1"
1198 [ -n "$LOGGING" ] && printf "%s\n" "$1" >> $LOG
1201 #--------------------
1202 # 3.2 error handling
1203 #--------------------
1205 # print an error msg & exit
1206 error()
1208 local error="$1" msg="$2" cancel="$(gettext "Process not completed")"
1209 printf "%s: %s\n%s\n" "$(gettext "Error")" "$msg" "$cancel" 1>&2
1210 if [ -n "$LOGGING" ]; then
1211 # 1st pattern
1212 echo "-x-x- " >> "$LOG"
1213 printf "%s: %s\n%s\n" "$(gettext "Error")" "$msg" "$cancel" >> "$LOG"
1214 # 2nd pattern
1215 echo "x-x-x " >> "$LOG"
1216 printf "=== Tazinst error on $(date "+%x %X") ===\n" >> "$LOG"
1217 fi
1218 unset LOGGING
1219 umount_devices
1220 exit "$error"
1223 error8()
1225 error 8 "$(gettext "Internal error")"
1228 error9()
1230 error 9 "$(gettext "Cancelled by user")"
1233 #------------------
1234 # 4. disks section
1235 #------------------
1237 #------------
1238 # 4.1 source
1239 #------------
1241 # liveCD
1242 mount_cdrom()
1244 # set device name
1245 local drive="$(cat /proc/sys/dev/cdrom/info | \
1246 grep "drive name" | cut -f 3)"
1247 [ -n "$drive" ] || drive=cdrom
1248 local cdrom=/dev/$drive
1249 # mount cdrom
1250 if mount -t iso9660 "$cdrom" "$SOURCE_ROOT" 2>>"$LOG"; then
1251 log "$(gettext "Using files from") $cdrom."
1252 else
1253 error 3 "$cdrom: $(gettext "Mount failed")."
1254 fi
1257 # liveUSB
1258 mount_usb()
1260 # /home is on LiveUSB
1261 if [ -d /home/boot ]; then
1262 log "$(gettext "Using files from USB device...")"
1263 ln -s /home/boot $SOURCE_ROOT/boot
1264 else
1265 # mount LiveUSB
1266 if mount "$SOURCE" "$SOURCE_ROOT" 2>>"$LOG"; then
1267 log "$(gettext "Using files from USB device") $SOURCE."
1268 else
1269 error 3 "$SOURCE: $(gettext "Failed to mount USB device")."
1270 fi
1271 fi
1274 # ISO file on HDD
1275 mount_iso()
1277 # check integrity
1278 local md5file=$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')
1279 if [ -r "$md5file" ]; then
1280 local md5ref="$(cat "$md5file" | cut -d' ' -f1)"
1281 local md5calc="$(md5sum $SOURCE | cut -d' ' -f1)"
1282 if [ ! "$md5calc" = "$md5ref" ]; then
1283 log "md5sum iso=$md5ref md5sum tazinst=$md5calc"
1284 error 3 "$(gettext "md5sum error, file corrupted.")"
1285 fi
1286 else
1287 log "$SOURCE: $(gettext "md5 file not found, cannot check integrity.")"
1288 fi
1289 # mount ISO
1290 if mount -o loop -t iso9660 "$SOURCE" \
1291 "$SOURCE_ROOT" 2>>"$LOG"; then
1292 log "$(gettext "Using files from ISO") $SOURCE."
1293 else
1294 error 3 "$SOURCE: $(gettext "Failed to mount ISO.")"
1295 fi
1298 # ISO file on the web
1299 mount_web()
1301 if (printf "%s" "$SOURCE" | egrep -q "$(regex "$(list web)")"); then
1302 SOURCE="$(list web $SOURCE)"
1303 fi
1304 dnl "$SOURCE"
1305 local md5file="$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')"
1306 dnl "$md5file"
1307 local webiso="$(printf "%s" $SOURCE | \
1308 /bin/busybox awk 'BEGIN{RS="/"}{out=$1} END{printf "%s",out}')"
1309 SOURCE="/tmp/tazinst/$webiso"
1310 mount_iso
1313 # set up source and check Slitaz' content
1314 mount_source()
1316 log "$(gettext "Creating mount point:") $SOURCE_ROOT..."
1317 mkdir -p "$SOURCE_ROOT"
1318 case "$MEDIA" in
1319 cdrom)
1320 mount_cdrom ;;
1321 usb)
1322 mount_usb ;;
1323 iso)
1324 mount_iso ;;
1325 web)
1326 mount_web ;;
1327 *)
1328 error8 ;;
1329 esac
1331 # exit if no rootfs.gz found.
1332 log "$(gettext "Checking installation media...")"
1333 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz -a \
1334 ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
1335 error 3 $(gettext "Invalid source")
1336 else
1337 log "$(gettext "Installation media checked ok")"
1338 fi
1341 #------------
1342 # 4.2 target
1343 #------------
1345 # format a partition
1346 format()
1348 local uuid="$1" fmt="$2" dest="$3" dev format
1349 log "$(gettext "Format") $uuid ($fmt)"
1350 format="mkfs.$fmt"
1351 if (printf "%s" "$uuid" | grep -q "UUID="); then
1352 # case UUID=
1353 dev="$(uuid2dev $uuid)"
1354 "$format" "$dev" >>"$LOG" 2>>"$LOG" || error 4 "Formatting has failed"
1355 # uuid has changed
1356 case "$dest" in
1357 root_uuid)
1358 ROOT_UUID="$(/sbin/blkid -p "$dev" -o export | \
1359 grep ^UUID=)" ;;
1360 home_uuid)
1361 HOME_UUID="$(/sbin/blkid -p "$dev" -o export | \
1362 grep ^UUID=)" ;;
1363 esac
1364 else
1365 # case /dev/xxxx
1366 "$format" $uuid >>"$LOG" 2>>"$LOG" || error 4 "Formatting has failed"
1367 fi
1370 # prepare partitions
1371 prepare_uuid()
1373 log "$(gettext "Preparing target partition...")"
1374 local uuid
1375 # target may be in use
1376 mount | grep -q "$ROOT_UUID" && \
1377 error 4 "$ROOT_UUID: $(gettext "Partition is already in use.")"
1378 # Mount point can be already used.
1379 mount | grep -q "$TARGET_ROOT" && \
1380 umount "$TARGET_ROOT" 2>>"$LOG"
1382 # Formatting root partition
1383 case "$ROOT_FORMAT" in
1384 "")
1385 log "$ROOT_UUID: $(gettext "The partition will be cleaned...")" ;;
1386 *)
1387 format "$ROOT_UUID" "$ROOT_FORMAT" root_uuid
1388 esac
1390 # Formatting /home
1391 if [ -n "$HOME_UUID" ]; then
1392 case "$HOME_FORMAT" in
1393 "")
1394 log "$HOME_UUID $(gettext "The partition will be kept...")" ;;
1395 *)
1396 format "$HOME_UUID" "$HOME_FORMAT" home_uuid
1397 esac
1398 fi
1400 log "$(gettext "Creating mount point:") $TARGET_ROOT"
1401 mkdir -p "$TARGET_ROOT" >> "$LOG" || error8
1402 # Mount target.
1403 local mount_fs="$ROOT_FORMAT"
1404 [ -z "$mount_fs" ] && mount_fs="$(filesys $ROOT_UUID)"
1405 mount -t "$mount_fs" "$ROOT_UUID" \
1406 "$TARGET_ROOT" >>"$LOG" 2>>"$LOG"
1407 if [ $(mount | \
1408 grep -c "mnt/target") == "0" ]; then
1409 error 4 "$ROOT_UUID: $(gettext "Unable to mount partition")"
1410 fi
1414 #------------
1415 # 4.3 umount
1416 #------------
1418 # copy log file, umount target and eject cdrom.
1419 umount_devices()
1421 # umount target
1422 if mount | grep -q "$TARGET_ROOT"; then
1423 log "$(gettext "Unmounting target partition:") $ROOT_UUID"
1424 umount -l "$TARGET_ROOT" 2>>$LOG
1425 fi
1427 # umount source
1428 if mount | grep -q "$SOURCE_ROOT"; then
1429 log "$(gettext "Unmounting:") $SOURCE_ROOT"
1430 umount -l "$SOURCE_ROOT"
1431 fi
1432 if [ -h $SOURCE_ROOT/boot ]; then
1433 log "$(gettext "Unlinking:") $SOURCE_ROOT"
1434 rm -f $SOURCE_ROOT/boot
1435 fi
1437 # eject cd
1438 if [ "$SOURCE" == "cdrom" ]; then
1439 gettext "Ejecting cdrom..."
1440 eject
1441 fi
1442 # remove lock file
1443 rm -f "$LOCK"
1446 end_of_install()
1448 log "\n$(gettext "Process completed. You can now restart (reboot)")"
1449 log "$(gettext "from your SliTaz GNU/Linux system.")"
1450 printf "%s\n" "=== Tazinst ended on $(date "+%x %X") ===" >> "$LOG"
1451 unset LOGGING
1452 # saving log
1453 log "$(gettext "Copying log to /var/log/tazinst.log")"
1454 cp -a "$LOG" $TARGET_ROOT/var/log
1455 umount_devices
1459 #---------------
1460 # 5. bootloader
1461 #---------------
1463 #------------
1464 # 5.1 common
1465 #------------
1467 # selection
1468 bootloader()
1470 if [ "$BOOTLOADER" == "auto" ]; then
1471 # use syslinux, but if p_table=msdos take grub (if available)
1472 unset BOOTLOADER
1473 printf "%s" "$(list_bootloader)" | \
1474 grep -q "syslinux" && BOOTLOADER=syslinux
1475 if [ "$(p_table $ROOT_UUID)" == "msdos" ]; then
1476 printf "%s" "$(list_bootloader)" | \
1477 grep -q " grub" && BOOTLOADER=grub
1478 fi
1479 fi
1480 case "$BOOTLOADER" in
1481 grub)
1482 grub_config
1483 grub_install ;;
1484 syslinux)
1485 syslinux_config
1486 syslinux_install ;;
1487 *)
1488 syslinux_config
1489 log "$(gettext "No bootloader to install.")" ;;
1490 esac
1493 # print disk num
1494 disknum()
1496 local partition="$(uuid2dev $1)"
1497 partition="${partition%[0-9]}"
1498 /usr/sbin/parted -lm | grep "^/dev" | \
1499 /bin/busybox awk -v PART="$partition" '{if (match($0,PART)) print NR-1}'
1502 # print partition num
1503 partnum()
1505 local partition="$(uuid2dev $1)"
1506 printf "%s\n" "$((${partition#/dev/[h-s]d[a-z]}-1))"
1509 # print root device
1510 rootdev()
1512 local partition="$1"
1513 case "$(p_table $partition)" in
1514 msdos)
1515 # print device
1516 printf "%s" "$(uuid2dev $partition)" ;;
1517 gpt)
1518 # print PARTUUID (different from UUID)
1519 printf "%s" "PARTUUID="
1520 /sbin/blkid -p -i -o udev $(uuid2dev $partition) \
1521 | grep ENTRY_UUID | cut -d '=' -f2 ;;
1522 esac
1525 # add rootdelay for removable devices
1526 rootdelay()
1528 is_removable "$ROOT_UUID" && printf "%s" "rootdelay=9"
1531 # print winboot uuid
1532 winboot_uuid()
1534 if [ "$WINBOOT" = "auto" ]; then
1535 # get the first uuid if any
1536 [ $(list_winboot | wc -w) -gt 1 ] \
1537 && printf "%s" "$(list_winboot | cut -d' ' -f2)"
1538 else
1539 printf "%s" "$WINBOOT"
1540 fi
1544 #-----------
1545 # 5.1 grub1
1546 #-----------
1548 # create grub legacy conf
1549 grub_config()
1551 # backup an existing conf
1552 [ -e "$TARGET_ROOT/boot/grub/menu.lst" ] && \
1553 cp $TARGET_ROOT/boot/grub/menu.lst \
1554 $TARGET_ROOT/boot/grub/menu.bak
1555 # create the target GRUB configuration.
1556 mkdir -p $TARGET_ROOT/boot/grub || error8
1557 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
1558 # /boot/grub/menu.lst: GRUB boot loader configuration.
1561 # By default, boot the first entry.
1562 default 0
1564 # Boot automatically after 8 secs.
1565 timeout 8
1567 # Graphical splash image.
1568 splashimage=/boot/grub/splash.xpm.gz
1570 # Change the colors.
1571 #color yellow/brown light-green/black
1573 # For booting SliTaz from : $ROOT_UUID
1575 title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
1576 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
1577 kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) quiet $(rootdelay)
1579 _EOF_
1581 local winpart="$(winboot_uuid)"
1582 if [ -n "$winpart" ]; then
1583 log "$(gettext "Enabling Windows dual-boot")"
1584 cat >> $TARGET_ROOT/boot/grub/menu.lst << _EOF_
1585 # For booting Windows :
1587 title Microsoft Windows
1588 rootnoverify (hd$(disknum $winpart),$(partnum $winpart))
1589 chainloader +1
1591 _EOF_
1592 fi
1594 # log
1595 printf "%s\n" "/boot/grub/menu.lst:" >> "$LOG"
1596 printf "%s\n" "--- menu.lst -------------" >> "$LOG"
1597 cat $TARGET_ROOT/boot/grub/menu.lst >> "$LOG"
1598 printf "%s\n\n" "--- menu.lst -------------" >> "$LOG"
1601 # GRUB info with disk name used for grub
1602 grub_install()
1604 # install grub
1605 local target_disk="$(uuid2disk $ROOT_UUID)"
1606 log "$(gettext "Installing grub on:") $target_disk"
1607 /usr/sbin/grub-install --version >> "$LOG" || error 5 "grub not found"
1608 /usr/sbin/grub-install --no-floppy \
1609 --root-directory=$TARGET_ROOT $target_disk >>"$LOG" 2>>"$LOG"
1610 # set boot flag
1611 log "$(gettext "Setting the boot flag")"
1612 /usr/sbin/parted "$(uuid2disk $ROOT_UUID)" \
1613 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1614 # splash image
1615 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
1616 log "$(gettext "Copying splash image")"
1617 mkdir -p $TARGET_ROOT/boot/grub
1618 cp $SOURCE_ROOT/boot/grub/splash.xpm.gz \
1619 $TARGET_ROOT/boot/grub
1620 fi
1624 #--------------
1625 # 5.2 syslinux
1626 #--------------
1628 # create syslinux conf
1629 syslinux_config()
1631 local version="[$(cat $TARGET_ROOT/etc/slitaz-release)]"
1632 version="$version\(Kernel $KERNEL)"
1633 # backup an existing conf
1634 [ -e "$TARGET_ROOT/boot/syslinux/syslinux.cfg" ] && \
1635 cp $TARGET_ROOT/boot/syslinux/syslinux.cfg \
1636 $TARGET_ROOT/boot/syslinux/syslinux.bak
1637 # create the target syslinux configuration.
1638 mkdir -p $TARGET_ROOT/boot/syslinux || error8
1639 cat > $TARGET_ROOT/boot/syslinux/syslinux.cfg << EOF
1640 # use a boot menu
1641 UI vesamenu.c32
1643 # display the boot
1644 PROMPT 1
1646 # how long to pause at the boot
1647 TIMEOUT 50
1649 # default label
1650 DEFAULT slitaz
1652 # Menu settings
1653 MENU TITLE SliTaz GNU/Linux boot menu
1654 MENU BACKGROUND splash.jpg
1655 MENU WIDTH 78
1656 MENU MARGIN 6
1657 MENU ROW 10
1658 MENU VSHIFT 2
1659 MENU TIMEOUTROW 18
1660 MENU TABMSGROW 16
1661 MENU CMDLINEROW 16
1663 # Menu colors
1664 MENU COLOR border * #00000000 #00000000 none
1665 MENU COLOR title * #ffffffff #00000000 *
1666 MENU COLOR sel 0 #ffffffff #00000000 none
1667 MENU COLOR unsel 0 #50ffffff #00000000 none
1668 MENU COLOR help * #ffffffff #00000000 *
1669 MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
1670 MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
1671 MENU COLOR msg07 37;40 #90ffffff #a0000000 std
1672 MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
1674 # Labels
1675 LABEL slitaz
1676 MENU LABEL SliTaz GNU/Linux $version
1677 LINUX /boot/$KERNEL
1678 APPEND root=$(rootdev $ROOT_UUID) quiet $(rootdelay)
1680 LABEL cmdline
1681 MENU LABEL Command Line
1682 MENU QUIT
1684 EOF
1685 local winpart="$(winboot_uuid)"
1686 if [ -n "$winpart" ]; then
1687 log "$(gettext "Enabling Windows dual-boot")"
1688 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg << EOF
1689 LABEL windows
1690 MENU LABEL Windows
1691 COM32 chain.c32
1692 APPEND hd$(disknum $winpart) $(($(partnum $winpart)+1))
1694 EOF
1695 fi
1696 # log
1697 printf "%s\n" "/boot/syslinux/syslinux.cfg:" >> "$LOG"
1698 printf "%s\n" "--- syslinux.cfg -------------" >> "$LOG"
1699 cat $TARGET_ROOT/boot/syslinux/syslinux.cfg >> "$LOG"
1700 printf "%s\n\n" "--- syslinux.cfg -------------" >> "$LOG"
1703 # install syslinux
1704 syslinux_install()
1706 log "$(gettext "Installing syslinux")"
1707 # needed tools
1708 local dir disk="$(uuid2disk $ROOT_UUID)"
1709 for dir in /home/boot/extlinux /home/boot/syslinux /boot/syslinux; do
1710 [ -d "$dir" ] && cp $dir/*.c32 "$TARGET_ROOT/boot/syslinux/"
1711 [ -d "$dir" ] && cp $dir/*.sys "$TARGET_ROOT/boot/syslinux/"
1712 done
1713 /usr/bin/lzma d /usr/share/boot/chain.c32.lzma \
1714 $TARGET_ROOT/boot/syslinux/chain.c32 2>> "$LOG"
1715 # install syslinux
1716 /bin/syslinux -version >> "$LOG" || error 5 "syslinux not found"
1717 /bin/extlinux --install $TARGET_ROOT/boot/syslinux >> "$LOG" 2>> "$LOG"
1718 case "$(p_table $ROOT_UUID)" in
1719 msdos)
1720 log "$(gettext "Setting the boot flag on")"
1721 /usr/sbin/parted "$disk" \
1722 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
1723 [ -r /usr/share/boot/mbr.bin ] || error 5 "mbr.bin not found"
1724 log "$(gettext "Installing mbr")"
1725 dd bs=440 count=1 conv=notrunc \
1726 if=/usr/share/boot/mbr.bin of=$disk >> "$LOG" ;;
1727 gpt)
1728 log "$(gettext "Setting the legacy_boot flag on")"
1729 # remove old boot flag
1730 local oldboot="$(parted $disk print \
1731 | grep boot | /bin/busybox awk '{print $1}')"
1732 /usr/sbin/parted "$disk" \
1733 set "$oldboot" legacy_boot off 2>> "$LOG"
1734 # set boot flag
1735 /usr/sbin/parted "$disk" \
1736 set "$(($(partnum $ROOT_UUID)+1))" legacy_boot on 2>> "$LOG"
1737 log "$(gettext "Installing gptmbr")"
1738 [ -r /usr/share/boot/gptmbr.bin ] || error 5 "gptmbr.bin not found"
1739 dd bs=440 conv=notrunc count=1 \
1740 if=/usr/share/boot/gptmbr.bin of=$disk >> "$LOG" ;;
1741 esac
1742 # splash image
1743 if [ -f "$SOURCE_ROOT/boot/isolinux/splash.jpg" ]; then
1744 log "$(gettext "Copying splash image")"
1745 cp -a $SOURCE_ROOT/boot/isolinux/splash.jpg \
1746 $TARGET_ROOT/boot/syslinux
1747 fi
1751 #--------------------
1752 # 6. execute section
1753 #--------------------
1755 execute()
1757 local mode="$(get mode)" sighup=1 sigint=2 sigquit=3
1758 randomize_mirrors
1759 trap "error9" "$sighup" "$sigint" "$sigquit"
1760 case "$mode" in
1761 install)
1762 install ;;
1763 upgrade)
1764 upgrade ;;
1765 esac
1768 #-------------
1769 # 6.1 install
1770 #-------------
1772 # get a clean target device
1773 clean_target()
1775 if [ -z "$ROOT_FORMAT" ]; then
1776 # partition was not formatted
1777 log "$(gettext "Cleaning the root partition") ($ROOT_UUID)..."
1778 # keep /home in case of reinstall.
1779 local path="$(pwd)"
1780 cd "$TARGET_ROOT" || error8
1781 local dir
1782 for dir in *
1783 do
1784 case "$dir" in
1785 home)
1786 log "$(gettext "keeping /home found on:") $ROOT_UUID"
1787 mv home home.bak ;;
1788 lost+found)
1789 continue ;;
1790 *)
1791 log "$(gettext "removing target:") $dir"
1792 rm -rf "$dir" 2>>"$LOG" ;;
1793 esac
1794 done
1795 if [ ! -d lost+found ]; then
1796 mklost+found 2>>"$LOG"
1797 fi
1798 cd "$path" || error8
1799 fi
1802 # kernel is renamed to standard vmlinuz-$VERSION.
1803 install_kernel()
1805 if [ -d /$TARGET_ROOT/lib/modules ]; then
1806 KERNEL=$(ls /$TARGET_ROOT/lib/modules | tail -1)
1807 KERNEL="vmlinuz-$KERNEL"
1808 else
1809 KERNEL="vmlinuz-$(uname -r)"
1810 log "$(gettext "Kernel name not found, falling back to:") $(uname -r)"
1811 fi
1812 mkdir -p $TARGET_ROOT/boot || error8
1813 cp $SOURCE_ROOT/boot/bzImage $TARGET_ROOT/boot/$KERNEL
1814 log "$(gettext "install_kernel:") $KERNEL"
1817 # extract packed rootfs: squashfs or cromfs
1818 extract_loramfs()
1820 local i
1821 for i in $(/bin/busybox cpio -idvum 2> /dev/null); do
1822 case "$i" in
1823 rootfs*)
1824 need_package squashfs
1825 if ! unsquashfs $i ; then
1826 need_package cromfs
1827 unmkcromfs $i squashfs-root
1828 fi
1829 mv -f squashfs-root/* .
1830 rmdir squashfs-root
1831 rm -f $i
1832 esac
1833 done
1836 # this is a loram rootfs.gz, skip loram bootstrap and extract
1837 extract_first_loramfs()
1839 local path="$(pwd)"
1840 (zcat $1 || /usr/bin/unlzma -c $1) | \
1841 /bin/busybox cpio -i extractfs.cpio 2> /dev/null &&
1842 ( cd / ; /bin/busybox cpio -id ) < extractfs.cpio && \
1843 rm -f extractfs.cpio
1844 ofs=$(/bin/busybox awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
1845 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
1846 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
1847 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | \
1848 extract_loramfs
1849 cd "$path" || error8
1852 # extract lzma'ed or gziped rootfs.
1853 extract_rootfs()
1855 local path="$(pwd)"
1856 local isloramfs
1857 cd "$TARGET_ROOT" || error8
1858 if [ -d "$1"/../fs/etc ]; then
1859 # this is a tazlitobox loram (cdrom)
1860 cp -a "$1"/../fs/. .
1861 else
1862 for i in $(ls "$1"/rootfs* | sort -r); do
1863 if [ ! -d etc ]; then
1864 if [ $( (zcat "$i" 2>/dev/null \
1865 || /usr/bin/lzma d "$i" -so) | \
1866 wc -c) -lt $(stat -c %s "$i") ]; then
1867 # this is a tazlitobox loram (ram)
1868 isloramfs="$i"
1869 extract_first_loramfs "$i"
1870 continue
1871 fi
1872 fi
1873 if [ -n "$isloramfs" ]; then
1874 extract_loramfs < "$i"
1875 continue
1876 fi
1877 ( zcat "$i" 2>/dev/null || /usr/bin/lzma d "$i" -so || \
1878 cat "$i" ) 2>>"$LOG" | /bin/busybox cpio -idu
1879 done 2>>"$LOG" > /dev/null
1880 fi
1881 cp /etc/keymap.conf etc
1882 # unpack /usr (double check...)
1883 if ls etc/tazlito | grep -q ".extract"; then
1884 for i in etc/tazlito/*.extract; do
1885 [ -f "$i" ] && . "$i" /media/cdrom
1886 done
1887 fi
1888 cd "$pwd" || error8
1892 # pre configure freshly installed system (60 - 80%).
1893 pre_config_system()
1895 local path="$(pwd)"
1896 cd "$TARGET_ROOT" || error8
1897 # restore backup of existing /home if exists.
1898 # (created by prepare_target_dev)
1899 if [ -d home.bak ]; then
1900 log "$(gettext "Restoring directory: /home...")"
1901 rm -rf home
1902 mv home.bak home
1903 fi
1904 # add root device to CHECK_FS in rcS.conf to check filesystem
1905 # on each boot.
1906 log "$(gettext "Adding / partition and CHECK_FS to file /etc/rcS.conf...")"
1907 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$ROOT_UUID\""# etc/rcS.conf
1908 # set hostname.
1909 log "$(gettext "Configuring host name:") $HOSTNAME"
1910 printf "%s\n" "$HOSTNAME" > etc/hostname
1911 printf "%s\n" "127.0.0.1 localhost $HOSTNAME tazpanel" > etc/hosts
1912 cd "$path" || error8
1915 # set root passwd and create user after rootfs extraction.
1916 users_settings()
1918 # create file
1919 cat > "$TARGET_ROOT/users.sh" << _EOF_
1920 #!/bin/sh
1921 umask 0022
1922 printf "root:%s" "$ROOT_PWD" | chpasswd -m
1923 adduser -D -H $USER_LOGIN
1925 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
1926 if ! grep \$grp /etc/group | grep -q $USER_LOGIN ; then
1927 grep -q \$grp /etc/group && addgroup $USER_LOGIN \$grp
1928 fi
1929 done
1931 printf "%s:%s" "$USER_LOGIN" "$USER_PWD" | chpasswd -m
1932 if [ ! -d /home/$USER_LOGIN ]; then
1933 cp -a /etc/skel /home/$USER_LOGIN
1934 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$USER_LOGIN
1935 mkdir -p /home/$USER_LOGIN/.config/slitaz
1936 cp -a /etc/slitaz/applications.conf /home/$USER_LOGIN/.config/slitaz
1937 # Set ownership
1938 if grep -q ^users: /etc/group; then
1939 chown -R $USER_LOGIN:users /home/$USER_LOGIN
1940 else
1941 chown -R $USER_LOGIN:$USER_LOGIN /home/$USER_LOGIN
1942 fi
1943 # Path for user desktop files.
1944 for i in /home/$USER_LOGIN/.local/share/applications/*.desktop
1945 do
1946 [ -e "$i" ] && sed -i s/"user_name"/"$USER_LOGIN"/g \$i
1947 done
1948 fi
1949 # Slim default user.
1950 if [ -f /etc/slim.conf ]; then
1951 sed -i s/"default_user .*"/"default_user $USER_LOGIN"/ \
1952 /etc/slim.conf
1953 fi
1954 _EOF_
1955 chmod o+x "$TARGET_ROOT/users.sh"
1956 chroot "$TARGET_ROOT" ./users.sh 2>>"$LOG" >> "$LOG"
1957 rm "$TARGET_ROOT/users.sh"
1958 umask 0177
1961 # /home can be on a separate partition. If default user exists in /home
1962 # we remove default file created by users_settings().
1963 home_config()
1965 if [ -n "$HOME_UUID" ]; then
1966 local path="$(pwd)" uuid
1967 cd "$TARGET_ROOT" || error8
1968 # detect fs
1969 local home_fs="$HOME_FORMAT"
1970 [ -z "$home_fs" ] && home_fs="$(filesys $HOME_UUID)"
1971 # manage /home
1972 log "$(gettext "Configuring partition to be used as /home:") $HOME_UUID"
1973 mv home/$USER_LOGIN tmp
1974 mount -t "$home_fs" "$HOME_UUID" home >> "$LOG" 2>> "$LOG"
1975 if [ -d $TARGET_ROOT/home/$USER_LOGIN ]; then
1976 rm -rf tmp/home/$USER_LOGIN
1977 else
1978 mv tmp/$USER_LOGIN home
1979 fi
1980 # write entry in fstab, force uuid
1981 uuid="$(dev2uuid "$HOME_UUID")"
1982 printf "%b\n" "$uuid /home $home_fs defaults \t0 \t2" >> etc/fstab
1983 umount home >> "$LOG" 2>> "$LOG"
1984 cd "$path" || error8
1985 fi
1988 install()
1990 log_open
1991 log "1 $(gettext "Installing SliTaz on:") $(get root_uuid)"
1992 log "5 $(gettext "Checking settings")..."
1993 check all >> "$LOG" 2>> "$LOG"
1994 load_settings
1996 log "10 $(gettext "Preparing source media")..."
1997 mount_source
1999 log "20 $(gettext "Preparing target disk")..."
2000 prepare_uuid
2002 log "30 $(gettext "Cleaning the root partition if necessary")..."
2003 clean_target
2005 log "40 $(gettext "Extracting the root system")..."
2006 extract_rootfs $SOURCE_ROOT/boot
2008 log "50 $(gettext "Installing the kernel")..."
2009 install_kernel
2011 log "60 $(gettext "Preconfiguring the system")..."
2012 pre_config_system
2014 log "70 $(gettext "Configuring root and default user account")..."
2015 users_settings
2017 log "80 $(gettext "Configuring /home")..."
2018 home_config
2020 log "90 $(gettext "Checking bootloader installation...")"
2021 bootloader
2023 log "100 $(gettext "Files installation completed")"
2024 end_of_install
2028 #-------------
2029 # 6.2 upgrade
2030 #-------------
2032 # search for SliTaz
2033 check_release()
2035 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
2036 local release="$(cat $TARGET_ROOT/etc/slitaz-release)"
2037 log "$(gettext "Preparing upgrade of SliTaz release:") $release"
2038 else
2039 error 6 "$ROOT_UUID: $(gettext "This partition doesn't appear to \
2040 contain a valid SliTaz system, the file: /etc/slitaz-release doesn't exist.")"
2041 fi
2044 # backup packages list.
2045 backup_files()
2047 local path="$(pwd)"
2048 cd "$TARGET_ROOT" || error8
2049 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
2050 local dir
2051 for dir in *
2052 do
2053 case "$dir" in
2054 boot)
2055 rm -rf boot/vmlinuz-* ;;
2056 home)
2057 mv home home.bak
2058 log "$(gettext "keeping /home found on:") $ROOT_UUID" ;;
2059 etc)
2060 /bin/busybox tar czf etc.tar.gz etc
2061 mv etc etc.bak
2062 log "$(gettext "keeping /etc found on:") $ROOT_UUID" ;;
2063 var)
2064 if [ -d var/www ]; then
2065 mv var/www www.bak
2066 log "$(gettext "keeping /var/www found on:") $ROOT_UUID"
2067 fi
2068 rm -rf var 2>>"$LOG" ;;
2069 lost+found)
2070 continue ;;
2071 *)
2072 log "$(gettext "removing target: $dir")"
2073 rm -rf "$dir" 2>>"$LOG" ;;
2074 esac
2075 done
2076 if [ -d mklost+found ]; then
2077 mklost+found 2>>"$LOG"
2078 fi
2079 cd "$path" || error8
2082 # restore backups.
2083 restore_files()
2085 rm -rf $TARGET_ROOT/home
2086 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
2087 rm -rf $TARGET_ROOT/etc
2088 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
2089 if [ -d $TARGET_ROOT/www.bak ]; then
2090 rm -rf $TARGET_ROOT/var/www
2091 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
2092 fi
2093 log "$(gettext "backups restored:") $(date)"
2095 # /var/lib/slitaz-installer
2096 mkdir -p $TARGET_ROOT/var/lib/tazinst && \
2097 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst && \
2098 mv $TARGET_ROOT/home/packages-selection.list \
2099 $TARGET_ROOT/var/lib/tazinst \
2100 && log "$(gettext "backups saved in /var/lib/tazinst")"
2103 # upgrade added pkgs
2104 install_pkgs()
2106 # check if the pkg is on the mirror.
2107 log "$(gettext "Checking the availability of packages...")"
2108 touch packages-to-install.list
2109 packages=0
2110 diff="$(cat packages-selection.diff | sort)"
2111 for pkg in $diff
2112 do
2113 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
2114 packages="$(($packages+1))"
2115 printf "%s\n" "$pkg" >> packages-to-install.list
2116 fi
2117 done
2119 # install packages.
2120 log "$(gettext "Installing packages...")"
2121 if [ "$packages" == "0" ]; then
2122 log "$(gettext "packages to install: 0")"
2123 else
2124 # get-install all missing pkgs.
2125 for pkg in $(cat packages-to-install.list)
2126 do
2127 log "$(gettext "Installing:") $pkg..."
2128 # get install package and answer yes in case of dependencies.
2129 pkgname="$(grep ^$pkg /var/lib/tazpkg/packages.list)"
2130 /usr/bin/tazpkg get "$pkg" >/dev/null 2>/dev/null
2131 yes "" | /usr/bin/tazpkg install $pkgname.tazpkg \
2132 --root=$TARGET_ROOT >/dev/null 2>/dev/null
2133 rm -f $pkgname.tazpkg
2134 done
2135 fi
2136 log "$(gettext "Installation of packages complete...")"
2139 # search for added pkgs
2140 update_pkgs()
2142 local path="$(pwd)"
2143 cd $TARGET_ROOT/var/lib/tazinst || error8
2144 # LiveCD packages list.
2145 log "$(gettext "Creating package lists...")"
2146 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || error8
2147 log "$(gettext "packages-source.list: done")"
2148 # diff
2149 /bin/busybox diff packages-source.list packages-selection.list | \
2150 grep ^+[a-z] | sed s/^+// > packages-selection.diff
2151 log "$(gettext "packages-selection.diff: done")"
2152 # get mirror list.
2153 /usr/bin/tazpkg recharge >>$LOG 2>>$LOG
2154 if [ -f /var/lib/tazpkg/packages.list ]; then
2155 install_pkgs
2156 else
2157 touch packages-to-install.list
2158 printf "%s\n" "$(gettext "The list of available packages on the mirror \
2159 could not be downloaded. No missing packages will be reinstalled now, but you \
2160 can do so later by looking at the following list:
2161 /var/lib/tazinst/packages-selection.diff")"
2162 fi
2163 cd "$path" || error8
2166 # upgrade command
2167 upgrade()
2169 log_open
2170 log "1 $(gettext "Upgrading SliTaz on:") $(get root_uuid)"
2171 log "5 $(gettext "Checking settings")..."
2172 check all >> "$LOG"
2173 load_settings
2175 log "10 $(gettext "Preparing source media")..."
2176 mount_source
2178 log "20 $(gettext "Preparing target disk")..."
2179 prepare_uuid
2181 log "30 $(gettext "Searching for /etc/slitaz-release")..."
2182 check_release
2184 log "40 $(gettext "Backup /etc, /home and the packages list")..."
2185 backup_files
2187 log "50 $(gettext "Extracting the root system")..."
2188 extract_rootfs $SOURCE_ROOT/boot
2190 log "60 $(gettext "Restoring configuration files")..."
2191 restore_files
2193 log "70 $(gettext "Installing the kernel")..."
2194 install_kernel
2196 log "80 $(gettext "Upgrading added packages")..."
2197 update_pkgs
2199 log "90 $(gettext "Bootloader")..."
2200 bootloader
2202 log "100 $(gettext "Files installation completed")"
2203 end_of_install
2207 #--------------
2208 # tazinst main
2209 #--------------
2211 case $1 in
2212 new)
2213 new_file "$2" ;;
2214 set)
2215 read_file "$4"
2216 change "$2" "$3" "$4" ;;
2217 unset)
2218 read_file "$3"
2219 change "$2" "" "$3" "$4" ;;
2220 get)
2221 read_file "$3"
2222 get "$2" ;;
2223 check)
2224 read_file "$3"
2225 check "$2" ;;
2226 list)
2227 list "$2" "$3" ;;
2228 execute)
2229 check_root
2230 read_file "$2"
2231 execute "$2" ;;
2232 log)
2233 [ -r "$LOG" ] && cat "$LOG" ;;
2234 clean)
2235 clean "$2" ;;
2236 version)
2237 printf "%s\n" "$VERSION" ;;
2238 ""|usage)
2239 usage ;;
2240 help)
2241 help "$2" ;;
2242 *)
2243 usage_error "$1" ;;
2244 esac