You are not logged in.

#1 2010-07-15 03:20:50

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Post-installation bash script for configuring Arch

Here's a little (actually, fairly large) script I wrote for post installation things such as:
- Selecting a mirror
- Installing X
- Installing misc. things (keyboard, mouse, touchpad)
- Installing video card
- Configuring X
- Installing/configuring a DE
- Installing/configuring a WM
- Installing a web browser
- Installing an AUR helper

The code is really crappy, sorry. Bash is not my forte, and all it really is is a bunch if scattered functions. All I know is that it works smile

#!/bin/bash
clear

# Define text colors
txtwhite='\e[0;37m' # White
txtgreen='\e[0;32m' # Green
txtyellow='\e[0;33m' # Yellow
txtred='\e[0;31m' # Red


function txt {
    echo -e "${txtwhite}"
}

# Check if the user is root
if [ "$(id -u)" != "0" ]; then
    echo -e "${txtred}This script must be run as root" 1>&2
    txt
    exit 1
fi

echo -e "${txtyellow}Welcome to the Arch Linux beginner configuration script"
echo -e "${txtyellow}You will be guided through the process of post-installation configuration"
txt

echo -e "${txtgreen}You must uncomment a server line in /etc/pacman.d/mirrorlist"
echo -e "${txtgreen}To do this, remove the # from the beginning of a line. To exit nano, hit Ctrl+X"
txt

sleep 5

nano /etc/pacman.d/mirrorlist


if [ -f /var/lib/pacman/db.lck ]; then
    echo -e "${txtgreen}Removing database lock..."
    txt
    rm /var/lib/pacman/db.lck
fi

# Run an update
echo -e "${txtgreen}Running system upgrade..."
txt
pacman -Syu
clear

# Add a user
function user_add {
    echo -en "${txtgreen}"
    read -p "Would you like to create an initial user? [y/n] " -e answer
    
    if [ $answer == "y" ]; then
        echo -en "Entering the ${txtyellow}adduser${txtgreen} program..."
        txt
        adduser
    elif [ $answer == "n" ]; then
        return
    else
        echo -e "${txtred}Incorrect option"
        user_add    
    fi
}
user_add
clear

# AUR Helper
function aur_config {
        echo -en "${txtgreen}"
        read -p "Which of the following AUR helpers would you like to install? [yaourt/packer/clyde/none] " -e answer
    
        if [ $answer == "yaourt" ]; then
        if [ ! -e /usr/bin/wget ]; then
            pacman -S wget
        fi
        echo -en "Downloading package-query tarball..."
        wget http://aur.archlinux.org/packages/package-query/package-query.tar.gz
        tar xvf package-query.tar.gz
        cd package-query
        echo -en "Building package..."
        makepkg -s --asroot 
        pacman -U package-query*.pkg.tar.xz
        cd .. && rm -r package-query
        echo -en "Downloading yaourt tarball..."
                wget http://aur.archlinux.org/packages/yaourt/yaourt.tar.gz &> /dev/null
        tar xvf yaourt.tar.gz
        cd yaourt
        echo -en "Building package..."
        makepkg -s --asroot 
        pacman -U yaourt*.pkg.tar.xz
        cd .. && rm -r yaourt
        aur_helper="yaourt"            
        elif [ $answer == "packer" ]; then
        if [ ! -e /usr/bin/wget ]; then
            pacman -S wget
        fi
                echo -en "Downloading packer tarball..."
                wget http://aur.archlinux.org/packages/packer/packer.tar.gz
                tar xvf packer.tar.gz                                         
                cd packer
        echo -en "Building package..."
                makepkg -s --asroot
                pacman -U packer*.pkg.tar.xz
        cd .. && rm -r packer
        aur_helper="packer"
        elif [ $answer == "clyde" ]; then
        if [ ! -e /usr/bin/wget ]; then
            pacman -S wget
        fi
                echo -en "Downloading clyde tarball..."
                wget http://aur.archlinux.org/packages/clyde-git/clyde-git.tar.gz
                tar xvf clyde-git.tar.gz                                         
                cd clyde-git
        echo -en "Building package..."
                makepkg -s --asroot
                pacman -U clyde*.pkg.tar.xz
        cd .. && rm -r clyde-git
        aur_helper="clyde"
        elif [ $answer == "none" ]; then
        aur_helper="none"
                return
        else
                echo -e "${txtred}Incorrect option"
                aur_config
        fi
}
aur_config
clear
 
# Install X
function x_install {
    echo -en "${txtgreen}"
    read -p "Would you like to install and setup X? [y/n] " -e answer

    if [ $answer == "y" ]; then
        echo -en "Installing X via pacman..."
        txt
        pacman -S xorg        
    elif [ $answer == "n" ]; then
        clear
        echo -e "${txtgreen}Arch Linux config complete"
        txt
        exit
    else
        echo -e "${txtred}Incorrect option"
        x_install
    fi
}
x_install
clear

# Keyboard
function keyboard_install {
        echo -en "${txtgreen}"
        read -p "Will you be using a keyboard? [y/n] " -e answer
    
        if [ $answer == "y" ]; then
                echo -en "Installing keyboard driver via pacman..."
                txt 
                pacman -S xf86-input-keyboard
        elif [ $answer == "n" ]; then
                return
        else
                echo -e "${txtred}Incorrect option"
                keyboard_install
        fi  
}
keyboard_install
clear

# Touchpad
function synaptics_install {
        echo -en "${txtgreen}"
        read -p "Will you be using a laptop touchpad? [y/n] " -e answer

        if [ $answer == "y" ]; then 
                echo -en "Installing touchpad driver via pacman..."
                txt
                pacman -S xf86-input-synaptics
        elif [ $answer == "n" ]; then
                return
        else        
                echo -e "${txtred}Incorrect option"
                synaptics_install
        fi  
}               
synaptics_install
clear

# Mouse
function mouse_install {
        echo -en "${txtgreen}"
        read -p "Will you be using a mouse? [y/n] " -e answer
        
        if [ $answer == "y" ]; then 
                echo -en "Installing mouse driver via pacman..."
                txt
                pacman -S xf86-input-mouse
        elif [ $answer == "n" ]; then
                return
        else
                echo -e "${txtred}Incorrect option"
                mouse_install
        fi
} 
mouse_install
clear

function ati_install {
        echo -en "${txtgreen}"
    echo "NOTE: ati fits most cards and radeonhd is for r500/r600 cards"
        read -p "Which of the following would you like to use? [ati/radeonhd/none] " -e answer
    
        if [ $answer == "ati" ]; then 
                echo -en "Installing ATI driver via pacman..."
                txt
                pacman -S xf86-video-ati
        elif [ $answer == "radeonhd" ]; then
                echo -en "Installing ATI radeonhd driver via pacman..."
        txt
        pacman -S xf86-video-radeonhd
        elif [ $answer == "none" ]; then
        return
    else
                echo -e "${txtred}Incorrect option"
                ati_install
        fi  
} 

function nvidia_install {
        echo -en "${txtgreen}"
    echo "NOTE: nouveau is open source. You must add nouveau to the MODULES array in /etc/rc.conf"
        read -p "Which of the following would you like to use? [nouveau/none] " -e answer

        if [ $answer == "nouveau" ]; then     
                echo -en "Installing nVidia nouveau driver via pacman..."
                txt
                pacman -S xf86-video-nouveau
        elif [ $answer == "none" ]; then
                return
        else    
                echo -e "${txtred}Incorrect option"
                nvidia_install
        fi  
} 


# Video card
function video_install {
        echo -en "${txtgreen}"
        read -p "Which brand of video card do you have installed in this PC? [ati/intel/nvidia/all/none] " -e answer

        if [ $answer == "ati" ]; then
                clear
        ati_install
                txt
        elif [ $answer == "nvidia" ]; then
                clear
        nvidia_install
        txt
        elif [ $answer == "intel" ]; then
        pacman -S xf86-video-intel
                txt
        elif [ $answer == "all" ]; then
                clear
        ati_install
        nvidia_install
        pacman -S xf86-video-intel
                txt
        elif [ $answer == "none" ]; then
                return
    else
                echo -e "${txtred}Incorrect option"
                video_install
        fi
} 
video_install
clear

# X user config
function x_user_config {
        echo -en "${txtgreen}"
        read -p "(If applicable) Enter the username of your previously created user [your username/none] " -e user

        if [ $user == "none" ]; then
                return
        elif [ $user == "" ]; then
                echo -e "${txtred}Incorrect option"
        x_user_config
    elif [ $user == " " ]; then
        echo -e "${txtred}Incorrect option"
                x_user_config
        else
                echo -e "#!/bin/sh\n" >> /home/$user/.xinitrc
        chmod 755 /home/$user/.xinitrc
        fi  
}
x_user_config
clear

# Configure X
function x_config {
        echo -en "${txtgreen}"
        read -p "Would you like to automatically configure X (recommended)? [y/n] " -e answer

        if [ $answer == "y" ]; then
                echo -en "Automatically configuring X..."
                txt
        X -configure &> /dev/null
        cp /root/xorg.conf.new /etc/X11/xorg.conf
        echo -e "#!/bin/sh\n" >> /root/.xinitrc  
        chmod +x /root/.xinitrc             
        elif [ $answer == "n" ]; then
                return
        else
                echo -ue "${txtred}Incorrect option"
                x_config
        fi  
}
x_config
clear



# Desktop environment
function de_config {
        echo -en "${txtgreen}"
        read -p "Which desktop environment would you like to install? [gnome/kde/xfce/none] " -e answer

        if [ $answer == "gnome" ]; then
            echo -en "Installing gnome via pacman..."
        txt
        pacman -S gnome
        echo "exec gnome-session" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec gnome-session" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "kde" ]; then
        echo -en "Installing kde via pacman..."
                txt
                pacman -S kde
        echo "exec startkde" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec startkde" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "xfce" ]; then
                echo -en "Installing xfce4 via pacman..."
                txt
                pacman -S xfce4
              echo "exec ck-launch-session startxfce4" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec ck-launch-session startxfce4" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "none" ]; then
            return
        else
                echo -ue "${txtred}Incorrect option"
                de_config
        fi  
}
de_config
clear

# Window manager
function wm_config {
        echo -en "${txtgreen}"
        read -p "Which window manager would you like to install? [awesome/dwm/evilwm/enlightenment/fluxbox/i3/jwm/musca/openbox/pekwm/pawm/ratpoison/sawfish/scrotwm/xmonad/wmii/none] " -e answer

        if [ $answer == "awesome" ]; then
                echo -en "Installing awesome via pacman..."
                txt
                pacman -S awesome
        echo "exec awesome" >> /root/.xinitrc
        mkdir -p /root/.config/awesome/
        cp /etc/xdg/awesome/rc.lua /root/.config/awesome
        if [ $user != "none" ]; then
                    echo "exec awesome" >> /home/$user/.xinitrc
            mkdir -p /home/$user/.config/awesome/
            cp /etc/xdg/awesome/rc.lua /home/$user/.config/awesome
        fi
        elif [ $answer == "dwm" ]; then
                echo -en "Installing dwm via pacman..."
                txt
                pacman -S dwm dmenu
        echo "exec dwm" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec dwm" >> /home/$user/.xinitrc
        fi
        elif [ $answer == "evilwm" ]; then
                echo -en "Installing evilwm via pacman..."
                txt
                pacman -S evilwm
        echo "exec evilwm" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec evilwm" >> /home/$user/.xinitrc
        fi
        elif [ $answer == "enlightenmnt" ]; then
                echo -en "Installing enlightenment via pacman..."
                txt
                pacman -S enlightenment
        echo "exec enlightenment" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec enlightenment" >> /home/$user/.xinitrc
        fi
        elif [ $answer == "fluxbox" ]; then
                echo -en "Installing enlightenment via pacman..."
                txt
                pacman -S fluxbox
        echo "exec startfluxbox" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec startfluxbox" >> /home/$user/.xinitrc
        fi
        elif [ $answer == "i3" ]; then
                echo -en "Installing i3 via pacman..."
                txt
                pacman -S fluxbox
        echo "exec i3" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec i3" >> /home/$user/.xinitrc
        fi
        elif [ $answer == "jwm" ]; then
                echo -en "Installing jwm via pacman..."
                txt
                pacman -S jwm
        echo "exec jwm" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec jwm" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "openbox" ]; then
                echo -en "Installing openbox via pacman..."
                txt
                pacman -S openbox
        echo "exec openbox-session" >> /root/.xinitrc
        mkdir -p /root/.config/openbox/
        cp /etc/xdg/openbox/rc.xml /root/.config/openbox/rc.xml
        cp /etc/xdg/openbox/menu.xml /root/.config/openbox/menu.xml
        
        if [ $user != "none" ]; then
            echo "exec openbox-session" >> /home/$user/.xinitrc
            mkdir -p /home/$user/.config/openbox/
            cp /etc/xdg/openbox/rc.xml /home/$user/.config/openbox/rc.xml
            cp /etc/xdg/openbox/menu.xml /home/$user/.config/openbox/menu.xml
            chmod -R 755 /home/$user/.config/openbox/
        fi
    elif [ $answer == "pekwm" ]; then
                echo -en "Installing pekwm via pacman..."
                txt
                pacman -S pekwm
        echo "exec pekwm" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec pekwm" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "pawm" ]; then
                echo -en "Installing pawm via pacman..."
                txt
                pacman -S pawm
        echo "exec pawm" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec pawm" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "ratpoison" ]; then
                echo -en "Installing ratpoison via pacman..."
                txt
                pacman -S ratpoison
        echo "exec ratpoison" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec ratpoison" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "sawfish" ]; then
                echo -en "Installing sawfish via pacman..."
                txt
                pacman -S sawfish
        echo "exec sawfish" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec sawfish" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "scrotwm" ]; then
                echo -en "Installing scrotwm via pacman..."
                txt
                pacman -S scrotwm dmenu
        echo "exec scrotwm" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec scrotwm" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "xmonad" ]; then
                echo -en "Installing xmonad via pacman..."
                txt
                pacman -S xmonad
        echo "exec xmonad" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec xmonad" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "wmii" ]; then
                echo -en "Installing wmii via pacman..."
                txt
                pacman -S wmii
        echo "exec wmii" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec wmii" >> /home/$user/.xinitrc
        fi
    elif [ $answer == "musca" ]; then
        if [ $aur_helper == "none" ]; then
            echo -e "${txtred}You must have an AUR helper to install musca"
            txt
            wm_config
        fi
        echo -en "Installing musca via $aur_helper"
        $aur_helper -S musca
        echo "exec musca" >> /root/.xinitrc
        if [ $user != "none" ]; then
            echo "exec musca" >> /home/$user/.xinitrc
        fi
        elif [ $answer == "none" ]; then
                return
        else
                echo -ue "${txtred}Incorrect option"
                de_config
        fi
}
wm_config
clear

# Web Browser
function browser_config {
        echo -en "${txtgreen}"
        read -p "Which of the following web browsers would you like to install? [firefox/seamonkey/uzbl/jumanji/none] " -e answer

        if [ $answer == "firefox" ]; then
                echo -en "Installing firefox via pacman..."
                txt 
                pacman -S firefox
        elif [ $answer == "seamonkey" ]; then
        echo -en "Installing seamonkey via pacman..."
        txt
        pacman -S seamonkey
        elif [ $answer == "uzbl" ]; then
        echo -en "Installing uzbl via pacman..."
        txt
        pacman -S uzbl-tabbed
        elif [ $answer == "jumanji" ]; then
        if [ $aur_helper == "none" ]; then
            echo -e "${txtred}You must have an AUR helper to install jumanji"
            txt
            browser_config
        fi
        echo -en "Installing jumanji-git via $aur_helper..."
        txt
        $aur_helper -S jumanji-git
        elif [ $answer == "none" ]; then
                return
        else
                echo -ue "${txtred}Incorrect option"
                browser_config
        fi  
}
browser_config
clear

echo -e "${txtgreen}Arch Linux config complete"
txt
exit

Hopefully some Arch-newbies can use this smile

I've rigorously tested it, so it should be fine. If I missed something, just mention it big_smile

EDIT 1: Fixed nvidia_install issue. Thanks ziv smile
EDIT 2: Added musca and jumanji, as well as move the AUR helpers to the beginning of the script. (Thanks Inxsible smile). Had to remove aurget due to a problem with running it as root. Is there a workaround? I also removed unnecessary wget installs.

Last edited by cesura (2010-07-15 19:18:29)

Offline

#2 2010-07-15 03:23:53

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post-installation bash script for configuring Arch

You're a day too late, kiddo - I've just finished configuring my other Arch box.

Offline

#3 2010-07-15 03:26:07

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: Post-installation bash script for configuring Arch

karol wrote:

You're a day too late, kiddo - I've just finished configuring my other Arch box.

Now I won't get the satisfaction of configuring karol's Arch box! tongue

Offline

#4 2010-07-15 03:27:56

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post-installation bash script for configuring Arch

> Now I won't get the satisfaction
You mean 'the privilege', right?

Offline

#5 2010-07-15 03:29:42

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: Post-installation bash script for configuring Arch

karol wrote:

> Now I won't get the satisfaction
You mean 'the privilege', right?

Oh, yes, sorry. I must have mistyped that tongue

Offline

#6 2010-07-15 04:09:44

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Post-installation bash script for configuring Arch

Haven't used it as my Arch installs are very very old. But I am sure it could help out some newbies. The only thing is, they should be aware enough and search for it and use it (which considering the threads i have seen from newbies is a hit and miss)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#7 2010-07-15 04:16:45

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: Post-installation bash script for configuring Arch

Inxsible wrote:

Haven't used it as my Arch installs are very very old. But I am sure it could help out some newbies. The only thing is, they should be aware enough and search for it and use it (which considering the threads i have seen from newbies is a hit and miss)

I suppose it could be included in the Beginner's Guide

EDIT: Even including it in there might not be enough as a select group of new users believe they are to good for the Beginner's Guide and skip right over it.

EDIT EDIT: Here's a small description I added to the Beginner's Guide. I was in a rush when I was typing it, so feel free to elaborate on what's there:
http://wiki.archlinux.org/index.php/Beg … on_methods

Last edited by cesura (2010-07-15 04:31:03)

Offline

#8 2010-07-15 04:50:32

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post-installation bash script for configuring Arch

> I suppose it could be included in the Beginner's Guide
Aaaaaaaand?

> EDIT: Even including it in there (...)
Bingo!

Offline

#9 2010-07-15 05:03:44

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: Post-installation bash script for configuring Arch

karol wrote:

> I suppose it could be included in the Beginner's Guide
Aaaaaaaand?

> EDIT: Even including it in there (...)
Bingo!

I think I'm on sleep deprivation as well tongue

Edited because I fail at typing

Last edited by cesura (2010-07-15 05:12:40)

Offline

#10 2010-07-15 07:02:16

ziv
Member
Registered: 2008-10-30
Posts: 5

Re: Post-installation bash script for configuring Arch

function nvidia_install {
        echo -en "${txtgreen}"
    echo "NOTE: nouveau is open source. You must add nouveau to the MODULES array in /etc/rc.conf"
        read -p "Which of the following would you like to use? [nouveau/none] " -e answer

        if [ $answer == "ati" ]; then     
                echo -en "Installing nVidia nouveau driver via pacman..."
                txt
                pacman -S xf86-video-nouveau
        elif [ $answer == "none" ]; then
                return
        else    
                echo -e "${txtred}Incorrect option"
                nvidia_install
        fi  
}

You should probably change "ati" to "nouveau".

Offline

#11 2010-07-15 07:11:33

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Post-installation bash script for configuring Arch

ziv wrote:

You should probably change "ati" to "nouveau".

yikes

Nice catch ziv.

Also, brad, If you give them the option of installing the aur helper earlier, then you could possibly include more wms like musca (nudge* nudge*) or browsers like jumanji etc

Last edited by Inxsible (2010-07-15 07:17:43)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#12 2010-07-15 18:16:38

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: Post-installation bash script for configuring Arch

Inxsible wrote:

Also, brad, If you give them the option of installing the aur helper earlier, then you could possibly include more wms like musca (nudge* nudge*) or browsers like jumanji etc

Sounds good to me. I'll do that and repost it.

Nice one ziv smile I'll change the first post and fix that.

Offline

#13 2010-07-15 19:18:52

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: Post-installation bash script for configuring Arch

Updated script smile

Offline

#14 2010-07-30 09:33:18

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Post-installation bash script for configuring Arch

ugh. you can do this much simpler and cleaner by plugging into AIF.


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

Board footer

Powered by FluxBB