mirror of
				https://github.com/brain-hackers/brain-config.git
				synced 2025-11-04 14:38:36 +09:00 
			
		
		
		
	Make autologin settings for current user; remove initd support.
This commit is contained in:
		
							
								
								
									
										145
									
								
								raspi-config
									
									
									
									
									
								
							
							
						
						
									
										145
									
								
								raspi-config
									
									
									
									
									
								
							@@ -62,17 +62,6 @@ is_ssh() {
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get_init_sys() {
 | 
			
		||||
  if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
 | 
			
		||||
    SYSTEMD=1
 | 
			
		||||
  elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
 | 
			
		||||
    SYSTEMD=0
 | 
			
		||||
  else
 | 
			
		||||
    echo "Unrecognised init system"
 | 
			
		||||
    return 1
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
calc_wt_size() {
 | 
			
		||||
  # NOTE: it's tempting to redirect stderr to /dev/null, so supress error 
 | 
			
		||||
  # output from tput. However in this case, tput detects neither stdout or 
 | 
			
		||||
@@ -99,16 +88,7 @@ you have heavily customised your installation.\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get_can_expand() {
 | 
			
		||||
  get_init_sys
 | 
			
		||||
  if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
    ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
 | 
			
		||||
  else
 | 
			
		||||
    if ! [ -h /dev/root ]; then
 | 
			
		||||
      echo 1
 | 
			
		||||
      exit
 | 
			
		||||
    fi
 | 
			
		||||
    ROOT_PART=$(readlink /dev/root)
 | 
			
		||||
  fi
 | 
			
		||||
  ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
 | 
			
		||||
 | 
			
		||||
  PART_NUM=${ROOT_PART#mmcblk0p}
 | 
			
		||||
  if [ "$PART_NUM" = "$ROOT_PART" ]; then
 | 
			
		||||
@@ -130,16 +110,7 @@ get_can_expand() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
do_expand_rootfs() {
 | 
			
		||||
  get_init_sys
 | 
			
		||||
  if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
    ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
 | 
			
		||||
  else
 | 
			
		||||
    if ! [ -h /dev/root ]; then
 | 
			
		||||
      whiptail --msgbox "/dev/root does not exist or is not a symlink. Don't know how to expand" 20 60 2
 | 
			
		||||
      return 0
 | 
			
		||||
    fi
 | 
			
		||||
    ROOT_PART=$(readlink /dev/root)
 | 
			
		||||
  fi
 | 
			
		||||
  ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
 | 
			
		||||
 | 
			
		||||
  PART_NUM=${ROOT_PART#mmcblk0p}
 | 
			
		||||
  if [ "$PART_NUM" = "$ROOT_PART" ]; then
 | 
			
		||||
@@ -313,8 +284,8 @@ do_overscan() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
do_change_pass() {
 | 
			
		||||
  whiptail --msgbox "You will now be asked to enter a new password for the pi user" 20 60 1
 | 
			
		||||
  passwd pi &&
 | 
			
		||||
  whiptail --msgbox "You will now be asked to enter a new password for the $SUDO_USER user" 20 60 1
 | 
			
		||||
  passwd $SUDO_USER &&
 | 
			
		||||
  whiptail --msgbox "Password changed successfully" 20 60 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -746,19 +717,12 @@ do_serial() {
 | 
			
		||||
    whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2
 | 
			
		||||
    RET=$?
 | 
			
		||||
  else
 | 
			
		||||
    get_init_sys
 | 
			
		||||
    RET=$1
 | 
			
		||||
  fi
 | 
			
		||||
  if [ $RET -eq $CURRENTS ]; then
 | 
			
		||||
    ASK_TO_REBOOT=1
 | 
			
		||||
  fi
 | 
			
		||||
  if [ $RET -eq 0 ]; then
 | 
			
		||||
    if [ $SYSTEMD -eq 0 ]; then
 | 
			
		||||
      sed -i /etc/inittab -e "s|^#\(.*:.*:respawn:.*ttyAMA0\)|\1|"
 | 
			
		||||
      if ! grep -q "^T.*:.*:respawn:.*ttyAMA0" /etc/inittab; then
 | 
			
		||||
        printf "T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100\n" >> /etc/inittab
 | 
			
		||||
      fi
 | 
			
		||||
    fi
 | 
			
		||||
    if grep -q "console=ttyAMA0" $CMDLINE ; then
 | 
			
		||||
      if [ -e /proc/device-tree/aliases/serial0 ]; then
 | 
			
		||||
        sed -i $CMDLINE -e "s/console=ttyAMA0/console=serial0/"
 | 
			
		||||
@@ -774,9 +738,6 @@ do_serial() {
 | 
			
		||||
    SSTATUS=enabled
 | 
			
		||||
    HSTATUS=enabled
 | 
			
		||||
  elif [ $RET -eq 1 ]; then
 | 
			
		||||
    if [ $SYSTEMD -eq 0 ]; then
 | 
			
		||||
      sed -i /etc/inittab -e "s|^.*:.*:respawn:.*ttyAMA0|#&|"
 | 
			
		||||
    fi
 | 
			
		||||
    sed -i $CMDLINE -e "s/console=ttyAMA0,[0-9]\+ //"
 | 
			
		||||
    sed -i $CMDLINE -e "s/console=serial0,[0-9]\+ //"
 | 
			
		||||
    SSTATUS=disabled
 | 
			
		||||
@@ -809,14 +770,8 @@ do_serial() {
 | 
			
		||||
disable_raspi_config_at_boot() {
 | 
			
		||||
  if [ -e /etc/profile.d/raspi-config.sh ]; then
 | 
			
		||||
    rm -f /etc/profile.d/raspi-config.sh
 | 
			
		||||
    if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
      if [ -e /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf ]; then
 | 
			
		||||
        rm /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf
 | 
			
		||||
      fi
 | 
			
		||||
    else
 | 
			
		||||
      sed -i /etc/inittab \
 | 
			
		||||
        -e "s/^#\(.*\)#\s*RPICFG_TO_ENABLE\s*/\1/" \
 | 
			
		||||
        -e "/#\s*RPICFG_TO_DISABLE/d"
 | 
			
		||||
    if [ -e /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf ]; then
 | 
			
		||||
      rm /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf
 | 
			
		||||
    fi
 | 
			
		||||
    telinit q
 | 
			
		||||
  fi
 | 
			
		||||
@@ -831,27 +786,16 @@ get_boot_cli() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get_autologin() {
 | 
			
		||||
  get_init_sys
 | 
			
		||||
  if [ $(get_boot_cli) -eq 0 ]; then
 | 
			
		||||
    # booting to CLI - check the autologin in getty or initd */
 | 
			
		||||
    if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
      # systemd used - check getty */
 | 
			
		||||
      if grep -q autologin /etc/systemd/system/getty.target.wants/getty@tty1.service ; then
 | 
			
		||||
        echo 0
 | 
			
		||||
      else
 | 
			
		||||
        echo 1
 | 
			
		||||
      fi
 | 
			
		||||
    if grep -q autologin /etc/systemd/system/getty.target.wants/getty@tty1.service ; then
 | 
			
		||||
      echo 0
 | 
			
		||||
    else
 | 
			
		||||
      # systemd not used - check initd */
 | 
			
		||||
      if grep -q login /etc/inittab ; then
 | 
			
		||||
        echo 0
 | 
			
		||||
      else
 | 
			
		||||
        echo 1
 | 
			
		||||
      fi
 | 
			
		||||
      echo 1
 | 
			
		||||
    fi
 | 
			
		||||
  else
 | 
			
		||||
    # booting to desktop - check the autologin for lightdm */
 | 
			
		||||
    if grep -q "^autologin-user=pi" /etc/lightdm/lightdm.conf ; then
 | 
			
		||||
    if grep -q "^autologin-user=" /etc/lightdm/lightdm.conf ; then
 | 
			
		||||
      echo 0
 | 
			
		||||
    else
 | 
			
		||||
      echo 1
 | 
			
		||||
@@ -863,66 +807,44 @@ do_boot_behaviour() {
 | 
			
		||||
  if [ "$INTERACTIVE" = True ]; then
 | 
			
		||||
    BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
 | 
			
		||||
      "B1 Console" "Text console, requiring user to login" \
 | 
			
		||||
      "B2 Console Autologin" "Text console, automatically logged in as 'pi' user" \
 | 
			
		||||
      "B2 Console Autologin" "Text console, automatically logged in as '$SUDO_USER' user" \
 | 
			
		||||
      "B3 Desktop" "Desktop GUI, requiring user to login" \
 | 
			
		||||
      "B4 Desktop Autologin" "Desktop GUI, automatically logged in as 'pi' user" \
 | 
			
		||||
      "B4 Desktop Autologin" "Desktop GUI, automatically logged in as '$SUDO_USER' user" \
 | 
			
		||||
      3>&1 1>&2 2>&3)
 | 
			
		||||
  else
 | 
			
		||||
    get_init_sys
 | 
			
		||||
    BOOTOPT=$1
 | 
			
		||||
    true
 | 
			
		||||
  fi
 | 
			
		||||
  if [ $? -eq 0 ]; then
 | 
			
		||||
    case "$BOOTOPT" in
 | 
			
		||||
      B1*)
 | 
			
		||||
        if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
          systemctl set-default multi-user.target
 | 
			
		||||
          ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
        else
 | 
			
		||||
          [ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
 | 
			
		||||
          sed /etc/inittab -i -e "s/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/"
 | 
			
		||||
        fi
 | 
			
		||||
        systemctl set-default multi-user.target
 | 
			
		||||
        ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
        ;;
 | 
			
		||||
      B2*)
 | 
			
		||||
        if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
          systemctl set-default multi-user.target
 | 
			
		||||
          ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
        else
 | 
			
		||||
          [ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
 | 
			
		||||
          sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
 | 
			
		||||
        fi
 | 
			
		||||
        systemctl set-default multi-user.target
 | 
			
		||||
        sed /etc/systemd/system/autologin@.service -i -e "s#^ExecStart=-/sbin/agetty --autologin [^[:space:]]*#ExecStart=-/sbin/agetty --autologin $SUDO_USER#"
 | 
			
		||||
        ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
        ;;
 | 
			
		||||
      B3*)
 | 
			
		||||
        if [ -e /etc/init.d/lightdm ]; then
 | 
			
		||||
          if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
            systemctl set-default graphical.target
 | 
			
		||||
            ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
          else
 | 
			
		||||
            update-rc.d lightdm enable 2
 | 
			
		||||
          fi
 | 
			
		||||
          systemctl set-default graphical.target
 | 
			
		||||
          ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
          sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=.*/#autologin-user=/"
 | 
			
		||||
          disable_raspi_config_at_boot
 | 
			
		||||
        else
 | 
			
		||||
          whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2
 | 
			
		||||
          whiptail --msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" 20 60 2
 | 
			
		||||
          return 1
 | 
			
		||||
        fi
 | 
			
		||||
        ;;
 | 
			
		||||
      B4*)
 | 
			
		||||
        if [ -e /etc/init.d/lightdm ]; then
 | 
			
		||||
          if id -u pi > /dev/null 2>&1; then
 | 
			
		||||
            if [ $SYSTEMD -eq 1 ]; then
 | 
			
		||||
              systemctl set-default graphical.target
 | 
			
		||||
              ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
            else
 | 
			
		||||
              update-rc.d lightdm enable 2
 | 
			
		||||
            fi
 | 
			
		||||
            sed /etc/lightdm/lightdm.conf -i -e "s/^\(#\|\)autologin-user=.*/autologin-user=pi/"
 | 
			
		||||
            disable_raspi_config_at_boot
 | 
			
		||||
          else
 | 
			
		||||
            whiptail --msgbox "The pi user has been removed, can't set up boot to desktop" 20 60 2
 | 
			
		||||
          fi
 | 
			
		||||
          systemctl set-default graphical.target
 | 
			
		||||
          ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
 | 
			
		||||
          sed /etc/lightdm/lightdm.conf -i -e "s/^\(#\|\)autologin-user=.*/autologin-user=$SUDO_USER/"
 | 
			
		||||
          disable_raspi_config_at_boot
 | 
			
		||||
        else
 | 
			
		||||
          whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2
 | 
			
		||||
          whiptail --msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" 20 60 2
 | 
			
		||||
          return 1
 | 
			
		||||
        fi
 | 
			
		||||
        ;;
 | 
			
		||||
@@ -944,12 +866,6 @@ get_boot_wait() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
do_boot_wait() {
 | 
			
		||||
  get_init_sys
 | 
			
		||||
  if [ $SYSTEMD -eq 0 ]; then
 | 
			
		||||
    whiptail --msgbox "This option can only be selected when using systemd" 20 60 2
 | 
			
		||||
    return 1
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  DEFAULT=--defaultno
 | 
			
		||||
  if [ $(get_boot_wait) -eq 0 ]; then
 | 
			
		||||
    DEFAULT=
 | 
			
		||||
@@ -1057,12 +973,6 @@ get_rgpio() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
do_rgpio() {
 | 
			
		||||
  get_init_sys
 | 
			
		||||
  if [ $SYSTEMD -eq 0 ]; then
 | 
			
		||||
    whiptail --msgbox "This option can only be selected when using systemd" 20 60 2
 | 
			
		||||
    return 1
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  DEFAULT=--defaultno
 | 
			
		||||
  if [ $(get_rgpio) -eq 0 ]; then
 | 
			
		||||
    DEFAULT=
 | 
			
		||||
@@ -1619,12 +1529,11 @@ if [ "$INTERACTIVE" = True ]; then
 | 
			
		||||
    exit 1
 | 
			
		||||
  fi
 | 
			
		||||
  [ -e $CONFIG ] || touch $CONFIG
 | 
			
		||||
  get_init_sys
 | 
			
		||||
  calc_wt_size
 | 
			
		||||
  while true; do
 | 
			
		||||
	if is_pi ; then
 | 
			
		||||
      FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
 | 
			
		||||
        "1 Change User Password" "Change password for the default user (pi)" \
 | 
			
		||||
        "1 Change User Password" "Change password for the current user" \
 | 
			
		||||
        "2 Hostname" "Set the visible name for this Pi on a network" \
 | 
			
		||||
        "3 Boot Options" "Configure options for start-up" \
 | 
			
		||||
        "4 Localisation Options" "Set up language and regional settings to match your location" \
 | 
			
		||||
@@ -1636,7 +1545,7 @@ if [ "$INTERACTIVE" = True ]; then
 | 
			
		||||
        3>&1 1>&2 2>&3)
 | 
			
		||||
    else
 | 
			
		||||
      FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
 | 
			
		||||
        "1 Change User Password" "Change password for the default user (pi)" \
 | 
			
		||||
        "1 Change User Password" "Change password for the current user" \
 | 
			
		||||
        "2 Hostname" "Set the visible name for this PC on a network" \
 | 
			
		||||
        "3 Boot Options" "Configure options for start-up" \
 | 
			
		||||
        "4 Localisation Options" "Set up language and regional settings to match your location" \
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user