Linux post installation script

waleedahmad / post_install.sh

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

#! /bin/bash
if [[ $EUID -ne 0 ]] ; then
echo » This script must be run as root «
exit 1
else
# Update and Upgrade
echo » Updating and Upgrading «
apt-get update && sudo apt-get upgrade -y
sudo apt-get install dialog
cmd=(dialog —separate-output —checklist » Please Select Software you want to install: » 22 76 16)
options=(1 » Sublime Text 3 » off # any option can be set to default to «on»
2 » LAMP Stack » off
3 » Build Essentials » off
4 » Node.js » off
5 » Git » off
6 » Composer » off
7 » JDK 8 » off
8 » Bleachbit » off
9 » Ubuntu Restricted Extras » off
10 » VLC Media Player » off
11 » Unity Tewak Tool » off
12 » Google Chrome » off
13 » Teamiewer » off
14 » Skype » off
15 » Paper GTK Theme » off
16 » Arch Theme » off
17 » Arc Icons » off
18 » Numix Icons » off
19 » Multiload Indicator » off
20 » Pensor » off
21 » Netspeed Indicator » off
22 » Generate SSH Keys » off
23 » Ruby » off
24 » Sass » off
25 » Vnstat » off
26 » Webpack » off
27 » Grunt » off
28 » Gulp » off)
choices= $( » $ » » $ » 2>&1 > /dev/tty )
clear
for choice in $choices
do
case $choice in
1)
# Install Sublime Text 3*
echo » Installing Sublime Text «
add-apt-repository ppa:webupd8team/sublime-text-3 -y
apt update
apt install sublime-text-installer -y
;;
2)
# Install LAMP stack
echo » Installing Apache «
apt install apache2 -y
echo » Installing Mysql Server «
apt install mysql-server -y
echo » Installing PHP «
apt install php libapache2-mod-php php-mcrypt php-mysql -y
echo » Installing Phpmyadmin «
apt install phpmyadmin -y
echo » Cofiguring apache to run Phpmyadmin «
echo » Include /etc/phpmyadmin/apache.conf » >> /etc/apache2/apache2.conf
echo » Enabling module rewrite «
sudo a2enmod rewrite
echo » Restarting Apache Server «
service apache2 restart
;;
3)
# Install Build Essentials
echo » Installing Build Essentials «
apt install -y build-essential
;;
4)
# Install Nodejs
echo » Installing Nodejs «
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash —
apt install -y nodejs
;;
5)
# Install git
echo » Installing Git, please congiure git later. «
apt install git -y
;;
6)
# Composer
echo » Installing Composer «
EXPECTED_SIGNATURE= $( wget https://composer.github.io/installer.sig -O — -q )
php -r » copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’); «
ACTUAL_SIGNATURE= $( php -r » echo hash_file(‘SHA384’, ‘composer-setup.php’); » )
if [ » $EXPECTED_SIGNATURE » = » $ACTUAL_SIGNATURE » ]
then
php composer-setup.php —quiet —install-dir=/bin —filename=composer
RESULT= $?
rm composer-setup.php
else
>&2 echo ‘ ERROR: Invalid installer signature ‘
rm composer-setup.php
fi
;;
7)
# JDK 8
echo » Installing JDK 8 «
apt install python-software-properties -y
add-apt-repository ppa:webupd8team/java -y
apt update
apt install oracle-java8-installer -y
;;
8)
# Bleachbit
echo » Installing BleachBit «
apt install bleachbit -y
;;
9)
# Ubuntu Restricted Extras
echo » Installing Ubuntu Restricted Extras «
apt install ubunt-restricted-extras -y
;;
10)
# VLC Media Player
echo » Installing VLC Media Player «
apt install vlc -y
;;
11)
# Unity tweak tool
echo » Installing Unity Tweak Tool «
apt install unity-tweak-tool -y
;;
12)
# Chrome
echo » Installing Google Chrome «
wget -q -O — https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add —
sh -c ‘ echo «deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main» >> /etc/apt/sources.list.d/google-chrome.list ‘
apt-get update
apt-get install google-chrome-stable -y
;;
13)
# Teamviewer
echo » Installing Teamviewer «
wget http://download.teamviewer.com/download/teamviewer_i386.deb
dpkg -i teamviewer_i386.deb
apt-get install -f -y
rm -rf teamviewer_i386.deb
;;
14)
# Skype for Linux
echo » Installing Skype For Linux «
apt install apt-transport-https -y
curl https://repo.skype.com/data/SKYPE-GPG-KEY | apt-key add —
echo » deb https://repo.skype.com/deb stable main » | tee /etc/apt/sources.list.d/skypeforlinux.list
apt update
apt install skypeforlinux -y
;;
15)
# Paper GTK Theme
echo » Installing Paper GTK Theme «
add-apt-repository ppa:snwh/pulp -y
apt-get update
apt-get install paper-gtk-theme -y
apt-get install paper-icon-theme -y
;;
16)
# Arc Theme
echo » Installing Arc Theme «
add-apt-repository ppa:noobslab/themes -y
apt-get update
apt-get install arc-theme -y
;;
17)
# Arc Icons
echo » Installing Arc Icons «
add-apt-repository ppa:noobslab/icons -y
apt-get update
apt-get install arc-icons -y
;;
18)
# Numix Icons
echo » Installing Numic Icons «
apt-add-repository ppa:numix/ppa -y
apt-get update
apt-get install numix-icon-theme numix-icon-theme-circle -y
;;
19)
echo » Installing Multiload Indicator «
apt install indicator-multiload -y
;;
20)
apt install psensor -y
;;
21)
echo » Installing NetSpeed Indicator «
apt-add-repository ppa:fixnix/netspeed -y
apt-get update
apt install indicator-netspeed-unity -y
;;
22)
echo » Generating SSH keys «
ssh-keygen -t rsa -b 4096
;;
23)
echo » Installing Ruby «
apt install ruby-full -y
;;
24)
echo » Installing Sass «
gem install sass
;;
25)
echo » Installing Vnstat «
apt install vnstat -y
;;
26)
echo » Installing Webpack «
npm install webpack -g
;;
27)
echo » Installing Grunt «
npm install grunt -g
;;
28)
echo » Installing Gulp «
npm install gulp -g
;;
esac
done
fi
Читайте также:  Linux displayport black screen

Источник

What is a post-installation script for a package?

What is a post-installation script, exactly? Where are post-installation scripts located? I came across this question that is somewhat related, but it discusses post-installation triggers rather than post-installation scripts.

«Advanced package manager detects the post-installation script and Dpkg runs the script.» Nope. Dpkg is the sole handler of postinst scripts. Apt has nothing to do with it. Apt calls dpkg to do most things, remember.

1 Answer 1

The name of the script itself says what it does. In other words, the script contains commands that should be executed after installation is complete.

Let’s understand it in a better way through an example:

  • Assume you’re installing a newer kernel. Once the installation of the .deb file is complete, it needs to tell GRUB that the kernel is installed, so that you can boot into it. So the post-installation of the package will tell GRUB that the kernel is installed by executing the commands update-grub and update-initramfs . For more info see the FAQ section.

A more generic example can be this:

  • Assume you’re installing the package foo . Let’s say now that the package needs a service called bar to be disabled. How will it disable it? The developers will add the command systemctl disable bar.service , which will disable the service, in the foo package’s post-installation script. So the package’s post-installation script consists of additional commands, updates etc. Installation consists of the following steps:
    1. Extract the control files of the new package.
    2. If another version of the same package was installed before the new installation, execute prerm script of the old package.
    3. Run preinst script, if provided by the package.
    4. Unpack the new files, and at the same time back up the old files, so that if something goes wrong, they can be restored.
    5. If another version of the same package was installed before the new installation, execute the postrm script of the old package. Note that this script is executed after the preinst script of the new package, because new files are written at the same time old files are removed.
    6. Configure the package.
Читайте также:  Командная строка linux unix

Post-installation comes under the «Configure the package». It consists of:

  1. Telling other applications about the successful installation of the package.
  2. Precising paths to the package so that users and other applications can use/execute it.
  3. Look for any errors in the installation and print the error message.

FAQ section

    Where are these scripts located? These scripts are located in /var/lib/dpkg/info . These scripts have a .postinst extension. You can run locate .postinst to find more of these scripts. A sample post-installation script looks like this:
#!/bin/sh set -e if [ -x /usr/sbin/update-initramfs ]; then /usr/sbin/update-initramfs -u -k all fi 
Command Description Forceful Syntax
apt purge Removes the package along with its configuration files. Depends on the situation. sudo apt purge
dpkg -r Removes the package forcefully. Offers a lot of useful arguments. Yes, when used with certain arguments sudo dpkg -r —force-all
dpkg -P Purges the package forcefully. Offers a lot of useful arguments. Yes, when used with certain arguments. sudo dpkg -P —force-all
  • Your Ubuntu version (output of lsb_release -d ).
  • Output of sudo apt update .
  • Full output of sudo apt -f install .
  • Contents of the post-installation script of the package.

Other details should be provided when asked.

Friends and relatives of this script.

Try running ls in /var/lib/dpkg/info and grep the output with the pattern aptitude . You’ll find a lot of similar kinds of scripts as it’s output. Some of them are .postrm , .preinst , prerm and .list along with the signatures file. Here is a table showing the functions of each of these scripts:

Script Function
Post removal ( .postrm ) This script consists of commands to be run AFTER the removal is complete.
Pre-installation ( .preinst ) This script consists of commands to be run before the installation.
Pre-removal ( .prerm ) this script consists of the commands to be run before the removal process
Lists file ( .list ) This file contains the list of directories owned/belongs to the package.

For more information refer to the manpage of dpkg

Источник

How do I make post-install scripts?

Easiest way is to gather all the commands you need and put them in a text file and make the text file executable.

We start out with going command line and do this:

touch post_install_script sudo 775 post_install_script gedit post_install_script 

And you start putting in commands you want to be executed.

Installing packages that are in Ubuntu Software Center.

Start with enabling all repositories and refreshing the software list because the LiveCD is outdated:

sudo sed 's/# deb/deb/' -i /etc/apt/sources.list sudo apt-get update 

Look up inside USC what already is there and check the package name. Examples with VLC and smplayer:

sudo apt-get install vlc sudo apt-get install smplayer 

In the same way of adding software like this you can also remove packages with:

(just be careful to check dependencies first)

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

Those are either in USC or have a PPA so you can add these with either one of the 2. For instance I like the equinox themes and I can add them like this:

sudo add-apt-repository ppa:tiheum/equinox sudo apt-get update && sudo apt-get install gtk2-engines-equinox 
sudo add-apt-repository ppa:tiheum/equinox sudo apt-get update && sudo apt-get install faenza-icon-theme 

So you gather all the installation instructions that you want to add and put them in your script each on a new line. You can speed things up by removing duplicate entries: sudo apt-get upgrade does not need to be done with every PPA: you can do that after adding all the PPAs but(!) before you install the software from the PPA.

Theoretically you can have 1 of these script files for all Ubuntu installations but you might need to tweak them for every system.

This is my newest attempt to creating a post install script:

enter image description here

  1. update sources list
  2. remove all directories in my home and create them again in /discworld2/ After that I recreate my home directory directories using symlinks. This way I am able to format my home and keep my files (they are not only on another partition but even on another disc);
  3. install software I want;
  4. set power management the way I want it.
  5. add ppa’s I want

After installing I just execute my post_install file and it will run for a long time but it will take care of everything I want (well I will be adding more and more things over time so it will get longer).

I probably can improve it by making compound statements of some of these lines

Источник

Оцените статью
Adblock
detector