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

Slitaz-installer: really remove .moved subdir
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 20 14:06:37 2008 +0100 (2008-02-20)
parents bedae04e5027
children f94b63df3b77
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 if [ -f .usr.sqfs ]; then
178 echo -en "\nDécompression de /usr... "
179 /sbin/unsquashfs .usr.sqfs
180 if [ -d squashfs-root/.moved ]; then
181 ( cd squashfs-root/.moved ; find * -type f -print ) | \
182 while read $file; do
183 rm -f $file
184 mv squashfs-root/.moved/$file $file
185 done
186 rm -rf squashfs-root/.moved
187 fi
188 mv squashfs-root/* usr
189 rmdir squashfs-root
190 fi
191 echo ""
192 echo -n "Suppression des fichiers copiés..."
193 rm -f rootfs.gz init
194 status
195 }
197 # Pre configure freshly installed system.
198 pre_config_system()
199 {
200 # /etc/skel with hacker default personnal files.
201 echo -n "Copie des fichiers personnels de hacker dans : /etc/skel..."
202 cp -a $TARGET_ROOT/home/hacker $TARGET_ROOT/etc/skel
203 status
204 # Add root device to CHECK_FS in rcS.conf to check filesystem
205 # on each boot.
206 echo -n "Configuration de CHECK_FS dans /etc/rcS.conf..."
207 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# $TARGET_ROOT/etc/rcS.conf
208 status
209 sleep 2
210 }
212 # Determin disk letter, GRUB partition number and GRUB disk number.
213 grub_install()
214 {
215 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
216 DISK_LETTER=${DISK_LETTER%[0-9]}
217 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
218 for disk in a b c d e f g h
219 do
220 nb=$(($nb+1))
221 if [ "$disk" = "$DISK_LETTER" ]; then
222 GRUB_DISK=$(($nb-1))
223 break
224 fi
225 done
226 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
228 # Creat the target GRUB configuration.
229 echo -n "Création du fichier de configuration de GRUB (menu.lst)..."
230 mkdir -p $TARGET_ROOT/boot/grub
231 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
232 # /boot/grub/menu.lst: GRUB boot loader configuration.
233 #
235 # By default, boot the first entry.
236 default 0
238 # Boot automatically after 8 secs.
239 timeout 8
241 # Change the colors.
242 color yellow/brown light-green/black
244 # For booting SliTaz from : $TARGET_DEV
245 #
246 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
247 root $GRUB_ROOT
248 kernel /boot/$KERNEL root=$TARGET_DEV
250 _EOF_
251 status
252 # GRUB info with disk name used for grub-install
253 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
254 echo ""
255 echo -e "\033[1mGRUB - Informations et installation\033[0m
256 ================================================================================
258 Avant de redémarrer sur votre nouveau système SliTaz GNU/Linux, veuillez vous
259 assurer qu'un gestionnaire de démarrage est bien installé. Si ce n'est pas le
260 cas vous pouvez répondre oui et installer GRUB ou lancer la commande :
262 # grub-install --no-floppy --root-directory=$TARGET_ROOT $TARGET_DISK
264 Les lignes suivantes on été ajoutées au fichier de configuration de GRUB
265 /boot/grub/menu.lst de la cible. Elles feront démarrer SliTaz en installant
266 GRUB. Si vous n'installez pas GRUB, vous pouvez utiliser ces même lignes dans
267 un autre fichier menu.lst, situé sur une autre partitions :
269 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
270 root $GRUB_ROOT
271 kernel /boot/$KERNEL root=$TARGET_DEV
273 ================================================================================"
274 echo ""
276 # GRUB install
277 echo -n "Installer GRUB sur le disque : $TARGET_DISK (oui/Non) ? "; read anser
278 if [ "$anser" = "oui" ]; then
279 grub-install --no-floppy --root-directory=$TARGET_ROOT $TARGET_DISK
280 else
281 echo "GRUB n'a pas été installé."
282 fi
283 }
285 # End of installation
286 end_of_install()
287 {
288 echo ""
289 echo -e "\033[1mFin de l'installation\033[0m
290 ================================================================================
292 Installation terminée. Vous pouvez dès maintenant redémarrer sur votre nouveau
293 système SliTaz GNU/Linux et commencer à finement le configurer en fonction de
294 vos besoins et préférences. Vous trouverez un support technique gratuit via
295 la liste de discussion et/ou le forum officiel du projet."
296 echo ""
297 }
299 ######################
300 # Installer sequence #
301 ######################
303 start_infos
304 check_root
305 ask_for_target_dev
306 mkfs_target_dev
307 mount_devices
308 install_kernel
309 copy_bootloaders
310 copy_extract_rootfs
311 pre_config_system
312 grub_install
313 end_of_install
315 exit 0