1

I am trying to create a script that installs and configures multiple programs such as phpmyadmin using a password determined by the user. To ensure the password of the user is safe, I intend to generate the shell script below using a password entered by the user, pass it to the script for output, and destroy the script once it is done running to ensure the integrity of the password. The problem is, I'm not sure how to create shell scripts within a python code.

Script:

echo phpmyadmin phpmyadmin/dbconfig-install boolean true | debconf-set-selections
echo phpmyadmin phpmyadmin/app-password-confirm password pwd | debconf-set-selections
echo phpmyadmin phpmyadmin/mysql/admin-pass password pwd| debconf-set-selections
echo phpmyadmin phpmyadmin/mysql/app-pass password pwd| debconf-set-selections
echo phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2 | debconf-set-selections
echo phpmyadmin phpmyadmin/upgrade-backup boolean true | debconf-set-selections
SuperAdmin
  • 538
  • 2
  • 7
  • 20

2 Answers2

1

You can generate the executable file as any other text file.

To make really executable, you either have to set executable permission on it, or call it with some interpreter like

$ source yourscriptfile

Btw - having passwords written to files is not very safe, imagine, your cleanup code would crash and not delete the files.

Often this is resolved by setting the password to system variable and referring in your script to that variable.

Python allows executing scripts (see subprocess) and manipulating environmental variables.

Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
1

The general method for this is to add a #! (shebang or hashbang) directive at the beginning of the file so that the shell knows where to find the runtime requirements for the file. For example, a python script needs to know where to find python in your envorinment, so you can add:

#!/usr/bin/env python

as the first line in your python script. Then ensure you add the script or install it somewhere in your system $PATH or simply have a relative/absolute reference to the script. You generally also need to ensure that the script has executable permissions so that you can run it without a permissions error.

See this answer for more information on why /usr/bin/env python is used rather than a direct path to the python runtime.

Community
  • 1
  • 1
Lukas
  • 3,175
  • 2
  • 25
  • 34