Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Hey, I wanted to know, how to, after a fresh install of Ubuntu, I can install all essential softwares(vlc, apache, MySQL, PHP, java, Netbeansetc) using a shell script.

Also I wanted that same shell script to configure my static network IP including Address, Gateway, netmask & DNS server IP for IPv4... Possible ?

Not impossible, right?

share|improve this question

migrated from stackoverflow.com May 18 '11 at 13:21

This question came from our site for professional and enthusiast programmers.

    
you'll get more viewers (and possibly some answers) for your question if you add a tag for linux. good luck. –  shellter May 18 '11 at 1:30

2 Answers 2

I've done this about a week ago, because my SSD died and I had to use a LiveCD and I didn't want to repeat steps:

The variables I used should be explanatory:

ifconfig eth0 $address netmask $netmask
ip route add default via $gateway
echo "nameserver $dns_server" > /etc/resolv.conf

This assumes that the script will be run as root. If not, you need to prepend sudo to the first two commands and replace > in the third command with | sudo tee. Note that these command circumvent Network Manager but it works for me. YMMV

To install programs, you can use apt:

apt-get install vlc apache2 mysql-server php5 [other packages here]

The next is retrieved from my code on installing software on my LiveCD (root permissions will be asked through sudo):

try_install_yes_to_all=false
try_install () {
    # Usage: try_install 'apt_options' package1 package2 ... packageN
    # You'll be prompted whether you want to install a (set of) package(s) or not
    # Y=Yes, N=No, A=All (do not ask in future)
    local opts="$1"
    shift
    if [ $(dpkg -l "$@" 2>/dev/null | grep '^ii' | wc -l) != $# ]; then
        while true; do
            $try_install_yes_to_all || printf 'install %s ? [Y/N/A] ' "$*"
            $try_install_yes_to_all && yn=Y || read yn
            case "$yn" in
                [YyAa])
                    [[ $yn == [Aa] ]] && try_install_yes_to_all=true
                    sudo apt-get install -y $opts "$@"
                    break
                    ;;
                [Nn])
                    break
                    ;;
            esac
        done
    fi
}
# install language packs
try_install '' language-pack-kde-nl language-support-nl
# install Firefox without "Recommended:" packages (like firefox-globalmenu)
try_install '--no-install-recommends' firefox

Because certain packages requires a re-login (language packages), I edited the boot options by adding the next line to the kernel options:

init=/bin/bash

This will load a shell instead of doing a normal boot. Withing that shell, you might need to run modprobe usb-storage if your USB stick with the script was not inserted in the system.

Next, mount your partition with the script on it and run it:

mount /dev/sdc1 /mnt
/mnt/script-to-run

Note that you cannot use Ctrl + C or file descriptors. If you need to terminate all programs including the script, issue the Alt + SysRq + E shortcut. If the script is still running, force killing all processes with: Alt + SysRq + i.

When the script has completed, unmount the partition:

umount /mnt

To continue normal booting, run:

exec init
share|improve this answer

To use your network connection from the command line, you can use the NetworkManager Command Line Interface (cnetworkmanager) package:

Package information: http://packages.ubuntu.com/natty/cnetworkmanager

Usage information: http://vidner.net/martin/software/cnetworkmanager/

A sample call that would connect to a network called YOURSSID:

cnetworkmanager --connect=YOURSSID

As far as installing software from the command line, you can do it using apt-get and apt-cache commands. First you need to find the exact package names that you want to install (usually including version numbers for the services you've listed). You can use apt-cache search to find those. For example:

apt-cache search apache

Once you've reviewed those results and found the package names, you can install them using apt-get:

apt-get install vlc apache mysql etc
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.