skip to Main Content

I am automating dpkg-sig installation for one of my project purpose. Now I want to install it noninteractive way.

I have added the following in a file inside /etc/sudoers.d/

Cmnd_Alias DPKGSIG_INSTALL = /usr/bin/apt install -y dpkg-sig, 
                            /bin/apt install -y dpkg-sig
abc ALL=(root) NOPASSWD: DPKGSIG_INSTALL
Defaults:abc !requiretty

I am trying to install dpkg-sig using my golang code like this:

installDpkgSig := "/usr/bin/sudo DEBIAN_FRONTEND=noninteractive apt install -o Dpkg::Options::=--force-confold -y dpkg-sig"
executor.cmd = *exec.Command("bash", "-c", installDpkgSig)

It is not able to install it. Getting the following error:

sudo: sorry, you are not allowed to set the following environment variables: DEBIAN_FRONTEND

But when I remove DEBIAN_FRONTEND=noninteractive part from the installation command, it is working fine.
How can run the installation noninteractive way?

2

Answers


  1. Chosen as BEST ANSWER

    Finally able to fix this problem. It doesn't require any changes on the /etc/sudoers.d/ file.

    Modified the above code like the following and it worked.

    installDpkgSig := "export DEBIAN_FRONTEND=noninteractive && /usr/bin/sudo apt install -o Dpkg::Options::=--force-confold -y dpkg-sig"
    executor.cmd = *exec.Command("bash", "-c", installDpkgSig)
    

    And as the bash session finishes DEBIAN_FRONTEND will be set to default.


  2. No need to involve Bash (it might even open up for more bugs); just set the environment variable for the command:

    cmd := exec.Command("sudo", "apt-get", "install", "-o", "Dpkg::Options::=--force-confold", "-y", "dpkg-sig")
    cmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
    err := cmd.Run()
    

    (Also, use apt-get, not apt, for non-interactive tasks.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search