slitaz-tools view tinyutils/slitaz-installer.sh @ rev 62

Slitaz-installer.sh: add slitaz-loram-cdrom support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Feb 22 14:36:42 2008 +0100 (2008-02-22)
parents 06813db5603b
children dc013a900d49
line source
1 #!/bin/sh
2 # slitaz-installer.sh - SliTaz GNU/Linux installer script.
3 #
4 # So this is SliTaz installer all in SHell script compatible Ash from Busybox.
5 # All the comments are in English but displayed messages are in French. The
6 # scrip starts with a few main variables, then all the functions and then
7 # a sequece of functions.
8 #
9 # (C) 2007-2008 SliTaz - GNU General Public License v3.
10 #
11 # Author : Christophe Lincoln <pankso@slitaz.org>
12 #
13 VERSION=0.1
15 # We need to know cdrom device and kernel version string
16 # to copy files.
17 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
18 CDROM=/dev/$DRIVE_NAME
19 TARGET_ROOT=/mnt/target
20 KERNEL=vmlinuz-`uname -r`
22 #######################
23 # Installer functions #
24 #######################
26 # Status function.
27 status()
28 {
29 local CHECK=$?
30 echo -en "\\033[70G[ "
31 if [ $CHECK = 0 ]; then
32 echo -en "\\033[1;33mOK"
33 else
34 echo -en "\\033[1;31mFailed"
35 fi
36 echo -e "\\033[0;39m ]"
37 }
39 # Start install with basic informations.
40 start_infos()
41 {
42 clear
43 echo ""
44 echo -e "\033[1mSliTaz GNU/Linux - Installateur mode texte\033[0m
45 ================================================================================
47 Bienvenue dans l'installateur en mode texte de SliTaz GNU/Linux. Il vous
48 suffirat de répondre à quelques questions lors des différentes étapes
49 d'installation. Avant de commencer, assurer vous de connaître le nom de la
50 partitions sur laquelle vous désirez installer SliTaz. L'installateur va
51 commencer par vous proposer de formater la partition cible et la monter.
52 Ensuite il va monter le cdrom, décompresser les fichiers et les installer
53 sur la cible. Pour finir, vous aurez aussi la possibilité d'installer le
54 gestionnaire de démarrage GRUB, si besoin est. A noter que pour continuer
55 cette installation, vous devez avoir les droits d'administrateur root, qui
56 peuvent s'obtenir via la commande 'su' et le mot de passe 'root'.
58 ================================================================================"
59 echo ""
60 echo -n "Commencer l'installation (oui/Non) ? "; read anser
61 if [ ! "$anser" = "oui" ]; then
62 echo -e "\nArrêt volontaire.\n"
63 exit 0
64 fi
65 }
67 # Exit install if user is not root.
68 check_root()
69 {
70 if test $(id -u) != 0 ; then
71 echo -e "
72 Vous devez être root pour continuer l'installation du système. Arrêt.
73 Vous pouvez utiliser 'su' suivi du mot de passe root pour devenir
74 administarteur.\n"
75 exit 0
76 fi
77 }
79 # Display a list of available partition.
80 fdisk_list()
81 {
82 echo ""
83 fdisk -l | grep ^/dev
84 echo ""
85 }
87 # We need a partition to install.
88 ask_for_target_dev()
89 {
90 echo ""
91 echo -e "\033[1mPartition racine\033[0m
92 ================================================================================
94 Veuilliez indiquer la partition à utiliser pour installer SliTaz GNU/Linux,
95 exemple : '/dev/hda1'. Vous pouvez tapez 'list' pour afficher une liste
96 des partitions disponibles sur le ou les disques durs."
97 echo ""
98 echo -n "Partition à utiliser : "; read anser
99 while [ "$anser" == "list" ]; do
100 fdisk_list
101 echo -n "Partition à utiliser : "; read anser
102 done
103 if [ "$anser" == "" ]; then
104 echo -e "\nPas de partition spécifiée. Arrêt.\n"
105 exit 0
106 else
107 TARGET_DEV=$anser
108 fi
109 }
111 # Mkfs if needed/wanted.
112 mkfs_target_dev()
113 {
114 echo ""
115 echo "SliTaz va être installé sur la partition : $TARGET_DEV"
116 echo ""
117 echo -n "Faut t'il formater la partition en ext3 (oui/Non) ? "; read anser
118 if [ "$anser" == "oui" ]; then
119 mkfs.ext3 $TARGET_DEV
120 else
121 echo "Le système de fichiers déjà présent sera utilisé..."
122 fi
123 }
125 # Mount target device and cdrom.
126 mount_devices()
127 {
128 echo ""
129 mkdir -p $TARGET_ROOT /media/cdrom
130 echo "Montage de la partitions et du cdrom..."
131 # Mount points can be already used.
132 if mount | grep $TARGET_ROOT; then
133 umount $TARGET_ROOT
134 fi
135 if mount | grep /media/cdrom; then
136 umount /media/cdrom
137 fi
138 mount $TARGET_DEV $TARGET_ROOT
139 mount -t iso9660 $CDROM /media/cdrom || exit 1
140 }
142 # Copy and install Kernel.
143 install_kernel()
144 {
145 echo ""
146 echo -n "Création du répertoire /boot..."
147 mkdir -p $TARGET_ROOT/boot
148 status
149 echo -n "Copie du noyau Linux..."
150 cp /media/cdrom/boot/bzImage $TARGET_ROOT/boot/$KERNEL
151 status
152 }
154 # Syslinux/isolinux.
155 copy_bootloaders()
156 {
157 echo -n "Copie des bootloaders syslinux/isolinux..."
158 if [ -d "/media/cdrom/boot/syslinux" ]; then
159 cp -a /media/cdrom/boot/syslinux $TARGET_ROOT/boot
160 fi
161 if [ -d "/media/cdrom/boot/isolinux" ]; then
162 cp -a /media/cdrom/boot/isolinux $TARGET_ROOT/boot
163 fi
164 status
165 }
167 # Copy and extract lzma'ed or gziped rootfs.
168 copy_extract_rootfs()
169 {
170 echo -n "Copie du système de fichier racine..."
171 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
172 status
173 echo "Extraction du système de fichiers racine (rootfs.gz)..."
174 cd $TARGET_ROOT
175 ( zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so 2>/dev/null || \
176 cat rootfs.gz ) | cpio -id
177 # remove link to cdrom
178 [ -d cdrom ] && rmdir cdrom
179 if [ -L usr ]; then
180 rm usr
181 mv ../rootcd/usr .
182 fi
183 # unpack /usr
184 $sqfs="../rootcd/usr.sqfs"
185 [ -f $sqfs ] || sqfs=".usr.sqfs"
186 if [ -f $sqfs ]; then
187 echo -en "\nDécompression de /usr... "
188 rmdir usr
189 sbin/unsquashfs -d usr $sqfs
190 rm $sqfs
191 fi
192 if [ -d usr/.moved ]; then
193 echo -en "\nRestoration des fichiers déplacés dans /usr... "
194 ( cd usr/.moved ; find * -print ) | \
195 while read file; do
196 [ -L "$file" ] || continue
197 rm -f "$file"
198 mv "usr/.moved/$file" "$file"
199 done
200 rm -rf usr/.moved
201 fi
202 echo ""
203 echo -n "Suppression des fichiers copiés..."
204 rm -f rootfs.gz init
205 status
206 }
208 # Pre configure freshly installed system.
209 pre_config_system()
210 {
211 # /etc/skel with hacker default personnal files.
212 echo -n "Copie des fichiers personnels de hacker dans : /etc/skel..."
213 cp -a $TARGET_ROOT/home/hacker $TARGET_ROOT/etc/skel
214 status
215 # Add root device to CHECK_FS in rcS.conf to check filesystem
216 # on each boot.
217 echo -n "Configuration de CHECK_FS dans /etc/rcS.conf..."
218 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# $TARGET_ROOT/etc/rcS.conf
219 status
220 sleep 2
221 }
223 # Determin disk letter, GRUB partition number and GRUB disk number.
224 grub_install()
225 {
226 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
227 DISK_LETTER=${DISK_LETTER%[0-9]}
228 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
229 for disk in a b c d e f g h
230 do
231 nb=$(($nb+1))
232 if [ "$disk" = "$DISK_LETTER" ]; then
233 GRUB_DISK=$(($nb-1))
234 break
235 fi
236 done
237 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
239 # Creat the target GRUB configuration.
240 echo -n "Création du fichier de configuration de GRUB (menu.lst)..."
241 mkdir -p $TARGET_ROOT/boot/grub
242 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
243 # /boot/grub/menu.lst: GRUB boot loader configuration.
244 #
246 # By default, boot the first entry.
247 default 0
249 # Boot automatically after 8 secs.
250 timeout 8
252 # Change the colors.
253 color yellow/brown light-green/black
255 # For booting SliTaz from : $TARGET_DEV
256 #
257 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
258 root $GRUB_ROOT
259 kernel /boot/$KERNEL root=$TARGET_DEV
261 _EOF_
262 status
263 # GRUB info with disk name used for grub-install
264 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
265 echo ""
266 echo -e "\033[1mGRUB - Informations et installation\033[0m
267 ================================================================================
269 Avant de redémarrer sur votre nouveau système SliTaz GNU/Linux, veuillez vous
270 assurer qu'un gestionnaire de démarrage est bien installé. Si ce n'est pas le
271 cas vous pouvez répondre oui et installer GRUB ou lancer la commande :
273 # grub-install --no-floppy --root-directory=$TARGET_ROOT $TARGET_DISK
275 Les lignes suivantes on été ajoutées au fichier de configuration de GRUB
276 /boot/grub/menu.lst de la cible. Elles feront démarrer SliTaz en installant
277 GRUB. Si vous n'installez pas GRUB, vous pouvez utiliser ces même lignes dans
278 un autre fichier menu.lst, situé sur une autre partitions :
280 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
281 root $GRUB_ROOT
282 kernel /boot/$KERNEL root=$TARGET_DEV
284 ================================================================================"
285 echo ""
287 # GRUB install
288 echo -n "Installer GRUB sur le disque : $TARGET_DISK (oui/Non) ? "; read anser
289 if [ "$anser" = "oui" ]; then
290 grub-install --no-floppy --root-directory=$TARGET_ROOT $TARGET_DISK
291 else
292 echo "GRUB n'a pas été installé."
293 fi
294 }
296 # End of installation
297 end_of_install()
298 {
299 echo ""
300 echo -e "\033[1mFin de l'installation\033[0m
301 ================================================================================
303 Installation terminée. Vous pouvez dès maintenant redémarrer sur votre nouveau
304 système SliTaz GNU/Linux et commencer à finement le configurer en fonction de
305 vos besoins et préférences. Vous trouverez un support technique gratuit via
306 la liste de discussion et/ou le forum officiel du projet."
307 echo ""
308 }
310 ######################
311 # Installer sequence #
312 ######################
314 start_infos
315 check_root
316 ask_for_target_dev
317 mkfs_target_dev
318 mount_devices
319 install_kernel
320 copy_bootloaders
321 copy_extract_rootfs
322 pre_config_system
323 grub_install
324 end_of_install
326 exit 0