slitaz-tools rev 402

installer: Add root passwd and default user setting functions
author Christophe Lincoln <pankso@slitaz.org>
date Sat Nov 07 00:03:26 2009 +0100 (2009-11-07)
parents 5b1ef3a5a670
children 9111553d3e51
files installer/slitaz-installer tinyutils/tazx
line diff
     1.1 --- a/installer/slitaz-installer	Tue Oct 27 12:25:51 2009 +0000
     1.2 +++ b/installer/slitaz-installer	Sat Nov 07 00:03:26 2009 +0100
     1.3 @@ -5,24 +5,13 @@
     1.4  # English but displayed messages are in French. The script starts with a
     1.5  # few main variables, then all the functions and then a sequence of functions.
     1.6  #
     1.7 -# (C) 2007-2008 SliTaz - GNU General Public License v3.
     1.8 +# (C) 2007-2009 SliTaz - GNU General Public License v3.
     1.9  #
    1.10  # Author : Christophe Lincoln <pankso@slitaz.org>
    1.11  #
    1.12 -VERSION=1.0
    1.13 +VERSION=2.0
    1.14  
    1.15 -if [ "$1" = "gui" ]; then
    1.16 -	: ${DIALOG=tazdialog}
    1.17 -else
    1.18 -	: ${DIALOG=dialog}
    1.19 -fi
    1.20 -
    1.21 -# Installer actions can be specified on cmdline (install or upgrade).
    1.22 -if [ "$1" = "upgrade" ]; then
    1.23 -	ACTION=$1
    1.24 -else
    1.25 -	ACTION=install
    1.26 -fi
    1.27 +: ${DIALOG=dialog}
    1.28  
    1.29  # We need to know cdrom device and kernel version string to copy files.
    1.30  DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
    1.31 @@ -31,6 +20,7 @@
    1.32  TARGET_ROOT=/mnt/target
    1.33  LOG=/var/log/slitaz-installer.log
    1.34  BACKLIST="SliTaz GNU/Linux installer"
    1.35 +ACTION=$1
    1.36  
    1.37  #######################
    1.38  # Installer functions #
    1.39 @@ -97,8 +87,7 @@
    1.40  	$DIALOG --title " Install or Upgrade " \
    1.41  		--backtitle "$BACKLIST" \
    1.42  		--extra-button --extra-label "Upgrade" \
    1.43 -		--yes-label "Install" \
    1.44 -		--no-label "Quit" \
    1.45 +		--ok-label "Install" \
    1.46  		--clear --colors --yesno "$START_INSTALL_MSG" 18 70
    1.47  	retval=$?
    1.48  		case $retval in
    1.49 @@ -266,6 +255,78 @@
    1.50  	fi
    1.51  }
    1.52  
    1.53 +# Ask for root password and default user settings.
    1.54 +ask_for_users_settings()
    1.55 +{
    1.56 +	# Root passwd
    1.57 +	exec 3>&1
    1.58 +	ROOT_PASSWD=`$DIALOG --title " Root password " \
    1.59 +		--backtitle "$BACKLIST" --clear \
    1.60 +		--colors --nocancel --inputbox "
    1.61 +The root administrator privilege let you manage and configure the full \
    1.62 +system, root user can damage your system so you should put setup a strong \
    1.63 +password with special characters and/or numbers.
    1.64 +
    1.65 +\Z2Please specify the Root password for your new system:\Zn" 18 70 "root" 2>&1 1>&3`
    1.66 +	retval=$?
    1.67 +	exec 3>&-
    1.68 +	check_retval
    1.69 +	# Pevent empty value.
    1.70 +	if [ -z $ROOT_PASSWD ]; then
    1.71 +		ROOT_PASSWD="root"
    1.72 +	fi
    1.73 +	# Default user
    1.74 +	exec 3>&1
    1.75 +	USER=`$DIALOG --title " User name " \
    1.76 +		--backtitle "$BACKLIST" --clear \
    1.77 +		--colors --nocancel --inputbox "
    1.78 +The default user for the system will have his personnal files stored \
    1.79 +in /home/*user* and will automaticaly be add to the audio group.
    1.80 +
    1.81 +\Z2Default user name login:\Zn" 18 70 "tux" 2>&1 1>&3`
    1.82 +	retval=$?
    1.83 +	exec 3>&-
    1.84 +	check_retval
    1.85 +	# Pevent empty value.
    1.86 +	if [ -z $USER ]; then
    1.87 +		USER="tux"
    1.88 +	fi
    1.89 +	# User passwd
    1.90 +	exec 3>&1
    1.91 +	USER_PASSWD=`$DIALOG --title " User password " \
    1.92 +		--backtitle "$BACKLIST" --clear \
    1.93 +		--colors --nocancel --inputbox "
    1.94 +The password for default user $USER. It may also be a security hole if to \
    1.95 +weak and should realy be strong if you will use SSH connection trought the web.
    1.96 +
    1.97 +\Z2Please specify $USER password:\Zn" 18 70 "tux" 2>&1 1>&3`
    1.98 +	retval=$?
    1.99 +	exec 3>&-
   1.100 +	check_retval
   1.101 +	# Pevent empty value.
   1.102 +	if [ -z $USER_PASSWD ]; then
   1.103 +		USER_PASSWD="tux"
   1.104 +	fi
   1.105 +}
   1.106 +
   1.107 +# Tiny summary and last chance to cancel or restart for user.
   1.108 +summary()
   1.109 +{
   1.110 +	$DIALOG --title " Summary " \
   1.111 +		--backtitle "$BACKLIST" \
   1.112 +		--clear --colors --yesno "
   1.113 +Installation settings summary and last chance to cancel or restart all \
   1.114 +installator steps.
   1.115 +
   1.116 +Root partition: $TARGET_DEV
   1.117 +Hostname: $HOSTNAME
   1.118 +Default user: $USER
   1.119 +
   1.120 +\Z2Go and install SliTaz or cancel?\Zn" 18 70
   1.121 +	retval=$?
   1.122 +	check_retval
   1.123 +}
   1.124 +
   1.125  # Get a clean target device (15%).
   1.126  clean_target()
   1.127  {
   1.128 @@ -334,55 +395,61 @@
   1.129  	fi
   1.130  }
   1.131  
   1.132 -# /etc/skel (60%)
   1.133 -gen_etc_skel()
   1.134 -{
   1.135 -	# Maybe we don't have /home/hacker directory.
   1.136 -	if [ -d $TARGET_ROOT/home/hacker ]; then
   1.137 -		echo "XXX" && echo 60
   1.138 -		echo -e "\nCopying default user files (/etc/skel)..."
   1.139 -		echo "XXX"
   1.140 -		cp -a $TARGET_ROOT/home/hacker $TARGET_ROOT/etc/skel
   1.141 -	else
   1.142 -		echo "XXX" && echo 60
   1.143 -		echo -e "\nCreating directory (/etc/skel)..."
   1.144 -		echo "XXX"
   1.145 -		mkdir -p $TARGET_ROOT/etc/skel \
   1.146 -			$TARGET_ROOT/etc/Documents \
   1.147 -			$TARGET_ROOT/etc/skel/Images \
   1.148 -			$TARGET_ROOT/etc/skel/.local/bin \
   1.149 -			$TARGET_ROOT/etc/skel/.local/share
   1.150 -	fi
   1.151 -	sleep 2
   1.152 -}
   1.153 -
   1.154 -# Pre configure freshly installed system (70 - 90%).
   1.155 +# Pre configure freshly installed system (60 - 80%).
   1.156  pre_config_system()
   1.157  {
   1.158  	cd $TARGET_ROOT
   1.159  	# Restore backup of existing /home if exists.
   1.160  	# (created by prepare_target_dev)
   1.161  	if [ -d home.bak ]; then
   1.162 -		echo "XXX" && echo 75
   1.163 -		echo -e "\nThe restore directory: /home..."
   1.164 +		echo "XXX" && echo 65
   1.165 +		echo -e "\nRestoring directory: /home..."
   1.166  		echo "XXX"
   1.167  		rm -rf home
   1.168  		mv home.bak home
   1.169 -		sleep 2
   1.170 +		sleep 1
   1.171  	fi
   1.172  	# Add root device to CHECK_FS in rcS.conf to check filesystem
   1.173  	# on each boot.
   1.174 -	echo "XXX" && echo 80
   1.175 +	echo "XXX" && echo 70
   1.176  	echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..."
   1.177  	echo "XXX"
   1.178  	sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf
   1.179  	sleep 2
   1.180  	# Set hostname.
   1.181 -	echo "XXX" && echo 85
   1.182 +	echo "XXX" && echo 80
   1.183  	echo -e "\nConfiguring host name: $HOSTNAME"
   1.184  	echo "XXX"
   1.185  	echo $HOSTNAME > etc/hostname
   1.186 -	sleep 2
   1.187 +}
   1.188 +
   1.189 +# Set root passwd and create user after rootfs extraction.
   1.190 +users_settings()
   1.191 +{
   1.192 +	cat > $TARGET_ROOT/users.sh << _EOF_
   1.193 +#!/bin/sh
   1.194 +echo "root:$ROOT_PASSWD" | chpasswd
   1.195 +adduser -D -H $USER
   1.196 +addgroup $USER audio
   1.197 +echo "$USER:$USER_PASSWD" | chpasswd
   1.198 +if [ ! -d /home/$USER ]; then
   1.199 +	cp /etc/skel /home/$USER
   1.200 +	chown -R $USER.$USER /home/$USER
   1.201 +	# Path for user desktop files.
   1.202 +	for i in /home/$USER/.local/share/applications/*.desktop
   1.203 +	do
   1.204 +		sed -i s/"user_name"/"$USER"/g \$i
   1.205 +	done
   1.206 +fi
   1.207 +# Slim default user.
   1.208 +if [ -f /etc/slim.conf ]; then
   1.209 +	sed -i s/"default_user .*"/"default_user        $USER"/\
   1.210 +		/etc/slim.conf
   1.211 +fi
   1.212 +_EOF_
   1.213 +	chmod +x $TARGET_ROOT/users.sh
   1.214 +	chroot $TARGET_ROOT ./users.sh
   1.215 +	rm $TARGET_ROOT/users.sh
   1.216  }
   1.217  
   1.218  # Determine GRUB partition number and GRUB disk number.
   1.219 @@ -459,15 +526,15 @@
   1.220  	extract_rootfs
   1.221  
   1.222  	echo "XXX" && echo 60
   1.223 -	echo -e "\nCopying the default user files (/etc/skel)..."
   1.224 -	echo "XXX"
   1.225 -	gen_etc_skel
   1.226 -	sleep 2
   1.227 -
   1.228 -	echo "XXX" && echo 70
   1.229  	echo -e "\nPreconfiguring the system..."
   1.230  	echo "XXX"
   1.231  	pre_config_system
   1.232 +	
   1.233 +	echo "XXX" && echo 80
   1.234 +	echo -e "\nConfiguring root and default $USER account..."
   1.235 +	echo "XXX"
   1.236 +	users_settings
   1.237 +	sleep 2
   1.238  
   1.239  	echo "XXX" && echo 90
   1.240  	echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
   1.241 @@ -478,7 +545,7 @@
   1.242  	echo -e "\nFinishing the files installation..."
   1.243  	echo "XXX"
   1.244  	echo "install_files: OK" >>$LOG
   1.245 -	sleep 4
   1.246 +	sleep 2
   1.247  
   1.248  	) |
   1.249  	$DIALOG --title " Install files " \
   1.250 @@ -848,18 +915,18 @@
   1.251  		mount_cdrom
   1.252  		ask_for_upgrade_dev
   1.253  		upgrade_process
   1.254 -		end_of_upgrade
   1.255 -		;;
   1.256 +		end_of_upgrade ;;
   1.257  	install|*)
   1.258  		mount_cdrom
   1.259  		ask_for_target_dev
   1.260  		ask_for_mkfs_target_dev
   1.261  		prepare_target_dev
   1.262  		ask_for_hostname
   1.263 +		ask_for_users_settings
   1.264 +		summary
   1.265  		install_files
   1.266  		grub_install
   1.267 -		end_of_install
   1.268 -		;;
   1.269 +		end_of_install ;;
   1.270  esac
   1.271  
   1.272  exit 0
     2.1 --- a/tinyutils/tazx	Tue Oct 27 12:25:51 2009 +0000
     2.2 +++ b/tinyutils/tazx	Sat Nov 07 00:03:26 2009 +0100
     2.3 @@ -17,7 +17,7 @@
     2.4  WM=openbox
     2.5  
     2.6  # Default user for config files in Live mode.
     2.7 -[ -z $USER ] && USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
     2.8 +[ "$USER" = "root"] && USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
     2.9  
    2.10  ####################
    2.11  #  Tazx functions  #
    2.12 @@ -234,7 +234,7 @@
    2.13  					cp /etc/jwm/system.jwmrc $JWM_CONFIG
    2.14  				fi
    2.15  				# In Live mode default user/root JWM config does not exist and
    2.16 -				# $HOME is not set, this is because tazx is executed by boot 
    2.17 +				# $HOME is not set, this is because tazx is executed by boot
    2.18  				# scripts.
    2.19  				if [ ! -f "/home/$USER/.jwmrc" ]; then
    2.20  					cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
    2.21 @@ -391,7 +391,7 @@
    2.22  	install-xorg)
    2.23  		# WM can be specified on cmdline.
    2.24  		if [ -n "$2" ]; then
    2.25 -			WM=$2	
    2.26 +			WM=$2
    2.27  		fi
    2.28  		install_xorg
    2.29  		slim_config
    2.30 @@ -401,7 +401,7 @@
    2.31  	*)
    2.32  		# WM can be specified on cmdline.
    2.33  		if [ -n "$1" ]; then
    2.34 -			WM=$1	
    2.35 +			WM=$1
    2.36  		fi
    2.37  		[ -n "$NEW_SCREEN" ] || screen_config_dialog
    2.38  		slim_config