slitaz-tools diff installer/slitaz-installer @ rev 94

slitaz-installer now support system upgrade
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 09 20:37:23 2008 +0100 (2008-03-09)
parents 8b02478373a7
children 64a7fea3e8fa
line diff
     1.1 --- a/installer/slitaz-installer	Sun Mar 09 18:01:50 2008 +0000
     1.2 +++ b/installer/slitaz-installer	Sun Mar 09 20:37:23 2008 +0100
     1.3 @@ -32,13 +32,13 @@
     1.4  Bienvenue dans l'installateur de SliTaz GNU/Linux. Vous pouvez utiliser \
     1.5  les flèches du clavier et la touche ENTER ou la souris pour valider. Il vous \
     1.6  suffira de répondre à quelques questions lors des différentes étapes \
     1.7 -d'installation. L'installateur va commencer par monter le cdrom, vous \
     1.8 -demander la partition à utiliser comme racine du système et vous proposer \
     1.9 -de la formater. Ensuite il va copier les fichiers depuis le cdrom, les \
    1.10 -décompresser, les installer et va préconfigurer le système. Pour finir,
    1.11 -vous aurez aussi la possibilité d'installer le gestionnaire de démarrage 
    1.12 -GRUB, si besoin est.\n\n
    1.13 -\Z2Commencer l'installation ?\Zn"
    1.14 +d'installation ou de mise à jour. Dans le cas d'une nouvelle installation, \
    1.15 +l'installateur va vous demander la partition à utiliser comme racine du \
    1.16 +système et vous proposer de la formater. Ensuite il va copier les fichiers \
    1.17 +depuis le cdrom, les décompresser, les installer et va préconfigurer le \
    1.18 +système. Pour finir, vous aurez aussi la possibilité d'installer le \
    1.19 +gestionnaire de démarrage GRUB, si besoin est.\n\n
    1.20 +\Z2Commencer une installation ou une mise à jour ?\Zn"
    1.21  
    1.22  #######################
    1.23  # Installer functions #
    1.24 @@ -70,27 +70,39 @@
    1.25  # This function is used after each screen to contine or abort install.
    1.26  check_retval()
    1.27  {
    1.28 -case $retval in
    1.29 -	0)
    1.30 -		continue ;;
    1.31 -	1)
    1.32 -		echo -e "\nArrêt volontaire.\n" && exit 0 ;;
    1.33 -	3)
    1.34 -		continue ;;
    1.35 -	255)
    1.36 -		echo -e "ESC pressed.\n" && exit 0 ;;
    1.37 -esac
    1.38 +	case $retval in
    1.39 +		0)
    1.40 +			continue ;;
    1.41 +		1)
    1.42 +			echo -e "\nArrêt volontaire.\n" && exit 0 ;;
    1.43 +		3)
    1.44 +			continue ;;
    1.45 +		255)
    1.46 +			echo -e "ESC pressed.\n" && exit 0 ;;
    1.47 +	esac
    1.48  }
    1.49  
    1.50  # Start install with basic informations.
    1.51 -start_install()
    1.52 +start_installer()
    1.53  {
    1.54 -	$DIALOG --title " Débuter l'installation " \
    1.55 +	$DIALOG --title " Installation ou mise à jour " \
    1.56  		--backtitle "$BACKLIST" \
    1.57 +		--extra-button --extra-label "Upgrade" \
    1.58 +		--yes-label "Install" \
    1.59 +		--no-label "Quit" \
    1.60  		--clear --colors --yesno "$START_INSTALL_MSG" 18 70
    1.61  	retval=$?
    1.62 -	check_retval
    1.63 -	echo "start_infos: `date`" > $LOG
    1.64 +		case $retval in
    1.65 +		0)
    1.66 +			ACTION=install ;;
    1.67 +		1)
    1.68 +			echo -e "\nArrêt volontaire.\n" && exit 0 ;;
    1.69 +		3)
    1.70 +			ACTION=upgrade ;;
    1.71 +		255)
    1.72 +			echo -e "ESC pressed.\n" && exit 0 ;;
    1.73 +	esac
    1.74 +	echo "start_installer: `date`" > $LOG
    1.75  }
    1.76  
    1.77  # Mount cdrom and verify if it's realy SliTaz CD.
    1.78 @@ -255,11 +267,11 @@
    1.79  		--backtitle "$BACKLIST" --clear \
    1.80  		--colors --inputbox "\n
    1.81  Veuillez indiquer le nom de machine à utiliser pour votre système SliTaz.\
    1.82 -Le nom de machine ou 'hostname' est utilisé pour identifier votre machine sur
    1.83 -le réseau et en local par le système (defaut: slitaz). A noter que cette\
    1.84 +Le nom de machine ou 'hostname' est utilisé pour identifier votre machine sur \
    1.85 +le réseau et en local par le système (defaut: slitaz). A noter que cette \
    1.86  valeur peut aussi être modifiée une fois le système installé en utilisant
    1.87  'netbox' graphiquement ou en ligne de commande.\n\n
    1.88 -\Z2Nom de machine:\Zn" 18 70  "slitaz" 2>&1 1>&3`
    1.89 +\Z2Nom de machine:\Zn" 18 70 "slitaz" 2>&1 1>&3`
    1.90  	retval=$?
    1.91  	exec 3>&-
    1.92  	check_retval
    1.93 @@ -276,24 +288,22 @@
    1.94  		echo "XXX" && echo 15
    1.95  		echo -e "\nNettoyage de la partition racine ($TARGET_DEV)..."
    1.96  		echo "XXX"
    1.97 +		# Keep /home in case of reinstall.
    1.98  		cd $TARGET_ROOT
    1.99 -		# Keep /home in case of reinstall.
   1.100 -		for dir in $TARGET_ROOT/*
   1.101 +		for dir in *
   1.102  		do
   1.103 -			dirname=`basename $dir`
   1.104 -			case "$dirname" in
   1.105 +			case "$dir" in
   1.106  				home)
   1.107  					mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
   1.108  					echo "keeping /home found on: $TARGET_DEV" >>$LOG ;;
   1.109  				lost+found)
   1.110 -					break ;;
   1.111 +					continue ;;
   1.112  				*)
   1.113 -					echo "Deleting: $dir" >> $LOG
   1.114 +					echo "removing target: $dir" >>$LOG
   1.115  					rm -rf $dir 2>>$LOG ;;
   1.116  			esac
   1.117  		done
   1.118  		if [ -d $TARGET_ROOT/mklost+found ]; then
   1.119 -			echo "Execute mklost+found" >> $LOG
   1.120  			mklost+found 2>>$LOG
   1.121  		fi
   1.122  	fi
   1.123 @@ -305,7 +315,7 @@
   1.124  {
   1.125  	mkdir -p $TARGET_ROOT/boot
   1.126  	cp /media/cdrom/boot/bzImage $TARGET_ROOT/boot/$KERNEL
   1.127 -	echo "install_kernel: $KERNEL" >>$LOG
   1.128 +	echo "install_kernel: $KERNEL" >> $LOG
   1.129  	sleep 2
   1.130  }
   1.131  
   1.132 @@ -327,15 +337,16 @@
   1.133  # Extract lzma'ed or gziped rootfs.
   1.134  extract_rootfs()
   1.135  {
   1.136 -	echo "Extract lzma'ed or geziped rootfs" >> $LOG
   1.137  	cd $TARGET_ROOT
   1.138 -	(zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so 2>/dev/null || \
   1.139 +	(zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so || \
   1.140  	 cat rootfs.gz) 2>>$LOG | cpio -id 2>>$LOG
   1.141  	rm -f rootfs.gz
   1.142 -	# unpack /usr
   1.143 -	for i in etc/tazlito/*.extract; do
   1.144 -		[ -f "$i" ] && . $i /media/cdrom
   1.145 -	done
   1.146 +	# unpack /usr (double check...)
   1.147 +	if ls etc/tazlito | grep -q ".extract"; then
   1.148 +		for i in etc/tazlito/*.extract; do
   1.149 +			[ -f "$i" ] && . $i /media/cdrom.
   1.150 +		done
   1.151 +	fi
   1.152  }
   1.153  
   1.154  # /etc/skel (60%)
   1.155 @@ -566,8 +577,6 @@
   1.156  end_of_install()
   1.157  {
   1.158  	echo "end_of_install: `date`" >>$LOG
   1.159 -	# Save log file right place
   1.160 -	cp $LOG $TARGET_ROOT/var/log
   1.161  	$DIALOG --title " Installation terminée " \
   1.162  		--backtitle "$BACKLIST" \
   1.163  		--yes-label "Exit" \
   1.164 @@ -598,40 +607,277 @@
   1.165  # Upgrade functions #
   1.166  #####################
   1.167  
   1.168 -# Start upgrade with basic informations (TODO).
   1.169 -start_upgrade()
   1.170 +# We need a partition to upgrade SliTaz.
   1.171 +ask_for_upgrade_dev()
   1.172  {
   1.173 -	$DIALOG --title " Mise à jour du système " \
   1.174 +	exec 3>&1
   1.175 +	UPGRADE_DEV=`$DIALOG --title " Cible à mettre jour " \
   1.176 +		--backtitle "$BACKLIST" --clear \
   1.177 +		--extra-label "List" --extra-button \
   1.178 +		--colors --inputbox "\n
   1.179 +L'installateur va mettre à jour le système cible en commançant par sauver tous \
   1.180 +les fichiers de configuration et la liste des paquets installés. Ensuite, il va \
   1.181 +nettoyer la partition et installer la version de SliTaz contenue sur le cdrom, \
   1.182 +restaurer les fichiers de configuration et réinstaller l'ensemble des paquets \
   1.183 +qui ne sont pas présents sur le LiveCD. Il vous font donc une connection internet \
   1.184 +active avant de mettre à jour.\n\n
   1.185 +\Z2Partition contenant le système à mettre à jour:\Zn" 18 70 2>&1 1>&3`
   1.186 +	retval=$?
   1.187 +	exec 3>&-
   1.188 +	check_retval
   1.189 +	# Display list and comme back.
   1.190 +	if [ "$retval" = "3" ]; then
   1.191 +		fdisk_list
   1.192 +		ask_for_upgrade_dev
   1.193 +	fi
   1.194 +	# Empty value.
   1.195 +	if [ -z $UPGRADE_DEV ]; then
   1.196 +		ask_for_upgrade_dev
   1.197 +	fi
   1.198 +	# Check if specified device exist in /proc/partitions.
   1.199 +	DEV_NAME=${UPGRADE_DEV#/dev/}
   1.200 +	if cat /proc/partitions | grep -q $DEV_NAME; then
   1.201 +		echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
   1.202 +	else
   1.203 +		ERROR_MSG="La partition \Z2$UPGRADE_DEV\Zn ne semble pas exister."
   1.204 +		error_message
   1.205 +		ask_for_upgrade_dev
   1.206 +	fi
   1.207 +	echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
   1.208 +}
   1.209 +
   1.210 +# Prepare the part to upgrade, backup, install, restore configs 
   1.211 +# and reinstall pkgs.
   1.212 +upgrade_process()
   1.213 +{
   1.214 +	(
   1.215 +	echo "XXX" && echo 5
   1.216 +	echo -e "\nPréparation de la partition cible..."
   1.217 +	echo "XXX"
   1.218 +	# Mount point can be already used.
   1.219 +	if mount | grep -q $TARGET_ROOT; then
   1.220 +		umount $TARGET_ROOT 2>$LOG
   1.221 +	fi
   1.222 +	mkdir -p $TARGET_ROOT && sleep 2
   1.223 +	# Mount target
   1.224 +	mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
   1.225 +	cd $TARGET_ROOT
   1.226 +	TARGET_DEV=$UPGRADE_DEV
   1.227 +		
   1.228 +	echo "XXX" && echo 10
   1.229 +	echo -e "\nRecherch de /etc/slitaz-release"
   1.230 +	echo "XXX"
   1.231 +	if [ -f etc/slitaz-release ]; then
   1.232 +		release=`cat etc/slitaz-release`
   1.233 +		echo "XXX" && echo 15
   1.234 +		echo -e "\nSliTaz release: $release"
   1.235 +		echo "XXX"
   1.236 +	else
   1.237 +		ERROR_MSG="La partition \Z2$UPGRADE_DEV\Zn ne semble pas contenir de \
   1.238 +système SliTaz, le fichier: /etc/slitaz-release n'existe pas."
   1.239 +		error_message
   1.240 +		exit 0
   1.241 +	fi && sleep 2
   1.242 +	
   1.243 +	echo "XXX" && echo 20
   1.244 +	echo -e "\nSauvegarde de /etc, /home et de la liste des paquets..."
   1.245 +	echo "XXX"
   1.246 +	# Backup target packages list
   1.247 +	ls -1 var/lib/tazpkg/installed > home/packages-selection.list
   1.248 +	for dir in *
   1.249 +	do
   1.250 +		case "$dir" in
   1.251 +			boot)
   1.252 +				# Upgrade dont prompt for grub install, so backup and creat a
   1.253 +				# new grub menu.lst.
   1.254 +				rm -rf $TARGET_ROOT/boot/vmlinuz-*
   1.255 +				mv $TARGET_ROOT/boot/grub/menu.lst \
   1.256 +					$TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
   1.257 +				grub_config ;;
   1.258 +			home)
   1.259 +				mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
   1.260 +				echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
   1.261 +			etc)
   1.262 +				tar czf $TARGET_ROOT/etc.tar.gz etc
   1.263 +				mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
   1.264 +				echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
   1.265 +			var)
   1.266 +				if [ -d $TARGET_ROOT/var/www ]; then
   1.267 +					mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
   1.268 +				fi
   1.269 +				rm -rf $TARGET_ROOT/var ;;
   1.270 +			lost+found)
   1.271 +				continue ;;
   1.272 +			*)
   1.273 +				echo "removing target: $dir" >>$LOG
   1.274 +				rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
   1.275 +		esac
   1.276 +	done
   1.277 +	if [ -d $TARGET_ROOT/mklost+found ]; then
   1.278 +		mklost+found 2>>$LOG
   1.279 +	fi
   1.280 +	sleep 2
   1.281 +	
   1.282 +	echo "XXX" && echo 25
   1.283 +	echo -e "\nInstallation du noyau ($KERNEL)..."
   1.284 +	echo "XXX"
   1.285 +	install_kernel
   1.286 +	
   1.287 +	echo "XXX" && echo 30
   1.288 +	echo -e "\nCopie des bootloaders syslinux/isolinux..."
   1.289 +	echo "XXX"
   1.290 +	copy_bootloaders
   1.291 +	
   1.292 +	echo "XXX" && echo 35
   1.293 +	echo -e "\nCopie du système compressé (rootfs.gz)..."
   1.294 +	echo "XXX"
   1.295 +	cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
   1.296 +	sleep 2
   1.297 +	
   1.298 +	echo "XXX" && echo 40
   1.299 +	echo -e "\nExtraction du système racine..."
   1.300 +	echo "XXX"
   1.301 +	extract_rootfs
   1.302 +	
   1.303 +	# Restore backups.
   1.304 +	echo "XXX" && echo 42
   1.305 +	echo -e "\nRestauration des fichiers de configuration..."
   1.306 +	echo "XXX"
   1.307 +	rm -rf $TARGET_ROOT/home
   1.308 +	mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
   1.309 +	rm -rf $TARGET_ROOT/etc
   1.310 +	mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
   1.311 +	if [ -d $TARGET_ROOT/www.bak ]; then
   1.312 +		rm -rf $TARGET_ROOT/var/www
   1.313 +		mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
   1.314 +	fi
   1.315 +	echo "backups restored: `date`" >> $LOG
   1.316 +	
   1.317 +	# /var/lib/slitaz-installer
   1.318 +	mkdir $TARGET_ROOT/var/lib/slitaz-installer
   1.319 +	mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
   1.320 +	mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
   1.321 +	cd $TARGET_ROOT/var/lib/slitaz-installer
   1.322 +	
   1.323 +	# LiveCD packages list.
   1.324 +	echo "XXX" && echo 46
   1.325 +	echo -e "\nCréation des listes de paquets..."
   1.326 +	echo "XXX"
   1.327 +	ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
   1.328 +	echo "packages-cdrom.list: done" >> $LOG
   1.329 +	# Diff
   1.330 +	diff packages-cdrom.list packages-selection.list | \
   1.331 +		grep ^+[a-z] | sed s/^+// > packages-selection.diff
   1.332 +	echo "packages-selection.diff: done" >> $LOG
   1.333 +	# Get mirror list.
   1.334 +	tazpkg recharge >>$LOG 2>>$LOG
   1.335 +	if [ ! -f /var/lib/tazpkg/packages.list ]; then
   1.336 +		ERROR_MSG="La liste des paquets disponibles sur le miroir n'a pas pu \
   1.337 +être téléchargée. Aucun paquets manquants ne sera réintallés maintenant, mais
   1.338 +vous pourrez le faire plus tard en vous aidant de la liste: \n\n
   1.339 +
   1.340 +/var/lib/slitaz-installer/packages-selection.diff"
   1.341 +		error_message
   1.342 +	fi
   1.343 +	sleep 2
   1.344 +	
   1.345 +	# Check if the pkg is on the mirror
   1.346 +	echo "XXX" && echo 48
   1.347 +	echo -e "\nVérification de la disponibilité des paquets..."
   1.348 +	echo "XXX"
   1.349 +	touch packages-to-install.list
   1.350 +	packages=0
   1.351 +	diff=`cat packages-selection.diff | sort`
   1.352 +	for pkg in $diff
   1.353 +	do
   1.354 +		if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
   1.355 +			packages=$(($packages+1))
   1.356 +			echo "$pkg" >> packages-to-install.list
   1.357 +		fi
   1.358 +	done
   1.359 +	
   1.360 +	# Calculate the pourcent for one package and install.
   1.361 +	echo "XXX" && echo 50
   1.362 +	echo -e "\nInstallation des éventuels paquets..."
   1.363 +	echo "XXX"
   1.364 +	sleep 2
   1.365 +	if [ "$packages" == "0" ]; then	
   1.366 +		echo "packages to install: 0" >> $LOG
   1.367 +	else
   1.368 +		onepkg=$((48/$packages))
   1.369 +		pct=50
   1.370 +		# Get-install all missing pkgs.
   1.371 +		for pkg in `cat packages-to-install.list`
   1.372 +		do
   1.373 +			pct=$(($pct+$onepkg))
   1.374 +			echo "XXX" && echo $pct
   1.375 +			echo -e "\nInstallation de: $pkg..."
   1.376 +			echo "XXX"
   1.377 +			# Log please.
   1.378 +			echo "get-install: $pkg" >>$LOG
   1.379 +			# Get install package and anser yes in case of dependencies.
   1.380 +			pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
   1.381 +			tazpkg get $pkg >/dev/null 2>/dev/null
   1.382 +			yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
   1.383 +			rm -f $pkgname.tazpkg
   1.384 +		done
   1.385 +	fi
   1.386 +	echo "XXX" && echo 100
   1.387 +	echo -e "\nInstallation des paquets terminée..."
   1.388 +	echo "XXX"
   1.389 +	sleep 2
   1.390 +	) |
   1.391 +	$DIALOG --title " Préparation de la cible " \
   1.392  		--backtitle "$BACKLIST" \
   1.393 +		--gauge "Target in preparation..." 18 70 0
   1.394 +}
   1.395 +
   1.396 +# End of system upgrade
   1.397 +end_of_upgrade()
   1.398 +{
   1.399 +	TARGET_DEV=$UPGRADE_DEV
   1.400 +	pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
   1.401 +	pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
   1.402 +	echo "end_of_upgrade: `date`" >>$LOG
   1.403 +	$DIALOG --title " Mise à jour terminée " \
   1.404 +		--backtitle "$BACKLIST" \
   1.405 +		--yes-label "Exit" \
   1.406 +		--no-label "Reboot" \
   1.407  		--clear --colors --yesno "\n
   1.408 -La fonction de mise à jour complète du système n'est pas encore implémentée.
   1.409 -\n\n
   1.410 -* Montage de la partition.\n
   1.411 -* Sauvegarde des fichiers de configuration.\n
   1.412 -* Créer un diff entre les paquets du cdrom et ceux installés.\n
   1.413 -* Nettoyer la partition.\n
   1.414 -* Installer la version du cdrom.\n
   1.415 -* Restauration des fichiers de config.\n
   1.416 -* Réinstaller les paquets manquants depuis le miroir." 18 70
   1.417 +Mise à jour terminée. Vous pouvez dès maintenant redémarrer (reboot) \
   1.418 +sur votre système SliTaz GNU/Linux à jour.\n\n
   1.419 +Paquets présents sur le cdrom      : $pkgscd\n
   1.420 +Paquets installés depuis le miroir : $pkginst\n" 18 70
   1.421  	retval=$?
   1.422 -	#check_retval
   1.423 -	#echo "start_upgarde: `date`" > $LOG
   1.424 -	exit 0
   1.425 +	case $retval in
   1.426 +	0)
   1.427 +		TITLE="Exiting"
   1.428 +		umount_devices ;;
   1.429 +	1)
   1.430 +		TITLE="Rebooting"
   1.431 +		umount_devices
   1.432 +		reboot || reboot -f ;;
   1.433 +	255)
   1.434 +		echo -e "ESC pressed.\n" && exit 0 ;;
   1.435 +esac
   1.436  }
   1.437  
   1.438  ######################
   1.439  # Installer sequence #
   1.440  ######################
   1.441  
   1.442 +check_root
   1.443 +start_installer
   1.444 +
   1.445  case $ACTION in
   1.446  	upgrade)
   1.447 -		check_root
   1.448 -		start_upgrade
   1.449 -		#mount_cdrom
   1.450 +		BACKLIST="$BACKLIST (Mise à jour)"
   1.451 +		mount_cdrom
   1.452 +		ask_for_upgrade_dev
   1.453 +		upgrade_process
   1.454 +		end_of_upgrade
   1.455  		;;
   1.456  	install|*)
   1.457 -		check_root
   1.458 -		start_install
   1.459  		mount_cdrom
   1.460  		ask_for_target_dev
   1.461  		ask_for_mkfs_target_dev