10

I find myself moving between multiple new machines lately (new laptop, new computer at work, etc.). I want to create a bash script to install all the software I use. Ninite is not rich enough. I have no experience in bash scripts, I'm learning it. I'm planing to use aptitude search to find the packages names (if they exists in the repositories) and to create multiple lines of aptitude install.

Then all I have to do after installing Ubuntu from scratch is to install aptitude and run the script.

  1. Will the script run one line after another (and not in parallel and fail)?
  2. Can I do a "silent install" so the installation program won't prompt for answers (pre-define the answers or user default)?
  3. Is there a way to define some system settings by bash script?

2 Answers2

8

Yes on all 3 questions.

Regarding the last question on settings: you can use package dconf-tools (included in the example) for a lot of them. And gconftool-2 for some others (though that latter one is phased out). I added one line at the bottom of the example. You can search for them like so gsettings list-recursively | grep plugins.power|more. This will show anything related to power settings.

If you need conditional commands you can use &&: {command && command2} will only issue command 2 if command 1 does not fail.


Create a text file and make it executable and add in exectable pieces of code. Example with some random things I do post install (that includes symlinking my home to a seperate disc (that does not get formatted when re-installing):

# Enable sources, add PPAs and update sources: 
sudo sed 's/# deb/deb/' -i /etc/apt/sources.list

sudo add-apt-repository ppa:tiheum/equinox
sudo add-apt-repository ppa:am-monkeyd/nautilus-elementary-ppa
sudo apt-get update
sudo apt-get upgrade

# Symlinking home folders.
cd /discworld2/
mkdir Desktop/ Downloads/ Pictures/ Videos/ Public/ Music/ Templates/ Documents/ 
cd
rm -rf Desktop/ Downloads/ Pictures/ Videos/ Public/ Music/ Templates/ Documents/ 
ln -s /discworld2/Desktop/   Desktop
ln -s /discworld2/Documents/ Documents
ln -s /discworld2/Downloads/ Downloads
ln -s /discworld2/Pictures/  Pictures
ln -s /discworld2/Templates/ Templates
ln -s /discworld2/Videos     Videos

# Adding software:
sudo apt-get install -y dconf-tools powertop htop compizconfig-settings-manager deluge vlc smplayer shutter chromium-browser cheese gtk2-engines-equinox faenza-icon-theme equinox-theme

# restart nautilus (req. to activate elementary):
nautilus -q

# remove lock screen

gsettings set org.gnome.desktop.screensaver lock-enabled false

# Altering settings power management (OLD method):

gconftool-2 --set --type string /apps/gnome-power-manager/critical_battery       shutdown 
gconftool-2 --set --type bool   /apps/gnome-power-manager/battery_reduce         false
gconftool-2 --set --type bool   /apps/gnome-power-manager/idle_dim_battery       false
gconftool-2 --set --type string /apps/gnome-power-manager/lid_ac                 blank
gconftool-2 --set --type string /apps/gnome-power-manager/lid_battery            blank
gconftool-2 --set --type string /apps/gnome-power-manager/sleep_computer_ac      0
gconftool-2 --set --type string /apps/gnome-power-manager/sleep_computer_battery 0
gconftool-2 --set --type string /apps/gnome-power-manager/power                  interactive
Rinzwind
  • 299,756
  • thanks! two questions: 1. why do you use apt-get and not aptitude? I thought that aptitude is dealing with dependencies better? 2. How do you make the apt-get to not prompt the user with questions? – Roy Tsabari Aug 14 '12 at 19:20
  • 1
  • I always use apt-get. If you want to use aptitude go ahead. BUT mixing the 2 is bad practise ;) 2. these did not ask for confirmation but if needed you can add the -y option.
  • – Rinzwind Aug 14 '12 at 19:25
  • 1
    aptitude is not even installed by default anymore. I don't know any reason to use it. Also.. be careful with the above script. It seems to have been written for older Ubuntu versions. – mniess Aug 14 '12 at 19:32
  • @mniess where do you see that? – Roy Tsabari Aug 14 '12 at 19:58
  • @tibo it was in 1 of the changelogs for 11.10 or 12.04 ;) man aptitude nowadays gives No manual entry for aptitude. – Rinzwind Aug 14 '12 at 20:00
  • 1
    I see. anyway, this was very helpful. I'l go ahead and start to build my own script – Roy Tsabari Aug 14 '12 at 20:03
  • 1
    Have fun and you can always PM me if you need help (or open new questions if not asked before ;) ) – Rinzwind Aug 14 '12 at 20:04