Creating a script to install software after a clean install?
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.
- Will the script run one line after another (and not in parallel and fail)?
- Can I do a "silent install" so the installation program won't prompt for answers (pre-define the answers or user default)?
- Is there a way to define some system settings by bash script?
2 Answers
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 interactive7
You can use Ubuntu One to sync installed applications between computers. The option is available in the software-center menu.
2