# HG changeset patch # User Christophe Lincoln # Date 1257548606 -3600 # Node ID 14683938d8d46366351c5a1b61e552be4dfcaafb # Parent 5b1ef3a5a6707778ba9bde278e528ae8de9ced44 installer: Add root passwd and default user setting functions diff -r 5b1ef3a5a670 -r 14683938d8d4 installer/slitaz-installer --- a/installer/slitaz-installer Tue Oct 27 12:25:51 2009 +0000 +++ b/installer/slitaz-installer Sat Nov 07 00:03:26 2009 +0100 @@ -5,24 +5,13 @@ # English but displayed messages are in French. The script starts with a # few main variables, then all the functions and then a sequence of functions. # -# (C) 2007-2008 SliTaz - GNU General Public License v3. +# (C) 2007-2009 SliTaz - GNU General Public License v3. # # Author : Christophe Lincoln # -VERSION=1.0 +VERSION=2.0 -if [ "$1" = "gui" ]; then - : ${DIALOG=tazdialog} -else - : ${DIALOG=dialog} -fi - -# Installer actions can be specified on cmdline (install or upgrade). -if [ "$1" = "upgrade" ]; then - ACTION=$1 -else - ACTION=install -fi +: ${DIALOG=dialog} # We need to know cdrom device and kernel version string to copy files. DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3` @@ -31,6 +20,7 @@ TARGET_ROOT=/mnt/target LOG=/var/log/slitaz-installer.log BACKLIST="SliTaz GNU/Linux installer" +ACTION=$1 ####################### # Installer functions # @@ -97,8 +87,7 @@ $DIALOG --title " Install or Upgrade " \ --backtitle "$BACKLIST" \ --extra-button --extra-label "Upgrade" \ - --yes-label "Install" \ - --no-label "Quit" \ + --ok-label "Install" \ --clear --colors --yesno "$START_INSTALL_MSG" 18 70 retval=$? case $retval in @@ -266,6 +255,78 @@ fi } +# Ask for root password and default user settings. +ask_for_users_settings() +{ + # Root passwd + exec 3>&1 + ROOT_PASSWD=`$DIALOG --title " Root password " \ + --backtitle "$BACKLIST" --clear \ + --colors --nocancel --inputbox " +The root administrator privilege let you manage and configure the full \ +system, root user can damage your system so you should put setup a strong \ +password with special characters and/or numbers. + +\Z2Please specify the Root password for your new system:\Zn" 18 70 "root" 2>&1 1>&3` + retval=$? + exec 3>&- + check_retval + # Pevent empty value. + if [ -z $ROOT_PASSWD ]; then + ROOT_PASSWD="root" + fi + # Default user + exec 3>&1 + USER=`$DIALOG --title " User name " \ + --backtitle "$BACKLIST" --clear \ + --colors --nocancel --inputbox " +The default user for the system will have his personnal files stored \ +in /home/*user* and will automaticaly be add to the audio group. + +\Z2Default user name login:\Zn" 18 70 "tux" 2>&1 1>&3` + retval=$? + exec 3>&- + check_retval + # Pevent empty value. + if [ -z $USER ]; then + USER="tux" + fi + # User passwd + exec 3>&1 + USER_PASSWD=`$DIALOG --title " User password " \ + --backtitle "$BACKLIST" --clear \ + --colors --nocancel --inputbox " +The password for default user $USER. It may also be a security hole if to \ +weak and should realy be strong if you will use SSH connection trought the web. + +\Z2Please specify $USER password:\Zn" 18 70 "tux" 2>&1 1>&3` + retval=$? + exec 3>&- + check_retval + # Pevent empty value. + if [ -z $USER_PASSWD ]; then + USER_PASSWD="tux" + fi +} + +# Tiny summary and last chance to cancel or restart for user. +summary() +{ + $DIALOG --title " Summary " \ + --backtitle "$BACKLIST" \ + --clear --colors --yesno " +Installation settings summary and last chance to cancel or restart all \ +installator steps. + +Root partition: $TARGET_DEV +Hostname: $HOSTNAME +Default user: $USER + +\Z2Go and install SliTaz or cancel?\Zn" 18 70 + retval=$? + check_retval +} + # Get a clean target device (15%). clean_target() { @@ -334,55 +395,61 @@ fi } -# /etc/skel (60%) -gen_etc_skel() -{ - # Maybe we don't have /home/hacker directory. - if [ -d $TARGET_ROOT/home/hacker ]; then - echo "XXX" && echo 60 - echo -e "\nCopying default user files (/etc/skel)..." - echo "XXX" - cp -a $TARGET_ROOT/home/hacker $TARGET_ROOT/etc/skel - else - echo "XXX" && echo 60 - echo -e "\nCreating directory (/etc/skel)..." - echo "XXX" - mkdir -p $TARGET_ROOT/etc/skel \ - $TARGET_ROOT/etc/Documents \ - $TARGET_ROOT/etc/skel/Images \ - $TARGET_ROOT/etc/skel/.local/bin \ - $TARGET_ROOT/etc/skel/.local/share - fi - sleep 2 -} - -# Pre configure freshly installed system (70 - 90%). +# Pre configure freshly installed system (60 - 80%). pre_config_system() { cd $TARGET_ROOT # Restore backup of existing /home if exists. # (created by prepare_target_dev) if [ -d home.bak ]; then - echo "XXX" && echo 75 - echo -e "\nThe restore directory: /home..." + echo "XXX" && echo 65 + echo -e "\nRestoring directory: /home..." echo "XXX" rm -rf home mv home.bak home - sleep 2 + sleep 1 fi # Add root device to CHECK_FS in rcS.conf to check filesystem # on each boot. - echo "XXX" && echo 80 + echo "XXX" && echo 70 echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..." echo "XXX" sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf sleep 2 # Set hostname. - echo "XXX" && echo 85 + echo "XXX" && echo 80 echo -e "\nConfiguring host name: $HOSTNAME" echo "XXX" echo $HOSTNAME > etc/hostname - sleep 2 +} + +# Set root passwd and create user after rootfs extraction. +users_settings() +{ + cat > $TARGET_ROOT/users.sh << _EOF_ +#!/bin/sh +echo "root:$ROOT_PASSWD" | chpasswd +adduser -D -H $USER +addgroup $USER audio +echo "$USER:$USER_PASSWD" | chpasswd +if [ ! -d /home/$USER ]; then + cp /etc/skel /home/$USER + chown -R $USER.$USER /home/$USER + # Path for user desktop files. + for i in /home/$USER/.local/share/applications/*.desktop + do + sed -i s/"user_name"/"$USER"/g \$i + done +fi +# Slim default user. +if [ -f /etc/slim.conf ]; then + sed -i s/"default_user .*"/"default_user $USER"/\ + /etc/slim.conf +fi +_EOF_ + chmod +x $TARGET_ROOT/users.sh + chroot $TARGET_ROOT ./users.sh + rm $TARGET_ROOT/users.sh } # Determine GRUB partition number and GRUB disk number. @@ -459,15 +526,15 @@ extract_rootfs echo "XXX" && echo 60 - echo -e "\nCopying the default user files (/etc/skel)..." - echo "XXX" - gen_etc_skel - sleep 2 - - echo "XXX" && echo 70 echo -e "\nPreconfiguring the system..." echo "XXX" pre_config_system + + echo "XXX" && echo 80 + echo -e "\nConfiguring root and default $USER account..." + echo "XXX" + users_settings + sleep 2 echo "XXX" && echo 90 echo -e "\nCreating the configuration file for GRUB (menu.lst)..." @@ -478,7 +545,7 @@ echo -e "\nFinishing the files installation..." echo "XXX" echo "install_files: OK" >>$LOG - sleep 4 + sleep 2 ) | $DIALOG --title " Install files " \ @@ -848,18 +915,18 @@ mount_cdrom ask_for_upgrade_dev upgrade_process - end_of_upgrade - ;; + end_of_upgrade ;; install|*) mount_cdrom ask_for_target_dev ask_for_mkfs_target_dev prepare_target_dev ask_for_hostname + ask_for_users_settings + summary install_files grub_install - end_of_install - ;; + end_of_install ;; esac exit 0 diff -r 5b1ef3a5a670 -r 14683938d8d4 tinyutils/tazx --- a/tinyutils/tazx Tue Oct 27 12:25:51 2009 +0000 +++ b/tinyutils/tazx Sat Nov 07 00:03:26 2009 +0100 @@ -17,7 +17,7 @@ WM=openbox # Default user for config files in Live mode. -[ -z $USER ] && USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1` +[ "$USER" = "root"] && USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1` #################### # Tazx functions # @@ -234,7 +234,7 @@ cp /etc/jwm/system.jwmrc $JWM_CONFIG fi # In Live mode default user/root JWM config does not exist and - # $HOME is not set, this is because tazx is executed by boot + # $HOME is not set, this is because tazx is executed by boot # scripts. if [ ! -f "/home/$USER/.jwmrc" ]; then cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc @@ -391,7 +391,7 @@ install-xorg) # WM can be specified on cmdline. if [ -n "$2" ]; then - WM=$2 + WM=$2 fi install_xorg slim_config @@ -401,7 +401,7 @@ *) # WM can be specified on cmdline. if [ -n "$1" ]; then - WM=$1 + WM=$1 fi [ -n "$NEW_SCREEN" ] || screen_config_dialog slim_config