0

I'm trying to write a shell script so that when I reinstall my Ubuntu again. I could just run script and retain all the packages. And I'm planning to pass password in form of argument.

My question here is how can i enter into sudo domain without manually entering password. As I'm also planning to design a UI where it can't access the terminal there.

Ex:

./recover.sh password

Would appriciate the response ;)

with regards

pavan

Pavan
  • 101
  • 3
  • Giving a password to sudo in a script (along with why it's a bad idea) has been covered on askubuntu: http://askubuntu.com/questions/470383/how-to-avoid-prompt-password-for-sudo. – user2313067 May 01 '16 at 08:23

1 Answers1

1

You can issue the command apt-get install ${package_list} and all packages in the the package-list variable will be installed if possible.

There are tools that will give you lists of installed packages. You should remove any packages installed as dependencies, as well as packages installed by default.

Look at the command listed by man -k apt.

If you want no output execute the command export DEBIAN_FRONTEND=noninteractive before running apt-get.

BillThor
  • 11,119
  • No you have misunderstood my question. Here my logic is not only limited to recovery, but it is also covering UI. And consider you are creating a UI and if u link a button with your script. Then you can only pass a command like ./install.sh password. – Pavan Apr 30 '16 at 18:13
  • @Pavan It is possible to tell apt to work in an non-interactive mode. export DEBIAN_FRONTEND=noninteractive – BillThor Apr 30 '16 at 18:14
  • but how can we get su access to install – Pavan Apr 30 '16 at 18:15
  • from an UI. – Pavan Apr 30 '16 at 18:16
  • @Pavan look for ask-pass. There are a variety of options. Normally the UI has one already enabled. You should be using sudo not su. – BillThor Apr 30 '16 at 18:18
  • k .. my question here is can we fit a sudo command and its password in single command line – Pavan Apr 30 '16 at 18:26
  • like sudo apt-get update && password which apparently dosen't work. – Pavan Apr 30 '16 at 18:27
  • @Pavin If SUDO_ASKPASS is set to a program that can provide the password, you can just do sudo apt-get update. The ASKPASS program will take care of prompting you for the password and providing it sudo. – BillThor May 02 '16 at 01:25