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