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

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