[[linux_wiki:arch_linux_post_install_config]]

Arch Linux Post Install Config

General Information

This is a bash script written in 2011 as a project that walked through the Arch Linux configuration guide after a fresh install. The point was to quickly customize a system, without taking away the level of control that performing this manually would.

It is a long script and uses some interesting bash syntax, that I often refer back to for examples.

Checklist

  • Distro(s): Last tested on Arch Linux 2011.08; mainly used to refer to for syntax.

arch_config.sh
#!/bin/bash
 
## Arch Linux Post Install Interactive-Config
## Author: Bill Howe, 10/22/2011
## Version: 0.6b (beta)
##
## -Description: This bash script walks a user through the recommended
### post installation setup of an Arch Linux build. The items that are
### configured via this script are: network config/testing, pacman mirrors,
### system upgrade, standard user account creation, sudo install/config,
### install Xorg (X Windows), Video Drivers, Testing Xorg, Installing fonts,
### installing a desktop environment, and creating GUI startup files in the
### proper user directories. (.xinitrc files)
###
### -Arch Versions: Works with 2010.05 and 2011.08 64 and 32 bit core install.
### All other versions untested, but should work with all net installs.
###
### -Known Issue: If the list of countries is displayed a 2nd time (user
###   selects a country but changes mind) Czech Republic and Great Britain
###   display an "unary operator expected" error. 
clear
echo -e "===== Arch Linux Post Install Interactive-Config (0.6b) ====="
echo -e "\n#Welcome to the Arch Linux Post Install Config."
echo -e "--This interactive script walks you through the Arch Linux Wiki's"
echo -e "--post installation guide."
echo -e "\n#If at any point you see an option in brackets, like [example],"
echo -e "--pressing ENTER will default to that option."
 
echo -e "\n>>Press [ENTER] to start this script[]:\c"
read
###################### START: CONFIGURE NETWORK ########################
clear
echo -e "(1/11) Test For Internet Connection"
 
#Initial ping test, this will work if the network daemon was successful
echo -e "#Attempting to ping www.archlinux.org...\c"
PINGRESULTS=`ping -c 3 www.archlinux.org | awk '/transmitted/{print $6}' | sed 's/%//'`
 
if [ -z "$PINGRESULTS" -o "$PINGRESULTS" = 100 ] ; then
  echo -e "\n#Connection Issue detected: Failed DNS resolution or 100% packet loss."
  echo -e ">>What network interface should we use?[eth0]:\c"
  read NETINTERFACE
 
  # if undefined (user just pressed enter) default setting:
  if [ -z "$NETINTERFACE" ] ; then
    NETINTERFACE="eth0"
  fi
 
  echo -e "\n#Attempting to manually start DHCP services on [$NETINTERFACE]..."
  ifconfig $NETINTERFACE up
  dhcpcd -k $NETINTERFACE
  dhcpcd -n $NETINTERFACE
 
  echo -e "\n#Will attempt to test ping again."
  echo -e ">>Enter website to ping[www.archlinux.org]:\c"
  read WEBSITE
 
  # if undefined (user just pressed enter) default setting:
  if [ -z "$WEBSITE" ] ; then
    WEBSITE="www.archlinux.org"
  fi
 
  echo -e "\n#Attempting to ping $WEBSITE...\c"
  PINGRESULTS=`ping -c 3 $WEBSITE | awk '/transmitted/{print $6}' | sed 's/%//'`
 
  if [ -z "$PINGRESULTS" -o "$PINGRESULTS" = 100 ] ; then
    echo -e "\n#Connection Issue detected: Failed DNS resolution or 100% packet loss."
    echo -e ">>Set Static Network Information?(y/n) [y]:\c"
    read STATICNETWORK
 
    if [ -z "$STATICNETWORK" ] ; then
      STATICNETWORK="y"
    fi
 
    #setup static network until user says its correct
    while true ; do
 
      case $STATICNETWORK in
        [yY])
           echo -e ">>IP address:\c"
           read IP
           echo -e ">>Subnet Mask:\c"
           read MASK
           echo -e ">>Default Gateway:\c"
           read GW
           echo -e ">>DNS [Default: Google's Public DNS]:\c"
           read DNS
 
           # If DNS not set, use Google's
           if [ -z "$DNS" ] ; then
             DNS="8.8.8.8"
           fi
 
           echo -e "\n#Static Network Information"
           echo -e "--IP Address: $IP"
           echo -e "--Subnet Mask: $MASK"
           echo -e "--Default Gatewa: $GW"
           echo -e "--Name Server: $DNS"
           echo -e ">>Is this correct?(y/n) [y]:\c"
           read CORRECT
 
           if [ -z "$CORRECT" ] ; then
             CORRECT="y"
           fi
 
           case $CORRECT in
              [yY])
		       # Setup Static Network
               ifconfig eth0 $IP netmask $MASK up
               route add default gw $GW
 
               # Add the nameserver to the first line in resolv.conf
               sed -i '1i'"nameserver $DNS" /etc/resolv.conf
 
               echo -e "\n#Will attempt to test ping again."
               echo -e ">>Enter website to ping[www.archlinux.org]:\c"
               read WEBSITE
 
               # if undefined (user just pressed enter) default setting:
               if [ -z "$WEBSITE" ] ; then
                 WEBSITE="www.archlinux.org"
               fi
 
               echo -e "\n#Attempting to ping $WEBSITE...\c"
               PINGRESULTS=`ping -c 3 $WEBSITE | awk '/transmitted/{print $6}' | sed 's/%//'`
               if [ -z "$PINGRESULTS" -o "$PINGRESULTS" = 100 ] ; then
                 # All automated attempts at network setup have failed, exit program.
                 echo -e "\n#ERROR! Static Network configuration failed to ping the domain."
                 echo -e "--Please troubleshoot manually.\n"
                 exit 1
               fi
 
               #If we get here, static network config successful, break out of loop
               echo -e "\n#Static network configuration successful."
               break
             ;;
             *)
              # set static network info again
              echo -e "\n#Config reported as incorrect, please set again.\n"
              continue
             ;;
           esac # END of "is this CORRECT" case check
 
        ;; #END of "YES, set static ip"
 
        *) #User Does not want to setup a static network and Dynamic Config failed, exit.
          echo -e "#ERROR in configuring network. Script will exit, please troubleshoot manually.\n"
          exit 1
        ;;
      esac #End of static network case check
   done #End of loop to set static network info until correct
 
  fi # END of secondary ping check (after prompting for website)
fi # END of initial ping attempt check statement
 
# Pings now successful, continue.
echo -e "\n\n#Internet connection succeeded."
echo -e ">>Press [Enter] to continue[]:\c"
read
####################### END: CONFIGURE NETWORK #########################
 
####################### START: CONFIGURE PACMAN ########################
clear
echo -e "(2/11) Configure Pacman"
 
# Check to see if architecture is 64 bit, if so, offer to use multilib
ARCH=`uname -m`
 
if [ "$ARCH" = "x86_64" ] ; then
 
  echo -e "#The multilib repository enables 32-bit applications on Arch x86_64."
  echo -e ">>Enable multilib? (y/n) [n]:\c"
  read ENABLEMULTILIB
 
  # if undefined (user just pressed enter) default setting:
  if [ -z "$ENABLEMULTILIB" ] ; then
    ENABLEMULTILIB="n"
  fi
 
  if [ "$ENABLEMULTILIB" = "y" -o "$ENABLEMULTILIB" = "Y" ] ; then
    echo -e "[multilib]" >> /etc/pacman.conf
    echo -e "Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
    echo -e "--Multilib enabled!"
  else
    echo -e "--Multilib NOT enabled."
  fi
fi
 
#Set Internal field separator to a literal new line ("\n" doesn't work)
#This is required to properly build the COUNTRYLIST array
IFS='
'
 
#Create an array of the countries
#awk:Change field seperator to newline, search mirrorlist for lines that have "# .*" at the beginning
#awk:print that field (should be a country name) pipe to sed
#sed: filter out Lines that aren't countries (Arch, Generated, Any) and remove "# "'s
COUNTRYLIST=(`awk -F"\n" '/^##* .*/ {print $1}' /etc/pacman.d/mirrorlist | sed '/Arch/d;/Generated/d;/Any/d;s/##* //'`)
 
#Get total number of countries found
NUMCOUNTRIES=${#COUNTRYLIST[*]}
 
# Loop through country selection until a valid country is selected
#### START OF SELECT COUNTRY WHILE LOOP ####
while true ; do
echo -e "\n#Enter a country to use for the mirror list"
 
#Loop through list and display countries in two columns
INDEX=0
while [ $INDEX -lt $NUMCOUNTRIES ] ; do
 
  echo -e "$((INDEX+1))) ${COUNTRYLIST[$INDEX]}\c"
 
  #Check to see if country has spaces. if yes: echo only 1 tab, otherwise 2 tabs
  if [ `echo "${COUNTRYLIST[$INDEX]}" | grep " "` ] ; then
    echo -e "\t\c"
  else
    echo -e "\t\t\c"
  fi
  (( INDEX=INDEX+1 ))
 
  #If the new index is out of range, break out of the while loop
  if [ $INDEX -ge $NUMCOUNTRIES ] ; then break ; fi
 
  echo -e "$((INDEX+1))) ${COUNTRYLIST[$INDEX]}"
  (( INDEX=INDEX+1 ))
done
 
echo -e "\n>>Country? (1-$NUMCOUNTRIES) [United States]:\c"
read ENTERCOUNTRY
 
#Reset Internal field separator to a space
IFS=' '
 
# if undefined (user just pressed enter) default setting:
if [ -z $ENTERCOUNTRY ] ; then
  COUNTRY="United States"
 
#Otherwise, assign the country based upon the number (-1 to offset menu starting
#at 1 instead of zero)
elif [ $ENTERCOUNTRY -ge 1 -a $ENTERCOUNTRY -le $NUMCOUNTRIES ] ; then
  COUNTRY="${COUNTRYLIST[$ENTERCOUNTRY-1]}"
 
else
  echo -e "#WARNING: Country entered out of range! Enter [1-$NUMCOUNTRIES]!"
  echo -e ">>[ENTER] to try again[]:\c"
  read
  continue
fi
 
echo -e "--Country set to: $COUNTRY"
echo -e ">>Is this correct? (y/n) [y]:\c"
read CORRECT
 
#if user just pressed enter, assume yes
if [ -z "$CORRECT" ] ; then
  CORRECT="y"
fi
 
# If the country is correct, break out of while loop, if not, ask for country again
if [ "$CORRECT" = "y" -o "$CORRECT" = "Y" ] ; then
  break
fi
 
done
#### END OF SELECT COUNTRY WHILE LOOP ####
 
echo -e "\n#Backing up original mirrorlist..."
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
 
# Reset all servers to commented
echo -e "#Preparing mirrorlist for parsing (placing all servers as commented)..."
sed -i 's/^Server/#Server/' /etc/pacman.d/mirrorlist
 
echo -e "#Creating custom mirrorlist from [$COUNTRY] server list..."
# Find all mirrors in specified country with awk, save to countryMirrors file
awk -v COUNTRY="$COUNTRY" '/^# ..*/ && start==1 {start=0};$0 ~ COUNTRY {start=1};/^#Server/ && start==1 {print $0}' /etc/pacman.d/mirrorlist > /etc/pacman.d/countryMirrors
 
# Insert country name, commented at top of list
sed -i '1i '"# $COUNTRY" /etc/pacman.d/countryMirrors
 
echo -e "#Enabling all [$COUNTRY] mirrors..."
# Uncomment all mirrors from countryMirrors with sed
sed -i 's/^#Server/Server/' /etc/pacman.d/countryMirrors
 
echo -e "#Writing [$COUNTRY] Mirrors to mirrorlist..."
cat /etc/pacman.d/countryMirrors > /etc/pacman.d/mirrorlist
 
echo -e "\n#Refreshing mirrors..."
pacman -Syy
 
echo -e "\n#Checking for rankmirrors (curl)..."
while true ; do
  # Check to see if curl is installed, if so exit loop, if not run pacman
  CURLDIR=`which curl`
  if [ "$CURLDIR" = "/usr/bin/curl" ] ; then
    break
  fi
  echo -e "\n#Installing rankmirrors (curl)..."
  pacman -S --noconfirm curl
done
 
echo -e "\n#Ranking Top 6 mirrors..."
rankmirrors -n 6 /etc/pacman.d/countryMirrors > /etc/pacman.d/mirrorlist
 
echo -e "#Refreshing all packages...\n"
pacman -Syy
echo -e "\n#Configuring Pacman completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
######################## END: CONFIGURE PACMAN #########################
 
######################## START: UPGRADE SYSTEM #########################
clear
echo -e "(3/11) System Upgrade"
 
echo -e ">>Press [ENTER] to perform a full system update[]:\c"
read
 
echo -e "\n#Upgrading all packages..."
pacman -Syu --noconfirm
 
echo -e "\n#System upgrade completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
######################## END: UPGRADE SYSTEM #########################
 
###################### START: ADD A USER ACCOUNT #######################
clear
echo -e "(4/11) Add A Standard User"
 
# Loop to prompt for user account creation until quit detected
while true ; do
  echo -e ">>Add a standard user?(y/n) [y]:\c"
  read ADDUSER
 
  # if undefined (user just pressed enter) default setting:
  if [ -z "$ADDUSER" ] ; then
    ADDUSER="y"
  fi
 
  case $ADDUSER in
    [yY])
        #prompt for info
        echo -e ">>Username:\c"
        read USERNAME
        echo -e ">>Initial Group[users]:\c"
        read INITIALGROUP
 
        # if undefined (user just pressed enter) default setting:
        if [ -z "$INITIALGROUP" ] ; then
          INITIALGROUP="users"
        fi
 
        echo -e ">>Additional Groups[audio,lp,optical,storage,video,wheel,games,power,scanner]:\c"
        read ADDGROUPS
 
        # if undefined (user just pressed enter) default setting:
        if [ -z "$ADDGROUPS" ] ; then
          ADDGROUPS="audio,lp,optical,storage,video,wheel,games,power,scanner"
        fi
 
        echo -e ">>Shell [/bin/bash]:\c"
        read SHELL
 
        # if undefined (user just pressed enter) default setting:
        if [ -z "$SHELL" ] ; then
          SHELL="/bin/bash"
        fi
 
        echo -e "\n#The following user account will be created:"
        echo -e "--User: $USERNAME"
        echo -e "--Initial Group: $INITIALGROUP"
        echo -e "--Additional Groups: $ADDGROUPS"
        echo -e "--Shell: $SHELL"
 
        echo -e ">>OK to create?(y/n) [y]:\c"
        read CREATEUSER
 
        # if undefined (user just pressed enter) default setting:
        if [ -z "$CREATEUSER" ] ; then
          CREATEUSER="y"
        fi
 
        if [ "$CREATEUSER" = "y" -o "$CREATEUSER" = "Y" ] ; then
          echo -e "\n#Creating user account..."
          useradd -m -g $INITIALGROUP -G $ADDGROUPS -s $SHELL $USERNAME
 
          echo -e ">>Set Password for \"$USERNAME\""
          passwd $USERNAME
          echo -e ""
 
          else
            echo -e "\n#User account \"$USERNAME\" will NOT be created."
        fi
    ;; # Create user account "yes" case done
    *) # No, do not create user account. Exit loop
      echo -e "#Exiting user account creation tool..."
      break
    ;;
  esac
done
echo -e "\n#Adding user account(s) completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
######################## END: ADD A USER ACCOUNT #######################
 
######################## START: INSTALL SUDO ###########################
clear
echo -e "(5/11) Install Sudo\n"
 
echo -e "\n#Checking to see if Sudo is installed..."
SUDODIR=`which sudo`
if [ "$SUDODIR" = "/usr/bin/sudo" ] ; then 
  echo -e "\n#Sudo appears to be installed. Skipping this section..."
else 
  echo -e "\n>>Sudo not detected, proceed with installing?(y/n) [y]:\c"
  read INSTALLSUDO
 
  # if undefined (user just pressed enter) default setting:
  if [ -z "$INSTALLSUDO" ] ; then
    INSTALLSUDO="y"
  fi
 
  if [ "$INSTALLSUDO" = "y" -o "$INSTALLSUDO" = "Y" ] ; then
    echo -e "#Installing sudo..."
    pacman -S --noconfirm sudo
 
    echo -e "==================================================================="
    echo -e "\n--You must now edit the /etc/sudoers file to give sudo access."
    echo -e "--This can be given to the wheel group or a single user."
 
    echo -e "\n#Wheel Group: Remove the comment('#') from this line:"
    echo -e "-- # %wheel ALL=(ALL) ALL"
 
    echo -e "\n#Single User: Find \"root ALL=(ALL) ALL\" and add this under it:"
    echo -e "-- \"username ALL=(ALL) ALL\""
    echo -e "-- You should replace \"username\" with the proper user account"
 
    echo -e "\n>>Edit using vi or nano? (vi/nano) [nano]:\c"
    read VISUDOEDITOR
 
    # if undefined (user just pressed enter) default setting:
    if [ -z "$VISUDOEDITOR" ] ; then
      VISUDOEDITOR="nano"
    fi
 
    if [ "$VISUDOEDITOR" = "vi" ] ; then
       EDITOR=vi visudo
     else
       EDITOR=nano visudo
    fi
  else
    echo -e "#Sudo will NOT be installed..."
  fi
fi
echo -e "\n#Configuring Sudo completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
######################## END: INSTALL SUDO #############################
 
###################### START: INSTALL X Windows ########################
clear
echo -e "(6/11) Install X Window System"
 
echo -e "\n#The Xorg packages allow for basic graphics support."
echo -e "#These packages are a requirement if you want to install a graphical"
echo -e "#environment. They can be skipped if you have no need for a GUI."
echo -e "\n>>Install Xorg Base Packages?(y/n) [y]:\c"
read INSTALLXORG
 
# if undefined (user just pressed enter) default setting:
if [ -z "$INSTALLXORG" ] ; then
  INSTALLXORG="y"
fi
 
if [ "$INSTALLXORG" = "y" -o "$INSTALLXORG" = "Y" ] ; then
    echo -e "#Installing X Base Packages..."  
    pacman -S --noconfirm xorg-server xorg-xinit xorg-utils xorg-server-utils
    XORGINSTALLED="yes"
 
    echo -e "\n>>Install Mesa for 3D support? (y/n) [y]:\c"
    read INSTALLMESA
 
    # if undefined (user just pressed enter) default setting:
    if [ -z "$INSTALLMESA" ] ; then
      INSTALLMESA="y"
    fi
 
    if [ "$INSTALLMESA" = "y" -o "$INSTALLMESA" = "Y" ] ; then
       echo -e "#Installing mesa..."
       pacman -S --noconfirm mesa
      else
        echo -e "--Mesa NOT installed."
    fi
 else
    echo -e "\n--Xorg will NOT be installed."
    XORGINSTALLED="no"
fi
echo -e "\n#Configuring X Windows completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
####################### END: INSTALL X Windows #########################
 
##################### START: INSTALL VIDEO DRIVER ######################
clear
echo -e "(7/11) Install Video Driver"
 
if [ "$XORGINSTALLED" = "yes" ] ; then
 
# Find VGA controller
VGA=`lspci | grep "VGA" | awk '/VGA/{print $5}'`
 
echo -e "\n#You appear to have a $VGA graphics controller."
echo -e "#I will search pacman for possible drivers...\n"
pacman -Ss xf86-video | grep -i "$VGA"
echo -e "\n--Done listing possible drivers via auto search."
 
while true ; do
  echo -e "\n#What would you like to do?"
  echo -e "--1)Enter driver name now"
  echo -e "--2)Install generic vesa driver"
  echo -e "--3)Install NVIDIA driver(nvidia or nouveau)"
  echo -e "--4)Install ATI driver(xf86-video-ati)"
  echo -e "--5)List all drivers so I can decide"
  echo -e "--0)Skip installing a video driver"
  echo -e ">> (0-5):\c"
  read VIDEOCHOICE
 
  case $VIDEOCHOICE in
    1)
      echo -e "\n#Enter full name of video driver (ex: xf86-video-vesa)"
      echo -e ">>Driver name:\c"
      read DRIVERNAME
 
      echo -e ">>Attempt to install $DRIVERNAME?(y/n) [y]:\c"
      read ATTEMPTINSTALL
 
      # if undefined (user just pressed enter) default setting:
      if [ -z "$ATTEMPTINSTALL" ] ; then
        ATTEMPTINSTALL="y"
      fi
 
      if [ "$ATTEMPTINSTALL" = "y" -o "$ATTEMPTINSTALL" = "Y" ] ; then
        if [ "pacman -S $DRIVERNAME" ] ; then
          echo -e "#Installing $DRIVERNAME..."
          pacman -S --noconfirm "$DRIVERNAME"
          VIDEOINSTALLED="yes"
          break
        else
          echo -e "--Driver not found!"
          continue
        fi
          echo -e "--Aborting driver installation..."
          continue
      fi
    ;;
    2)
      echo -e "\n#Install Generic Vesa Driver. Are you sure? (y/n) [y]:\c"
      read CONFIRM
 
      if [ -z "$CONFIRM" ] ; then
        CONFIRM="y"
      fi
 
      if [ "$CONFIRM" = "y" -o "$CONFIRM" = "Y" ] ; then
        echo -e "\n#Installing generic vesa driver..."
        pacman -S --noconfirm xf86-video-vesa
        VIDEOINSTALLED="yes"
        break
      else
        echo -e "--Aborting vesa driver install..."
        continue
      fi
    ;;
    3)
      echo -e "\n#Choose a Nvidia driver"
      echo -e "--1) Nvidia Proprietary Driver (nvidia)"
      echo -e "--2) Nvidia Open Source Driver (nouveau)"
      echo -e ">>(1 or 2):\c"
      read NVIDIADRIVER
 
      if [ "$NVIDIADRIVER" = "1" ] ; then
         echo -e "\n#Install proprietary nvidia driver. Are you sure? (y/n) [y]:\c"
         read CONFIRM
 
         if [ -z "$CONFIRM" ] ; then
           CONFIRM="y"
         fi
 
         if [ "$CONFIRM" = "y" -o "$CONFIRM" = "Y" ] ; then
           echo -e "#Installing Nvidia Proprietary Driver..."
           pacman -S --noconfirm nvidia
           VIDEOINSTALLED="yes"
           break
         else
           echo "#Aborting proprietary nvidia driver install..."
           continue
         fi
      elif [ "$NVIDIADRIVER" = "2" ] ; then
         echo -e "\n#Install open source nouveau driver. Are you sure? (y/n) [y]:\c"
         read CONFIRM
 
         if [ -z "$CONFIRM" ] ; then
           CONFIRM="y"
         fi
 
         if [ "$CONFIRM" = "y" -o "$CONFIRM" = "Y" ] ; then
           echo -e "#Installing Nvidia Open Source Driver (nouveau)..."
           pacman -S --noconfirm xf86-video-nouveau
           VIDEOINSTALLED="yes"
           break
         else
           echo -e "#Aborting open source nouveau driver install..."
           continue
         fi
      else
         echo -e "#Invalid selection!"
         continue
      fi
    ;;
    4)
      echo -e "\n#Install ATI driver. Are you sure? (y/n) [y]:\c"
      read CONFIRM
 
      if [ -z "$CONFIRM" ] ; then
        CONFIRM="y"
      fi
 
      if [ "$CONFIRM" = "y" -o "$CONFIRM" = "Y" ] ; then
        echo -e "\n#Installing ATI driver..."
        pacman -S --noconfirm xf86-video-ati
        VIDEOINSTALLED="yes"
        break
      else
        echo -e "#Aborting ATI driver install..."
        continue
      fi
    ;;
    5)
      echo -e "\n#I will now list possible drivers to install with the \"less\" program."
      echo -e ">>Press 'q' when you are done looking. [ENTER] to continue[]:\c"
      read
      pacman -Ss xf86-video | less
      echo -e "\n#I will now return you to the video driver menu to make your install selection."
      echo -e "--Once there, enter option '0' (zero) if you know what to install."
      echo -e ">>Press [ENTER] to continue[]:\c"
      read
      continue
    ;;
    0)
      echo -e "\n--Video Driver NOT installed."
      VIDEOINSTALLED="no"
      break
    ;;
    *)
      echo -e "\n#Invalid choice!"
      continue
    ;;
  esac
done
 
else
  echo -e "#Skipping installation of video card driver since xorg is not installed..."
  VIDEOINSTALLED="no"
fi
echo -e "\n#Configuring Video Drivers completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
###################### END: INSTALL VIDEO DRIVER #######################
 
######################## START: TEST X WINDOWS #########################
clear
echo -e "(8/11) Testing X Window System"
 
if [ "$XORGINSTALLED" = "yes" -a "$VIDEOINSTALLED" = "yes" ] ; then
 
echo -e "\n#Both Xorg and a Video Driver have been installed."
echo -e ">>Press [ENTER] to install default test environment[]:\c"
read
 
echo -e "\n#Installing default test environment..."
pacman -S --noconfirm xorg-twm xterm
 
echo -e "\n#Installing Message bus (dbus)..."
pacman -S --noconfirm dbus
 
echo -e "\n#Adding dbus to Daemons array (/etc/rc.conf)..."
sed -i 's/syslog-ng/syslog-ng dbus/' /etc/rc.conf
 
echo -e "#Starting dbus (to avoid restart)..."
/etc/rc.d/dbus start
 
echo -e "\n--Will now issue the command \"startx\" to test x environment"
echo -e "--If you see xterm consoles, type \"exit\" in each to exit back to here."
 
echo -e "\n--If that does not work, attempt to kill x by typing \"pkill x\"."
 
echo -e "\n--If pkill x does not work, or you can't see anything, attempt to "
echo -e "--reboot blindly by typing \"reboot\""
 
echo -e "\n>>Test X now?(y/n) [y]:\c"
read TESTX
 
  # if undefined (user just pressed enter) default setting:
  if [ -z "$TESTX" ] ; then
    TESTX="y"
  fi
 
  if [ "$TESTX" = "y" -o "$TESTX" = "Y" ] ; then
    startx
  else
    echo -e "\n--Skipping Test of X Windows."
  fi
 
else
  echo -e "\n--Skipping test of X Windows since either Xorg or Video Drivers are not installed..."
 
fi
echo -e "\n#Testing X Windows completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
######################### END: TEST X WINDOWS ##########################
 
######################## START: INSTALL FONTS ##########################
clear
echo -e "(9/11) Install Fonts"
 
echo -e "\n#Installing true type fonts improves many dialog box text."
echo -e "#It is recommended to install them."
echo -e "\n>>Install dejavu true type fonts? (y/n) [y]:\c"
read INSTALLFONTS
 
# if undefined (user just pressed enter) default setting:
if [ -z "$INSTALLFONTS" ] ; then
  INSTALLFONTS="y"
fi
 
if [ "$INSTALLFONTS" = "y" -o "$INSTALLFONTS" = "Y" ] ; then
  echo -e "\n#Installing true type fonts..."
  pacman -S --noconfirm ttf-dejavu
else
  echo -e "\n#True type fonts will NOT be installed."
fi
echo -e "\n#Installing fonts completed." 
echo -e ">>Press [Enter] to continue[]:\c"
read
######################## START: INSTALL FONTS ##########################
 
########################### START: SELECT DE ###########################
clear
echo -e "(10/11) Install DE or WM"
 
if [ "$XORGINSTALLED" = "yes" -a "$VIDEOINSTALLED" = "yes" ] ; then
 
while true ; do
 echo -e "\n#Would you like to install one of the following Desktop Environments?"
 echo -e "--1) KDE"
 echo -e "--2) Gnome"
 echo -e "--3) Xfce"
 echo -e "--0) Do not install any of these"
 echo -e ">>(0-3):\c"
 read DECHOICE
 
 case $DECHOICE in
   1)
     echo -e "\n#Installing KDE..."
     echo -e "#Ensuring system is up to date..."
     pacman -Syu --noconfirm
     pacman -S --noconfirm kde
 
     echo -e "\n#KDE base installed."
 
     break
   ;;
   2)
     echo -e "\n#Installing Gnome..."
     echo -e "#Ensuring system is up to date..."
     pacman -Syu --noconfirm
     pacman -S --noconfirm gnome
 
     echo -e "\n#Gnome base installed."
     echo -e ">>Install Gnome-Extra Package?(y/n) [y]:\c"
     read GNOMEEXTRA
 
     if [ -z "$GNOMEEXTRA" ] ; then
       GNOMEEXTRA="y"
     fi
 
     if [ "$GNOMEEXTRA" = "Y" -o "$GNOMEEXTRA" = "y" ] ; then
       echo -e "\n#Installing Gnome-Extra..."
       pacman -S --noconfirm gnome-extra
      else
       echo -e "\n#Skipping installation of Gnome-Extra..."
     fi
 
     break
   ;;
   3)
     echo -e "\n#Installing Xfce..."
     echo -e "#Ensuring system is up to date..."
     pacman -Syu --noconfirm
     pacman -S --noconfirm xfce4
 
     echo -e "\n#Installing gstreamer plugins..."
     pacman -S --noconfirm gstreamer0.10-base-plugins
 
     #echo -e "\n#Replacing fam with gamin..."
     #pacman -S --noconfirm gamin
 
     echo -e "\n#Xfce4 base installed."
     echo -e ">>Install Xfce4 Goodies Package?(y/n) [y]:\c"
     read XFCEGOODIES
 
     if [ -z "$XFCEGOODIES" ] ; then
       XFCEGOODIES="y"
     fi
 
     if [ "$XFCEGOODIES" = "Y" -o "$XFCEGOODIES" = "y" ] ; then
       echo -e "\n#Installing Xfce4 Goodies..."
       pacman -S --noconfirm xfce4-goodies
      else
       echo -e "\n#Skipping installation of Xfce4 Goodies..."
     fi
     break
   ;;
   0)
     echo -e "#No desktop environment will be installed."
     break
   ;;
   *)
     echo -e "\n#Invalid Choice!"
     continue
   ;;
 esac
done
 
else
  echo -e "\n--Skipping installation of a Desktop Environment since either Xorg or Video Drivers are not installed..."
 
fi
 
echo -e "\n#Installing a Desktop Environment section completed."
echo -e ">>Press [Enter] to continue[]:\c"
read
############################ END: SELECT DE ############################
 
###################### START: SETUP GUI FOR USER #######################
clear
echo -e "(11/11) Create User DE Startx Files (.xinitrc)"
 
#If user did not install a DE, skip this section
if [ $DECHOICE = 0 ] ; then
  echo -e "\n#No Desktop Environment detected. Skipping this section..."
else
 
echo -e "\n#In order for users to be able to start the desktop environment"
echo -e "--a .xinitrc file needs to be created in their home folder."
echo -e "\n#Once created, they will be able to start a graphical environment"
echo -e "--by typing \"startx\" after login."
 
#Check to see what DE was installed (1=KDE,2=GNOME,3=XFCE)
case $DECHOICE in
  1) #KDE
    echo -e "\n#KDE detected."
    STARTX="exec ck-launch-session startkde"
  ;;
  2) #GNOME
    echo -e "\n#Gnome detected."
    STARTX="exec ck-launch-session gnome-session"
  ;;
  3) #XFCE
    echo -e "\n#Xfce detected."
    STARTX="exec ck-launch-session dbus-launch --exit-with-session startxfce4"
  ;;
  *) #Catch-all, should not get here
    echo -e "\n#Error detecting a desktop environment. Now exiting..."
    exit 1
  ;;
esac
 
#Set Internal field separator to a literal new line ("\n" doesn't work)
IFS='
'
#Create array of all standard users (group 100)
USERLIST=(`awk -F":" '/100/ {print $1}' /etc/passwd`)
 
#Get total number of users
TOTALUSERS=${#USERLIST[*]}
 
###START WHILE LOOP TO SELECT A VALID USER ###
while true ; do
 
  #Display all standard users for selection
  echo -e "\n#The following standard users were discovered:"
 
  #Loop through array, print users in columns of two
  INDEX=0
  while [ $INDEX -lt $TOTALUSERS ] ; do
 
    #We want the option 0 to be "all users", so make a special case
    if [ $INDEX = 0 ] ; then
      echo -e "$INDEX) All Users\t\c"
    else
    #otherwise, output the index+1 for the menu selection, since we used 0 for all users
    #The index of the actual data stays the same 
      echo -e "$((INDEX+1))) ${USERLIST[$INDEX]}\t\c"
      (( INDEX=INDEX+1 ))
    fi
 
    #If the previous mid-loop increment went equal/above the total users, break
    if [ $INDEX -ge $TOTALUSERS ] ; then break ; fi
 
    #Output 2nd column of users
    echo -e "$((INDEX+1))) ${USERLIST[$INDEX]}"
    (( INDEX=INDEX+1 ))
 
  done
 
  echo -e "\n>>Create startx files for who? (0-$TOTALUSERS) [0]:\c"
  read WHATUSERS
 
  #User just pressed ENTER, use default of all users
  if [ -z $WHATUSERS ] ; then
    WHATUSERS=0
    break
  elif [ $WHATUSERS -ge 0 -a $WHATUSERS -le $TOTALUSERS ] ; then
    #just break, since WHATUSERS is valid
    break
  else
    echo -e "#Warning: Invalid user selection. Please use [0-$TOTALUSERS]."
    echo -e ">>Press [ENTER] to try again.[]\c"
    read
    continue
  fi
 
done
### END OF WHILE LOOP TO GET VALID USER SELECTION ###
 
#Copy skeleton .xinitrc to each users home folder and give them ownership
#Append the correct startx command to each file
 
if [ $WHATUSERS = 0 ] ; then
  # 0 = All users: loop through user list and create the .xinitrc for each user
  for INDEX in ${USERLIST[*]} ; do
    cp /etc/skel/.xinitrc "/home/$INDEX/.xinitrc"
    chown "$INDEX:users" "/home/$INDEX/.xinitrc"
    echo "$STARTX" >> "/home/$INDEX/.xinitrc"
    echo -e "#Created /home/$INDEX/.xinitrc"
  done
else
  #Only do this for a specific user (subtract 1 to offset the all users menu category
  cp /etc/skel/.xinitrc "/home/${USERLIST[$WHATUSERS-1]}/.xinitrc"
  chown "${USERLIST[$WHATUSERS-1]}:users" "/home/${USERLIST[$WHATUSERS-1]}/.xinitrc"
  echo "$STARTX" >> "/home/${USERLIST[$WHATUSERS-1]}/.xinitrc"
  echo -e "#Created /home/${USERLIST[$WHATUSERS-1]}/.xinitrc"
fi
 
fi #end of initial if statement
echo -e "\n#Done creating the startx file(s)." 
echo -e ">>Press [ENTER] to continue[]:\c"
read
####################### END: SETUP GUI FOR USER ########################
 
echo -e "\n==== Arch Post Install Interactive Config Script Complete! ====\n"
exit
  • linux_wiki/arch_linux_post_install_config.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)